UniSet  2.24.2
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  // -----------------------------------------------------------------------------
246  // -----------------------------------------------------------------------------
256  class MBTCPMaster:
257  public MBExchange
258  {
259  public:
260  MBTCPMaster( uniset::ObjectId objId, uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
261  const std::string& prefix = "mbtcp" );
262  virtual ~MBTCPMaster();
263 
265  static std::shared_ptr<MBTCPMaster> init_mbmaster( int argc, const char* const* argv,
266  uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
267  const std::string& prefix = "mbtcp" );
268 
269  static void help_print( int argc, const char* const* argv );
270 
271  virtual uniset::SimpleInfo* getInfo( const char* userparam = 0 ) override;
272 
273  protected:
274  virtual void sysCommand( const uniset::SystemMessage* sm ) override;
275  virtual std::shared_ptr<ModbusClient> initMB( bool reopen = false ) override;
276  virtual bool deactivateObject() override;
277  virtual bool reconfigure( const std::shared_ptr<uniset::UniXML>& xml, const std::shared_ptr<uniset::MBConfig>& mbconf ) override;
278 
279  std::string iaddr;
280  int port;
281 
282  void poll_thread();
283  void final_thread();
284  bool force_disconnect;
285 
286  private:
287  MBTCPMaster();
288 
289  std::shared_ptr<ModbusTCPMaster> mbtcp;
290 
291  // т.к. TCP может "зависнуть" на подключении к недоступному узлу
292  // делаем опрос в отдельном потоке
293  std::unique_ptr<ThreadCreator<MBTCPMaster>> pollThread;
294  };
295  // --------------------------------------------------------------------------
296 } // end of namespace uniset
297 // -----------------------------------------------------------------------------
298 #endif // _MBTCPMaster_H_
299 // -----------------------------------------------------------------------------
Definition: MBExchange.h:58
Definition: MBTCPMaster.h:258
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:210
virtual bool deactivateObject() override
Деактивация объекта (переопределяется для необходимых действий при завершении работы)
Definition: MBTCPMaster.cc:184
Definition: MessageType.h:171
Definition: CommonEventLoop.h:15
long ObjectId
Definition: UniSetTypes_i.idl:30
Definition: UniSetTypes_i.idl:65