18#include "../MimeType.hpp"
19#include "../ports/Kind.hpp"
21#include <dfx-utilities/UUIDGenerator.hpp>
39struct blank_construct_t {
explicit constexpr blank_construct_t()
noexcept =
default; };
103 std::vector<std::string>
const &
pathTaken() const noexcept {
return _pathTaken; }
106 std::chrono::microseconds
timestamp() const noexcept {
return _timestamp; }
118 template<
typename Clock = std::chrono::steady_clock>
119 requires std::chrono::is_clock_v<Clock>
121 {
return std::chrono::time_point<Clock, std::chrono::microseconds>(_timestamp); }
129 void addToPathTaken(std::string path) { _pathTaken.emplace_back(std::move(path)); }
135 bool hasMimeType() const noexcept {
return _mimeType.has_value(); }
163 template<DerivedFromMessage T>
164 bool is() const noexcept {
return dynamic_cast<T
const *
>(
this) !=
nullptr; }
170 template<DerivedFromMessage T>
171 T &
as() noexcept {
return static_cast<T &
>(*this); }
177 template<DerivedFromMessage T>
178 T
const &
as() const noexcept {
return static_cast<T
const &
>(*this); }
188 static std::unique_ptr<T>
create(Args && ... args)
189 {
return std::unique_ptr<T>(
new T(std::forward<Args>(args)...)); }
239 std::vector<std::string> _pathTaken;
240 std::chrono::microseconds _timestamp{};
243 std::optional<MimeType> _mimeType;
Convenience macros to explicitly control copy and move semantics.
Abstract base class for messages exchanged between nodes.
Definition Message.hpp:86
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:138
bool is() const noexcept
Check whether this message is of a given derived type.
Definition Message.hpp:164
DFX_DISABLE_COPY_AND_MOVE(Message)
Messages are non-copyable and non-movable.
static clockid_t timestampClock
Clock used by the constructor to capture timestamps.
Definition Message.hpp:197
static std::unique_ptr< T > create(Args &&... args)
Convenience allocator for derived message types.
Definition Message.hpp:188
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:101
std::vector< std::string > const & pathTaken() const noexcept
Sequence of "node.port" hops this message has traversed.
Definition Message.hpp:103
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:129
T const & as() const noexcept
Cast this message to a derived type (unchecked).
Definition Message.hpp:178
Message(MimeType mimeType, Message const *parent=nullptr)
Construct a message with an explicit MIME type, optionally inheriting from a parent.
T & as() noexcept
Cast this message to a derived type (unchecked).
Definition Message.hpp:171
void resetMimeType()
Clear the explicit MIME type (message then defaults to octet-stream).
Definition Message.hpp:146
Utils::UUID const & uuid() const noexcept
Unique identifier of this message instance.
Definition Message.hpp:99
virtual ~Message()
Virtual destructor.
Message(Message const *parent=nullptr)
Construct a message, optionally inheriting state from a parent message.
Message(blank_construct_t) noexcept
Construct a completely blank message without any timestamp or UUID attached to it This is mainly used...
Definition Message.hpp:215
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:120
std::chrono::microseconds timestamp() const noexcept
Construction timestamp in microseconds since timestampClock epoch. This is not "wall clock time" unle...
Definition Message.hpp:106
bool hasMimeType() const noexcept
Whether the message carries an explicit MIME type.
Definition Message.hpp:135
MIME type value object.
Definition MimeType.hpp:44
@ OctetStream
"application/octet-stream"
Definition MimeType.hpp:56
Definition Unpacker.hpp:20
Concept used by dfx::Core::Message::is() and dfx::Core::Message::as() to constrain types.
Definition Message.hpp:31
Definition Channel.hpp:25
std::unique_ptr< Message > MessagePtr
Unique ownership handle for messages.
Definition Message.hpp:27
constexpr blank_construct_t blank_construct
Tag used in constructor to indicate that the object should be as brut as possible.
Definition Message.hpp:41
Kind
Port kind (connection domain).
Definition Kind.hpp:29
Struct used when you explicitely want an object to be as bare as possible.
Definition Message.hpp:39
128-bit UUID value type.
Definition UUIDGenerator.hpp:33