allpix::Messenger
Module: Managers
Manager responsible for setting up communication between modules and sending messages between them. More…
#include <Messenger.hpp>
Public Functions
Name | |
---|---|
Messenger(const Messenger & ) =delete Copying the messenger is not allowed. |
|
Messenger & | operator=(const Messenger & ) =delete Copying the messenger is not allowed. |
Messenger(Messenger && ) =delete Disallow move because of mutex. |
|
Messenger & | operator=(Messenger && ) =delete Disallow move because of mutex. |
Messenger() Construct the messenger. |
|
~Messenger() Default destructor (checks if delegates are removed in DEBUG) |
|
template <typename T > void |
registerFilter(T * receiver, bool(T::*)(const std::shared_ptr< BaseMessage > &, const std::string &name) const filter, MsgFlags flags =MsgFlags::IGNORE_NAME) Register a function filtering all dispatched messages. |
template <typename T ,typename R > void |
registerFilter(T * receiver, bool(T::*)(const std::shared_ptr< R > &) const filter, MsgFlags flags =MsgFlags::NONE) Register a function filtering a particular message. |
template <typename T > void |
bindSingle(Module * receiver, MsgFlags flags =MsgFlags::NONE) Register subscription for a single message. |
template <typename T > void |
bindMulti(Module * receiver, MsgFlags flags =MsgFlags::NONE) Register subscription for multiple messages. |
template <typename T > void |
dispatchMessage(Module * module, std::shared_ptr< T > message, Event * event, const std::string & name ="-") Dispatches a message to subscribing modules. |
template <typename T > std::shared_ptr< T > |
fetchMessage(Module * module, Event * event) Fetches a single message of specified type meant for the calling module. |
template <typename T > std::vector< std::shared_ptr< T > > |
fetchMultiMessage(Module * module, Event * event) Fetches multiple messages of specified type meant for the calling module. |
std::vector< std::pair< std::shared_ptr< BaseMessage >, std::string > > | fetchFilteredMessages(Module * module, Event * event) Fetches filtered messages meant for the calling module. |
bool | hasReceiver(Module * source, const std::shared_ptr< BaseMessage > & message) Check if a specific message has a receiver. |
bool | isSatisfied(BaseDelegate * delegate, Event * event) const Check if a delegate has received its message. |
Friends
Name | |
---|---|
class | Module |
class | Event |
class | LocalMessenger |
Detailed Description
class allpix::Messenger;
Manager responsible for setting up communication between modules and sending messages between them.
Registers and sets up communication (delegates) between modules by dispatching messages from one module to all other modules listening to these message types. The Messenger implements different way of receiving messages using Delegate classes, either through registering a filter or by binding direct to one or multiple message types. Messages are only sent to modules that have registered to the exact type of message.
Public Functions Documentation
function Messenger
Messenger(
const Messenger &
) =delete
Copying the messenger is not allowed.
function operator=
Messenger & operator=(
const Messenger &
) =delete
Copying the messenger is not allowed.
function Messenger
Messenger(
Messenger &&
) =delete
Disallow move because of mutex.
function operator=
Messenger & operator=(
Messenger &&
) =delete
Disallow move because of mutex.
function Messenger
Messenger()
Construct the messenger.
function ~Messenger
~Messenger()
Default destructor (checks if delegates are removed in DEBUG)
function registerFilter
template <typename T >
void registerFilter(
T * receiver,
bool(T::*)(const std::shared_ptr< BaseMessage > &, const std::string &name) const filter,
MsgFlags flags =MsgFlags::IGNORE_NAME
)
Register a function filtering all dispatched messages.
Parameters:
- receiver Receiving module
- filter Filter function in the module (fetching a pointer to the base message and the name of the message)
- flags Message configuration flags (defaults to ignoring the message name)
function registerFilter
template <typename T ,
typename R >
void registerFilter(
T * receiver,
bool(T::*)(const std::shared_ptr< R > &) const filter,
MsgFlags flags =MsgFlags::NONE
)
Register a function filtering a particular message.
Parameters:
- receiver Receiving module
- filter Filter function in the module (fetching a pointer to the message)
- flags Message configuration flags
function bindSingle
template <typename T >
void bindSingle(
Module * receiver,
MsgFlags flags =MsgFlags::NONE
)
Register subscription for a single message.
Parameters:
- receiver Receiving module
- flags Message configuration flags
Warning: This allows to only receive a single message of the type per run unless the ALLOW_OVERWRITE flag is passed
function bindMulti
template <typename T >
void bindMulti(
Module * receiver,
MsgFlags flags =MsgFlags::NONE
)
Register subscription for multiple messages.
Parameters:
- receiver Receiving module
- flags Message configuration flags
function dispatchMessage
template <typename T >
void dispatchMessage(
Module * module,
std::shared_ptr< T > message,
Event * event,
const std::string & name ="-"
)
Dispatches a message to subscribing modules.
Parameters:
- module Pointer to the module that dispatched the message
- message Pointer to the message to dispatch
- event Pointer to the event to dispatch the message to
- name Optional message name (defaults to - indicating that it should dispatch to the module output parameter)
function fetchMessage
template <typename T >
std::shared_ptr< T > fetchMessage(
Module * module,
Event * event
)
Fetches a single message of specified type meant for the calling module.
Parameters:
Return: Shared pointer to message
function fetchMultiMessage
template <typename T >
std::vector< std::shared_ptr< T > > fetchMultiMessage(
Module * module,
Event * event
)
Fetches multiple messages of specified type meant for the calling module.
Parameters:
Return: Vector of shared pointers to messages
function fetchFilteredMessages
std::vector< std::pair< std::shared_ptr< BaseMessage >, std::string > > fetchFilteredMessages(
Module * module,
Event * event
)
Fetches filtered messages meant for the calling module.
Parameters:
Return: Vector of pairs containing shared pointer to and name of message
function hasReceiver
bool hasReceiver(
Module * source,
const std::shared_ptr< BaseMessage > & message
)
Check if a specific message has a receiver.
Parameters:
- source Module that will send the message
- message Instantiation of the message to check
Return: True if the message has at least one receiver, false otherwise
Messages should be bound during construction, so this function only gives useful information outside the constructor
function isSatisfied
bool isSatisfied(
BaseDelegate * delegate,
Event * event
) const
Check if a delegate has received its message.
Parameters:
- delegate Delegate to check if it was satisfied
- event Event to check the messages for this delegate
Return: True if satisfied, false otherwise
Friends
friend Module
friend class Module(
Module
);
friend Event
friend class Event(
Event
);
friend LocalMessenger
friend class LocalMessenger(
LocalMessenger
);
Updated on 2024-12-13 at 08:31:37 +0000