CommRaT 2.0.0
C++20 Real-Time Messaging Framework
Loading...
Searching...
No Matches
commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple > Class Template Reference

CRTP mixin for multi-output mailbox and subscriber management. More...

#include <commrat/module/io/multi_output_manager.hpp>

Public Member Functions

std::vector< SubscriberInfoget_output_subscribers (std::size_t output_idx) const
 Get subscribers for specific output index.
 
void remove_subscriber (uint32_t subscriber_base_addr)
 Remove subscriber from all output lists.
 
template<std::size_t Index>
auto & get_publish_mailbox_public ()
 Get PUBLISH mailbox for specific output index (public accessor)
 

Protected Member Functions

Derived & derived ()
 
const Derived & derived () const
 
void initialize_output_subscribers ()
 Initialize per-output subscriber lists.
 
void add_subscriber_to_output (uint32_t subscriber_base_addr, uint8_t input_index=0, std::size_t output_idx=0)
 Add subscriber to correct output-specific list.
 
std::size_t find_output_index_by_type_id (uint16_t type_id_low) const
 Public wrapper for find_output_index_by_type_id_impl.
 
template<std::size_t... Is>
void spawn_all_output_work_threads (std::index_sequence< Is... >)
 Spawn all output work threads.
 
template<std::size_t Index>
void spawn_output_work_thread ()
 Spawn work thread for a specific output index.
 
void join_output_work_threads ()
 Join all output work threads.
 
template<std::size_t Index>
void output_work_loop ()
 Work loop for a specific output index.
 
template<std::size_t... Is>
void start_all_mailbox_sets (std::index_sequence< Is... >)
 Start all MailboxSets (CMD/WORK/PUBLISH mailboxes)
 
template<std::size_t Index>
void start_mailbox_set ()
 Start a single MailboxSet (CMD/WORK/PUBLISH)
 
template<std::size_t... Is>
void stop_all_mailbox_sets (std::index_sequence< Is... >)
 Stop all MailboxSets.
 
template<std::size_t Index>
void stop_mailbox_set ()
 Stop a single MailboxSet (CMD/WORK/PUBLISH)
 
template<std::size_t Index>
auto & get_mailbox_set ()
 Get specific MailboxSet by index.
 
template<std::size_t Index>
auto & get_cmd_mailbox ()
 Get CMD mailbox for specific output index.
 
template<std::size_t Index>
auto & get_work_mailbox ()
 Get WORK mailbox for specific output index.
 
template<std::size_t Index>
auto & get_publish_mailbox ()
 Get PUBLISH mailbox for specific output index (internal)
 

Protected Attributes

std::vector< std::vector< SubscriberInfo > > output_subscribers_
 Per-output subscriber lists: output_subscribers_[output_index][subscriber_id].
 
Mutex output_subscribers_mutex_
 
std::vector< std::thread > output_work_threads_
 Per-output work threads: one thread per MailboxSet.
 

Detailed Description

template<typename Derived, typename UserRegistry, typename OutputTypesTuple>
class commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >

CRTP mixin for multi-output mailbox and subscriber management.

Provides infrastructure for modules with multiple output types:

  • Per-output MailboxSet access (CMD/WORK/PUBLISH mailboxes)
  • Per-output subscriber lists with type-based routing
  • Per-output work threads for independent subscription handling
  • Mailbox lifecycle management (start/stop)

Only active when Derived::use_mailbox_sets == true (multi-output modules). Single-output modules use the traditional mailbox accessors in Module.

Template Parameters
DerivedThe Module class (CRTP pattern)
UserRegistryThe application's MessageRegistry
OutputTypesTuplestd::tuple<OutputType1, OutputType2, ...>

Definition at line 46 of file multi_output_manager.hpp.

Member Function Documentation

◆ add_subscriber_to_output()

template<typename Derived , typename UserRegistry , typename OutputTypesTuple >
void commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::add_subscriber_to_output ( uint32_t  subscriber_base_addr,
uint8_t  input_index = 0,
std::size_t  output_idx = 0 
)
inlineprotected

Add subscriber to correct output-specific list.

Extracts type ID from subscriber base address and routes to the appropriate output's subscriber list.

Parameters
subscriber_base_addrSubscriber's base mailbox address Format: [type_id_low:16][system:8][instance:8]
input_indexWhich input DATA mailbox the subscriber wants (0 = default)
output_idxWhich output this subscription is for

