Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

l1394_nodefactory.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           l1394_nodefactory.cpp  -  description
00003                              -------------------
00004     begin                : Wed Jan 31 2001
00005     copyright            : (C) 2001-2004 by Michael Repplinger
00006     email                : repplix@studcs.uni-sb.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "l1394_nodefactory.h"
00019 #include "l1394_card.h"
00020 #include "l1394_dcccamera.h"
00021 #include "l1394_fcpnode.h"
00022 #include "l1394_phynode.h"
00023 #include "l1394_avccamera.h"
00024 #include "l1394_avcvcr.h"
00025 
00026 #include <iostream>
00027 
00028 
00029 using std::hex;
00030 using std::dec;
00031 
00032 namespace L1394 {
00033 namespace internal {
00034 
00035 NodeFactory* NodeFactory::getNodeFactory()
00036 {
00037   mutex.lock();
00038   if (factory == NULL)
00039     factory = new NodeFactory();
00040   mutex.unlock();
00041   return factory;
00042 }
00043 
00044 NodeFactory::NodeFactory()
00045 {
00046   if (factory != NULL)
00047   {
00048     message->errorStream() << "L1394_NodeFactory > NodeFactory already exist" << endl;
00049     delete factory;
00050   }
00051   factory = this;
00052 }
00053 
00054 NodeFactory::~NodeFactory()
00055 {
00056   mutex.lock();
00057   factory = 0;
00058   mutex.unlock();
00059 }
00060 
00061 Card* NodeFactory::createCard(const u_int32_t card_id, const u_int32_t node_id, raw1394handle_t default_handle)
00062 {
00063   message->debugStream() << "L1394_NodeFactory > create Card "<< endl;
00064   return (new Card(card_id, node_id, default_handle));
00065 }
00066 
00067 
00068 Node* NodeFactory::createNode(Card* card, const u_int32_t node_id)
00069 {
00070 //  message->debugStream() << "create Node "<< endl;
00071   switch(scanNode(card, node_id))
00072   {
00073     case _DccNode :
00074       return ( new DccCamera( node_id, card ) );
00075     case _FcpNode :
00076       return ( new FcpNode  ( node_id, card ) );
00077     case _SBP2Node:
00078       return ( new Node     ( node_id, card ) );
00079     case _UnknownNode:
00080       return ( new Node     ( node_id, card ) );
00081     case _PhyNode:
00082       return ( new PhyNode  ( node_id, card ) );
00083     case _Card :
00084       return card;
00085     break;
00086   }
00087   return 0;
00088 }
00089 
00090 NodeType NodeFactory::scanNode(Card* card, const u_int32_t new_node_number)
00091 {
00092   if (card == NULL) {
00093     message->errorStream() << "NodeFactory > Card is NULL in scanNode" << endl;
00094     return _UnknownNode;
00095   }
00096   // is it this card object
00097   if (card->getNodeID() == new_node_number)
00098     return _Card;
00099 
00100   int i = 0;
00101   while (card->getTopoMap()->getQuadlet(i).getBitRange(24,29) != new_node_number && i < card->getTopoMap()->getSize())
00102     i++;
00103 
00104   if (card->getTopoMap()->getQuadlet(i).getBit(22) == 0)
00105       return _PhyNode;
00106 
00107   Quadlet tmp_quadlet;
00108 
00109   int counter = 0x0c;
00110 
00111 
00112   while (tmp_quadlet.getByte(0) != 0x13 && counter < 0x80)
00113   {
00114     card->requestTransaction()->read(CSR_REGISTER_BASE+CSR_CONFIG_ROM+counter, &tmp_quadlet, new_node_number);
00115      counter     = counter+4;
00116      card->releaseTransaction();
00117   }
00118 
00119   int version = 0;
00120 
00121   if (tmp_quadlet.getByte(0) == 0x13)
00122   {
00123     tmp_quadlet.setByte(0,0x00);
00124     version = tmp_quadlet.toInt();
00125   }
00126   else
00127     return _UnknownNode;
00128 
00129   switch(version)
00130   {
00131     // is it a DCC Camera ?
00132     case 0x100  : return _DccNode;  break;
00133     case 0x101  : return _DccNode;  break;
00134 
00135     // is it a FCP node ??
00136     case 0x10000: return _FcpNode;  break;
00137     case 0x10001: return _FcpNode;  break;
00138 
00139     // is it a SBP2 node ??
00140     case 0x10483: return _SBP2Node; break;
00141 
00142     // else return node not defiened
00143     default :  return _UnknownNode;  break;
00144   }
00145 
00146 }
00147 
00148 Device* NodeFactory::createDevice(FcpNode* node, int subunit_value)
00149 {
00150   switch(subunit_value >> 3)
00151   {
00152     case SUBUNIT_TAPE :
00153       message->debugStream()<< "L1394_NodeFactory > It's a tape recorder/player subunitnr "  << endl;
00154       return new AvcVcr(node, subunit_value); //implement subunit_tape
00155       break;
00156 
00157     case SUBUNIT_VIDEO_MONITOR :
00158       message->debugStream() << "L1394_NodeFactory > It's a video monitor" << endl;
00159       message->warningStream() << "L1394_NodeFactory > VIDEO MONITOR Not Implemented !!" << endl;
00160       return NULL;
00161       break;
00162 
00163     case SUBUNIT_DISC :
00164       message->debugStream() << "L1394_NodeFactory > It's a disc player" << endl;
00165       message->warningStream() << "L1394_NodeFactory > DISC Not Implemented !!" << endl;
00166       return NULL;
00167       break;
00168 
00169     case SUBUNIT_TUNER :
00170       message->debugStream() << "L1394_NodeFactory > It's a tuner" << endl;
00171       message->warningStream() << "L1394_NodeFactory > TUNER Not Implemented !!" << endl;
00172       return NULL;
00173       break;
00174 
00175     case SUBUNIT_VIDEO_CAMERA :
00176       message->debugStream() << "L1394_NodeFactory > It's a video camera subunitnr "<< endl;
00177       return new AvcCamera(node, subunit_value);
00178       break;
00179 
00180     default :
00181       message->debugStream() << "L1394_NodeFactory > Unkown subunit type 0x"<< hex << subunit_value << dec << endl;
00182       return NULL;
00183       break;
00184     }
00185 }
00186 
00187 
00188 NodeFactory* NodeFactory::factory = NULL;
00189 Message*     NodeFactory::message = SMessage::getInstance();
00190 ThreadMutex  NodeFactory::mutex;
00191 } //end namespcace internal
00192 } //end namespcace L1394

Generated on Wed Aug 24 00:36:40 2005 for L1394 by doxygen 1.4.2
L1394 library (NMM) grahics.cs.uni-sb.de/~repplix/l1394_home/