dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
InputPort.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// Standard includes
12#include <atomic>
13
14// Project includes
15#include "../messages/Message.hpp"
16#include "Port.hpp"
17#include <dfx-utilities/JsonValidator.hpp>
18
19namespace dfx::Core
20{
56class InputPort : public Port
57{
58public:
67 InputPort(Id id, NodeWPtr node, std::string name, Kind kind, MimeTypes supportedMimeTypes = {}, std::optional<bool> allowsMimeTypePropagation = std::nullopt);
68
71 MimeTypes supportedMimeTypes() const noexcept { return _supportedMimeTypes; }
72
79 bool isMimeTypeSupported(MimeType const & mimeType) const noexcept;
80
81public:
87
99
100public:
105 void setAllowUnknownControlCommand(bool allow) { _allowUnknownControlCommand = allow; }
106
108 bool isUnknownControlCommandAllowed() const noexcept { return _allowUnknownControlCommand; }
109
118 void registerControlCommand(std::string_view command, nlohmann::json schema, bool allowOverride = false);
119
124 void deregisterControlCommand(std::string_view command);
125
126public:
129
138 bool testAndSetScheduled() noexcept { return _scheduled->test_and_set(std::memory_order::acq_rel); }
139
144 void clearScheduled() noexcept { _scheduled->clear(std::memory_order::release); }
145
147
148private:
149 MimeTypes _supportedMimeTypes;
150
151private:
152 bool _allowUnknownControlCommand = false;
153 Utils::JsonValidator _controlJsonValidator;
154 std::unique_ptr<std::atomic_flag> _scheduled;
155};
156} // !namespace dfx::Core
void setAllowUnknownControlCommand(bool allow)
Allow or forbid unknown control commands.
Definition InputPort.hpp:105
void registerControlCommand(std::string_view command, nlohmann::json schema, bool allowOverride=false)
Register a control command JSON schema for validation.
InputPort(Id id, NodeWPtr node, std::string name, Kind kind, MimeTypes supportedMimeTypes={}, std::optional< bool > allowsMimeTypePropagation=std::nullopt)
Construct an input port.
bool isUnknownControlCommandAllowed() const noexcept
Whether unknown control commands are accepted.
Definition InputPort.hpp:108
void processMessage(MessagePtr message)
Process a single message received on this input port.
void clearScheduled() noexcept
Clears the scheduled flag, allowing new tasks to be queued for this port.
Definition InputPort.hpp:144
void deregisterControlCommand(std::string_view command)
Deregister a control command schema.
bool testAndSetScheduled() noexcept
Attempts to claim the scheduling right for this port. This is an atomic test-and-set operation used b...
Definition InputPort.hpp:138
MimeTypes supportedMimeTypes() const noexcept
Return the list of MIME types supported by this input port. An empty list means “accept anything”.
Definition InputPort.hpp:71
void processAllPendingMessages()
Drain and process all pending messages from all attached channels.
bool isMimeTypeSupported(MimeType const &mimeType) const noexcept
Check whether a MIME type is compatible with this port.
MIME type value object.
Definition MimeType.hpp:44
Port(Id id, NodeWPtr node, Mode mode, Kind kind, std::string name, std::optional< bool > allowsMimeTypePropagation)
Construct a port.
NodePtr node() const noexcept
Get the owning node.
Definition Port.hpp:87
std::string const & name() const noexcept
Get the port name.
Definition Port.hpp:95
Kind kind() const noexcept
Get the port kind.
Definition Port.hpp:99
std::optional< bool > allowsMimeTypePropagation() const noexcept
Check if this node allow mime-type propagation.
Definition Port.hpp:106
uint32_t Id
Identifier type of a port (unique within a node by not unique accross a graph).
Definition Port.hpp:69
Registry of JSON Schemas with validation helpers.
Definition JsonValidator.hpp:46
Definition Channel.hpp:25
std::unique_ptr< Message > MessagePtr
Unique ownership handle for messages.
Definition Message.hpp:27
std::vector< MimeType > MimeTypes
Convenience alias for a list of MIME types.
Definition MimeType.hpp:130
std::weak_ptr< Node > NodeWPtr
Weak pointer type for Nodes.
Definition Node.hpp:66
Kind
Port kind (connection domain).
Definition Kind.hpp:29