dpyMwServer.h
Go to the documentation of this file.
1 
4 #pragma once
5 #include <boost/shared_ptr.hpp>
6 #include <boost/asio.hpp>
7 #include <boost/make_shared.hpp>
8 #include <boost/any.hpp>
9 #include <boost/system/error_code.hpp>
10 #include <boost/function.hpp>
11 #include <boost/enable_shared_from_this.hpp>
12 #include <boost/chrono.hpp>
13 #include <boost/asio/waitable_timer_service.hpp>
14 #include <boost/thread.hpp>
15 
16 // The forward reference.
17 class DpyMwPublisher;
18 class DpyMwRouter;
19 
20 
28 typedef boost::function<void(const std::string&, const std::string&, int)> f_proto_message_server;
29 
35 typedef std::map<uint64_t, f_proto_message_server> map_proto_register_server;
36 
37 typedef boost::asio::basic_waitable_timer<boost::chrono::steady_clock> steady_timer;
38 
44 class DpyMwServer: public boost::enable_shared_from_this<DpyMwServer>
45 {
46 
50  struct Global_config
51  {
52  int time_count;
53  int period;
54  int response_type;
55  };
56 
57 private:
58  boost::asio::io_service publisherIo;
59 
60  bool m_working;
61  steady_timer m_publisherTimer;
62  steady_timer m_heartbeatTimer;
63  int timerCounter;
64  boost::shared_ptr<DpyMwPublisher> m_publisher;
65  boost::shared_ptr<DpyMwRouter> m_router;
66  int lastPublisherID = 0;
67  std::map<int, Global_config> m_map_publishers;
71  boost::thread bt;
72 
73 protected:
77  boost::asio::io_service& mIo;
86  void sendResponse(int messageType, std::string content, const std::string& id_dealer, int msgId, boost::system::error_code &ec);
87  void sendPublication(int messageType, std::string content, boost::system::error_code &ec);
91  virtual void RegisterCallbacks()=0;
95  virtual void RegisterPublications()=0;
99  std::mutex m_map_mutex;
100 
101 public:
102  explicit DpyMwServer(boost::asio::io_service& io, int rport, int pport);
103  virtual ~DpyMwServer();
104  void start();
105  void stop();
106  void publish(int messageType, int frecuency);
107 
108 private:
109  void router_handler(const std::string &id, const std::string &payload);
110  void publisherTimer_handler(const boost::system::error_code& e);
111  void heartbeatTimer_handler(const boost::system::error_code& e);
112 
113 };
std::map< uint64_t, f_proto_message_server > map_proto_register_server
Map to keep functions with a type of message associated.
Definition: dpyMwServer.h:35
virtual void RegisterPublications()=0
boost::function< void(const std::string &, const std::string &, int)> f_proto_message_server
Lambda function to be called depending on the message received.
Definition: dpyMwServer.h:28
boost::asio::basic_waitable_timer< boost::chrono::steady_clock > steady_timer
Typedef to use a steady timer.
Definition: dpyMwClient.h:52
Router class.
Definition: dpyMwRouter.h:26
Manages router and publisher.
Definition: dpyMwServer.h:44
map_proto_register_server m_publisher_map
Definition: dpyMwServer.h:85
boost::asio::io_service & mIo
Definition: dpyMwServer.h:77
virtual void RegisterCallbacks()=0
map_proto_register_server m_register_map
Definition: dpyMwServer.h:81
std::mutex m_map_mutex
Definition: dpyMwServer.h:99
Publisher class.
Definition: dpyMwPublisher.h:27
boost::asio::basic_waitable_timer< boost::chrono::steady_clock > steady_timer
Typedef to use a steady timer.
Definition: dpyMwServer.h:37