Fawkes API Fawkes Development Version
openprs_comm.h
1
2/***************************************************************************
3 * openprs_comm.h - OpenPRS communication wrapper for Fawkes
4 *
5 * Created: Mon Aug 18 14:33:55 2014
6 * Copyright 2014 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. A runtime exception applies to
13 * this software (see LICENSE.GPL_WRE file mentioned below for details).
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
19 *
20 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
21 */
22
23#ifndef _PLUGINS_OPENPRS_ASPECT_OPENPRS_COMM_H_
24#define _PLUGINS_OPENPRS_ASPECT_OPENPRS_COMM_H_
25
26#include <boost/asio.hpp>
27#include <boost/signals2.hpp>
28#include <string>
29#include <thread>
30#include <vector>
31
32namespace fawkes {
33
34class OpenPRSServerProxy;
35class Logger;
36
38{
39public:
40 OpenPRSComm(const char * local_name,
41 const char * hostname,
42 unsigned short port,
43 OpenPRSServerProxy *server_proxy,
44 Logger * logger = NULL);
45 virtual ~OpenPRSComm();
46
47 /** Get OpenPRS local name.
48 * @return OpenPRS local name */
49 const std::string &
50 name() const
51 {
52 return name_;
53 }
54
55 void send_message(const char *recipient, const char *message);
56 void broadcast_message(const char *message);
57 void multicast_message(std::vector<const char *> &recipients, const char *message);
58
59 void send_message(const std::string &recipient, const std::string &message);
60 void broadcast_message(const std::string &message);
61 void multicast_message(const std::vector<std::string> &recipients, const std::string &message);
62
63 void send_message_f(const std::string &recipient, const char *format, ...);
64 void broadcast_message_f(const char *format, ...);
65 void multicast_message_f(const std::vector<std::string> &recipients, const char *format, ...);
66
67 void transmit_command(const char *recipient, const char *message);
68 void transmit_command(const std::string &recipient, const std::string &message);
69 void transmit_command_f(const std::string &recipient, const char *format, ...);
70
71 /** Boost signal for a received message. */
72 typedef boost::signals2::signal<void(std::string, std::string)> signal_msg_rcvd_type;
73
74 /** Signal that is invoked when a message has been received.
75 * @return signal
76 */
79 {
80 return sig_rcvd_;
81 }
82
83private: // methods
84 void start_recv();
85 void handle_recv(const boost::system::error_code &err);
86 std::string read_string_from_socket(boost::asio::posix::stream_descriptor &socket);
87
88private: // members
89 const std::string name_;
90 int mp_socket_;
91 OpenPRSServerProxy *server_proxy_;
92 Logger * logger_;
93
94 boost::asio::io_service io_service_;
95 std::thread io_service_thread_;
96 boost::asio::io_service::work io_service_work_;
97 boost::asio::posix::stream_descriptor sd_mp_socket_;
98
99 signal_msg_rcvd_type sig_rcvd_;
100};
101
102} // end namespace fawkes
103
104#endif
Interface for logging.
Definition: logger.h:42
OpenPRS communication wrapper.
Definition: openprs_comm.h:38
void transmit_command(const char *recipient, const char *message)
Transmit a command to an OpenPRS kernel.
const std::string & name() const
Get OpenPRS local name.
Definition: openprs_comm.h:50
void multicast_message(std::vector< const char * > &recipients, const char *message)
Send a message to multiple OpenPRS kernel.
signal_msg_rcvd_type & signal_msg_rcvd()
Signal that is invoked when a message has been received.
Definition: openprs_comm.h:78
void multicast_message_f(const std::vector< std::string > &recipients, const char *format,...)
Send a message to multiple OpenPRS kernel.
virtual ~OpenPRSComm()
Destructor.
void broadcast_message_f(const char *format,...)
Send a formatted message to all OpenPRS kernels.
void transmit_command_f(const std::string &recipient, const char *format,...)
Transmit a command to an OpenPRS kernel.
void broadcast_message(const char *message)
Send a message to all OpenPRS kernels.
void send_message_f(const std::string &recipient, const char *format,...)
Send a formatted message to an OpenPRS kernel.
OpenPRSComm(const char *local_name, const char *hostname, unsigned short port, OpenPRSServerProxy *server_proxy, Logger *logger=NULL)
Constructor.
boost::signals2::signal< void(std::string, std::string)> signal_msg_rcvd_type
Boost signal for a received message.
Definition: openprs_comm.h:72
void send_message(const char *recipient, const char *message)
Send a message to an OpenPRS kernel.
Proxy for the OpenPRS server communication.
Fawkes library namespace.