00001 00030 #ifndef _HEARTBEAT_H 00031 #define _HEARTBEAT_H 00032 #include <WritableType.H> 00033 #include <Capability.H> 00034 #include <COMObject.H> 00035 #include <queue> 00036 #include <vector> 00037 00038 // $Id: Type.H 66 2007-01-23 20:53:23Z fwph $ 00039 00040 #define HEARTBEAT "Heartbeat" 00041 // IDNUMBER is used to identify data events . IDNUMBER+1 is the info event. this 00042 // system will probably go away soon... 00043 //#define HEARTBEATIDNUMBER 10 00044 00045 namespace WURDE { 00046 class Capability; 00047 class CommsManager; 00048 class Logger; 00049 00050 00051 class InterfaceStream { 00052 public: std::string streamname; 00053 std::string type; 00054 }; 00055 00056 00057 class HeartbeatInfoStruct { 00058 public: Writable< std::string > moduleName; 00059 std::string source; 00060 Writable< ProcessLocale > locale; 00061 Writable< RunState > state; 00062 MessageType mType; 00063 std::string target; 00064 Time timestamp; 00065 Writable< std::vector< InterfaceStream > > interfaces; 00066 Writable< ProcessType > managedType; 00067 }; 00068 00069 00070 class HeartbeatDataStruct { 00071 public: std::string source; 00072 Time timestamp; 00073 float TTL; 00074 }; 00075 00081 class Heartbeat : virtual public Capability { 00082 00083 public: 00089 explicit Heartbeat(const std::string & streamname); 00090 00096 Heartbeat(const ConnectionStrategy & strategy,const std::string & gblName); 00097 00103 Heartbeat(const std::string & streamname,const std::string & gblName); 00104 00105 ~Heartbeat(); 00106 00107 00111 void init(const std::string & streamname,const ConnectionStrategy & strategy, const std::string & gblName); 00112 00113 00118 HeartbeatDataStruct data; 00119 00123 HeartbeatInfoStruct info; 00124 00128 HeartbeatInfoStruct requests; 00129 00130 //RobotObject imps 00131 void runUpdate(); 00132 void setManager(CommsManager *myManager_); 00133 void setCOMObject(COMBase *object){ myCOMObject = dynamic_cast<COMObject<HeartbeatInfoStruct,HeartbeatDataStruct> *> (object);} 00134 void disconnect(){if(myCOMObject){myCOMObject->disconnect();}} 00135 void activateSupplier(); 00136 void activateConsumer(); 00137 std::string getInterfaceName(){ return HEARTBEAT;} 00138 void setStreamName(const std::string & name); 00139 void setGlobalName(const std::string & name); 00140 bool newData(); 00141 bool newInfo(); 00142 void setAutoPing(const bool & val); 00143 void doPing(); 00144 // int getID(){return HEARTBEATIDNUMBER;} 00145 00149 bool getQueueMode(){return m_queue;}; 00150 00154 void setQueueMode(const bool & val); 00155 00160 HeartbeatDataStruct getNextData(); 00161 00166 HeartbeatInfoStruct getNextInfo(); 00167 00171 HeartbeatInfoStruct getNextRequest(){return getNextInfo();} 00172 00173 void publishData(); 00174 void publishInfo(); 00175 //void publishRequest(); 00176 00177 protected: 00178 COMObject<HeartbeatInfoStruct, HeartbeatDataStruct> *myCOMObject; 00179 00180 bool m_queue; 00181 00182 //notes that the object should be initialized as soon as a streamname is received 00183 bool m_initialize; 00184 std::queue<HeartbeatDataStruct> m_dataVector; 00185 std::queue<HeartbeatInfoStruct> m_infoVector; 00186 std::queue<HeartbeatInfoStruct> m_requestVector; 00187 00188 }; 00189 00190 } 00191 00192 00193 #endif