22 #include "gex_receiver_thread.h" 24 #include "TestMessage.pb.h" 35 :
Thread(
"GossipExampleReceiverThread",
Thread::OPMODE_WAITFORWAKEUP),
50 gossip_group->message_register().add_message_type<gossip_example::TestMessage>();
51 }
catch (std::runtime_error &e) {
54 sig_rcvd_conn_ =
gossip_group->signal_received().connect(
55 boost::bind(&GossipExampleReceiverThread::handle_peer_msg,
this, _1, _2, _3, _4));
57 sig_recv_error_conn_ =
gossip_group->signal_recv_error().connect(
58 boost::bind(&GossipExampleReceiverThread::handle_peer_recv_error,
this, _1, _2));
60 sig_send_error_conn_ =
gossip_group->signal_send_error().connect(
61 boost::bind(&GossipExampleReceiverThread::handle_peer_send_error,
this, _1));
67 sig_rcvd_conn_.disconnect();
68 sig_recv_error_conn_.disconnect();
69 sig_send_error_conn_.disconnect();
78 GossipExampleReceiverThread::handle_peer_msg(boost::asio::ip::udp::endpoint &endpoint,
79 uint16_t component_id,
81 std::shared_ptr<google::protobuf::Message> msg)
83 if (component_id == gossip_example::TestMessage::COMP_ID
84 && msg_type == gossip_example::TestMessage::MSG_TYPE) {
85 std::shared_ptr<gossip_example::TestMessage> tm =
86 std::dynamic_pointer_cast<gossip_example::TestMessage>(msg);
91 "Message with proper component_id and msg_type, but no conversion. " 92 " Wrong component ID/message type to C++ type mapping?");
104 GossipExampleReceiverThread::handle_peer_recv_error(boost::asio::ip::udp::endpoint &endpoint,
108 "Failed to receive peer message from %s:%u: %s",
109 endpoint.address().to_string().c_str(),
118 GossipExampleReceiverThread::handle_peer_send_error(std::string msg)
virtual void log_info(const char *component, const char *format,...)=0
Log informational message.
Fawkes library namespace.
virtual void loop()
Code to execute in the thread.
Thread class encapsulation of pthreads.
Thread aspect to communicate with a group of robots.
virtual void init()
Initialize the thread.
virtual ~GossipExampleReceiverThread()
Destructor.
Logger * logger
This is the Logger member used to access the logger.
Thread aspect to use blocked timing.
RefPtr< GossipGroup > gossip_group
Gossip group to communicate with other robots.
const char * name() const
Get name of thread.
virtual void log_warn(const char *component, const char *format,...)=0
Log warning message.
GossipExampleReceiverThread()
Constructor.
virtual void finalize()
Finalize the thread.