UniSet
1.4.0
|
00001 #ifndef UNetSender_H_ 00002 #define UNetSender_H_ 00003 // ----------------------------------------------------------------------------- 00004 #include <ostream> 00005 #include <string> 00006 #include <vector> 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 "UDPPacket.h" 00015 // ----------------------------------------------------------------------------- 00016 /* 00017 * 00018 */ 00019 class UNetSender 00020 { 00021 public: 00022 UNetSender( const std::string host, const ost::tpport_t port, SMInterface* smi, 00023 const std::string s_field="", const std::string s_fvalue="", SharedMemory* ic=0 ); 00024 00025 ~UNetSender(); 00026 00027 struct UItem 00028 { 00029 UItem(): 00030 iotype(UniversalIO::UnknownIOType), 00031 id(UniSetTypes::DefaultObjectId), 00032 pack_ind(-1){} 00033 00034 UniversalIO::IOTypes iotype; 00035 UniSetTypes::ObjectId id; 00036 IOController::AIOStateList::iterator ait; 00037 IOController::DIOStateList::iterator dit; 00038 int pack_ind; 00039 00040 friend std::ostream& operator<<( std::ostream& os, UItem& p ); 00041 }; 00042 00043 typedef std::vector<UItem> DMap; 00044 00045 void start(); 00046 void stop(); 00047 00048 void send(); 00049 void real_send(); 00050 00052 void updateFromSM(); 00053 00055 void updateSensor( UniSetTypes::ObjectId id, long value ); 00056 00058 void updateItem( DMap::iterator& it, long value ); 00059 00060 inline void setSendPause( int msec ){ sendpause = msec; } 00061 00063 void askSensors( UniversalIO::UIOCommand cmd ); 00064 00066 void initIterators(); 00067 00068 protected: 00069 00070 std::string s_field; 00071 std::string s_fvalue; 00072 00073 SMInterface* shm; 00074 00075 bool initItem( UniXML_iterator& it ); 00076 bool readItem( UniXML& xml, UniXML_iterator& it, xmlNode* sec ); 00077 00078 void readConfiguration(); 00079 00080 private: 00081 UNetSender(); 00082 00083 ost::UDPBroadcast* udp; 00084 ost::IPV4Address addr; 00085 ost::tpport_t port; 00086 std::string s_host; 00087 00088 std::string myname; 00089 int sendpause; 00090 bool activated; 00091 00092 UniSetTypes::uniset_mutex pack_mutex; 00093 UniSetUDP::UDPMessage mypack; 00094 DMap dlist; 00095 int maxItem; 00096 unsigned long packetnum; 00097 UniSetUDP::UDPPacket s_msg; 00098 00099 ThreadCreator<UNetSender>* s_thr; // send thread 00100 }; 00101 // ----------------------------------------------------------------------------- 00102 #endif // UNetSender_H_ 00103 // -----------------------------------------------------------------------------