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

topology.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_MESSAGE_BUS_SERVICE_TOPOLOGY_HPP
10 #define EAGINE_MESSAGE_BUS_SERVICE_TOPOLOGY_HPP
11 
12 #include "../serialize.hpp"
13 #include "../subscriber.hpp"
14 
15 namespace eagine::msgbus {
16 //------------------------------------------------------------------------------
17 template <typename Base = subscriber>
18 class network_topology : public Base {
19  using This = network_topology;
20 
21 protected:
22  using Base::Base;
23 
24  void add_methods() {
25  Base::add_methods();
26  Base::add_method(
27  this, EAGINE_MSG_MAP(eagiMsgBus, topoRutrCn, This, _handle_router));
28  Base::add_method(
29  this, EAGINE_MSG_MAP(eagiMsgBus, topoBrdgCn, This, _handle_bridge));
30  Base::add_method(
31  this, EAGINE_MSG_MAP(eagiMsgBus, topoEndpt, This, _handle_endpoint));
32  }
33 
34 public:
35  void discover_topology() {
36  message_view message{};
37  message.set_target_id(broadcast_endpoint_id());
38  const auto msg_id{EAGINE_MSGBUS_ID(topoQuery)};
39  this->bus().post(msg_id, message);
40  }
41 
42  virtual void router_appeared(const router_topology_info& info) = 0;
43  virtual void bridge_appeared(const bridge_topology_info& info) = 0;
44  virtual void endpoint_appeared(const endpoint_topology_info& info) = 0;
45 
46 private:
47  auto _handle_router(const message_context&, stored_message& message)
48  -> bool {
49  router_topology_info info{};
50  if(default_deserialize(info, message.content())) {
51  router_appeared(info);
52  }
53  return true;
54  }
55 
56  auto _handle_bridge(const message_context&, stored_message& message)
57  -> bool {
58  bridge_topology_info info{};
59  if(default_deserialize(info, message.content())) {
60  bridge_appeared(info);
61  }
62  return true;
63  }
64 
65  auto _handle_endpoint(const message_context&, stored_message& message)
66  -> bool {
67  endpoint_topology_info info{};
68  if(default_deserialize(info, message.content())) {
69  endpoint_appeared(info);
70  }
71  return true;
72  }
73 };
74 //------------------------------------------------------------------------------
75 } // namespace eagine::msgbus
76 
77 #endif // EAGINE_MESSAGE_BUS_SERVICE_TOPOLOGY_HPP
#define EAGINE_MSG_MAP(CLASS_ID, METHOD_ID, CLASS, METHOD)
Constructs an instance of static message handler map.
Definition: handler_map.hpp:72
@ info
Informational log entries.
static constexpr auto broadcast_endpoint_id() noexcept -> identifier_t
Returns the special broadcase message bus endpoint id.
Definition: message.hpp:42
Message bus code is placed in this namespace.
Definition: eagine.hpp:58
auto default_deserialize(T &value, memory::const_block blk) -> deserialization_result< memory::const_block >
Uses the default backend to deserialize a value from a memory block.
Definition: serialize.hpp:235
auto bus() noexcept -> auto &
Returns a reference to the associated endpoint.
Definition: subscriber.hpp:38

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