Definition at line 88 of file multi_output_manager.hpp.

References commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::derived(), commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::output_subscribers_, and commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::output_subscribers_mutex_.

◆ derived() [1/2]

◆ derived() [2/2]

template<typename Derived , typename UserRegistry , typename OutputTypesTuple >
const Derived & commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::derived ( ) const
inlineprotected

Definition at line 50 of file multi_output_manager.hpp.

◆ find_output_index_by_type_id()

template<typename Derived , typename UserRegistry , typename OutputTypesTuple >
std::size_t commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::find_output_index_by_type_id ( uint16_t  type_id_low) const
inlineprotected

Public wrapper for find_output_index_by_type_id_impl.

Definition at line 193 of file multi_output_manager.hpp.

◆ get_cmd_mailbox()

template<typename Derived , typename UserRegistry , typename OutputTypesTuple >
template<std::size_t Index>
auto & commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::get_cmd_mailbox ( )
inlineprotected

Get CMD mailbox for specific output index.

Template Parameters
IndexOutput index (0-based)
Returns
Reference to CMD mailbox for that output type

Definition at line 405 of file multi_output_manager.hpp.

References commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::derived().

◆ get_mailbox_set()

template<typename Derived , typename UserRegistry , typename OutputTypesTuple >
template<std::size_t Index>
auto & commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::get_mailbox_set ( )
inlineprotected

Get specific MailboxSet by index.

Template Parameters
IndexOutput index (0-based)
Returns
Reference to MailboxSet<UserRegistry, OutputType, CommandTypes...>

Definition at line 394 of file multi_output_manager.hpp.

References commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::derived().

◆ get_output_subscribers()

template<typename Derived , typename UserRegistry , typename OutputTypesTuple >
std::vector< SubscriberInfo > commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::get_output_subscribers ( std::size_t  output_idx) const
inline

Get subscribers for specific output index.

Thread-safe accessor for per-output subscriber lists. Used by Publisher to send messages only to relevant subscribers.

Parameters
output_idxOutput index (0-based)
Returns
Copy of subscriber list for that output

Definition at line 121 of file multi_output_manager.hpp.

References commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::output_subscribers_, and commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::output_subscribers_mutex_.

◆ get_publish_mailbox()

template<typename Derived , typename UserRegistry , typename OutputTypesTuple >
template<std::size_t Index>
auto & commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::get_publish_mailbox ( )
inlineprotected

Get PUBLISH mailbox for specific output index (internal)

Template Parameters
IndexOutput index (0-based)
Returns
Reference to PUBLISH mailbox for that output type

Definition at line 427 of file multi_output_manager.hpp.

References commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::derived().

◆ get_publish_mailbox_public()

template<typename Derived , typename UserRegistry , typename OutputTypesTuple >
template<std::size_t Index>
auto & commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::get_publish_mailbox_public ( )
inline

Get PUBLISH mailbox for specific output index (public accessor)

Public accessor needed by Publisher to access per-output mailboxes.

Template Parameters
IndexOutput index (0-based)
Returns
Reference to PUBLISH mailbox for that output type

Definition at line 441 of file multi_output_manager.hpp.

References commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::derived().

◆ get_work_mailbox()

template<typename Derived , typename UserRegistry , typename OutputTypesTuple >
template<std::size_t Index>
auto & commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::get_work_mailbox ( )
inlineprotected

Get WORK mailbox for specific output index.

Template Parameters
IndexOutput index (0-based)
Returns
Reference to WORK mailbox for that output type

Definition at line 416 of file multi_output_manager.hpp.

References commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::derived().

◆ initialize_output_subscribers()

template<typename Derived , typename UserRegistry , typename OutputTypesTuple >
void commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::initialize_output_subscribers ( )
inlineprotected

Initialize per-output subscriber lists.

Called from Module constructor to resize vector for multi-output modules.

Definition at line 72 of file multi_output_manager.hpp.

References commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::output_subscribers_.

◆ join_output_work_threads()

template<typename Derived , typename UserRegistry , typename OutputTypesTuple >
void commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::join_output_work_threads ( )
inlineprotected

◆ output_work_loop()

template<typename Derived , typename UserRegistry , typename OutputTypesTuple >
template<std::size_t Index>
void commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::output_work_loop ( )
inlineprotected

Work loop for a specific output index.

