00001 /*************************************************************************** 00002 l1394nodecontainer.h - description 00003 ------------------- 00004 begin : Fri Sep 8 2000 00005 copyright : (C) 2000-2004 by Michael Repplinger 00006 email : repplinger@cs.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 #ifndef L1394NODECONTAINER_H 00019 #define L1394NODECONTAINER_H 00020 00021 #include "l1394_message.h" 00022 #include "Thread.hpp" 00023 #include <map> 00024 00025 00026 using std::map; 00027 00028 namespace L1394{ 00029 class Node; 00030 namespace internal{ 00031 /*! \class NodeContainer 00032 * \ingroup Internal 00033 * \brief This class stores and manages the Node objects. 00034 * 00035 * A NodeContainer object stores the Node objects, created by the Card objects 00036 * <BR> 00037 * To store the objects two (STL)single associated container are used.The 00038 * Node objects are stored as key/value pairs, for fast access to them. 00039 * The key is the GUID, the value the object pointer. <BR> 00040 * The first container stores the active Node objects, that are connected to FireWire bus 00041 * The second one stores the inactive Node objects. An inactive node object is a Node 00042 * object, that was disconnected from FireWire bus, but was not deleted. 00043 * After a defined timeout, node objects for disconnected nodes are deleted. 00044 * 00045 * @author Michael Repplinger 00046 */ 00047 00048 class NodeContainer { 00049 00050 00051 public: 00052 00053 static NodeContainer* getNodeContainer(); 00054 00055 /*! \fn ~NodeContainer() 00056 * \brief destructor 00057 */ 00058 ~NodeContainer(); 00059 00060 00061 /*! \fn getNode(u_int64_t guid) 00062 * \brief This method returns the Node object with guid, NULL if this node not exist. 00063 * 00064 * If you use this function, the internal reference counter is increased. 00065 * \param guid : u_int64_t value with the guid 00066 * \return Node* : pointer to the Node object with guid value, NULL if the Node object not exist 00067 */ 00068 Node* getNode(u_int64_t guid) ; 00069 00070 00071 /*! \fn findNode(u_int64_t guid) 00072 * \brief This method returns the Node object with guid, NULL if this node not exist. 00073 * 00074 * The difference between getNode(u_int64_t guid) is, that the reference counter 00075 * is not be increased. This method is for internal use only. 00076 * \param guid : u_int64_t value with the guid 00077 * \return Node* : pointer to the Node object with guid value, NULL if the Node object not exist 00078 */ 00079 Node* findNode(u_int64_t guid); 00080 00081 00082 /*! \fn nodeExist(u_int64_t guid) 00083 * \brief This method checks, if a Node object with a specific guid exist. 00084 * \param u_int64_t value for the guid 00085 * \return bool : This method return true, if a Node object with guid exist, else false. 00086 */ 00087 bool nodeExist(u_int64_t guid); 00088 00089 00090 /*! \fn release(Node* node) 00091 * \brief This method releases Node objects. 00092 * 00093 * You must use this function, if you get a Node object with getNode(u_int64_t guid). 00094 * This method decrease the reference counter and if the reference counter is less than 00095 * 1, the Node object is inserted in the inactive_node_list. 00096 * \param node : pointer to the Node object. 00097 */ 00098 void release(Node* node); 00099 00100 00101 /*! \fn insert(Node* node) 00102 * \brief This method inserts a new Node object into the node_list. 00103 * 00104 * If a Node object with this guid exist, the Node will not be inserted in 00105 * the node_list. 00106 * \param node : pointer to Node object that should be inserted. 00107 */ 00108 void insert(Node* node); 00109 00110 void removeNode(const Node* n); 00111 00112 protected: 00113 /*! \fn NodeContainer() 00114 * \brief Constructor 00115 */ 00116 NodeContainer(); 00117 00118 private: 00119 //map for active nodes 00120 map <u_int64_t, Node*> node_list; 00121 00122 //map for inactive nodes 00123 map <u_int64_t, Node*> inactive_node_list; 00124 00125 Message* message; 00126 static NodeContainer* container; 00127 static ThreadMutex mutex; 00128 }; 00129 } 00130 } 00131 #endif