![]() |
CommRaT 2.0.0
C++20 Real-Time Messaging Framework
|
Type-restricted mailbox with optimized buffer sizing. More...
#include <commrat/mailbox/typed_mailbox.hpp>
Public Member Functions | |
| TypedMailbox (const MailboxConfig &config) | |
| Construct a typed mailbox. | |
| ~TypedMailbox ()=default | |
| TypedMailbox (const TypedMailbox &)=delete | |
| TypedMailbox & | operator= (const TypedMailbox &)=delete |
| TypedMailbox (TypedMailbox &&) noexcept=default | |
| TypedMailbox & | operator= (TypedMailbox &&) noexcept=default |
| auto | start () -> MailboxResult< void > |
| void | stop () |
| bool | is_running () const |
| uint32_t | mailbox_id () const |
| template<typename PayloadT > | |
| auto | send (PayloadT &message, uint32_t dest_mailbox) -> MailboxResult< void > |
| Send a message (type-restricted) | |
| template<typename PayloadT > | |
| auto | send (PayloadT &message, uint32_t dest_mailbox, uint64_t timestamp) -> MailboxResult< void > |
| Send a message with explicit timestamp (type-restricted) | |
| template<typename PayloadT > | |
| auto | send (const TimsMessage< PayloadT > &tims_message, uint32_t dest_mailbox) -> MailboxResult< void > |
| Send a TimsMessage (type-restricted) | |
| template<typename PayloadT > | |
| auto | receive () -> MailboxResult< TimsMessage< PayloadT > > |
| Blocking receive for specific payload type. | |
| template<typename PayloadT > | |
| auto | receive_for (std::chrono::milliseconds timeout) -> MailboxResult< TimsMessage< PayloadT > > |
| Receive with timeout for specific payload type. | |
| template<typename PayloadT > | |
| auto | try_receive () -> MailboxResult< TimsMessage< PayloadT > > |
| Non-blocking receive (type-restricted) | |
| template<typename Visitor > | |
| auto | receive_any (Visitor &&visitor) -> MailboxResult< void > |
| Blocking receive any allowed message type using visitor pattern. | |
| template<typename Visitor > | |
| auto | receive_any_for (std::chrono::milliseconds timeout, Visitor &&visitor) -> MailboxResult< void > |
| Receive any allowed message type with timeout. | |
| auto & | get_underlying_mailbox () |
| Receive any allowed message using a visitor. | |
| const auto & | get_underlying_mailbox () const |
Static Public Member Functions | |
| template<typename PayloadT > | |
| static constexpr bool | is_allowed () |
| Check if a payload type is allowed in this mailbox. | |
Static Public Attributes | |
| static constexpr size_t | max_message_size |
| Maximum message size for allowed types only. | |
| static constexpr size_t | num_allowed_types = sizeof...(AllowedPayloadTypes) |
Type-restricted mailbox with optimized buffer sizing.
Unlike regular Mailbox which can handle all types in the registry, TypedMailbox is restricted to a specific subset of payload types. This enables:
Key Feature: Separate receive and send type restrictions!
| Registry | Full message registry (MessageRegistry<...>) |
| AllowedPayloadTypes | Payload types this mailbox can RECEIVE (determines buffer size) |
| SendOnlyTypes | Additional types that can be SENT but not received (no buffer impact) |
Memory Savings Example:
Usage Example:
Definition at line 82 of file typed_mailbox.hpp.
|
inlineexplicit |
Construct a typed mailbox.
| config | Mailbox configuration (buffer sizes optimized automatically) |
Definition at line 146 of file typed_mailbox.hpp.
|
default |
|
delete |
|
defaultnoexcept |
|
inline |
Receive any allowed message using a visitor.
The visitor will be called with the received message if its type is in AllowedPayloadTypes. Otherwise returns error.
| visitor | Callable that accepts any allowed message type |
Example:
Get reference to underlying RegistryMailbox
Needed for interop with legacy code that expects RegistryMailbox*. Use with caution - bypasses type restrictions!
Definition at line 389 of file typed_mailbox.hpp.
|
inline |
Definition at line 390 of file typed_mailbox.hpp.
|
inlinestaticconstexpr |
Check if a payload type is allowed in this mailbox.
Definition at line 134 of file typed_mailbox.hpp.
|
inline |
Definition at line 177 of file typed_mailbox.hpp.
|
inline |
Definition at line 181 of file typed_mailbox.hpp.
|
delete |
|
defaultnoexcept |
|
inline |
Blocking receive for specific payload type.
| PayloadT | Payload type (must be in AllowedPayloadTypes) |
Definition at line 289 of file typed_mailbox.hpp.
|
inline |
Blocking receive any allowed message type using visitor pattern.
| Visitor | Callable accepting TimsMessage<T> for any allowed T |
Definition at line 336 of file typed_mailbox.hpp.
|
inline |
Receive any allowed message type with timeout.
| Visitor | Callable accepting TimsMessage<T> for any allowed T |
| timeout | Maximum time to wait |
Definition at line 348 of file typed_mailbox.hpp.
|
inline |
Receive with timeout for specific payload type.
| PayloadT | Payload type (must be in AllowedPayloadTypes) |
| timeout | Maximum time to wait |
Definition at line 306 of file typed_mailbox.hpp.
|
inline |
Send a TimsMessage (type-restricted)
Definition at line 266 of file typed_mailbox.hpp.
|
inline |
Send a message (type-restricted)
| PayloadT | Payload type (must be in AllowedPayloadTypes) |
| message | Message to send |
| dest_mailbox | Destination mailbox ID |
Compile-time validation:
Definition at line 202 of file typed_mailbox.hpp.
References commrat::TimsMessage< PayloadT >::header, and commrat::TimsHeader::msg_type.
|
inline |
Send a message with explicit timestamp (type-restricted)
| PayloadT | Payload type (must be in AllowedPayloadTypes) |
| message | Message to send |
| dest_mailbox | Destination mailbox ID |
| timestamp | Explicit timestamp to set in TimsHeader |
Definition at line 237 of file typed_mailbox.hpp.
References commrat::TimsMessage< PayloadT >::header, and commrat::TimsHeader::msg_type.
|
inline |
Definition at line 169 of file typed_mailbox.hpp.
|
inline |
Definition at line 173 of file typed_mailbox.hpp.
|
inline |
Non-blocking receive (type-restricted)
| PayloadT | Payload type (must be in AllowedPayloadTypes) |
Definition at line 321 of file typed_mailbox.hpp.
|
staticconstexpr |
Maximum message size for allowed types only.
This is the key optimization: buffer sized for max(AllowedPayloadTypes) instead of max(all registry types).
Definition at line 125 of file typed_mailbox.hpp.
|
staticconstexpr |
Definition at line 128 of file typed_mailbox.hpp.