40#include <boost/mp11.hpp>
41#include <boost/noncopyable.hpp>
47namespace knp::core::messaging::impl
52class MessageEndpointImpl;
74 using AllSubscriptions = boost::mp11::mp_transform<Subscription, messaging::AllMessages>;
108 template <
typename Variant,
typename Type>
109 static constexpr size_t get_type_index = boost::mp11::mp_find<Variant, Type>::value;
139 template <
typename MessageType>
140 Subscription<MessageType> &
subscribe(
const UID &receiver,
const std::vector<UID> &senders);
148 template <
typename MessageType>
183 template <
class MessageType>
202 std::shared_ptr<messaging::impl::MessageEndpointImpl> impl_;
The MessageEndpoint class is a definition of message endpoints.
std::vector< MessageType > unload_messages(const knp::core::UID &receiver_uid)
Read messages of the specified type received via subscription.
const SubscriptionContainer & get_endpoint_subscriptions() const
Get access to subscription container of the endpoint.
MessageEndpoint & operator=(MessageEndpoint &)=delete
Avoid copy assignment of an endpoint.
static constexpr size_t get_type_index
Find index of an entity type in its variant.
boost::mp11::mp_transform< Subscription, messaging::AllMessages > AllSubscriptions
List of subscription types based on message types specified in messaging::AllMessages.
MessageEndpoint(MessageEndpoint &&endpoint) noexcept
Move constructor for message endpoints.
MessageEndpoint()=default
Message endpoint default constructor.
Subscription< MessageType > & subscribe(const UID &receiver, const std::vector< UID > &senders)
Add a subscription to messages of the specified type from senders with given UIDs.
std::map< std::pair< size_t, UID >, SubscriptionVariant > SubscriptionContainer
Type of subscription container.
void send_message(const knp::core::messaging::MessageVariant &message)
Send a message to the message bus.
boost::mp11::mp_rename< AllSubscriptions, std::variant > SubscriptionVariant
Subscription variant that contains any subscription type specified in AllSubscriptions.
virtual ~MessageEndpoint()
Message endpoint destructor.
static std::pair< size_t, UID > get_subscription_key(const SubscriptionVariant &subscription)
Get subscription key from a subscription variant.
static UID get_receiver_uid(const SubscriptionVariant &subscription)
Get receiver UID from a subscription variant.
size_t receive_all_messages(const std::chrono::milliseconds &sleep_duration=std::chrono::milliseconds(0))
Receive all messages that were sent to the endpoint.
void remove_receiver(const UID &receiver)
Remove all subscriptions for a receiver with given UID.
bool receive_message()
Receive a message from the message bus.
bool unsubscribe(const UID &receiver)
Unsubscribe from messages of a specified type.
Message envelope routines.
Common header for messaging.
boost::mp11::mp_rename< AllMessages, std::variant > MessageVariant
Message variant that contains any message type specified in AllMessages.
Subscription class that determines message exchange between entities in the network.