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

bridge.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_MESSAGE_BUS_BRIDGE_HPP
10 #define EAGINE_MESSAGE_BUS_BRIDGE_HPP
11 
12 #include "../main_ctx_object.hpp"
13 #include "../timeout.hpp"
14 #include "connection.hpp"
15 #include "context_fwd.hpp"
16 #include <memory>
17 
18 namespace eagine::msgbus {
19 //------------------------------------------------------------------------------
20 class bridge_state;
21 class bridge
22  : public main_ctx_object
23  , public connection_user {
24 
25  static constexpr auto invalid_id() noexcept -> identifier_t {
26  return 0U;
27  }
28 
29  static constexpr auto is_valid_id(identifier_t id) noexcept -> bool {
30  return id != invalid_id();
31  }
32 
33 public:
34  bridge(main_ctx_parent parent) noexcept
35  : main_ctx_object(EAGINE_ID(MsgBusBrdg), parent)
36  , _context{make_context(*this)} {
37  _setup_from_config();
38  }
39 
40  void add_certificate_pem(memory::const_block blk);
41  void add_ca_certificate_pem(memory::const_block blk);
42 
43  auto add_connection(std::unique_ptr<connection>) -> bool final;
44 
45  auto has_id() const noexcept -> bool {
46  return is_valid_id(_id);
47  }
48 
49  auto update() -> bool;
50  auto is_done() const noexcept -> bool;
51  void cleanup();
52 
53  auto no_connection_timeout() const noexcept -> auto& {
54  return _no_connection_timeout;
55  }
56 
57 private:
58  void _setup_from_config();
59 
60  auto _recoverable_state() const noexcept -> bool;
61  auto _check_state() -> bool;
62  auto _update_connections() -> bool;
63 
64  auto _do_send(message_id, message_view&) -> bool;
65  auto _send(message_id, message_view&) -> bool;
66  auto _handle_special(message_id, const message_view&, bool) -> bool;
67  auto _do_push(message_id, message_view&) -> bool;
68  auto _forward_messages() -> bool;
69 
70  shared_context _context{};
71 
72  const process_instance_id_t _instance_id{process_instance_id()};
73  identifier_t _id{invalid_id()};
74  timeout _no_id_timeout{std::chrono::seconds{2}, nothing};
75 
76  std::chrono::steady_clock::time_point _forwarded_since_i2c{
77  std::chrono::steady_clock::now()};
78  std::chrono::steady_clock::time_point _forwarded_since_c2o{
79  std::chrono::steady_clock::now()};
80  std::intmax_t _state_count{0};
81  std::intmax_t _forwarded_messages_i2c{0};
82  std::intmax_t _forwarded_messages_c2o{0};
83  std::intmax_t _dropped_messages_i2c{0};
84  std::intmax_t _dropped_messages_c2o{0};
85  float _message_age_sum_i2c{0.F};
86  float _message_age_sum_c2o{0.F};
87 
88  std::shared_ptr<bridge_state> _state{};
89  timeout _no_connection_timeout{std::chrono::seconds{30}};
90  std::unique_ptr<connection> _connection{};
91 };
92 //------------------------------------------------------------------------------
93 } // namespace eagine::msgbus
94 
95 #if !EAGINE_LINK_LIBRARY || defined(EAGINE_IMPLEMENTING_LIBRARY)
96 #include <eagine/message_bus/bridge.inl>
97 #endif
98 
99 #endif // EAGINE_MESSAGE_BUS_BRIDGE_HPP
const main_ctx_object_parent_info & main_ctx_parent
Alias for main_ctx_object_parent_info parameter type.
Definition: main_ctx_fwd.hpp:24
#define EAGINE_ID(NAME)
Macro for constructing instances of eagine::identifier.
Definition: identifier.hpp:353
basic_block< true > const_block
Alias for const byte memory span.
Definition: block.hpp:32
main_ctx_object(identifier obj_id, main_ctx_parent parent) noexcept
Initialization from object id and parent.
Definition: main_ctx_object.hpp:77
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
auto process_instance_id() const noexcept -> process_instance_id_t
Returns the process id.
std::uint64_t identifier_t
The underlying integer type for eagine::identifier.
Definition: identifier_t.hpp:19
@ bridge
Message bus bridge.
static constexpr nothing_t nothing
Constant of nothing_t type.
Definition: nothing.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).