UniSet  2.6.0
MBTCPMaster.h
1 /*
2  * Copyright (c) 2015 Pavel Vainerman.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as
6  * published by the Free Software Foundation, version 2.1.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Lesser Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 // -----------------------------------------------------------------------------
17 #ifndef _MBTCPMaster_H_
18 #define _MBTCPMaster_H_
19 // -----------------------------------------------------------------------------
20 #include <ostream>
21 #include <string>
22 #include <map>
23 #include <vector>
24 #include <memory>
25 #include "MBExchange.h"
26 #include "modbus/ModbusTCPMaster.h"
27 // -------------------------------------------------------------------------
28 namespace uniset
29 {
30  // -----------------------------------------------------------------------------
211  // -----------------------------------------------------------------------------
221  class MBTCPMaster:
222  public MBExchange
223  {
224  public:
225  MBTCPMaster( uniset::ObjectId objId, uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
226  const std::string& prefix = "mbtcp" );
227  virtual ~MBTCPMaster();
228 
230  static std::shared_ptr<MBTCPMaster> init_mbmaster( int argc, const char* const* argv,
231  uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
232  const std::string& prefix = "mbtcp" );
233 
235  static void help_print( int argc, const char* const* argv );
236 
237  virtual uniset::SimpleInfo* getInfo( const char* userparam = 0 ) override;
238 
239  protected:
240  virtual void sysCommand( const uniset::SystemMessage* sm ) override;
241  virtual std::shared_ptr<ModbusClient> initMB( bool reopen = false ) override;
242  virtual void sigterm( int signo ) override;
243  virtual bool deactivateObject() override;
244 
245  std::string iaddr;
246  int port;
247 
248  void poll_thread();
249  void final_thread();
250  bool force_disconnect;
251 
252  private:
253  MBTCPMaster();
254 
255  std::shared_ptr<ModbusTCPMaster> mbtcp;
256 
257  // т.к. TCP может "зависнуть" на подключении к недоступному узлу
258  // делаем опрос в отдельном потоке
259  std::shared_ptr<ThreadCreator<MBTCPMaster>> pollThread;
260  };
261  // --------------------------------------------------------------------------
262 } // end of namespace uniset
263 // -----------------------------------------------------------------------------
264 #endif // _MBTCPMaster_H_
265 // -----------------------------------------------------------------------------
Definition: MBExchange.h:55
Definition: CallbackTimer.h:29
static std::shared_ptr< MBTCPMaster > init_mbmaster(int argc, const char *const *argv, uniset::ObjectId shmID, const std::shared_ptr< SharedMemory > &ic=nullptr, const std::string &prefix="mbtcp")
Definition: MBTCPMaster.cc:234
static void help_print(int argc, const char *const *argv)
Definition: MBTCPMaster.cc:223
Definition: MessageType.h:166
virtual void sigterm(int signo) override
Definition: MBTCPMaster.cc:181
virtual bool deactivateObject() override
Деактивиция объекта (переопределяется для необходимых действий перед деактивацией) ...
Definition: MBTCPMaster.cc:208
Definition: MBTCPMaster.h:221
Definition: UniSetTypes_i.idl:64
long ObjectId
Definition: UniSetTypes_i.idl:30