00001 #ifndef _ROBOOBJECTS_COMOBJECT_H 00002 #define _ROBOOBJECTS_COMOBJECT_H 00003 00029 #include <Time.H> 00030 #include <queue> 00031 00032 //$Id: COMObject.H 66 2007-01-23 20:53:23Z fwph $ 00033 00034 namespace WURDE { 00035 00041 class COMBase { 00042 public: 00043 COMBase(const std::string &name){}; 00044 virtual ~COMBase(){}; 00045 }; 00046 00054 template <class InfoType, class DataType> 00055 class COMObject : public COMBase { 00056 public: 00057 COMObject(const std::string & name) : COMBase(name), m_streamname(name),m_globalName(name){ 00058 m_newData=false; 00059 m_newInfo=false; 00060 m_supplier=false; 00061 // m_lastDataTime.now(); 00062 //m_lastInfoTime.now(); 00063 //m_lastRequestTime.now(); 00064 m_queue=false; 00065 } 00066 00067 virtual ~COMObject(){}; 00068 00072 virtual void activateSupplier()=0; 00073 00077 virtual void activateConsumer()=0; 00078 00084 virtual void runUpdate(const bool & publishData,const bool & publishInfo)=0; 00085 00089 virtual void disconnect()=0; 00090 00095 void setAcceptAny(const bool & val) { m_acceptAny=true;} 00096 00103 virtual void setQueueMode(const bool & val)=0; 00104 00109 virtual void setStreamName(const std::string & name)=0; 00110 00116 virtual void setGlobalName(const std::string & name)=0; 00117 00118 // virtual int getID()=0; 00119 00123 // void timestampData(); 00124 00125 /* 00126 * the autorequest stuff needs to be handled in the 00127 * communication adapter object, since the data shouldn't be 00128 * passed through if we're doing autorequests, and it shouldn't 00129 * overwrite the current data in that case either. 00130 */ 00131 00132 void setAutoPing(const bool &val){m_doAutoPing=val;} 00133 void doPing(){m_doPing=true;} 00134 00135 void setStaging(DataType *staging_){m_data=staging_;} 00136 void setInfo(InfoType *info){m_incoming=info;} 00137 void setRequests(InfoType *requests){m_outgoing=requests;} 00138 00139 void setDataVector(std::queue<DataType> *dataVector){m_dataVector=dataVector;} 00140 void setInfoVector(std::queue<InfoType> *infoVector){m_incomingVector=infoVector;} 00141 void setRequestVector(std::queue<InfoType> *requestVector){m_outgoingVector=requestVector;} 00142 00143 bool isSupplier(){return m_supplier;} 00144 bool newInfo(){return m_newInfo;} 00145 bool newData(){return m_newData;} 00146 void resetInfo(){m_newInfo=false;} 00147 void resetData(){m_newData=false;} 00148 00149 protected: 00150 COMObject<InfoType,DataType>(){} 00151 COMObject<InfoType,DataType>(const COMObject<InfoType,DataType> &){} 00152 00153 std::string m_streamname; 00154 std::string m_globalName; 00155 00156 bool m_newData; 00157 bool m_newInfo; 00158 00159 /* If true, respond to pings automatically(Suppliers). */ 00160 bool m_doAutoPing; 00161 00162 /* If true, send a ping (Consumers). */ 00163 bool m_doPing; 00164 00165 /* If true, this is a data supplier. */ 00166 bool m_supplier; 00167 00168 /* If true, we queue data and info rather than overwriting. */ 00169 bool m_queue; 00170 00171 /* If true, accept messages with target or streamname "Any" */ 00172 bool m_acceptAny; 00173 00174 InfoType *m_incoming; 00175 InfoType *m_outgoing; 00176 DataType *m_data; 00177 00178 std::queue<InfoType> *m_incomingVector; 00179 std::queue<InfoType> *m_outgoingVector; 00180 std::queue<DataType> *m_dataVector; 00181 00182 InfoType m_lastInfoIn; 00183 InfoType m_lastInfoOut; 00184 DataType m_lastData; 00185 00186 }; 00187 00188 00189 }; 00190 00191 #endif