UniSet  2.2.1
MBTCPPersistentSlave.h
00001 // -----------------------------------------------------------------------------
00002 #ifndef _MBTCPPersistentSlave_H_
00003 #define _MBTCPPersistentSlave_H_
00004 // -----------------------------------------------------------------------------
00005 #include <unordered_map>
00006 #include "MBSlave.h"
00007 #include "modbus/ModbusTCPServer.h"
00008 // -----------------------------------------------------------------------------
00018 // -----------------------------------------------------------------------------
00020 class MBTCPPersistentSlave:
00021     public MBSlave
00022 {
00023     public:
00024         MBTCPPersistentSlave( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr, const std::string& prefix = "mbs" );
00025         virtual ~MBTCPPersistentSlave();
00026 
00028         static std::shared_ptr<MBTCPPersistentSlave> init_mbslave( int argc, const char* const* argv,
00029                 UniSetTypes::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
00030                 const std::string& prefix = "mbs" );
00031 
00033         static void help_print( int argc, const char* const* argv );
00034 
00035         UniSetTypes::SimpleInfo* getInfo( CORBA::Long userparam ) override;
00036 
00037     protected:
00038         virtual void execute_tcp() override;
00039         virtual void initIterators() override;
00040         virtual bool deactivateObject() override;
00041         virtual void sigterm( int signo ) override;
00042 
00043         timeout_t sessTimeout;  
00044         timeout_t waitTimeout;
00045         ModbusTCPServer::Sessions sess; 
00046         unsigned int sessMaxNum;
00047         PassiveTimer ptUpdateInfo;
00048 
00049         struct ClientInfo
00050         {
00051             ClientInfo(): iaddr(""), respond_s(UniSetTypes::DefaultObjectId), invert(false),
00052                 askCount(0), askcount_s(UniSetTypes::DefaultObjectId)
00053             {
00054                 ptTimeout.setTiming(0);
00055             }
00056 
00057             std::string iaddr;
00058 
00059             UniSetTypes::ObjectId respond_s = { UniSetTypes::DefaultObjectId };
00060             IOController::IOStateList::iterator respond_it;
00061             bool invert = { false };
00062             PassiveTimer ptTimeout;
00063             timeout_t tout = { 2000 };
00064 
00065             long askCount;
00066             UniSetTypes::ObjectId askcount_s = { UniSetTypes::DefaultObjectId };
00067             IOController::IOStateList::iterator askcount_it;
00068 
00069             inline void initIterators( const std::shared_ptr<SMInterface>& shm )
00070             {
00071                 shm->initIterator( respond_it );
00072                 shm->initIterator( askcount_it );
00073             }
00074 
00075             const std::string getShortInfo() const;
00076         };
00077 
00078         typedef std::unordered_map<std::string, ClientInfo> ClientsMap;
00079         ClientsMap cmap;
00080 
00081 
00082         UniSetTypes::ObjectId sesscount_id;
00083         IOController::IOStateList::iterator sesscount_it;
00084 };
00085 // -----------------------------------------------------------------------------
00086 #endif // _MBTCPPersistentSlave_H_
00087 // -----------------------------------------------------------------------------