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

discovery.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_MESSAGE_BUS_SERVICE_DISCOVERY_HPP
10 #define EAGINE_MESSAGE_BUS_SERVICE_DISCOVERY_HPP
11 
12 #include "../serialize.hpp"
13 #include "../subscriber.hpp"
14 
15 namespace eagine::msgbus {
16 //------------------------------------------------------------------------------
17 struct subscriber_info {
18  identifier_t endpoint_id{0U};
20 };
21 //------------------------------------------------------------------------------
22 template <typename Base = subscriber>
23 class subscriber_discovery : public Base {
24  using This = subscriber_discovery;
25 
26 protected:
27  using Base::Base;
28 
29  void add_methods() {
30  Base::add_methods();
31  Base::add_method(
32  this, EAGINE_MSG_MAP(eagiMsgBus, stillAlive, This, _handle_alive));
33  Base::add_method(
34  this,
35  EAGINE_MSG_MAP(eagiMsgBus, subscribTo, This, _handle_subscribed));
36  Base::add_method(
37  this,
38  EAGINE_MSG_MAP(eagiMsgBus, unsubFrom, This, _handle_unsubscribed));
39  Base::add_method(
40  this,
41  EAGINE_MSG_MAP(eagiMsgBus, notSubTo, This, _handle_not_subscribed));
42  }
43 
44 public:
45  virtual void is_alive(const subscriber_info&) = 0;
46  virtual void on_subscribed(const subscriber_info&, message_id) = 0;
47  virtual void on_unsubscribed(const subscriber_info&, message_id) = 0;
48  virtual void not_subscribed(const subscriber_info&, message_id) = 0;
49 
50 private:
51  auto _handle_alive(const message_context&, stored_message& message)
52  -> bool {
53  subscriber_info info{};
54  info.endpoint_id = message.source_id;
55  info.instance_id = message.sequence_no;
56  is_alive(info);
57  return true;
58  }
59 
60  auto _handle_subscribed(const message_context&, stored_message& message)
61  -> bool {
62  message_id sub_msg_id{};
63  if(default_deserialize_message_type(sub_msg_id, message.content())) {
64  subscriber_info info{};
65  info.endpoint_id = message.source_id;
66  info.instance_id = message.sequence_no;
67  on_subscribed(info, sub_msg_id);
68  }
69  return true;
70  }
71 
72  auto _handle_unsubscribed(const message_context&, stored_message& message)
73  -> bool {
74  message_id sub_msg_id{};
75  if(default_deserialize_message_type(sub_msg_id, message.content())) {
76  subscriber_info info{};
77  info.endpoint_id = message.source_id;
78  info.instance_id = message.sequence_no;
79  on_unsubscribed(info, sub_msg_id);
80  }
81  return true;
82  }
83 
84  auto _handle_not_subscribed(const message_context&, stored_message& message)
85  -> bool {
86  message_id sub_msg_id{};
87  if(default_deserialize_message_type(sub_msg_id, message.content())) {
88  subscriber_info info{};
89  info.endpoint_id = message.source_id;
90  info.instance_id = message.sequence_no;
91  not_subscribed(info, sub_msg_id);
92  }
93  return true;
94  }
95 };
96 //------------------------------------------------------------------------------
97 } // namespace eagine::msgbus
98 
99 #endif // EAGINE_MESSAGE_BUS_SERVICE_DISCOVERY_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.
std::uint32_t process_instance_id_t
Unique process identifier type (does not necessarily match to OS PID).
Definition: identifier_t.hpp:22
Message bus code is placed in this namespace.
Definition: eagine.hpp:58
@ instance_id
The endpoint instance id has changed.
std::uint64_t identifier_t
The underlying integer type for eagine::identifier.
Definition: identifier_t.hpp:19
auto default_deserialize_message_type(message_id &msg_id, memory::const_block blk)
Default-deserializes the specified message id from a memory block.
Definition: serialize.hpp:266
@ message_id
The message type id has been verified.

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