#include <message_manager.hpp>
template<typename MessageDataType>
class cbeam::concurrency::message_manager< MessageDataType >
- Examples
- cbeam/concurrency/message_manager.hpp.
◆ message_id_type
template<typename MessageDataType>
◆ message_logger_type
template<typename MessageDataType>
Typedef for a message logging function.
Defines a function type used for logging messages. The function takes three parameters: the message ID, the message data of type MessageDataType
, and a boolean flag indicating whether the message is outgoing (true) or incoming (false). This allows for flexible integration of custom logging functionality within the message processing flow.
◆ order_type
template<typename MessageDataType>
Enum class defining the order in which messages are processed.
This enumeration specifies the order in which messages are handled by the message handlers. The available ordering types are:
- FIFO (First In First Out): Messages are processed in the order they are received. This is a traditional approach that ensures a predictable processing order.
- FILO (First In Last Out): The most recently received message is processed first. This approach can be useful for prioritizing newer messages.
- RANDOM: Messages are processed in a random order. In certain algorithmic contexts, such as fill algorithms for raster graphics, introducing randomness can reduce the overall length of the message queue. This is due to the reduction of path dependencies and the increased entropy in message processing, which avoids consistent biases towards older (FIFO) or newer (FILO) messages. However, for long message queues, the efficiency might decrease due to the overhead of random access in a
std::deque
. Nevertheless, the RANDOM mode can be beneficial if it aligns with the algorithmic needs and the message queues remain short.
Enumerator |
---|
FIFO | Process messages in the order they were received.
|
FILO | Process the most recently received message first.
|
RANDOM | Process messages in a random order, reducing path dependencies in certain algorithms but less efficient for long queues.
|
◆ add_handler()
template<typename MessageDataType>
Adds a message handler for a specified message ID.
This method registers a new message handler for a specified ID. The handler will process messages sent to the given message ID. Handlers can be customized with functions to execute on message reception, exception occurrence, idle state, and handler exit. The method supports specifying a thread name and the order in which messages are processed.
- Parameters
-
message_id | The message ID for which the handler is being added. It can be any arbitrary number and does not require sequential order. |
on_message | A function to be called when a message is received. The function should accept a message of the type specified by the MessageDataType template parameter. |
on_exception | Optional. A function to be called if an exception occurs during message processing. It must accept a std::exception object. |
on_exit | Optional. A function to be called when the message handler is about to exit. |
thread_name | Optional. A name for the thread running the handler. Useful for debugging purposes. |
order | The order in which messages will be processed by this handler. Can be FIFO (First In First Out), FILO (First In Last Out), or RANDOM. |
- Note
- This method is thread-safe and synchronizes the addition of handlers.
- Examples
- cbeam/concurrency/message_manager.hpp.
◆ dispose()
template<typename MessageDataType>
◆ send_message()
template<typename MessageDataType>
Sends a message of specified ID and data.
This method enqueues a message of a specified ID. The message is added to the queue corresponding to this ID and will be processed according to the queue's order type (FIFO, FILO, or RANDOM). If a maximum queue size is specified and the queue is full, this method will block until there is space available in the queue. The add_handler
method does not need to be called prior to this; message_id
can be any arbitrary number, assuming a corresponding handler is or will be registered. As it uses an internal std::map
, IDs do not need to be sequential numbers.
- Parameters
-
message_id | The message ID to be sent. This can be any arbitrary number and does not require sequential order. |
message_data | The message data to be sent. This must be of the type specified by the MessageDataType template parameter. |
max_queued_messages | The maximum number of messages allowed in the queue of this ID. If the queue is full, this method will block until space is available. A value of 0 means no limit on the queue size. |
- Note
- This method is thread-safe and ensures that messages are enqueued in a synchronized manner.
- Examples
- cbeam/concurrency/message_manager.hpp.
◆ set_logger()
template<typename MessageDataType>
◆ wait_until_empty()
template<typename MessageDataType>
The documentation for this class was generated from the following file: