|
UniSet
2.0.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::IOType iotype; 00035 UniSetTypes::ObjectId id; 00036 IOController::IOStateList::iterator ioit; 00037 int pack_ind; 00038 00039 friend std::ostream& operator<<( std::ostream& os, UItem& p ); 00040 }; 00041 00042 typedef std::vector<UItem> DMap; 00043 00044 void start(); 00045 void stop(); 00046 00047 void send(); 00048 void real_send(); 00049 00051 void updateFromSM(); 00052 00054 void updateSensor( UniSetTypes::ObjectId id, long value ); 00055 00057 void updateItem( DMap::iterator& it, long value ); 00058 00059 inline void setSendPause( int msec ){ sendpause = msec; } 00060 00062 void askSensors( UniversalIO::UIOCommand cmd ); 00063 00065 void initIterators(); 00066 00067 protected: 00068 00069 std::string s_field; 00070 std::string s_fvalue; 00071 00072 SMInterface* shm; 00073 00074 bool initItem( UniXML::iterator& it ); 00075 bool readItem( const std::shared_ptr<UniXML>& xml, UniXML::iterator& it, xmlNode* sec ); 00076 00077 void readConfiguration(); 00078 00079 private: 00080 UNetSender(); 00081 00082 ost::UDPBroadcast* udp; 00083 ost::IPV4Address addr; 00084 ost::tpport_t port; 00085 std::string s_host; 00086 00087 std::string myname; 00088 int sendpause; 00089 std::atomic_bool activated; 00090 00091 UniSetTypes::uniset_rwmutex pack_mutex; 00092 UniSetUDP::UDPMessage mypack; 00093 DMap dlist; 00094 int maxItem; 00095 unsigned long packetnum; 00096 UniSetUDP::UDPPacket s_msg; 00097 00098 ThreadCreator<UNetSender>* s_thr; // send thread 00099 }; 00100 // ----------------------------------------------------------------------------- 00101 #endif // UNetSender_H_ 00102 // -----------------------------------------------------------------------------
1.7.6.1