Fawkes API Fawkes Development Version
gossip_group.h
1
2/***************************************************************************
3 * gossip_group.h - Robot Group Communication - Gossip Group
4 *
5 * Created: Tue Mar 04 10:56:48 2014
6 * Copyright 2006-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_GOSSIP_GOSSIP_GOSSIP_GROUP_H_
24#define _PLUGINS_GOSSIP_GOSSIP_GOSSIP_GROUP_H_
25
26#include <google/protobuf/message.h>
27#include <protobuf_comm/peer.h>
28
29#include <boost/asio.hpp>
30#include <boost/signals2.hpp>
31#include <memory>
32
33namespace protobuf_comm {
34class ProtobufBroadcastPeer;
35}
36
37namespace fawkes {
38
39class ServicePublisher;
40class NetworkService;
41class GossipGroupManager;
42
44{
45 friend GossipGroupManager;
46
47public:
49
50 void send(std::string &peer, google::protobuf::Message &m);
51
52 void broadcast(google::protobuf::Message &m);
53
54 /** Get the protobuf message register.
55 * @return message register */
56 protobuf_comm::MessageRegister &
58 {
59 return pb_peer_->message_register();
60 }
61
62 /** Signal that is invoked when a message has been received.
63 * @return signal */
64 boost::signals2::signal<void(boost::asio::ip::udp::endpoint &,
65 uint16_t,
66 uint16_t,
67 std::shared_ptr<google::protobuf::Message>)> &
69 {
70 return pb_peer_->signal_received();
71 }
72
73 /** Signal that is invoked when receiving a message failed.
74 * @return signal */
75 boost::signals2::signal<void(boost::asio::ip::udp::endpoint &, std::string)> &
77 {
78 return pb_peer_->signal_recv_error();
79 }
80
81 /** Signal that is invoked when sending a message failed.
82 * @return signal */
83 boost::signals2::signal<void(std::string)> &
85 {
86 return pb_peer_->signal_send_error();
87 }
88
89 /** Get group name.
90 * @return group name. */
91 const std::string &
92 name() const
93 {
94 return name_;
95 }
96
97 /** Get Protobuf broadcast peer.
98 * @return protobuf broadcast peer. */
99 std::shared_ptr<protobuf_comm::ProtobufBroadcastPeer>
100 peer() const
101 {
102 return pb_peer_;
103 }
104
105private:
106 GossipGroup(std::string & group_name,
107 std::string & peer_name,
108 std::string & broadcast_address,
109 unsigned short broadcast_port,
110 ServicePublisher * service_publisher,
111 const std::string &crypto_key,
112 const std::string &crypto_cipher);
113
114 GossipGroup(std::string & group_name,
115 std::string & peer_name,
116 std::string & broadcast_address,
117 unsigned short send_port,
118 unsigned short recv_port,
119 ServicePublisher * service_publisher,
120 const std::string &crypto_key,
121 const std::string &crypto_cipher);
122
123private:
124 std::string name_;
125
126 ServicePublisher * service_publisher_;
127 std::shared_ptr<NetworkService> service_;
128 std::shared_ptr<protobuf_comm::ProtobufBroadcastPeer> pb_peer_;
129};
130
131} // end namespace fawkes
132
133#endif
Abstract class for a Gossip group manager.
Gossip group communication handler.
Definition: gossip_group.h:44
boost::signals2::signal< void(boost::asio::ip::udp::endpoint &, std::string)> & signal_recv_error()
Signal that is invoked when receiving a message failed.
Definition: gossip_group.h:76
boost::signals2::signal< void(std::string)> & signal_send_error()
Signal that is invoked when sending a message failed.
Definition: gossip_group.h:84
const std::string & name() const
Get group name.
Definition: gossip_group.h:92
~GossipGroup()
Destructor.
boost::signals2::signal< void(boost::asio::ip::udp::endpoint &, uint16_t, uint16_t, std::shared_ptr< google::protobuf::Message >)> & signal_received()
Signal that is invoked when a message has been received.
Definition: gossip_group.h:68
protobuf_comm::MessageRegister & message_register()
Get the protobuf message register.
Definition: gossip_group.h:57
void broadcast(google::protobuf::Message &m)
Broadcast a message to all peers in the group.
void send(std::string &peer, google::protobuf::Message &m)
Send a message.
std::shared_ptr< protobuf_comm::ProtobufBroadcastPeer > peer() const
Get Protobuf broadcast peer.
Definition: gossip_group.h:100
Service publisher interface.
Fawkes library namespace.