UniSet
1.4.0
|
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 ); 00083 virtual ~UNetExchange(); 00084 00086 static UNetExchange* init_unetexchange( int argc, const char* argv[], 00087 UniSetTypes::ObjectId shmID, SharedMemory* ic=0 ); 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 sidLostPackets(UniSetTypes::DefaultObjectId) 00146 {} 00147 00148 ReceiverInfo(UNetReceiver* _r1, UNetReceiver* _r2 ): 00149 r1(_r1),r2(_r2), 00150 sidRespond(UniSetTypes::DefaultObjectId), 00151 respondInvert(false), 00152 sidLostPackets(UniSetTypes::DefaultObjectId) 00153 {} 00154 00155 UNetReceiver* r1; 00156 UNetReceiver* r2; 00158 void step( SMInterface* shm, const std::string myname ); 00159 00160 inline void setRespondID( UniSetTypes::ObjectId id, bool invert=false ) 00161 { 00162 sidRespond = id; 00163 respondInvert = invert; 00164 } 00165 inline void setLostPacketsID( UniSetTypes::ObjectId id ){ sidLostPackets = id; } 00166 inline void initIterators( SMInterface* shm ) 00167 { 00168 shm->initAIterator(aitLostPackets); 00169 shm->initDIterator(ditRespond); 00170 } 00171 00172 // Сводная информация по двум каналам 00173 // сумма потерянных пакетов и наличие связи 00174 // хотя бы по одному каналу 00175 // ( реализацию см. ReceiverInfo::step() ) 00176 UniSetTypes::ObjectId sidRespond; 00177 IOController::DIOStateList::iterator ditRespond; 00178 bool respondInvert; 00179 UniSetTypes::ObjectId sidLostPackets; 00180 IOController::AIOStateList::iterator aitLostPackets; 00181 }; 00182 00183 typedef std::list<ReceiverInfo> ReceiverList; 00184 ReceiverList recvlist; 00185 00186 bool no_sender; 00187 UNetSender* sender; 00188 UNetSender* sender2; 00189 }; 00190 // ----------------------------------------------------------------------------- 00191 #endif // UNetExchange_H_ 00192 // -----------------------------------------------------------------------------