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

service.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_MESSAGE_BUS_SERVICE_HPP
10 #define EAGINE_MESSAGE_BUS_SERVICE_HPP
11 
12 #include "../bool_aggregate.hpp"
13 #include "invoker.hpp"
14 #include "serialize.hpp"
15 #include "service_interface.hpp"
16 #include "skeleton.hpp"
17 #include "subscriber.hpp"
18 
19 namespace eagine::msgbus {
20 //------------------------------------------------------------------------------
23 template <typename Base = subscriber>
25  : public Base
26  , public connection_user
27  , public service_interface {
28 
29  using This = service_composition;
30 
31 public:
34  : Base{bus} {
35  _init();
36  }
37 
39  // NOLINTNEXTLINE(hicpp-noexcept-move,performance-noexcept-move-constructor)
41  : Base{static_cast<Base&&>(that)} {
42  _init();
43  }
44 
47 
49  auto operator=(service_composition&&) = delete;
50 
52  auto operator=(const service_composition&) = delete;
53 
54  ~service_composition() noexcept override {
55  this->retract_subscriptions();
56  this->finish();
57  }
58 
60  auto add_connection(std::unique_ptr<connection> conn) -> bool final {
61  return this->bus().add_connection(std::move(conn));
62  }
63 
65  auto update_and_process_all() -> bool final {
66  some_true something_done{};
67  something_done(this->update());
68  something_done(this->process_all());
69  return something_done;
70  }
71 
72 protected:
73  void add_methods() {
74  Base::add_methods();
75  Base::add_method(
76  this,
77  EAGINE_MSG_MAP(eagiMsgBus, qrySubscrp, This, _handle_sup_query));
78  Base::add_method(
79  this,
80  EAGINE_MSG_MAP(eagiMsgBus, qrySubscrb, This, _handle_sub_query));
81  }
82 
83 private:
84  auto _handle_sup_query(const message_context&, stored_message& message)
85  -> bool {
86  this->respond_to_subscription_query(message.source_id);
87  return true;
88  }
89 
90  auto _handle_sub_query(const message_context&, stored_message& message)
91  -> bool {
92  message_id sub_msg_id{};
93  if(default_deserialize_message_type(sub_msg_id, message.content())) {
94  this->respond_to_subscription_query(message.source_id, sub_msg_id);
95  }
96  return true;
97  }
98 
99  void _init() {
100  this->add_methods();
101  this->init();
102  this->announce_subscriptions();
103  }
104 };
105 //------------------------------------------------------------------------------
106 template <typename Signature, std::size_t MaxDataSize = 8192 - 128>
107 using default_callback_invoker = callback_invoker<
108  Signature,
111  block_data_sink,
112  block_data_source,
113  MaxDataSize>;
114 //------------------------------------------------------------------------------
115 template <typename Signature, std::size_t MaxDataSize = 8192 - 128>
116 using default_invoker = invoker<
117  Signature,
120  block_data_sink,
121  block_data_source,
122  MaxDataSize>;
123 //------------------------------------------------------------------------------
124 template <typename Signature, std::size_t MaxDataSize = 8192 - 128>
125 using default_skeleton = skeleton<
126  Signature,
129  block_data_sink,
130  block_data_source,
131  MaxDataSize>;
132 //------------------------------------------------------------------------------
133 template <typename Signature, std::size_t MaxDataSize = 8192 - 128>
134 using default_function_skeleton = function_skeleton<
135  Signature,
138  block_data_sink,
139  block_data_source,
140  MaxDataSize>;
141 //------------------------------------------------------------------------------
142 template <typename Signature, std::size_t MaxDataSize = 8192 - 128>
143 using default_lazy_skeleton = lazy_skeleton<
144  Signature,
147  block_data_sink,
148  block_data_source,
149  MaxDataSize>;
150 //------------------------------------------------------------------------------
151 template <typename Signature, std::size_t MaxDataSize = 8192 - 128>
152 using default_async_skeleton = async_skeleton<
153  Signature,
156  block_data_sink,
157  block_data_source,
158  MaxDataSize>;
159 //------------------------------------------------------------------------------
160 } // namespace eagine::msgbus
161 
162 #endif // EAGINE_MESSAGE_BUS_SERVICE_HPP
void announce_subscriptions() const
Sends messages to the bus saying which messages this can handle.
Definition: subscriber.hpp:438
void respond_to_subscription_query(identifier_t source_id) const noexcept
Sends messages responding to a subscription query.
Definition: subscriber.hpp:461
auto operator=(service_composition &&)=delete
Not move assignable.
#define EAGINE_MSG_MAP(CLASS_ID, METHOD_ID, CLASS, METHOD)
Constructs an instance of static message handler map.
Definition: handler_map.hpp:72
auto update() const noexcept -> bool
Updates the internal endpoint state (should be called repeatedly).
Definition: subscriber.hpp:51
service_composition(endpoint &bus)
Construction from a reference to an endpoint.
Definition: service.hpp:33
service_composition(service_composition &&that)
Move constructible.
Definition: service.hpp:40
Interface for classes that can use message bus connections.
Definition: connection.hpp:155
Class storing initially false value and logically or-ing other values.
Definition: bool_aggregate.hpp:16
string_deserializer_backend default_deserializer_backend
Alias for default deserialization backend for bus messages.
Definition: serialize.hpp:41
void retract_subscriptions() const noexcept
Sends messages to the bus saying which messages this cannot handle.
Definition: subscriber.hpp:454
Message bus code is placed in this namespace.
Definition: eagine.hpp:58
string_serializer_backend default_serializer_backend
Alias for default serialization backend for bus messages.
Definition: serialize.hpp:36
Message bus client endpoint that can send and receive messages.
Definition: endpoint.hpp:30
auto process_all() -> span_size_t
Handles (and removes) all poending received messages.
Definition: subscriber.hpp:430
Helper mixin class for message bus services composed of several parts.
Definition: service.hpp:24
auto add_connection(std::unique_ptr< connection > conn) -> bool final
Adds a connection to the associated endpoint.
Definition: service.hpp:60
auto bus() noexcept -> auto &
Returns a reference to the associated endpoint.
Definition: subscriber.hpp:38
auto update_and_process_all() -> bool final
Updates the associated endpoint and processes all incoming messages.
Definition: service.hpp:65
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
Interface for message bus services.
Definition: service_interface.hpp:19

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