dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
ControlMessage.hpp
1// SPDX-FileCopyrightText: 2025-2026 Vincent Leroy
2// SPDX-License-Identifier: MIT
3//
4// This file is part of dfx.
5//
6// Licensed under the MIT License. See the LICENSE file in the project root
7// for full license information.
8
9#pragma once
10
11// Third-party includes
12#include <nlohmann/json.hpp>
13
14// Project includes
15#include "Message.hpp"
16
17namespace dfx::Core
18{
55class ControlMessage : public Message
56{
57 friend class Message;
58 friend class details::Unpacker;
59
60public:
62 int version() const noexcept { return _version; }
63
65 std::string const & command() const noexcept { return _command; }
66
68 nlohmann::json const & params() const noexcept { return _params; }
69
80 nlohmann::json toJson() const;
81
82public:
84 Kind kind() const override { return Kind::Control; }
85
92 MessagePtr clone() const override;
93
94protected:
101 void cloneFromBase(Message const & base) override;
102
103protected:
105 explicit ControlMessage(blank_construct_t) noexcept : Message(blank_construct) {}
106
112 explicit ControlMessage(Message const * parent = nullptr);
113
122 explicit ControlMessage(std::string command, nlohmann::json params = {}, int version = 1, Message const * parent = nullptr);
123
124private:
125 int _version = 1;
126 std::string _command;
127 nlohmann::json _params;
128};
129} // !namespace dfx::Core
ControlMessage(blank_construct_t) noexcept
Construct a completely blank message without any timestamp or UUID attached to it.
Definition ControlMessage.hpp:105
int version() const noexcept
Protocol version of this control message (default: 1).
Definition ControlMessage.hpp:62
Kind kind() const override
This message belongs to the control-plane connectivity domain.
Definition ControlMessage.hpp:84
std::string const & command() const noexcept
Command name carried by this message.
Definition ControlMessage.hpp:65
nlohmann::json const & params() const noexcept
JSON parameters carried by this message (may be null).
Definition ControlMessage.hpp:68
void cloneFromBase(Message const &base) override
Copy base and derived state from base into this instance.
MessagePtr clone() const override
Clone this message (deep copy).
ControlMessage(std::string command, nlohmann::json params={}, int version=1, Message const *parent=nullptr)
Construct a control message with command, params and version.
ControlMessage(Message const *parent=nullptr)
Construct an empty control message, optionally inheriting from a parent.
nlohmann::json toJson() const
Serialize this control message to JSON.
Abstract base class for messages exchanged between nodes.
Definition Message.hpp:86
Definition Unpacker.hpp:20
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
@ Control
Control-plane ports.
Definition Kind.hpp:41
Struct used when you explicitely want an object to be as bare as possible.
Definition Message.hpp:39