OGLplus  (0.59.0) a C++ wrapper for rendering APIs

endpoint_info.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_MESSAGE_BUS_SERVICE_ENDPOINT_INFO_HPP
10 #define EAGINE_MESSAGE_BUS_SERVICE_ENDPOINT_INFO_HPP
11 
12 #include "../../bool_aggregate.hpp"
13 #include "../../main_ctx.hpp"
14 #include "../../maybe_unused.hpp"
15 #include "../service.hpp"
16 #include "../types.hpp"
17 #include <array>
18 #include <chrono>
19 
20 namespace eagine::msgbus {
21 //------------------------------------------------------------------------------
22 template <typename Base = subscriber>
23 class endpoint_info_provider : public Base {
24  using This = endpoint_info_provider;
25 
26 protected:
27  using Base::Base;
28 
29  void add_methods() {
30  Base::add_methods();
31 
32  Base::add_method(_respond(
33  EAGINE_MSG_ID(eagiEptInf, response),
34  this,
36  This, _get_endpoint_info))[EAGINE_MSG_ID(eagiEptInf, request)]);
37  }
38 
39 public:
40  virtual auto provide_endpoint_info() -> endpoint_info = 0;
41 
42 private:
43  auto _get_endpoint_info() -> endpoint_info {
44  auto result{provide_endpoint_info()};
45  if(result.app_name.empty()) {
46  result.app_name = main_ctx::get().app_name();
47  }
48  return result;
49  }
50 
51  default_function_skeleton<endpoint_info(), 1024> _respond;
52 };
53 //------------------------------------------------------------------------------
54 template <typename Base = subscriber>
55 class endpoint_info_consumer : public Base {
56 
57  using This = endpoint_info_consumer;
58 
59 protected:
60  using Base::Base;
61 
62  void add_methods() {
63  Base::add_methods();
64 
65  Base::add_method(_info(
66  this,
68  This,
69  on_endpoint_info_received))[EAGINE_MSG_ID(eagiEptInf, response)]);
70  }
71 
72 public:
73  void query_endpoint_info(identifier_t endpoint_id) {
74  _info.invoke_on(
75  this->bus(), endpoint_id, EAGINE_MSG_ID(eagiEptInf, request));
76  }
77 
78  virtual void
79  on_endpoint_info_received(const result_context&, endpoint_info&&) = 0;
80 
81 private:
82  default_callback_invoker<endpoint_info(), 1024> _info;
83 };
84 //------------------------------------------------------------------------------
85 } // namespace eagine::msgbus
86 
87 #endif // EAGINE_MESSAGE_BUS_SERVICE_ENDPOINT_INFO_HPP
#define EAGINE_MSG_ID(API, NAME)
Macro for instantiating objects of static_message_id.
Definition: message_id.hpp:148
@ endpoint_info
The endpoint information has appeared or changed.
Message bus code is placed in this namespace.
Definition: eagine.hpp:58
std::uint64_t identifier_t
The underlying integer type for eagine::identifier.
Definition: identifier_t.hpp:19
auto bus() noexcept -> auto &
Returns a reference to the associated endpoint.
Definition: subscriber.hpp:38
static auto get() noexcept -> main_ctx &
Returns the single instance.
Definition: main_ctx.hpp:64
#define EAGINE_MEM_FUNC_C(CLASS, FUNC)
Macro for creating object of member_function_constant.
Definition: mem_func_const.hpp:186

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).