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
39namespace fawkes {
40class AspectIniFin;
41class SubProcess;
42class OpenPRSServerProxy;
43class OpenPRSMessagePasserProxy;
44} // namespace fawkes
45
53{
54public:
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() */
63protected:
64 virtual void
66 {
67 Thread::run();
68 }
69
70private: // 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
75private: // 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
OpenPRS environment thread.
virtual void loop()
Code to execute in the thread.
OpenPRSThread()
Constructor.
virtual ~OpenPRSThread()
Destructor.
virtual void init()
Initialize the thread.
virtual void finalize()
Finalize the thread.
virtual void run()
Stub to see name in backtrace for easier debugging.
Thread aspect provide a new aspect.
Thread aspect to access to BlackBoard.
Definition: blackboard.h:34
Thread aspect to use blocked timing.
Thread aspect that allows to obtain the current time from the clock.
Definition: clock.h:34
Thread aspect to access configuration data.
Definition: configurable.h:33
Thread aspect to log output.
Definition: logging.h:33
OpenPRSAspect initializer/finalizer.
OpenPRSManagerAspect initializer/finalizer.
Proxy for the OpenPRS server communication.
Proxy for the OpenPRS server communication.
Sub-process execution with stdin/stdout/stderr redirection.
Definition: proc.h:37
Thread class encapsulation of pthreads.
Definition: thread.h:46
Fawkes library namespace.