Fawkes API  Fawkes Development Version
openprs_thread.h
1 
2 /***************************************************************************
3  * openprs_thread.h - OpenPRS aspect provider thread
4  *
5  * Created: Thu Aug 14 15:52:35 2014
6  * Copyright 2014-2015 Tim Niemueller [www.niemueller.de]
7  ****************************************************************************/
8 
9 /* This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Library General Public License for more details.
18  *
19  * Read the full text in the LICENSE.GPL file in the doc directory.
20  */
21 
22 #ifndef _PLUGINS_OPENPRS_OPENPRS_THREAD_H_
23 #define _PLUGINS_OPENPRS_OPENPRS_THREAD_H_
24 
25 #include <aspect/aspect_provider.h>
26 #include <aspect/blackboard.h>
27 #include <aspect/blocked_timing.h>
28 #include <aspect/clock.h>
29 #include <aspect/configurable.h>
30 #include <aspect/logging.h>
31 #include <core/threading/thread.h>
32 #include <plugins/openprs/aspect/openprs_inifin.h>
33 #include <plugins/openprs/aspect/openprs_manager_inifin.h>
34 
35 #include <boost/asio.hpp>
36 #include <string>
37 #include <thread>
38 
39 namespace fawkes {
40 class AspectIniFin;
41 class SubProcess;
42 class OpenPRSServerProxy;
43 class OpenPRSMessagePasserProxy;
44 } // namespace fawkes
45 
47  public fawkes::LoggingAspect,
48  public fawkes::ClockAspect,
53 {
54 public:
55  OpenPRSThread();
56  virtual ~OpenPRSThread();
57 
58  virtual void init();
59  virtual void loop();
60  virtual void finalize();
61 
62  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
63 protected:
64  virtual void
65  run()
66  {
67  Thread::run();
68  }
69 
70 private: // methods
71  const std::list<fawkes::AspectIniFin *> inifin_list();
72  bool server_alive();
73  void check_deadline(boost::asio::deadline_timer &deadline, boost::asio::ip::tcp::socket &socket);
74 
75 private: // members
76  bool cfg_mp_run_;
77  std::string cfg_mp_bin_;
78  std::string cfg_mp_host_;
79  unsigned int cfg_mp_port_;
80  std::string cfg_mp_port_s_;
81  bool cfg_mp_use_proxy_;
82  unsigned int cfg_mp_proxy_port_;
83  bool cfg_server_run_;
84  std::string cfg_server_bin_;
85  std::string cfg_server_host_;
86  unsigned int cfg_server_port_;
87  std::string cfg_server_port_s_;
88  unsigned int cfg_server_proxy_port_;
89  float cfg_server_timeout_;
90  float cfg_kernel_timeout_;
91 
92  fawkes::SubProcess *proc_mp_;
93  fawkes::SubProcess *proc_srv_;
94 
95  fawkes::OpenPRSAspectIniFin openprs_aspect_inifin_;
96  fawkes::OpenPRSManagerAspectIniFin openprs_manager_aspect_inifin_;
98 
99  fawkes::OpenPRSServerProxy * openprs_server_proxy_;
100  fawkes::OpenPRSMessagePasserProxy *openprs_mp_proxy_;
101 
102  boost::asio::io_service io_service_;
103  std::thread io_service_thread_;
104  boost::asio::ip::tcp::socket server_socket_;
105  boost::asio::deadline_timer deadline_;
106 };
107 
108 #endif
OpenPRSThread::~OpenPRSThread
virtual ~OpenPRSThread()
Destructor.
Definition: openprs_thread.cpp:61
fawkes::LockPtr< fawkes::OpenPRSKernelManager >
fawkes::SubProcess
Sub-process execution with stdin/stdout/stderr redirection.
Definition: proc.h:37
fawkes::OpenPRSManagerAspectIniFin
OpenPRSManagerAspect initializer/finalizer.
Definition: openprs_manager_inifin.h:38
OpenPRSThread::OpenPRSThread
OpenPRSThread()
Constructor.
Definition: openprs_thread.cpp:51
OpenPRSThread::init
virtual void init()
Initialize the thread.
Definition: openprs_thread.cpp:66
fawkes::AspectProviderAspect
Thread aspect provide a new aspect.
Definition: aspect_provider.h:36
OpenPRSThread::run
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: openprs_thread.h:65
fawkes::BlockedTimingAspect
Thread aspect to use blocked timing.
Definition: blocked_timing.h:51
fawkes::OpenPRSMessagePasserProxy
Proxy for the OpenPRS server communication.
Definition: openprs_mp_proxy.h:38
fawkes::OpenPRSAspectIniFin
OpenPRSAspect initializer/finalizer.
Definition: openprs_inifin.h:40
fawkes::BlackBoardAspect
Thread aspect to access to BlackBoard.
Definition: blackboard.h:34
fawkes
Fawkes library namespace.
fawkes::LoggingAspect
Thread aspect to log output.
Definition: logging.h:33
OpenPRSThread::loop
virtual void loop()
Code to execute in the thread.
Definition: openprs_thread.cpp:251
fawkes::Thread
Thread class encapsulation of pthreads.
Definition: thread.h:46
OpenPRSThread::finalize
virtual void finalize()
Finalize the thread.
Definition: openprs_thread.cpp:225
fawkes::ConfigurableAspect
Thread aspect to access configuration data.
Definition: configurable.h:33
OpenPRSThread
OpenPRS environment thread.
Definition: openprs_thread.h:53
fawkes::ClockAspect
Thread aspect that allows to obtain the current time from the clock.
Definition: clock.h:34
fawkes::OpenPRSServerProxy
Proxy for the OpenPRS server communication.
Definition: openprs_server_proxy.h:39