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

connection.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_MESSAGE_BUS_CONNECTION_HPP
10 #define EAGINE_MESSAGE_BUS_CONNECTION_HPP
11 
12 #include "../callable_ref.hpp"
13 #include "../interface.hpp"
14 #include "../message_id.hpp"
15 #include "../type_identity.hpp"
16 #include "../valid_if/positive.hpp"
17 #include "connection_kind.hpp"
18 #include "message.hpp"
19 #include <type_traits>
20 
21 namespace eagine::msgbus {
22 //------------------------------------------------------------------------------
25 constexpr const span_size_t min_connection_data_size = 1024;
26 //------------------------------------------------------------------------------
32  none,
34  filepath,
36  ipv4
37 };
38 
39 template <typename Selector>
40 constexpr auto
41 enumerator_mapping(type_identity<connection_addr_kind>, Selector) noexcept {
42  return enumerator_map_type<connection_addr_kind, 3>{
43  {{"none", connection_addr_kind::none},
44  {"filepath", connection_addr_kind::filepath},
45  {"ipv4", connection_addr_kind::ipv4}}};
46 }
47 
50 template <connection_addr_kind Kind>
52  std::integral_constant<connection_addr_kind, Kind>;
53 //------------------------------------------------------------------------------
57 enum class connection_protocol {
59  stream,
61  datagram,
63  message
64 };
65 
66 template <typename Selector>
67 constexpr auto
68 enumerator_mapping(type_identity<connection_protocol>, Selector) noexcept {
69  return enumerator_map_type<connection_protocol, 3>{
70  {{"stream", connection_protocol::stream},
71  {"datagram", connection_protocol::datagram},
72  {"message", connection_protocol::message}}};
73 }
74 
79 template <connection_protocol Proto>
81  std::integral_constant<connection_protocol, Proto>;
82 
86 using stream_protocol_tag =
88 
94 //------------------------------------------------------------------------------
98 struct connection_info : interface<connection_info> {
99 
101  virtual auto kind() -> connection_kind = 0;
102 
104  virtual auto addr_kind() -> connection_addr_kind = 0;
105 
107  virtual auto type_id() -> identifier = 0;
108 };
109 //------------------------------------------------------------------------------
115 
117  using fetch_handler =
119 
123  virtual auto update() -> bool {
124  return false;
125  }
126 
128  virtual void cleanup() {}
129 
131  virtual auto is_usable() -> bool {
132  return true;
133  }
134 
137  return {0};
138  }
139 
143  virtual auto send(message_id msg_id, const message_view&) -> bool = 0;
144 
148  virtual auto fetch_messages(fetch_handler handler) -> bool = 0;
149 };
150 //------------------------------------------------------------------------------
155 struct connection_user : interface<connection_user> {
156 
159  virtual auto add_connection(std::unique_ptr<connection>) -> bool = 0;
160 };
161 //------------------------------------------------------------------------------
162 } // namespace eagine::msgbus
163 
164 #endif // EAGINE_MESSAGE_BUS_CONNECTION_HPP
virtual auto update() -> bool
Updates the internal state of the connection (called repeatedly).
Definition: connection.hpp:123
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
Declaration of class template storing a reference to a callable object.
Definition: callable_ref.hpp:24
std::integral_constant< connection_protocol, Proto > connection_protocol_tag
Tag template alias for specifying connection protocol kind.
Definition: connection.hpp:81
virtual void cleanup()
Cleans up the connection before destroying it.
Definition: connection.hpp:128
Primary template for conditionally valid values.
Definition: decl.hpp:49
virtual auto send(message_id msg_id, const message_view &) -> bool=0
Sent a message with the specified id.
Interface for message bus connections.
Definition: connection.hpp:114
Base template for abstract interfaces, implements common functionality.
Definition: interface.hpp:18
connection_protocol_tag< connection_protocol::stream > stream_protocol_tag
Tag type for specifying stream connection protocols.
Definition: connection.hpp:87
Interface for classes that can use message bus connections.
Definition: connection.hpp:155
Combines message information and a non-owning view to message content.
Definition: message.hpp:288
virtual auto type_id() -> identifier=0
Returns a description identifier of the implementation.
virtual auto max_data_size() -> valid_if_positive< span_size_t >
Returns the maximum data block size in bytes that can be sent.
Definition: connection.hpp:136
connection_protocol_tag< connection_protocol::datagram > datagram_protocol_tag
Tag type for specifying datagram connection protocols.
Definition: connection.hpp:93
Message bus code is placed in this namespace.
Definition: eagine.hpp:58
virtual auto kind() -> connection_kind=0
Returns the connection kind.
constexpr const span_size_t min_connection_data_size
The minimum guaranteed block size that can be sent through bus connections.
Definition: connection.hpp:25
connection_addr_kind
Message bus connection address kind enumeration.
Definition: connection.hpp:30
virtual auto addr_kind() -> connection_addr_kind=0
Returns the connection address kind.
callable_ref< bool(message_id, message_age, const message_view &)> fetch_handler
Alias for fetch handler callable reference type.
Definition: connection.hpp:118
connection_kind
Message bus connection kind bits enumeration.
Definition: connection_kind.hpp:21
Basic interface for retrieving message bus connection information.
Definition: connection.hpp:98
virtual auto fetch_messages(fetch_handler handler) -> bool=0
Fetch all enqueued messages that have been received since last fetch.
@ stream
Reliable stream protocol.
Template type used mostly for function type-tag dispatching.
Definition: type_identity.hpp:19
Class storing two identifier values representing class/method pair.
Definition: message_id.hpp:25
virtual auto add_connection(std::unique_ptr< connection >) -> bool=0
Adds the specified message bus connection. Result indicates if the connection was used or discarded.
connection_protocol
Message bus connection protocol.
Definition: connection.hpp:57
virtual auto is_usable() -> bool
Checks if the connection is in usable state.
Definition: connection.hpp:131
std::integral_constant< connection_addr_kind, Kind > connection_addr_kind_tag
Tag template alias for specifying connection address kind.
Definition: connection.hpp:52
std::chrono::duration< float > message_age
Alias for message age type.
Definition: message.hpp:54

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