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 <aspect/blocked_timing.h>
29 #include <aspect/configurable.h>
30 #include <aspect/logging.h>
31 #include <core/threading/thread.h>
32 #include <google/protobuf/message.h>
33 #include <protobuf_comm/message_register.h>
34 #include <protobuf_comm/peer.h>
35 
36 #include <boost/asio.hpp>
37 #include <list>
38 
39 namespace protobuf_comm {
40 class ProtobufStreamClient;
41 }
42 
47 {
48 public:
51 
52  virtual void init();
53  virtual void loop();
54  virtual void finalize();
55 
56  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
57 protected:
58  virtual void
59  run()
60  {
61  Thread::run();
62  }
63 
64 private:
65  void peer_send_error(std::string address, unsigned int port, std::string err);
66  void receive_raw_msg(boost::asio::ip::udp::endpoint &endpoint,
68  void * data,
69  size_t length);
70 
71 private:
72  std::vector<protobuf_comm::ProtobufBroadcastPeer *> peers_;
73  std::vector<protobuf_comm::ProtobufBroadcastPeer *> peers_crypto1_;
74  std::vector<protobuf_comm::ProtobufBroadcastPeer *> peers_crypto2_;
75 
76  //config values
77  std::vector<std::string> addresses_;
78  std::vector<unsigned int> send_ports_;
79  std::vector<unsigned int> recv_ports_;
80  std::vector<unsigned int> send_ports_crypto1_;
81  std::vector<unsigned int> recv_ports_crypto1_;
82  std::vector<unsigned int> send_ports_crypto2_;
83  std::vector<unsigned int> recv_ports_crypto2_;
84 
85  bool use_crypto1_, use_crypto2_;
86 
87  std::vector<std::string> proto_dirs_;
88  double package_loss_;
89 
90  //helper variables
91  bool initialized_;
92 };
93 
94 #endif
GazsimCommThread
Plugin simulates and manages communication for Simulation in Gazebo.
Definition: gazsim_comm_thread.h:47
fawkes::BlockedTimingAspect
Thread aspect to use blocked timing.
Definition: blocked_timing.h:51
protobuf_comm::frame_header_t
Network framing header.
Definition: frame_header.h:72
fawkes::LoggingAspect
Thread aspect to log output.
Definition: logging.h:33
GazsimCommThread::run
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: gazsim_comm_thread.h:59
GazsimCommThread::loop
virtual void loop()
Code to execute in the thread.
Definition: gazsim_comm_thread.cpp:149
fawkes::Thread
Thread class encapsulation of pthreads.
Definition: thread.h:46
fawkes::ConfigurableAspect
Thread aspect to access configuration data.
Definition: configurable.h:33
GazsimCommThread::finalize
virtual void finalize()
Finalize the thread.
Definition: gazsim_comm_thread.cpp:141
GazsimCommThread::init
virtual void init()
Initialize the thread.
Definition: gazsim_comm_thread.cpp:54