![]() |
CommRaT 2.0.0
C++20 Real-Time Messaging Framework
|
Strongly-typed mailbox for message-based communication. More...
#include <commrat/mailbox/mailbox.hpp>
Public Member Functions | |
| Mailbox (const MailboxConfig &config) | |
| Construct a mailbox with the given configuration. | |
| ~Mailbox () | |
| Destructor - automatically stops and cleans up. | |
| Mailbox (const Mailbox &)=delete | |
| Mailbox & | operator= (const Mailbox &)=delete |
| Mailbox (Mailbox &&other) noexcept | |
| Mailbox & | operator= (Mailbox &&other) noexcept |
| auto | start () -> MailboxResult< void > |
| Start the mailbox (initialize TiMS connection) | |
| void | stop () |
| Stop the mailbox. | |
| bool | is_running () const |
| Check if mailbox is running. | |
| template<typename T > requires is_registered<T> | |
| auto | send (T &message, uint32_t dest_mailbox) -> MailboxResult< void > |
| Send a message to a destination mailbox. | |
| template<typename T > requires is_registered<T> | |
| auto | receive () -> MailboxResult< TimsMessage< T > > |
| Receive a message of specific type (blocking) | |
| template<typename T > requires is_registered<T> | |
| auto | try_receive () -> std::optional< TimsMessage< T > > |
| Try to receive a message without blocking. | |
| template<typename T > requires is_registered<T> | |
| auto | receive_for (std::chrono::milliseconds timeout) -> MailboxResult< TimsMessage< T > > |
| Receive a message with timeout. | |
| auto | receive_any_raw (std::chrono::milliseconds timeout=std::chrono::milliseconds{-1}) -> MailboxResult< RawReceivedMessage > |
| Receive any message without knowing its type. | |
| template<typename Visitor > | |
| auto | receive_any (Visitor &&visitor) -> MailboxResult< void > |
| Receive any registered message type using a visitor. | |
| auto | clean () -> MailboxResult< void > |
| Clear all pending messages from the mailbox. | |
| uint32_t | mailbox_id () const |
| Get the mailbox ID. | |
| uint64_t | messages_sent () const |
| Get number of messages sent. | |
| uint64_t | messages_received () const |
| Get number of messages received. | |
Static Public Member Functions | |
| static constexpr size_t | num_message_types () |
| Get number of registered message types. | |
Static Public Attributes | |
| template<typename T > | |
| static constexpr bool | is_registered |
| Check if a type is registered with this mailbox at compile time For TimsMessage<PayloadT>, check if PayloadT is registered. | |
Strongly-typed mailbox for message-based communication.
A modern C++20 mailbox interface that provides compile-time type safety for message operations. Accepts MessageDefinition types which contain compile-time message IDs.
| MessageDefs | Pack of MessageDefinition types this mailbox can handle |
Example:
Definition at line 177 of file mailbox.hpp.
|
inlineexplicit |
Construct a mailbox with the given configuration.
| config | Mailbox configuration |
Definition at line 202 of file mailbox.hpp.
|
inline |
Destructor - automatically stops and cleans up.
Definition at line 211 of file mailbox.hpp.
References commrat::Mailbox< MessageDefs >::stop().
|
delete |
|
inlinenoexcept |
Definition at line 220 of file mailbox.hpp.
|
inline |
Clear all pending messages from the mailbox.
Definition at line 553 of file mailbox.hpp.
References commrat::MessageRegistry< MessageDefs... >::max_message_size, commrat::NotRunning, and commrat::TimsWrapper::receive_raw_bytes().
|
inline |
Check if mailbox is running.
Definition at line 274 of file mailbox.hpp.
|
inline |
Get the mailbox ID.
Definition at line 572 of file mailbox.hpp.
References commrat::MailboxConfig::mailbox_id.
|
inline |
Get number of messages received.
Definition at line 586 of file mailbox.hpp.
References commrat::TimsWrapper::get_messages_received().
|
inline |
Get number of messages sent.
Definition at line 579 of file mailbox.hpp.
References commrat::TimsWrapper::get_messages_sent().
|
inlinestaticconstexpr |
Get number of registered message types.
Definition at line 299 of file mailbox.hpp.
|
delete |
|
inlinenoexcept |
Definition at line 227 of file mailbox.hpp.
References commrat::Mailbox< MessageDefs >::stop().
|
inline |
Receive a message of specific type (blocking)
| T | Message type to receive |
Definition at line 352 of file mailbox.hpp.
References commrat::deserialize(), commrat::NetworkError, commrat::NotRunning, commrat::TimsWrapper::receive_raw_bytes(), and commrat::SerializationError.
|
inline |
Receive any registered message type using a visitor.
The visitor will be called with the received message, allowing runtime dispatch based on the actual message type received.
| visitor | Callable that accepts any registered message type |
Example:
Definition at line 506 of file mailbox.hpp.
References commrat::InvalidMessage, commrat::MessageRegistry< MessageDefs... >::max_message_size, commrat::TimsHeader::msg_type, commrat::NetworkError, commrat::NotRunning, commrat::TimsWrapper::receive_raw_bytes(), and commrat::MessageRegistry< MessageDefs... >::visit().
|
inline |
Receive any message without knowing its type.
Returns raw message data with type information. Useful for command loops that need to inspect the message type before deserializing.
| timeout | Maximum time to wait for a message |
Definition at line 444 of file mailbox.hpp.
|
inline |
Receive a message with timeout.
| T | Message type to receive |
| timeout | Maximum time to wait |
Definition at line 405 of file mailbox.hpp.
References commrat::deserialize(), commrat::NetworkError, commrat::NotRunning, commrat::TimsWrapper::receive_raw_bytes(), commrat::SerializationError, and commrat::Timeout.
|
inline |
Send a message to a destination mailbox.
| T | Message type (must be registered) |
| message | Message to send |
| dest_mailbox | Destination mailbox ID |
Definition at line 317 of file mailbox.hpp.
References commrat::InvalidDestination, commrat::NetworkError, commrat::NotRunning, commrat::TimsWrapper::send(), commrat::MessageRegistry< MessageDefs... >::serialize(), and commrat::SUCCESS.
|
inline |
Start the mailbox (initialize TiMS connection)
Definition at line 246 of file mailbox.hpp.
References commrat::AlreadyRunning, commrat::TimsWrapper::initialize(), commrat::NotInitialized, and commrat::SUCCESS.
|
inline |
Stop the mailbox.
Definition at line 264 of file mailbox.hpp.
References commrat::TimsWrapper::shutdown().
Referenced by commrat::Mailbox< MessageDefs >::~Mailbox(), and commrat::Mailbox< MessageDefs >::operator=().
|
inline |
Try to receive a message without blocking.
| T | Message type to receive |
Definition at line 386 of file mailbox.hpp.
|
staticconstexpr |
Check if a type is registered with this mailbox at compile time For TimsMessage<PayloadT>, check if PayloadT is registered.
Definition at line 287 of file mailbox.hpp.