message.h
Go to the documentation of this file.
/*
Copyright (c) 2026 - SD-Innovation S.A.S. - FRANCE
*/
/*
ver: 2.x.x - build: 2026-04-28
*/
/*
The zlib License Copyright (c) 2026 SD-Innovation S.A.S. This software is provided ‘as-is’, without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution.
*/
#pragma once
#include "defs.h"
namespace sdi_toolBox::desktop::eventBus
{
//--------------------------------------------------------------
class Message
{
friend class Bus;
public:
Message() = delete;
virtual ~Message() = default;
Message(const Message &obj) = delete;
Message(Message &&obj) noexcept = delete;
Message &operator=(const Message &obj) = delete;
Message &operator=(Message &&obj) noexcept = delete;
explicit Message(MessageTypeID messageTypeID);
[[nodiscard]] MessageTypeID getMessageTypeID() const;
[[nodiscard]] TimePoint getTimestamp() const;
private:
void updateTimestamp();
MessageTypeID m_messageTypeID;
TimePoint m_messagePostTimestamp{};
};
//--------------------------------------------------------------
//--------------------------------------------------------------
/* Constructor */
inline Message::Message(const MessageTypeID messageTypeID)
{
m_messageTypeID = messageTypeID;
}
//--------------------------------------------------------------
/* Get the unique identifier for the message type */
inline MessageTypeID Message::getMessageTypeID() const
{
return m_messageTypeID;
}
//--------------------------------------------------------------
/* Get the timestamp of when the message was posted to the bus */
inline TimePoint Message::getTimestamp() const
{
return m_messagePostTimestamp;
}
//--------------------------------------------------------------
/* Update the timestamp of when the message was posted to the bus */
inline void Message::updateTimestamp()
{
m_messagePostTimestamp = std::chrono::steady_clock::now();
}
//--------------------------------------------------------------
} // namespace sdi_toolBox::desktop::eventBus
sdi_toolBox::desktop::eventBus::Bus
Central message dispatcher for the event bus system.
Definition bus.h:63
sdi_toolBox::desktop::eventBus::Message
Base class for all messages dispatched through the event bus.
Definition message.h:54
sdi_toolBox::desktop::eventBus::Message::getTimestamp
TimePoint getTimestamp() const
Get the timestamp of when this message was posted to the bus.
Definition message.h:163
sdi_toolBox::desktop::eventBus::Message::operator=
Message & operator=(Message &&obj) noexcept=delete
Move assignment operator - deleted.
sdi_toolBox::desktop::eventBus::Message::operator=
Message & operator=(const Message &obj)=delete
Copy assignment operator - deleted.
sdi_toolBox::desktop::eventBus::Message::Message
Message(const Message &obj)=delete
Copy constructor - deleted.
sdi_toolBox::desktop::eventBus::Message::getMessageTypeID
MessageTypeID getMessageTypeID() const
Get the unique type identifier of this message.
Definition message.h:157
sdi_toolBox::desktop::eventBus::Message::Message
Message()=delete
Default constructor - deleted.
sdi_toolBox::desktop::eventBus::Message::Message
Message(Message &&obj) noexcept=delete
Move constructor - deleted.
sdi_toolBox::desktop::eventBus::Message::~Message
virtual ~Message()=default
Default destructor.
defs.h
sdi_toolBox::desktop::eventBus
Lightweight thread-safe event bus for decoupled message passing.
Definition bus.h:27
sdi_toolBox::desktop::eventBus::MessageTypeID
uint64_t MessageTypeID
Unique identifier for a message type.
Definition defs.h:21
sdi_toolBox::desktop::eventBus::TimePoint
std::chrono::steady_clock::time_point TimePoint
Monotonic timestamp type used throughout the event bus.
Definition defs.h:22