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 <core/threading/thread.h>
26 #include <aspect/aspect_provider.h>
27 #include <aspect/logging.h>
28 #include <aspect/clock.h>
29 #include <aspect/configurable.h>
30 #include <aspect/blackboard.h>
31 #include <aspect/blocked_timing.h>
32 #include <plugins/openprs/aspect/openprs_inifin.h>
33 #include <plugins/openprs/aspect/openprs_manager_inifin.h>
34 
35 #include <string>
36 #include <thread>
37 #include <boost/asio.hpp>
38 
39 namespace fawkes {
40  class AspectIniFin;
41  class SubProcess;
42  class OpenPRSServerProxy;
43  class OpenPRSMessagePasserProxy;
44 }
45 
47 : public fawkes::Thread,
48  public fawkes::LoggingAspect,
49  public fawkes::ClockAspect,
54 {
55  public:
56  OpenPRSThread();
57  virtual ~OpenPRSThread();
58 
59  virtual void init();
60  virtual void loop();
61  virtual void finalize();
62 
63  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
64  protected: virtual void run() { Thread::run(); }
65 
66  private: // methods
67  const std::list<fawkes::AspectIniFin *> inifin_list();
68  bool server_alive();
69  void check_deadline(boost::asio::deadline_timer &deadline,
70  boost::asio::ip::tcp::socket &socket);
71 
72  private: // members
73  bool cfg_mp_run_;
74  std::string cfg_mp_bin_;
75  std::string cfg_mp_host_;
76  unsigned int cfg_mp_port_;
77  std::string cfg_mp_port_s_;
78  bool cfg_mp_use_proxy_;
79  unsigned int cfg_mp_proxy_port_;
80  bool cfg_server_run_;
81  std::string cfg_server_bin_;
82  std::string cfg_server_host_;
83  unsigned int cfg_server_port_;
84  std::string cfg_server_port_s_;
85  unsigned int cfg_server_proxy_port_;
86  float cfg_server_timeout_;
87  float cfg_kernel_timeout_;
88 
89  fawkes::SubProcess *proc_mp_;
90  fawkes::SubProcess *proc_srv_;
91 
92  fawkes::OpenPRSAspectIniFin openprs_aspect_inifin_;
93  fawkes::OpenPRSManagerAspectIniFin openprs_manager_aspect_inifin_;
95 
96  fawkes::OpenPRSServerProxy *openprs_server_proxy_;
97  fawkes::OpenPRSMessagePasserProxy *openprs_mp_proxy_;
98 
99  boost::asio::io_service io_service_;
100  std::thread io_service_thread_;
101  boost::asio::ip::tcp::socket server_socket_;
102  boost::asio::deadline_timer deadline_;
103 
104 };
105 
106 #endif
Thread aspect to access to BlackBoard.
Definition: blackboard.h:34
Thread aspect that allows to obtain the current time from the clock.
Definition: clock.h:36
Proxy for the OpenPRS server communication.
Fawkes library namespace.
virtual void run()
Code to execute in the thread.
Definition: thread.cpp:939
virtual void run()
Stub to see name in backtrace for easier debugging.
Thread class encapsulation of pthreads.
Definition: thread.h:42
OpenPRSManagerAspect initializer/finalizer.
Thread aspect to use blocked timing.
Thread aspect to log output.
Definition: logging.h:35
Thread aspect provide a new aspect.
Thread aspect to access configuration data.
Definition: configurable.h:35
Sub-process execution with stdin/stdout/stderr redirection.
Definition: proc.h:39
Proxy for the OpenPRS server communication.
OpenPRSAspect initializer/finalizer.
OpenPRS environment thread.