Dripline-Cpp  v2.4.2
Dripline Implementation in C++
hub.hh
Go to the documentation of this file.
1 /*
2  * hub.hh
3  *
4  * Created on: Jan 7, 2016
5  * Author: N.S. Oblath
6  */
7 
8 #ifndef DRIPLINE_HUB_HH_
9 #define DRIPLINE_HUB_HH_
10 
11 #include "service.hh"
12 
13 #include "dripline_exceptions.hh"
14 
15 #include <unordered_map>
16 
17 namespace dripline
18 {
19 
70  class DRIPLINE_API hub : public service
71  {
72  private:
73  typedef std::function< reply_ptr_t( const dripline::request_ptr_t ) > handler_func_t;
74 
75  public:
76  hub( const scarab::param_node& a_config = scarab::param_node(), const std::string& a_queue_name = "", const std::string& a_broker_address = "", unsigned a_port = 0, const std::string& a_auth_file = "" , const bool a_make_connection = true );
77  virtual ~hub();
78 
80  void set_run_handler( const handler_func_t& a_func );
82  void register_get_handler( const std::string& a_key, const handler_func_t& a_func );
84  void register_set_handler( const std::string& a_key, const handler_func_t& a_func );
86  void register_cmd_handler( const std::string& a_key, const handler_func_t& a_func );
87 
89  void remove_get_handler( const std::string& a_key );
91  void remove_set_handler( const std::string& a_key );
93  void remove_cmd_handler( const std::string& a_key );
94 
95  private:
96  //*************************
97  // Hub request distributors
98  //*************************
99 
100  virtual reply_ptr_t do_run_request( const request_ptr_t a_request );
101  virtual reply_ptr_t do_get_request( const request_ptr_t a_request );
102  virtual reply_ptr_t do_set_request( const request_ptr_t a_request );
103  virtual reply_ptr_t do_cmd_request( const request_ptr_t a_request );
104 
105  handler_func_t f_run_handler;
106 
107  typedef std::unordered_map< std::string, handler_func_t > handler_funcs_t;
108  handler_funcs_t f_get_handlers;
109  handler_funcs_t f_set_handlers;
110  handler_funcs_t f_cmd_handlers;
111 
112  };
113 
114 } /* namespace dripline */
115 
116 #endif /* DRIPLINE_HUB_HH_ */
handler_funcs_t f_get_handlers
Definition: hub.hh:108
std::function< reply_ptr_t(const dripline::request_ptr_t) > handler_func_t
Definition: hub.hh:73
std::unordered_map< std::string, handler_func_t > handler_funcs_t
Definition: hub.hh:107
std::shared_ptr< msg_request > request_ptr_t
Definition: dripline_fwd.hh:23
Consumer of Dripline messages on a particular queue.
Definition: service.hh:72
Service class aimed at adding a Dripline API to an existing codebase.
Definition: hub.hh:70
#define DRIPLINE_API
Definition: dripline_api.hh:34
handler_func_t f_run_handler
Definition: hub.hh:105
handler_funcs_t f_set_handlers
Definition: hub.hh:109
std::shared_ptr< msg_reply > reply_ptr_t
Definition: dripline_fwd.hh:24
handler_funcs_t f_cmd_handlers
Definition: hub.hh:110