22 #include "gex_receiver_thread.h" 24 #include "TestMessage.pb.h" 35 :
Thread(
"GossipExampleReceiverThread",
Thread::OPMODE_WAITFORWAKEUP),
52 gossip_group->message_register().add_message_type<gossip_example::TestMessage>();
53 }
catch (std::runtime_error &e) {}
57 .connect(boost::bind(&GossipExampleReceiverThread::handle_peer_msg,
this, _1, _2, _3, _4));
59 sig_recv_error_conn_ =
61 .connect(boost::bind(&GossipExampleReceiverThread::handle_peer_recv_error,
this, _1, _2));
63 sig_send_error_conn_ =
65 .connect(boost::bind(&GossipExampleReceiverThread::handle_peer_send_error,
this, _1));
72 sig_rcvd_conn_.disconnect();
73 sig_recv_error_conn_.disconnect();
74 sig_send_error_conn_.disconnect();
84 GossipExampleReceiverThread::handle_peer_msg(boost::asio::ip::udp::endpoint &endpoint,
85 uint16_t component_id, uint16_t msg_type,
86 std::shared_ptr<google::protobuf::Message> msg)
88 if (component_id == gossip_example::TestMessage::COMP_ID &&
89 msg_type == gossip_example::TestMessage::MSG_TYPE)
91 std::shared_ptr<gossip_example::TestMessage> tm =
92 std::dynamic_pointer_cast<gossip_example::TestMessage>(msg);
96 logger->
log_warn(
name(),
"Message with proper component_id and msg_type, but no conversion. " 97 " Wrong component ID/message type to C++ type mapping?");
109 GossipExampleReceiverThread::handle_peer_recv_error(boost::asio::ip::udp::endpoint &endpoint,
113 endpoint.address().to_string().c_str(), endpoint.port(), msg.c_str());
120 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.