sdi_toolBox
message.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2026 - SD-Innovation S.A.S. - FRANCE
3*/
4
5/*
6ver: 2.x.x - build: 2026-04-28
7*/
8
9/*
10The 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.
11*/
12
13#pragma once
14
15#include "defs.h"
16
18{
19//--------------------------------------------------------------
54{
55 friend class Bus;
56
57 public:
60
66 Message() = delete;
67
71 virtual ~Message() = default;
72
78 Message(const Message &obj) = delete;
79
85 Message(Message &&obj) noexcept = delete;
86
92 Message &operator=(const Message &obj) = delete;
93
99 Message &operator=(Message &&obj) noexcept = delete;
100
108 explicit Message(MessageTypeID messageTypeID);
109
113
119 [[nodiscard]] MessageTypeID getMessageTypeID() const;
120
131 [[nodiscard]] TimePoint getTimestamp() const;
132
134
135 private:
142 void updateTimestamp();
143
144 MessageTypeID m_messageTypeID;
145 TimePoint m_messagePostTimestamp{};
146};
147//--------------------------------------------------------------
148
149//--------------------------------------------------------------
150/* Constructor */
151inline Message::Message(const MessageTypeID messageTypeID)
152{
153 m_messageTypeID = messageTypeID;
154}
155//--------------------------------------------------------------
156/* Get the unique identifier for the message type */
158{
159 return m_messageTypeID;
160}
161//--------------------------------------------------------------
162/* Get the timestamp of when the message was posted to the bus */
164{
165 return m_messagePostTimestamp;
166}
167//--------------------------------------------------------------
168/* Update the timestamp of when the message was posted to the bus */
169inline void Message::updateTimestamp()
170{
171 m_messagePostTimestamp = std::chrono::steady_clock::now();
172}
173//--------------------------------------------------------------
174} // namespace sdi_toolBox::desktop::eventBus
Central message dispatcher for the event bus system.
Definition bus.h:63
Base class for all messages dispatched through the event bus.
Definition message.h:54
TimePoint getTimestamp() const
Get the timestamp of when this message was posted to the bus.
Definition message.h:163
Message & operator=(Message &&obj) noexcept=delete
Move assignment operator - deleted.
Message & operator=(const Message &obj)=delete
Copy assignment operator - deleted.
Message(const Message &obj)=delete
Copy constructor - deleted.
MessageTypeID getMessageTypeID() const
Get the unique type identifier of this message.
Definition message.h:157
Message()=delete
Default constructor - deleted.
Message(Message &&obj) noexcept=delete
Move constructor - deleted.
virtual ~Message()=default
Default destructor.
Lightweight thread-safe event bus for decoupled message passing.
Definition bus.h:27
uint64_t MessageTypeID
Unique identifier for a message type.
Definition defs.h:21
std::chrono::steady_clock::time_point TimePoint
Monotonic timestamp type used throughout the event bus.
Definition defs.h:22