Fawkes API  Fawkes Development Version
gazsim_comm_thread.h
1 /***************************************************************************
2  * gazsim_comm_plugin.cpp - Plugin simulates peer-to-peer communication over
3  * an network with configurable instability and manages
4  * the frowarding of messages to different ports on
5  * the same machine.
6  *
7  * Created: Thu Sep 12 11:07:43 2013
8  * Copyright 2013 Frederik Zwilling
9  *
10  ****************************************************************************/
11 
12 /* This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Library General Public License for more details.
21  *
22  * Read the full text in the LICENSE.GPL file in the doc directory.
23  */
24 
25 #ifndef __PLUGINS_GAZSIM_COMM_COMM_THREAD_H_
26 #define __PLUGINS_GAZSIM_COMM_COMM_THREAD_H_
27 
28 #include <core/threading/thread.h>
29 #include <aspect/logging.h>
30 #include <aspect/configurable.h>
31 #include <aspect/blocked_timing.h>
32 #include <boost/asio.hpp>
33 #include <google/protobuf/message.h>
34 #include <protobuf_comm/peer.h>
35 #include <protobuf_comm/message_register.h>
36 #include <list>
37 
38 
39 namespace protobuf_comm {
40  class ProtobufStreamClient;
41 }
42 
44 : public fawkes::Thread,
48 {
49  public:
52 
53  virtual void init();
54  virtual void loop();
55  virtual void finalize();
56 
57  void receive_msg(boost::asio::ip::udp::endpoint &endpoint,
58  uint16_t component_id, uint16_t msg_type,
59  std::shared_ptr<google::protobuf::Message> msg);
60  void receive_raw_msg(boost::asio::ip::udp::endpoint &endpoint,
61  protobuf_comm::frame_header_t &header, void * data,
62  size_t length);
63 
64  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
65  protected: virtual void run() { Thread::run(); }
66 
67  private:
68  std::vector<protobuf_comm::ProtobufBroadcastPeer*> peers_;
69  std::vector<protobuf_comm::ProtobufBroadcastPeer*> peers_crypto1_;
70  std::vector<protobuf_comm::ProtobufBroadcastPeer*> peers_crypto2_;
71 
72  //config values
73  std::vector<std::string> addresses_;
74  std::vector<unsigned int> send_ports_;
75  std::vector<unsigned int> recv_ports_;
76  std::vector<unsigned int> send_ports_crypto1_;
77  std::vector<unsigned int> recv_ports_crypto1_;
78  std::vector<unsigned int> send_ports_crypto2_;
79  std::vector<unsigned int> recv_ports_crypto2_;
80 
81  bool use_crypto1_, use_crypto2_;
82 
83  std::vector<std::string> proto_dirs_;
84  double package_loss_;
85 
86  //helper variables
87  bool initialized_;
88 };
89 
90 #endif
Thread class encapsulation of pthreads.
Definition: thread.h:42
Network framing header.
Definition: frame_header.h:74
Plugin simulates and manages communication for Simulation in Gazebo.
Thread aspect to use blocked timing.
Thread aspect to log output.
Definition: logging.h:35
Thread aspect to access configuration data.
Definition: configurable.h:35
virtual void run()
Stub to see name in backtrace for easier debugging.