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 <protobuf_comm/peer.h>
27 
28 #include <google/protobuf/message.h>
29 
30 #include <boost/asio.hpp>
31 #include <boost/signals2.hpp>
32 #include <memory>
33 
34 namespace protobuf_comm {
35  class ProtobufBroadcastPeer;
36 }
37 
38 namespace fawkes {
39 #if 0 /* just to make Emacs auto-indent happy */
40 }
41 #endif
42 
43 class ServicePublisher;
44 class NetworkService;
45 
46 class GossipGroup {
47  friend class GossipGroupManager;
48  public:
49  ~GossipGroup();
50 
51  void send(std::string &peer,
52  google::protobuf::Message &m);
53 
54  void broadcast(google::protobuf::Message &m);
55 
56 
57 
58  /** Get the protobuf message register.
59  * @return message register */
61  { return pb_peer_->message_register(); }
62 
63  /** Signal that is invoked when a message has been received.
64  * @return signal */
65  boost::signals2::signal<void (boost::asio::ip::udp::endpoint &, uint16_t, uint16_t,
66  std::shared_ptr<google::protobuf::Message>)> &
68  { return pb_peer_->signal_received(); }
69 
70  /** Signal that is invoked when receiving a message failed.
71  * @return signal */
72  boost::signals2::signal<void (boost::asio::ip::udp::endpoint &, std::string)> &
74  { return pb_peer_->signal_recv_error(); }
75 
76  /** Signal that is invoked when sending a message failed.
77  * @return signal */
78  boost::signals2::signal<void (std::string)> &
80  { return pb_peer_->signal_send_error(); }
81 
82  /** Get group name.
83  * @return group name. */
84  const std::string & name() const { return name_; }
85 
86  /** Get Protobuf broadcast peer.
87  * @return protobuf broadcast peer. */
88  std::shared_ptr<protobuf_comm::ProtobufBroadcastPeer> peer() const
89  { return pb_peer_; }
90 
91  private:
92  GossipGroup(std::string &group_name, std::string &peer_name,
93  std::string &broadcast_address, unsigned short broadcast_port,
94  ServicePublisher *service_publisher,
95  const std::string &crypto_key, const std::string &crypto_cipher);
96 
97  GossipGroup(std::string &group_name, std::string &peer_name,
98  std::string &broadcast_address,
99  unsigned short send_port, unsigned short recv_port,
100  ServicePublisher *service_publisher,
101  const std::string &crypto_key, const std::string &crypto_cipher);
102 
103  private:
104  std::string name_;
105 
106  ServicePublisher *service_publisher_;
107  std::shared_ptr<NetworkService> service_;
108  std::shared_ptr<protobuf_comm::ProtobufBroadcastPeer> pb_peer_;
109 };
110 
111 
112 } // end namespace fawkes
113 
114 
115 #endif
Service publisher interface.
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:67
Fawkes library namespace.
std::shared_ptr< protobuf_comm::ProtobufBroadcastPeer > peer() const
Get Protobuf broadcast peer.
Definition: gossip_group.h:88
Register to map msg type numbers to Protobuf messages.
const std::string & name() const
Get group name.
Definition: gossip_group.h:84
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:73
Gossip group communication handler.
Definition: gossip_group.h:46
Abstract class for a Gossip group manager.
protobuf_comm::MessageRegister & message_register()
Get the protobuf message register.
Definition: gossip_group.h:60
boost::signals2::signal< void(std::string)> & signal_send_error()
Signal that is invoked when sending a message failed.
Definition: gossip_group.h:79