00001 /*************************************************************************** 00002 l1394_node.h - description 00003 ------------------- 00004 begin : Wed Jul 5 2000 00005 copyright : (C) 2000-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 #ifndef L1394NODE_H 00018 #define L1394NODE_H 00019 00020 00021 #include <netinet/in.h> 00022 #include <sys/poll.h> 00023 #include <sys/types.h> 00024 #include <sys/time.h> 00025 #include <unistd.h> 00026 #include <string> 00027 #include "libraw1394/raw1394.h" 00028 #include "libraw1394/csr.h" 00029 // new lib L1394 00030 00031 #include "l1394_resource.h" 00032 #include "l1394_qarray.h" 00033 #include "l1394_event.h" 00034 #include "l1394_csrrom.h" 00035 #include "l1394_nodefactory.h" 00036 #include "l1394_nodecontainer.h" 00037 #include "l1394_message.h" 00038 #include "l1394_iso.h" 00039 00040 namespace L1394 00041 { 00042 00043 class Device; 00044 class Card; 00045 00046 enum NodeState{ENABLED = 0, DISABLED}; 00047 00048 /** \class Node 00049 * \ingroup L1394_Node 00050 * \brief Every node connected to the FireWire bus is represented as a Node object. 00051 * 00052 * This class is base class for all Nodes and implements methods for the three basic transactions 00053 * read, write and lock. 00054 * You can also get information about a node, like GUID and the actual node_ID, or card_ID. 00055 * 00056 * This class provides also an reference counter to allow connecting a Node to more 00057 * than one card in the same PC. 00058 * Every node has an Event object, that can be used to get information 00059 * about BUSRESET and NODE_DESTROY events. (See the documentation of class 00060 * EventHandle ) 00061 * 00062 * This class is inherited by: 00063 * 00064 * Card : 00065 * A Card represents a FireWire card. The Card manages the 00066 * Node objects for FireWire nodes connected to a FireWire card. 00067 * For more information see the documentation of class Card . 00068 * 00069 * FcpNode : 00070 * A FcpNode represents a FireWire node using FCP protocol. 00071 * Normally a FcpNode represents an AV/C device, with up to 8 Subunits. 00072 * For more information see the documentation of class FcpNode . 00073 * 00074 * DccCamera : 00075 * A DccCamera represents a camera using DCC-protocol, like Sony DFW-V500 00076 * and DFW-VL500 cameras. 00077 * For more information see documentation of class DccCamera . 00078 * 00079 * PhyNode : 00080 * A PhyNode represents a FireWire node, with a physical layer only(like hubs). 00081 * For more information see the documentation of the class PhyNode . 00082 * 00083 *@author Michael Repplinger 00084 */ 00085 00086 class Node 00087 { 00088 public: 00089 /*! \name Node constructor 00090 * These functions creates a Node. 00091 */ 00092 //@{ 00093 /*! \fn Node(const u_int32_t node_id, const Card* parent) 00094 * \brief constructor 00095 * \param node_id : the actual node_id by instantiating the Node object. 00096 * \param parent : pointer to the parent-node 00097 */ 00098 Node(const u_int32_t node_id, const Card* parent); 00099 00100 00101 /*! \fn ~Node() 00102 * \brief destructor 00103 */ 00104 virtual ~Node(); 00105 //@} 00106 00107 00108 /*! \name Transactions 00109 * These methods implement the three basic asynchrone transaction (read, write and lock), defined in the 00110 * FireWire standard. 00111 */ 00112 //@{ 00113 /*! \fn read(const u_int64_t address, Quadlet* response) const 00114 * \brief This method reads 4 bytes (a Quadlet) from the CsrRom and stores the value in response 00115 * 00116 * For information about the structure of the CsrRom see IEEE-1212 specification. 00117 * \param address : u_int64_t value for the CSR-address. 00118 * \param response : pointer to the response Quadlet 00119 * \return int : L1394_FAILED, if the transaction fails, else L1394_SUCCESS. 00120 */ 00121 virtual int read(const u_int64_t address, Quadlet* response) const; 00122 00123 00124 /*! \fn write(const u_int64_t, const Quadlet& data) const 00125 * \brief This method writes 4 bytes (a Quadlet) to CsrRom. 00126 * \param address : u_int64_t value that specify the address in CSR. 00127 * \param data : Quadlet with the data to write in the CsrRom. 00128 * \return int : L1394_FAILED, if the transaction fails, else L1394_SUCCESS. 00129 */ 00130 virtual int write(const u_int64_t address ,const Quadlet& data ) const ; 00131 00132 00133 /*! \fn lock (const u_int64_t address, const Quadlet& data, const unsigned int extcode,const Quadlet& argument, Quadlet* result) const 00134 * \brief This method realizes an atomic transaction on the FireWire bus. 00135 * 00136 * An atomic transaction means, that no node can access the address during the lock operation. 00137 * \param address : u_int64_t value for the CSR-address 00138 * \param data : The data Quadlet defines the value that should be executed on the address 00139 * \param extcode : The extension code defines the type of lock operation. 00140 * \param argument : The argument value is compared with the actual address value and depending on the extension code a operation with the data value is executed. 00141 * \param result : If a value is returned, it is stored in result 00142 * \return int: L1394_FAILED, if the transaction fails, else L1394_SUCCESS. 00143 */ 00144 virtual int lock(const u_int64_t address,const Quadlet& data, const unsigned int extcode, const Quadlet& argument, Quadlet* result) const; 00145 //@} 00146 00147 00148 /** \name Node information 00149 * These functions report actual information about the status of a Node. 00150 */ 00151 //@{ 00152 /*! \fn getNodeID() const 00153 * \brief This method returns the current node_ID of a node. 00154 * 00155 * \return u_int32_t : value with the actual node ID. 00156 */ 00157 inline u_int32_t getNodeID() const {return __node_id;} 00158 00159 00160 /*! \fn getCardID() const 00161 * \brief returns the card_id of the parent node 00162 * \return u_int32_t : value with card number 00163 */ 00164 u_int32_t getCardID() const ; 00165 00166 00167 /*! \fn getParentCard() const 00168 * \brief This method returns a pointer to the current parent node 00169 */ 00170 inline const Card* getParentCard() const {return __parent;} 00171 00172 00173 /*! \fn getNodeType() const 00174 * \brief returns the type of a node (coded as integer value) 00175 * 00176 * \return NodeType : value with the node type. 00177 */ 00178 inline NodeType getNodeType() const {return __node_type;} 00179 00180 00181 /*! \fn getGuid() const 00182 * \brief This method returns the GUID of a node. 00183 * \return u_int64_t : value with the guid 00184 */ 00185 inline const u_int64_t& getGuid() const {return __guid;} 00186 00187 00188 /*! \fn isPhyOnly() const 00189 * \brief This method tests, if a node has only a physical layer, 00190 * like hubs. 00191 * \return true, if node has only a physical layer, else false. 00192 */ 00193 virtual bool isPhyOnly() const {return false;} 00194 00195 00196 /*! \fn getState() const 00197 * \brief This method reports the state of a node. 00198 * 00199 * A node has three states. L1394_ENABLED, if the node is connected to the 00200 * FireWire bus, L1394_DISABLED, if the node is not connected to the bus 00201 * 00202 * \return int : L1394_ENABLED, if the node is connected to the bus, else L1394_DISABLED. 00203 */ 00204 inline int getState() const {return __state;} 00205 00206 /*! \fn getRefCount() const 00207 * \brief This method returns the current ref-counter. 00208 */ 00209 inline int getRefCount() const {return __reference_counter;} 00210 00211 00212 /*! returns the node_type as const char* */ 00213 static const char* char_node_type[]; 00214 00215 00216 /*! \fn getEventObject() const 00217 * \brief This method returns the event object. 00218 */ 00219 virtual Event* getEventObject() const {return __event;} 00220 00221 00222 /*! \fn getIsoObject() const 00223 * \brief This method returns the Iso-Object, NULL if the Device is not ISO-Capable, 00224 * or configured. 00225 */ 00226 virtual Iso* getIsoObject() const {return 0;} 00227 00228 /*! \fn getDeviceList() const 00229 * \brief This method returns the list of device-interfaces provided by a Node. 00230 */ 00231 const list<Device*>& getDeviceList() const {return device_list;} 00232 //@} 00233 00234 /** \name internal Node methods 00235 * These methods are for INTERNAL USE ONLY!!!! Don't touch any of this methods or no correct work is possible. 00236 */ 00237 //@{ 00238 /*! \fn increaseRefCount() 00239 * \brief increases the reference counter (for internal use only) DON'T call this function!!! 00240 */ 00241 int increaseRefCount() ; 00242 00243 00244 /*! \fn decreaseRefCount() 00245 * \brief decreases the reference counter (for internal use only) DON'T call this function!!! 00246 */ 00247 int decreaseRefCount(); 00248 00249 00250 /*! \fn setNodeID(const u_int32_t node_number) 00251 * \brief This method sets the current node-ID. (for internal use only!!) 00252 */ 00253 void setNodeID(const u_int32_t node_id) { __node_id = node_id;} 00254 00255 /*! These method sets the current parent object. (for internal use only!!) 00256 */ 00257 void setParentCard(const Card* parent) { __parent = parent;} 00258 //@} 00259 00260 protected: 00261 /*! This method adds a Device object to the device list. You are responsible 00262 * to delete the pointer in this list. 00263 */ 00264 void addDevice(Device* device) {device_list.insert(device_list.end(), device);} 00265 00266 /*!\fn readGuid() 00267 * \brief This method reads the guid of a nodesetState 00268 */ 00269 void readGuid(); 00270 00271 00272 /*! \fn setState(const NodeState s) 00273 * \brief This method sets the state of a node. 00274 * 00275 * This method is for internal use only. If you inherit from this class 00276 * don't use this method or no correct work is possible. 00277 */ 00278 void setState(const NodeState s); 00279 00280 00281 /*! \fn setNodeType(const NodeType node_type) 00282 * \brief This method sets the node_type 00283 */ 00284 void setNodeType(const NodeType& node_type) {__node_type = node_type;} 00285 00286 00287 /*! \fn setGuid(const u_int64_t guid) 00288 * \brief This method sets the GUID 00289 */ 00290 void setGuid(const u_int64_t& guid) {__guid = guid;} 00291 00292 /** change the Eventobject. 00293 */ 00294 void setEvent(Event* event); 00295 00296 /* The global Message object */ 00297 internal::Message* message; 00298 00299 //! global bus reset counter 00300 static u_int32_t *reset_counter_array; 00301 00302 private: 00303 00304 //! The Global Unique Identifyer of a node 00305 u_int64_t __guid; 00306 00307 //! User defined name of node 00308 string __name; 00309 00310 //! The type of a node 00311 NodeType __node_type; 00312 00313 //! The event object for a node 00314 Event *__event; 00315 00316 //reference counter 00317 int __reference_counter; 00318 00319 NodeState __state; /* state of a node */ 00320 00321 u_int32_t __node_id; //! actual node_ID 00322 00323 const Card* __parent; //! actual node_ID 00324 00325 list<Device*> device_list; 00326 }; 00327 00328 } //end namespace l1394 00329 00330 #endif