dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
ControlMessage.hpp
1// SPDX-FileCopyrightText: 2025 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
59public:
61 int version() const noexcept { return _version; }
62
64 std::string const & command() const noexcept { return _command; }
65
67 nlohmann::json const & params() const noexcept { return _params; }
68
79 nlohmann::json toJson() const;
80
81public:
83 Kind kind() const override { return Kind::Control; }
84
91 MessagePtr clone() const override;
92
93protected:
100 void cloneFromBase(Message const & base) override;
101
102protected:
108 ControlMessage(MessagePtr const & parent = nullptr);
109
118 ControlMessage(std::string command, nlohmann::json params = {}, int version = 1, MessagePtr const & parent = nullptr);
119
120private:
121 int _version = 1;
122 std::string _command;
123 nlohmann::json _params;
124};
125} // !namespace dfx::Core
ControlMessage(MessagePtr const &parent=nullptr)
Construct an empty control message, optionally inheriting from a parent.
int version() const noexcept
Protocol version of this control message (default: 1).
Definition ControlMessage.hpp:61
Kind kind() const override
This message belongs to the control-plane connectivity domain.
Definition ControlMessage.hpp:83
std::string const & command() const noexcept
Command name carried by this message.
Definition ControlMessage.hpp:64
nlohmann::json const & params() const noexcept
JSON parameters carried by this message (may be null).
Definition ControlMessage.hpp:67
void cloneFromBase(Message const &base) override
Copy base and derived state from base into this instance.
ControlMessage(std::string command, nlohmann::json params={}, int version=1, MessagePtr const &parent=nullptr)
Construct a control message with command, params and version.
MessagePtr clone() const override
Clone this message (deep copy).
nlohmann::json toJson() const
Serialize this control message to JSON.
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
@ Control
Control-plane ports.
Definition Kind.hpp:41