Go to the documentation of this file.
9 #ifndef EAGINE_MESSAGE_BUS_ACTOR_HPP
10 #define EAGINE_MESSAGE_BUS_ACTOR_HPP
23 template <std::
size_t>
class Subscriber = static_subscriber>
27 using friend_of_endpoint::_accept_message;
28 using friend_of_endpoint::_make_endpoint;
29 using friend_of_endpoint::_move_endpoint;
54 void allow_subscriptions() {
55 _subscriber.allow_subscriptions();
62 _subscriber.process_one();
69 _subscriber.process_all();
73 auto _process_message(
78 if(!_accept_message(_endpoint, msg_id, message)) {
90 typename = std::enable_if_t<
sizeof...(MsgMaps) == N>>
92 : _endpoint{_make_endpoint(
95 , _subscriber{_endpoint, instance, msg_maps...} {
96 _subscriber.announce_subscriptions();
104 typename = std::enable_if_t<
105 (
sizeof...(MsgMaps) == N) && std::is_base_of_v<actor, Derived>>>
106 actor(Derived&& temp, Class* instance, MsgMaps... msg_maps) noexcept
107 : _endpoint{_move_endpoint(
108 std::move(temp._endpoint),
109 {this, EAGINE_THIS_MEM_FUNC_C(_process_message)})}
110 , _subscriber{_endpoint, instance, msg_maps...} {}
112 ~
actor() noexcept
override {
114 _subscriber.retract_subscriptions();
122 Subscriber<N> _subscriber;
127 #endif // EAGINE_MESSAGE_BUS_ACTOR_HPP
actor(main_ctx_object obj, Class *instance, MsgMaps... msg_maps)
Constructor usable from derived classes.
Definition: actor.hpp:91
auto update() -> bool
Updates the internal state, sends and receives pending messages.
Base class for main context objects.
Definition: main_ctx_object.hpp:71
static constexpr auto is_special_message(message_id msg_id) noexcept
Indicates if the specified message id denotes a special message bus message.
Definition: message.hpp:36
@ endpoint
Message bus client endpoint.
Base class for message bus actors with fixed number of message handlers.
Definition: actor.hpp:24
auto bus() noexcept -> endpoint &
Returns a reference to the associated endpoint.
Definition: actor.hpp:45
void process_all()
Processes all enqueued messages for which there are handlers.
Definition: actor.hpp:67
auto operator=(actor &&)=delete
Not moved assignable.
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
Message bus code is placed in this namespace.
Definition: eagine.hpp:58
#define EAGINE_THIS_MEM_FUNC_C(FUNC)
Macro for creating object of member_function_constant in member functions.
Definition: mem_func_const.hpp:206
Message bus client endpoint that can send and receive messages.
Definition: endpoint.hpp:30
auto add_connection(std::unique_ptr< connection > conn) -> bool final
Adds a connection for communication with a message bus router.
actor(Derived &&temp, Class *instance, MsgMaps... msg_maps) noexcept
Constructor usable from derived classes.
Definition: actor.hpp:106
actor(actor &&)=delete
Not move constructible.
void finish()
Says to the message bus that this endpoint is disconnecting.
Definition: endpoint.hpp:154
void block_message_type(message_id)
Sends a message to router to start blocking message type for this endpoint.
Class storing two identifier values representing class/method pair.
Definition: message_id.hpp:25
auto add_connection(std::unique_ptr< connection > conn) -> bool final
Adds a connection to the associated endpoint.
Definition: actor.hpp:50
Base for classes that need access to enpoint internal functionality.
Definition: endpoint.hpp:501
std::chrono::duration< float > message_age
Alias for message age type.
Definition: message.hpp:54
void process_one()
Processes a single enqueued message for which there is a handler.
Definition: actor.hpp:60