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

host_info.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_MESSAGE_BUS_SERVICE_HOST_INFO_HPP
10 #define EAGINE_MESSAGE_BUS_SERVICE_HOST_INFO_HPP
11 
12 #include "../../bool_aggregate.hpp"
13 #include "../../main_ctx.hpp"
14 #include "../../maybe_unused.hpp"
15 #include "../service.hpp"
16 #include <array>
17 #include <chrono>
18 
19 namespace eagine::msgbus {
20 //------------------------------------------------------------------------------
21 template <typename Base = subscriber>
22 class host_info_provider : public Base {
23  using This = host_info_provider;
24 
25 protected:
26  using Base::Base;
27 
28  void add_methods() {
29  Base::add_methods();
30 
31  Base::add_method(_host_id(
32  EAGINE_MSG_ID(eagiSysInf, hostId),
33  &main_ctx::get().system(),
35  system_info, host_id))[EAGINE_MSG_ID(eagiSysInf, rqHostId)]);
36 
37  Base::add_method(_hostname(
38  EAGINE_MSG_ID(eagiSysInf, hostname),
39  &main_ctx::get().system(),
41  system_info, hostname))[EAGINE_MSG_ID(eagiSysInf, rqHostname)]);
42  }
43 
44 private:
45  default_function_skeleton<valid_if_positive<host_id_t>() noexcept, 64>
46  _host_id;
47 
48  default_function_skeleton<valid_if_not_empty<std::string>() noexcept, 1024>
49  _hostname;
50 };
51 //------------------------------------------------------------------------------
52 template <typename Base = subscriber>
53 class host_info_consumer : public Base {
54 
55  using This = host_info_consumer;
56 
57 protected:
58  using Base::Base;
59 
60  void add_methods() {
61  Base::add_methods();
62 
63  Base::add_method(_host_id(
64  this,
66  on_host_id_received))[EAGINE_MSG_ID(eagiSysInf, hostId)]);
67 
68  Base::add_method(_hostname(
69  this,
71  on_hostname_received))[EAGINE_MSG_ID(eagiSysInf, hostname)]);
72  }
73 
74 public:
75  void query_host_id(identifier_t endpoint_id) {
76  _host_id.invoke_on(
77  this->bus(), endpoint_id, EAGINE_MSG_ID(eagiSysInf, rqHostId));
78  }
79 
80  virtual void on_host_id_received(
81  const result_context&,
82  valid_if_positive<host_id_t>&&) = 0;
83 
84  void query_hostname(identifier_t endpoint_id) {
85  _hostname.invoke_on(
86  this->bus(), endpoint_id, EAGINE_MSG_ID(eagiSysInf, rqHostname));
87  }
88 
89  virtual void on_hostname_received(
90  const result_context&,
91  valid_if_not_empty<std::string>&&) {}
92 
93 private:
94  default_callback_invoker<valid_if_positive<host_id_t>(), 32> _host_id;
95 
96  default_callback_invoker<valid_if_not_empty<std::string>(), 1024> _hostname;
97 };
98 //------------------------------------------------------------------------------
99 } // namespace eagine::msgbus
100 
101 #endif // EAGINE_MESSAGE_BUS_SERVICE_HOST_INFO_HPP
#define EAGINE_MSG_ID(API, NAME)
Macro for instantiating objects of static_message_id.
Definition: message_id.hpp:148
Message bus code is placed in this namespace.
Definition: eagine.hpp:58
#define EAGINE_THIS_MEM_FUNC_C(FUNC)
Macro for creating object of member_function_constant in member functions.
Definition: mem_func_const.hpp:206
valid_if< T, valid_if_not_empty_policy< T > > valid_if_not_empty
Specialization of valid_if, for values valid if not empty.
Definition: not_empty.hpp:42
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).