|
UniSet
1.7.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 virtual ~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 virtual 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 virtual void askSensors( UniversalIO::UIOCommand cmd ); 00064 00066 void initIterators(); 00067 00068 protected: 00069 UNetSender(); 00070 00071 std::string myname; 00072 UniSetUDP::UDPMessage mypack; 00073 DMap dlist; 00074 int maxItem; 00075 00076 std::string s_field; 00077 std::string s_fvalue; 00078 00079 SMInterface* shm; 00080 00081 virtual bool initItem( UniXML_iterator& it ); 00082 bool readItem( UniXML& xml, UniXML_iterator& it, xmlNode* sec ); 00083 00084 virtual void readConfiguration(); 00085 00086 private: 00087 00088 ost::UDPBroadcast* udp; 00089 ost::IPV4Address addr; 00090 ost::tpport_t port; 00091 std::string s_host; 00092 00093 int sendpause; 00094 bool activated; 00095 00096 UniSetTypes::uniset_mutex pack_mutex; 00097 unsigned long packetnum; 00098 UniSetUDP::UDPPacket s_msg; 00099 00100 ThreadCreator<UNetSender>* s_thr; // send thread 00101 }; 00102 // ----------------------------------------------------------------------------- 00103 #endif // UNetSender_H_ 00104 // -----------------------------------------------------------------------------
1.7.6.1