UNetUDP/UNetExchange.h
00001 #ifndef UNetExchange_H_
00002 #define UNetExchange_H_
00003
00004 #include <ostream>
00005 #include <string>
00006 #include <queue>
00007 #include <cc++/socket.h>
00008 #include "UniSetObject_LT.h"
00009 #include "Trigger.h"
00010 #include "Mutex.h"
00011 #include "SMInterface.h"
00012 #include "SharedMemory.h"
00013 #include "ThreadCreator.h"
00014 #include "UNetReceiver.h"
00015 #include "UNetSender.h"
00016
00077
00078 class UNetExchange:
00079 public UniSetObject_LT
00080 {
00081 public:
00082 UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmID, SharedMemory* ic=0, const std::string& prefix="unet" );
00083 virtual ~UNetExchange();
00084
00086 static UNetExchange* init_unetexchange( int argc, const char* argv[],
00087 UniSetTypes::ObjectId shmID, SharedMemory* ic=0, const std::string& prefix="unet" );
00088
00090 static void help_print( int argc, const char* argv[] );
00091
00092 bool checkExistUNetHost( const std::string& host, ost::tpport_t port );
00093
00094 protected:
00095
00096 xmlNode* cnode;
00097 std::string s_field;
00098 std::string s_fvalue;
00099
00100 SMInterface* shm;
00101 void step();
00102
00103 virtual void processingMessage( UniSetTypes::VoidMessage *msg );
00104 void sysCommand( UniSetTypes::SystemMessage *msg );
00105 void sensorInfo( UniSetTypes::SensorMessage*sm );
00106 void timerInfo( UniSetTypes::TimerMessage *tm );
00107 void askSensors( UniversalIO::UIOCommand cmd );
00108 void waitSMReady();
00109 void receiverEvent( UNetReceiver* r, UNetReceiver::Event ev );
00110
00111 virtual bool activateObject();
00112
00113
00114 virtual void sigterm( int signo );
00115
00116 void initIterators();
00117 void startReceivers();
00118
00119
00120 enum Timer
00121 {
00122 tmStep
00123 };
00124
00125 private:
00126 UNetExchange();
00127 bool initPause;
00128 UniSetTypes::uniset_mutex mutex_start;
00129
00130 PassiveTimer ptHeartBeat;
00131 UniSetTypes::ObjectId sidHeartBeat;
00132 int maxHeartBeat;
00133 IOController::AIOStateList::iterator aitHeartBeat;
00134 UniSetTypes::ObjectId test_id;
00135
00136 int steptime;
00138 bool activated;
00139 int activateTimeout;
00140
00141 struct ReceiverInfo
00142 {
00143 ReceiverInfo():r1(0),r2(0),
00144 sidRespond(UniSetTypes::DefaultObjectId),
00145 respondInvert(false),
00146 sidLostPackets(UniSetTypes::DefaultObjectId)
00147 {}
00148
00149 ReceiverInfo(UNetReceiver* _r1, UNetReceiver* _r2 ):
00150 r1(_r1),r2(_r2),
00151 sidRespond(UniSetTypes::DefaultObjectId),
00152 respondInvert(false),
00153 sidLostPackets(UniSetTypes::DefaultObjectId)
00154 {}
00155
00156 UNetReceiver* r1;
00157 UNetReceiver* r2;
00159 void step( SMInterface* shm, const std::string& myname );
00160
00161 inline void setRespondID( UniSetTypes::ObjectId id, bool invert=false )
00162 {
00163 sidRespond = id;
00164 respondInvert = invert;
00165 }
00166 inline void setLostPacketsID( UniSetTypes::ObjectId id ){ sidLostPackets = id; }
00167 inline void initIterators( SMInterface* shm )
00168 {
00169 shm->initAIterator(aitLostPackets);
00170 shm->initDIterator(ditRespond);
00171 }
00172
00173
00174
00175
00176
00177 UniSetTypes::ObjectId sidRespond;
00178 IOController::DIOStateList::iterator ditRespond;
00179 bool respondInvert;
00180 UniSetTypes::ObjectId sidLostPackets;
00181 IOController::AIOStateList::iterator aitLostPackets;
00182 };
00183
00184 typedef std::list<ReceiverInfo> ReceiverList;
00185 ReceiverList recvlist;
00186
00187 bool no_sender;
00188 UNetSender* sender;
00189 UNetSender* sender2;
00190 };
00191
00192 #endif // UNetExchange_H_
00193