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

system_info.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_MESSAGE_BUS_SERVICE_SYSTEM_INFO_HPP
10 #define EAGINE_MESSAGE_BUS_SERVICE_SYSTEM_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 system_info_provider : public Base {
23 
24 protected:
25  using Base::Base;
26 
27  void add_methods() {
28  Base::add_methods();
29 
30  Base::add_method(_uptime(
31  EAGINE_MSG_ID(eagiSysInf, uptime),
32  &main_ctx::get().system(),
34  system_info, uptime))[EAGINE_MSG_ID(eagiSysInf, rqUptime)]);
35 
36  Base::add_method(_cpu_concurrent_threads(
37  EAGINE_MSG_ID(eagiSysInf, cpuThreads),
38  &main_ctx::get().system(),
40  system_info,
41  cpu_concurrent_threads))[EAGINE_MSG_ID(eagiSysInf, rqCpuThrds)]);
42 
43  Base::add_method(_short_average_load(
44  EAGINE_MSG_ID(eagiSysInf, shortLoad),
45  &main_ctx::get().system(),
47  system_info,
48  short_average_load))[EAGINE_MSG_ID(eagiSysInf, rqShrtLoad)]);
49 
50  Base::add_method(_long_average_load(
51  EAGINE_MSG_ID(eagiSysInf, longLoad),
52  &main_ctx::get().system(),
54  system_info,
55  long_average_load))[EAGINE_MSG_ID(eagiSysInf, rqLongLoad)]);
56 
57  Base::add_method(_memory_page_size(
58  EAGINE_MSG_ID(eagiSysInf, memPageSz),
59  &main_ctx::get().system(),
61  system_info,
62  memory_page_size))[EAGINE_MSG_ID(eagiSysInf, rqMemPgSz)]);
63 
64  Base::add_method(_free_ram_size(
65  EAGINE_MSG_ID(eagiSysInf, freeRamSz),
66  &main_ctx::get().system(),
68  system_info,
69  free_ram_size))[EAGINE_MSG_ID(eagiSysInf, rqFreRamSz)]);
70 
71  Base::add_method(_total_ram_size(
72  EAGINE_MSG_ID(eagiSysInf, totalRamSz),
73  &main_ctx::get().system(),
75  system_info,
76  total_ram_size))[EAGINE_MSG_ID(eagiSysInf, rqTtlRamSz)]);
77 
78  Base::add_method(_free_swap_size(
79  EAGINE_MSG_ID(eagiSysInf, freeSwpSz),
80  &main_ctx::get().system(),
82  system_info,
83  free_swap_size))[EAGINE_MSG_ID(eagiSysInf, rqFreSwpSz)]);
84 
85  Base::add_method(_total_swap_size(
86  EAGINE_MSG_ID(eagiSysInf, totalSwpSz),
87  &main_ctx::get().system(),
89  system_info,
90  total_swap_size))[EAGINE_MSG_ID(eagiSysInf, rqTtlSwpSz)]);
91  }
92 
93 private:
94  default_function_skeleton<std::chrono::duration<float>() noexcept, 32>
95  _uptime;
96 
97  default_function_skeleton<valid_if_positive<span_size_t>() noexcept, 32>
98  _cpu_concurrent_threads;
99 
100  default_function_skeleton<valid_if_nonnegative<float>() noexcept, 32>
101  _short_average_load;
102 
103  default_function_skeleton<valid_if_nonnegative<float>() noexcept, 32>
104  _long_average_load;
105 
106  default_function_skeleton<valid_if_positive<span_size_t>() noexcept, 32>
107  _memory_page_size;
108 
109  default_function_skeleton<valid_if_positive<span_size_t>() noexcept, 32>
110  _free_ram_size;
111 
112  default_function_skeleton<valid_if_positive<span_size_t>() noexcept, 32>
113  _total_ram_size;
114 
115  default_function_skeleton<valid_if_nonnegative<span_size_t>() noexcept, 32>
116  _free_swap_size;
117 
118  default_function_skeleton<valid_if_nonnegative<span_size_t>() noexcept, 32>
119  _total_swap_size;
120 };
121 //------------------------------------------------------------------------------
122 template <typename Base = subscriber>
123 class system_info_consumer : public Base {
124 
125 protected:
126  using Base::Base;
127 
128  void add_methods() {
129  Base::add_methods();
130 
131  Base::add_method(_uptime(
132  this,
134  on_uptime_received))[EAGINE_MSG_ID(eagiSysInf, uptime)]);
135 
136  Base::add_method(_cpu_concurrent_threads(
137  this, EAGINE_THIS_MEM_FUNC_C(on_cpu_concurrent_threads_received))
138  [EAGINE_MSG_ID(eagiSysInf, cpuThreads)]);
139 
140  Base::add_method(_short_average_load(
141  this,
142  EAGINE_THIS_MEM_FUNC_C(on_short_average_load_received))[EAGINE_MSG_ID(
143  eagiSysInf, shortLoad)]);
144 
145  Base::add_method(_long_average_load(
146  this,
147  EAGINE_THIS_MEM_FUNC_C(on_long_average_load_received))[EAGINE_MSG_ID(
148  eagiSysInf, longLoad)]);
149 
150  Base::add_method(_memory_page_size(
151  this,
152  EAGINE_THIS_MEM_FUNC_C(on_memory_page_size_received))[EAGINE_MSG_ID(
153  eagiSysInf, memPageSz)]);
154 
155  Base::add_method(_free_ram_size(
156  this,
158  on_free_ram_size_received))[EAGINE_MSG_ID(eagiSysInf, freeRamSz)]);
159 
160  Base::add_method(_total_ram_size(
161  this,
163  on_total_ram_size_received))[EAGINE_MSG_ID(eagiSysInf, totalRamSz)]);
164 
165  Base::add_method(_free_swap_size(
166  this,
168  on_free_swap_size_received))[EAGINE_MSG_ID(eagiSysInf, freeSwpSz)]);
169 
170  Base::add_method(_total_swap_size(
171  this,
172  EAGINE_THIS_MEM_FUNC_C(on_total_swap_size_received))[EAGINE_MSG_ID(
173  eagiSysInf, totalSwpSz)]);
174  }
175 
176 public:
177  void query_uptime(identifier_t endpoint_id) {
178  _uptime.invoke_on(
179  this->bus(), endpoint_id, EAGINE_MSG_ID(eagiSysInf, rqUptime));
180  }
181 
182  virtual void
183  on_uptime_received(const result_context&, std::chrono::duration<float>&&) {}
184 
185  void query_cpu_concurrent_threads(identifier_t endpoint_id) {
186  _cpu_concurrent_threads.invoke_on(
187  this->bus(), endpoint_id, EAGINE_MSG_ID(eagiSysInf, rqCpuThrds));
188  }
189 
190  virtual void on_cpu_concurrent_threads_received(
191  const result_context&,
192  valid_if_positive<span_size_t>&&) {}
193 
194  void query_short_average_load(identifier_t endpoint_id) {
195  _short_average_load.invoke_on(
196  this->bus(), endpoint_id, EAGINE_MSG_ID(eagiSysInf, rqShrtLoad));
197  }
198 
199  virtual void on_short_average_load_received(
200  const result_context&,
201  valid_if_nonnegative<float>&&) {}
202 
203  void query_long_average_load(identifier_t endpoint_id) {
204  _long_average_load.invoke_on(
205  this->bus(), endpoint_id, EAGINE_MSG_ID(eagiSysInf, rqLongLoad));
206  }
207 
208  virtual void on_long_average_load_received(
209  const result_context&,
210  valid_if_nonnegative<float>&&) {}
211 
212  void query_memory_page_size(identifier_t endpoint_id) {
213  _memory_page_size.invoke_on(
214  this->bus(), endpoint_id, EAGINE_MSG_ID(eagiSysInf, rqMemPgSz));
215  }
216 
217  virtual void on_memory_page_size_received(
218  const result_context&,
219  valid_if_positive<span_size_t>&&) {}
220 
221  void query_free_ram_size(identifier_t endpoint_id) {
222  _free_ram_size.invoke_on(
223  this->bus(), endpoint_id, EAGINE_MSG_ID(eagiSysInf, rqFreRamSz));
224  }
225 
226  virtual void on_free_ram_size_received(
227  const result_context&,
228  valid_if_positive<span_size_t>&&) {}
229 
230  void query_total_ram_size(identifier_t endpoint_id) {
231  _total_ram_size.invoke_on(
232  this->bus(), endpoint_id, EAGINE_MSG_ID(eagiSysInf, rqTtlRamSz));
233  }
234 
235  virtual void on_total_ram_size_received(
236  const result_context&,
237  valid_if_positive<span_size_t>&&) {}
238 
239  void query_free_swap_size(identifier_t endpoint_id) {
240  _free_swap_size.invoke_on(
241  this->bus(), endpoint_id, EAGINE_MSG_ID(eagiSysInf, rqFreSwpSz));
242  }
243 
244  virtual void on_free_swap_size_received(
245  const result_context&,
246  valid_if_nonnegative<span_size_t>&&) {}
247 
248  void query_total_swap_size(identifier_t endpoint_id) {
249  _total_swap_size.invoke_on(
250  this->bus(), endpoint_id, EAGINE_MSG_ID(eagiSysInf, rqTtlSwpSz));
251  }
252 
253  virtual void on_total_swap_size_received(
254  const result_context&,
255  valid_if_nonnegative<span_size_t>&&) {}
256 
257 private:
258  default_callback_invoker<std::chrono::duration<float>(), 32> _uptime;
259 
260  default_callback_invoker<valid_if_positive<span_size_t>(), 32>
261  _cpu_concurrent_threads;
262 
263  default_callback_invoker<valid_if_nonnegative<float>(), 32>
264  _short_average_load;
265 
266  default_callback_invoker<valid_if_nonnegative<float>(), 32>
267  _long_average_load;
268 
269  default_callback_invoker<valid_if_positive<span_size_t>(), 32>
270  _memory_page_size;
271 
272  default_callback_invoker<valid_if_positive<span_size_t>(), 32>
273  _free_ram_size;
274 
275  default_callback_invoker<valid_if_positive<span_size_t>(), 32>
276  _total_ram_size;
277 
278  default_callback_invoker<valid_if_nonnegative<span_size_t>(), 32>
279  _free_swap_size;
280 
281  default_callback_invoker<valid_if_nonnegative<span_size_t>(), 32>
282  _total_swap_size;
283 };
284 //------------------------------------------------------------------------------
285 } // namespace eagine::msgbus
286 
287 #endif // EAGINE_MESSAGE_BUS_SERVICE_SYSTEM_INFO_HPP
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
valid_if< T, valid_if_positive_policy< T > > valid_if_positive
Specialization of valid_if, for values valid if positive.
Definition: positive.hpp:44
#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_nonneg_policy< T > > valid_if_nonnegative
Specialization of valid_if, for values valid if non-negative.
Definition: nonnegative.hpp:44
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).