Each MailboxSet gets its own work thread to handle subscriptions independently. This allows consumers to subscribe to specific output types without interference.

Main processing loop for WORK mailbox for a specific output.

Handles subscription protocol messages on the WORK mailbox for each output type independently. Runs in its own thread.

Template Parameters
IndexOutput index (0-based)

Definition at line 270 of file multi_output_manager.hpp.

References commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::derived(), and commrat::WORK.

◆ remove_subscriber()

template<typename Derived , typename UserRegistry , typename OutputTypesTuple >
void commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::remove_subscriber ( uint32_t  subscriber_base_addr)
inline

Remove subscriber from all output lists.

Called during unsubscription - removes subscriber from any output list that contains it.

Parameters
subscriber_base_addrSubscriber's base mailbox address

Definition at line 137 of file multi_output_manager.hpp.

References commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::output_subscribers_, and commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::output_subscribers_mutex_.

◆ spawn_all_output_work_threads()

template<typename Derived , typename UserRegistry , typename OutputTypesTuple >
template<std::size_t... Is>
void commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::spawn_all_output_work_threads ( std::index_sequence< Is... >  )
inlineprotected

Spawn all output work threads.

Creates one thread per output type using fold expression. Called from Module::start().

Definition at line 217 of file multi_output_manager.hpp.

References commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::output_work_threads_.

◆ spawn_output_work_thread()

template<typename Derived , typename UserRegistry , typename OutputTypesTuple >
template<std::size_t Index>
void commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::spawn_output_work_thread ( )
inlineprotected

Spawn work thread for a specific output index.

Template Parameters
IndexOutput index (0-based)

Definition at line 233 of file multi_output_manager.hpp.

References commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::derived(), and commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::output_work_threads_.

◆ start_all_mailbox_sets()

template<typename Derived , typename UserRegistry , typename OutputTypesTuple >
template<std::size_t... Is>
void commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::start_all_mailbox_sets ( std::index_sequence< Is... >  )
inlineprotected

Start all MailboxSets (CMD/WORK/PUBLISH mailboxes)

Called from Module::start() to initialize all multi-output mailboxes.

Definition at line 327 of file multi_output_manager.hpp.

◆ start_mailbox_set()

template<typename Derived , typename UserRegistry , typename OutputTypesTuple >
template<std::size_t Index>
void commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::start_mailbox_set ( )
inlineprotected

Start a single MailboxSet (CMD/WORK/PUBLISH)

Template Parameters
IndexOutput index (0-based)

Definition at line 339 of file multi_output_manager.hpp.

References commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::derived().

◆ stop_all_mailbox_sets()

template<typename Derived , typename UserRegistry , typename OutputTypesTuple >
template<std::size_t... Is>
void commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::stop_all_mailbox_sets ( std::index_sequence< Is... >  )
inlineprotected

Stop all MailboxSets.

Called from Module::stop() to shut down all multi-output mailboxes.

Definition at line 365 of file multi_output_manager.hpp.

◆ stop_mailbox_set()

template<typename Derived , typename UserRegistry , typename OutputTypesTuple >
template<std::size_t Index>
void commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::stop_mailbox_set ( )
inlineprotected

Stop a single MailboxSet (CMD/WORK/PUBLISH)

Template Parameters
IndexOutput index (0-based)

Definition at line 377 of file multi_output_manager.hpp.

References commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::derived().

Member Data Documentation

◆ output_subscribers_

template<typename Derived , typename UserRegistry , typename OutputTypesTuple >
std::vector<std::vector<SubscriberInfo> > commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::output_subscribers_
protected

Per-output subscriber lists: output_subscribers_[output_index][subscriber_id].

Each output type maintains its own subscriber list for type-safe publishing. Subscriptions are routed based on the subscriber's expected message type ID.

Now stores SubscriberInfo (base_addr + input_index) for multi-input routing.

Definition at line 64 of file multi_output_manager.hpp.

Referenced by commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::add_subscriber_to_output(), commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::get_output_subscribers(), commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::initialize_output_subscribers(), and commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::remove_subscriber().

◆ output_subscribers_mutex_

◆ output_work_threads_

template<typename Derived , typename UserRegistry , typename OutputTypesTuple >
std::vector<std::thread> commrat::MultiOutputManager< Derived, UserRegistry, OutputTypesTuple >::output_work_threads_
protected

The documentation for this class was generated from the following file: