UniSet  1.4.0
include/MBTCPMaster.h
00001 #ifndef _MBTCPMaster_H_
00002 #define _MBTCPMaster_H_
00003 // -----------------------------------------------------------------------------
00004 #include <ostream>
00005 #include <string>
00006 #include <map>
00007 #include <vector>
00008 #include "MBExchange.h"
00009 #include "modbus/ModbusTCPMaster.h"
00010 // -----------------------------------------------------------------------------
00179 // -----------------------------------------------------------------------------
00189 class MBTCPMaster:
00190     public MBExchange
00191 {
00192     public:
00193         MBTCPMaster( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmID, SharedMemory* ic=0,
00194                         const std::string prefix="mbtcp" );
00195         virtual ~MBTCPMaster();
00196     
00198         static MBTCPMaster* init_mbmaster( int argc, const char* const* argv, 
00199                                             UniSetTypes::ObjectId shmID, SharedMemory* ic=0,
00200                                             const std::string prefix="mbtcp" );
00201 
00203         static void help_print( int argc, const char* const* argv );
00204 
00205     protected:
00206         virtual void sysCommand( UniSetTypes::SystemMessage *sm );
00207 
00208         UniSetTypes::uniset_mutex mbMutex;
00209         std::string iaddr;
00210 //      ost::InetAddress* ia;
00211         int port;
00212         int recv_timeout;
00213 
00214 //      virtual void step();
00215         virtual ModbusClient* initMB( bool reopen=false );
00216         
00217         void poll_thread();
00218         bool force_disconnect;
00219 
00220      private:
00221         MBTCPMaster();
00222 
00223         ModbusTCPMaster* mbtcp;
00224 
00225         // т.к. TCP может "зависнуть" на подключении к недоступному узлу
00226         // делаем опрос в отдельном потоке
00227         ThreadCreator<MBTCPMaster>* pollThread; 
00228         UniSetTypes::uniset_mutex tcpMutex;
00229 };
00230 // -----------------------------------------------------------------------------
00231 #endif // _MBTCPMaster_H_
00232 // -----------------------------------------------------------------------------