include/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
00089 virtual UNetReceiver* create_receiver( const std::string& h, const ost::tpport_t p, SMInterface* shm );
00090 virtual UNetSender* create_sender( const std::string& h, const ost::tpport_t p, SMInterface* shm,
00091 const std::string& s_field="", const std::string& s_fvalue="", SharedMemory* ic=0 );
00092
00094 static void help_print( int argc, const char* argv[] );
00095
00096 bool checkExistUNetHost( const std::string& host, ost::tpport_t port );
00097
00098 std::list<UNetReceiver*> get_receivers();
00099
00101 void setIgnore(UniSetTypes::ObjectId id = UniSetTypes::DefaultObjectId, bool set = true);
00102
00103 protected:
00104 UNetExchange();
00105
00106 xmlNode* cnode;
00107 std::string s_field;
00108 std::string s_fvalue;
00109
00110 SMInterface* shm;
00111 void step();
00112
00113
00114 virtual void processingMessage( UniSetTypes::VoidMessage *msg );
00115 void sysCommand( UniSetTypes::SystemMessage *msg );
00116 void sensorInfo( UniSetTypes::SensorMessage*sm );
00117 void timerInfo( UniSetTypes::TimerMessage *tm );
00118 void askSensors( UniversalIO::UIOCommand cmd );
00119 void waitSMReady();
00120 void receiverEvent( UNetReceiver* r, UNetReceiver::Event ev );
00121
00122 virtual bool activateObject();
00123
00124
00125 virtual void sigterm( int signo );
00126
00127 void initIterators();
00128 void startReceivers();
00129
00130
00131 enum Timer
00132 {
00133 tmStep
00134 };
00135
00136 private:
00137 bool initPause;
00138 UniSetTypes::uniset_mutex mutex_start;
00139
00140 PassiveTimer ptHeartBeat;
00141 UniSetTypes::ObjectId sidHeartBeat;
00142 int maxHeartBeat;
00143 IOController::AIOStateList::iterator aitHeartBeat;
00144 UniSetTypes::ObjectId test_id;
00145
00146 int steptime;
00148 bool activated;
00149 int activateTimeout;
00150
00151 struct ReceiverInfo
00152 {
00153 ReceiverInfo():r1(0),r2(0),
00154 sidRespond(UniSetTypes::DefaultObjectId),
00155 respondInvert(false),
00156 sidLostPackets(UniSetTypes::DefaultObjectId)
00157 {}
00158
00159 ReceiverInfo(UNetReceiver* _r1, UNetReceiver* _r2 ):
00160 r1(_r1),r2(_r2),
00161 sidRespond(UniSetTypes::DefaultObjectId),
00162 respondInvert(false),
00163 sidLostPackets(UniSetTypes::DefaultObjectId)
00164 {}
00165
00166 UNetReceiver* r1;
00167 UNetReceiver* r2;
00169 void step( SMInterface* shm, const std::string& myname );
00170
00171 inline void setRespondID( UniSetTypes::ObjectId id, bool invert=false )
00172 {
00173 sidRespond = id;
00174 respondInvert = invert;
00175 }
00176 inline void setLostPacketsID( UniSetTypes::ObjectId id ){ sidLostPackets = id; }
00177 inline void initIterators( SMInterface* shm )
00178 {
00179 shm->initAIterator(aitLostPackets);
00180 shm->initDIterator(ditRespond);
00181 }
00182
00183
00184
00185
00186
00187 UniSetTypes::ObjectId sidRespond;
00188 IOController::DIOStateList::iterator ditRespond;
00189 bool respondInvert;
00190 UniSetTypes::ObjectId sidLostPackets;
00191 IOController::AIOStateList::iterator aitLostPackets;
00192 };
00193
00194 typedef std::list<ReceiverInfo> ReceiverList;
00195 ReceiverList recvlist;
00196
00197 bool no_sender;
00198 UNetSender* sender;
00199 UNetSender* sender2;
00200 };
00201
00202 #endif // UNetExchange_H_
00203