18#include "../MimeType.hpp"
19#include "../ports/Kind.hpp"
21#include <dfx-utilities/UUIDGenerator.hpp>
91 std::vector<std::string>
const &
pathTaken() const noexcept {
return _pathTaken; }
94 std::chrono::microseconds
timestamp() const noexcept {
return _timestamp; }
106 template<
typename Clock = std::chrono::steady_clock>
107 requires std::chrono::is_clock_v<Clock>
109 {
return std::chrono::time_point<Clock, std::chrono::microseconds>(_timestamp); }
117 void addToPathTaken(std::string path) { _pathTaken.emplace_back(std::move(path)); }
123 bool hasMimeType() const noexcept {
return _mimeType.has_value(); }
151 template<DerivedFromMessage T>
152 bool is() const noexcept {
return dynamic_cast<T
const *
>(
this) !=
nullptr; }
158 template<DerivedFromMessage T>
159 T &
as() noexcept {
return static_cast<T &
>(*this); }
165 template<DerivedFromMessage T>
166 T
const &
as() const noexcept {
return static_cast<T
const &
>(*this); }
176 static std::unique_ptr<T>
create(Args && ... args)
177 {
return std::unique_ptr<T>(
new T(std::forward<Args>(args)...)); }
223 std::vector<std::string> _pathTaken;
224 std::chrono::microseconds _timestamp{};
227 std::optional<MimeType> _mimeType;
Convenience macros to explicitly control copy and move semantics.
Abstract base class for messages exchanged between nodes.
Definition Message.hpp:76
Message(MessagePtr const &parent=nullptr)
Construct a message, optionally inheriting state from a parent message.
virtual Kind kind() const =0
Connectivity domain of this message (data/control "network").
MimeType mimeType() const noexcept
Get the message MIME type. If no explicit MIME type is set, returns dfx::Core::MimeType::OctetStream.
Definition Message.hpp:126
bool is() const noexcept
Check whether this message is of a given derived type.
Definition Message.hpp:152
static clockid_t timestampClock
Clock used by the constructor to capture timestamps.
Definition Message.hpp:185
static std::unique_ptr< T > create(Args &&... args)
Convenience allocator for derived message types.
Definition Message.hpp:176
void setMimeType(MimeType mimeType)
Set the message MIME type.
Utils::UUID const & parentUuid() const noexcept
UUID of the parent message if created from one, otherwise default UUID value.
Definition Message.hpp:89
std::vector< std::string > const & pathTaken() const noexcept
Sequence of "node.port" hops this message has traversed.
Definition Message.hpp:91
virtual MessagePtr clone() const =0
Clone this message (polymorphic deep copy).
virtual void cloneFromBase(Message const &base)
Copy the base-class state from another message.
void addToPathTaken(std::string path)
Append one hop to the message path trace.
Definition Message.hpp:117
T const & as() const noexcept
Cast this message to a derived type (unchecked).
Definition Message.hpp:166
T & as() noexcept
Cast this message to a derived type (unchecked).
Definition Message.hpp:159
void resetMimeType()
Clear the explicit MIME type (message then defaults to octet-stream).
Definition Message.hpp:134
Utils::UUID const & uuid() const noexcept
Unique identifier of this message instance.
Definition Message.hpp:87
virtual ~Message()
Virtual destructor.
DISABLE_COPY_AND_MOVE(Message)
Messages are non-copyable and non-movable.
Message(MimeType mimeType, MessagePtr const &parent=nullptr)
Construct a message with an explicit MIME type, optionally inheriting from a parent.
std::chrono::time_point< Clock, std::chrono::microseconds > timestampToTimePoint() const noexcept
Convert timestamp() into a time_point of the given clock type.
Definition Message.hpp:108
std::chrono::microseconds timestamp() const noexcept
Construction timestamp in microseconds since timestampClock epoch. This is not "wall clock time" unle...
Definition Message.hpp:94
bool hasMimeType() const noexcept
Whether the message carries an explicit MIME type.
Definition Message.hpp:123
MIME type value object.
Definition MimeType.hpp:44
@ OctetStream
"application/octet-stream"
Definition MimeType.hpp:56
Concept used by dfx::Core::Message::is() and dfx::Core::Message::as() to constrain types.
Definition Message.hpp:31
Definition Channel.hpp:22
std::unique_ptr< Message > MessagePtr
Unique ownership handle for messages.
Definition Message.hpp:27
Kind
Port kind (connection domain).
Definition Kind.hpp:29
128-bit UUID value type.
Definition UUIDGenerator.hpp:33