dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
InputPort.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// Project includes
12#include "../messages/Message.hpp"
13#include "Port.hpp"
14#include <dfx-utilities/JsonValidator.hpp>
15
16namespace dfx::Core
17{
54class InputPort : public Port
55{
56public:
65 InputPort(Id id, NodeWPtr node, std::string name, Kind kind, MimeTypes supportedMimeTypes = {}, std::optional<bool> allowsMimeTypePropagation = std::nullopt);
66
69 MimeTypes supportedMimeTypes() const noexcept { return _supportedMimeTypes; }
70
77 bool isMimeTypeSupported(MimeType const & mimeType) const noexcept;
78
79public:
82 bool hasPendingMessage() const;
83
89
101
102public:
107 void setAllowUnknownControlCommand(bool allow) { _allowUnknownControlCommand = allow; }
108
110 bool isUnknownControlCommandAllowed() const noexcept { return _allowUnknownControlCommand; }
111
120 void registerControlCommand(std::string_view command, nlohmann::json schema, bool allowOverride = false);
121
126 void deregisterControlCommand(std::string_view command);
127
128private:
129 MimeTypes _supportedMimeTypes;
130
131private:
132 bool _allowUnknownControlCommand = false;
133 Utils::JsonValidator _controlJsonValidator;
134};
135} // !namespace dfx::Core
void setAllowUnknownControlCommand(bool allow)
Allow or forbid unknown control commands.
Definition InputPort.hpp:107
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:110
void processMessage(MessagePtr message)
Process a single message received on this input port.
void deregisterControlCommand(std::string_view command)
Deregister a control command schema.
MimeTypes supportedMimeTypes() const noexcept
Return the list of MIME types supported by this input port. An empty list means “accept anything”.
Definition InputPort.hpp:69
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.
bool hasPendingMessage() const
Check whether any attached channel has at least one pending message.
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:22
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:63
Kind
Port kind (connection domain).
Definition Kind.hpp:29