sdi_toolBox
Friends | List of all members
Message Class Reference

#include <message.h>

Detailed Description

Base class for all messages dispatched through the event bus.

Every message circulating in the event bus system must derive from this class. It carries a unique message type identifier (MessageTypeID) used by the Bus to route the message to the appropriate subscribers, and a timestamp that is updated when the message is posted to the bus.

Note
The Message class is non-copyable and non-movable.
The default constructor is deleted: a MessageTypeID must always be provided at construction time.
The timestamp is set by the Bus internally when Bus::post() is called; it is not set at construction time.
Example - defining a custom message:
static constexpr sdi_toolBox::desktop::eventBus::MessageTypeID MY_EVENT = 1;
struct MyMessage : public sdi_toolBox::desktop::eventBus::Message
{
explicit MyMessage(int value)
: Message(MY_EVENT)
, payload(value)
{}
int payload{};
};
Base class for all messages dispatched through the event bus.
Definition message.h:54
uint64_t MessageTypeID
Unique identifier for a message type.
Definition defs.h:21
See also
Bus
MessageTypeID
TimePoint

Definition at line 53 of file message.h.

Public Member Functions

Construction & Destruction
 Message ()=delete
 Default constructor - deleted.
 
virtual ~Message ()=default
 Default destructor.
 
 Message (const Message &obj)=delete
 Copy constructor - deleted.
 
 Message (Message &&obj) noexcept=delete
 Move constructor - deleted.
 
Messageoperator= (const Message &obj)=delete
 Copy assignment operator - deleted.
 
Messageoperator= (Message &&obj) noexcept=delete
 Move assignment operator - deleted.
 
 Message (MessageTypeID messageTypeID)
 Construct a message with the given type identifier.
 
Accessors
MessageTypeID getMessageTypeID () const
 Get the unique type identifier of this message.
 
TimePoint getTimestamp () const
 Get the timestamp of when this message was posted to the bus.
 

Friends

class Bus
 Allow the Bus class to access private members.
 

Constructor & Destructor Documentation

◆ Message() [1/4]

Message ( )
delete

Default constructor - deleted.

A MessageTypeID must always be provided at construction time.

◆ ~Message()

virtual ~Message ( )
virtualdefault

Default destructor.

◆ Message() [2/4]

Message ( const Message obj)
delete

Copy constructor - deleted.

Message is non-copyable.

◆ Message() [3/4]

Message ( Message &&  obj)
deletenoexcept

Move constructor - deleted.

Message is non-movable.

◆ Message() [4/4]

Message ( MessageTypeID  messageTypeID)
inlineexplicit

Construct a message with the given type identifier.

Parameters
messageTypeIDUnique identifier representing the type of this message. Used by the Bus to route the message to the correct subscribers.

Definition at line 151 of file message.h.

Member Function Documentation

◆ operator=() [1/2]

Message & operator= ( const Message obj)
delete

Copy assignment operator - deleted.

Message is non-copyable.

◆ operator=() [2/2]

Message & operator= ( Message &&  obj)
deletenoexcept

Move assignment operator - deleted.

Message is non-movable.

◆ getMessageTypeID()

MessageTypeID getMessageTypeID ( ) const
inline

Get the unique type identifier of this message.

Returns
The MessageTypeID assigned at construction time.

Definition at line 157 of file message.h.

◆ getTimestamp()

TimePoint getTimestamp ( ) const
inline

Get the timestamp of when this message was posted to the bus.

The timestamp is recorded by the Bus when Bus::post() is called. It is left at its default-constructed (zero) value if the message has not yet been posted.

Returns
A TimePoint representing the moment the message was dispatched.
See also
Bus::post()

Definition at line 163 of file message.h.

Friends And Related Symbol Documentation

◆ Bus

friend class Bus
friend

Allow the Bus class to access private members.

Definition at line 55 of file message.h.