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

registry.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_MESSAGE_BUS_REGISTRY_HPP
10 #define EAGINE_MESSAGE_BUS_REGISTRY_HPP
11 
12 #include "../main_ctx_object.hpp"
13 #include "direct.hpp"
14 #include "endpoint.hpp"
15 #include "router.hpp"
16 #include "service_interface.hpp"
17 #include <memory>
18 
19 namespace eagine::msgbus {
20 //------------------------------------------------------------------------------
21 struct registered_entry {
22  std::unique_ptr<endpoint> _endpoint{};
23  std::unique_ptr<service_interface> _service{};
24 
25  auto update_service() -> bool;
26 };
27 //------------------------------------------------------------------------------
30 class registry : public main_ctx_object {
31 public:
33  registry(main_ctx_parent parent);
34 
37  [[nodiscard]] auto establish(identifier log_id) -> endpoint& {
38  return *(_add_entry(log_id)._endpoint);
39  }
40 
43  template <typename Service>
44  auto emplace(identifier log_id) -> std::
45  enable_if_t<std::is_base_of_v<service_interface, Service>, Service&> {
46  auto& entry = _add_entry(log_id);
47  auto temp{std::make_unique<Service>(*(entry._endpoint))};
48  auto& result = *temp;
49  entry._service = std::move(temp);
50  return result;
51  }
52 
53  auto update() -> bool;
54  auto update_all() -> bool;
55  void cleanup() {
56  _router.cleanup();
57  }
58 
59 private:
60  std::shared_ptr<direct_acceptor> _acceptor;
61  router _router;
62  std::vector<registered_entry> _entries;
63 
64  auto _add_entry(identifier log_id) -> registered_entry&;
65 };
66 //------------------------------------------------------------------------------
67 } // namespace eagine::msgbus
68 
69 #if !EAGINE_LINK_LIBRARY || defined(EAGINE_IMPLEMENTING_LIBRARY)
70 #include <eagine/message_bus/registry.inl>
71 #endif
72 
73 #endif // EAGINE_MESSAGE_BUS_REGISTRY_HPP
auto establish(identifier log_id) -> endpoint &
Establishes a new endpoint with the specified logger identifier.
Definition: registry.hpp:37
Helper class used to initialize main context objects.
Definition: main_ctx_object.hpp:45
Base class for main context objects.
Definition: main_ctx_object.hpp:71
registry(main_ctx_parent parent)
Construction from parent main context object.
auto emplace(identifier log_id) -> std::enable_if_t< std::is_base_of_v< service_interface, Service >, Service & >
Establishes an endpoint and instantiates a service object tied to it.
Definition: registry.hpp:44
Message bus code is placed in this namespace.
Definition: eagine.hpp:58
Class combining a local bus router and a set of endpoints.
Definition: registry.hpp:30
Message bus client endpoint that can send and receive messages.
Definition: endpoint.hpp:30

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