4 #include <boost/shared_ptr.hpp> 5 #include <boost/asio.hpp> 6 #include <boost/make_shared.hpp> 7 #include <boost/any.hpp> 8 #include <boost/system/error_code.hpp> 9 #include <boost/function.hpp> 10 #include <boost/enable_shared_from_this.hpp> 11 #include <boost/chrono.hpp> 12 #include <boost/asio/waitable_timer_service.hpp> 13 #include <boost/thread.hpp> 16 #include "gtest/gtest.h" 52 typedef boost::asio::basic_waitable_timer<boost::chrono::steady_clock>
steady_timer;
59 class DpyMwClient:
public boost::enable_shared_from_this<DpyMwClient>
72 std::condition_variable mCv;
73 boost::asio::io_service mIo;
78 boost::shared_ptr<DpyMwSubscriber> m_subscriber;
79 boost::shared_ptr<DpyMwDealer> m_dealer;
80 int lastMessageID = 0;
81 std::map<int, Global_config> m_map_dealerHandlers;
82 std::map<int, std::vector<boost::any>> m_map_subscriberHandlers;
97 void sendRequest(
int requestType,
int responseType, std::string content, boost::any handler,
int ms_timeout = 2000);
101 virtual void RegisterCallbacks()=0;
107 DpyMwClient(std::string& ip,
int dport,
int sport);
111 void subscribe(
int messageType, boost::any handler);
112 void unsubscribe(
int messageType);
115 void monitorServiceAvailability_U();
119 void dealer_handler(
const std::string &msg);
120 void dealerTimer_handler(
const boost::system::error_code& e);
121 void heartbeatTimer_handler(
const boost::system::error_code& e);
122 void subscriber_handler(
const std::string &msg);
126 FRIEND_TEST(Client_dealer_test, Request_timeout);
127 FRIEND_TEST(Client_dealer_test, Request_answered);
Subscriber class.
Definition: dpyMwSubscriber.h:27
boost::asio::basic_waitable_timer< boost::chrono::steady_clock > steady_timer
Typedef to use a steady timer.
Definition: dpyMwClient.h:52
std::map< uint64_t, f_proto_message_client > map_proto_register_client
Map to keep functions with a type of message associated.
Definition: dpyMwClient.h:43
boost::function< void(const std::string &, boost::any, int)> f_proto_message_client
Prototype of the function to call depending on the message received.
Definition: dpyMwClient.h:36
std::mutex m_map_mutex
Definition: dpyMwClient.h:105
Dealer class.
Definition: dpyMwDealer.h:27
map_proto_register_client m_register_map
Definition: dpyMwClient.h:95
boost::function< void(const bool &alive)> f_hearbeat_handler
Prototype of the handler function used to keep track of service availability.
Definition: dpyMwClient.h:50
Manages dealer and susbriber.
Definition: dpyMwClient.h:59
ServiceState
Service states.
Definition: dpyMwClient.h:24