dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
dfx::Core::InputPort Class Reference

Incoming message endpoint attached to a node. More...

#include <dfx-core/ports/InputPort.hpp>

Inheritance diagram for dfx::Core::InputPort:
[legend]
Collaboration diagram for dfx::Core::InputPort:
[legend]

Public Member Functions

 InputPort (Id id, NodeWPtr node, std::string name, Kind kind, MimeTypes supportedMimeTypes={}, std::optional< bool > allowsMimeTypePropagation=std::nullopt)
 Construct an input port.
MimeTypes supportedMimeTypes () const noexcept
 Return the list of MIME types supported by this input port. An empty list means “accept anything”.
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.
void processAllPendingMessages ()
 Drain and process all pending messages from all attached channels.
void processMessage (MessagePtr message)
 Process a single message received on this input port.
void setAllowUnknownControlCommand (bool allow)
 Allow or forbid unknown control commands.
bool isUnknownControlCommandAllowed () const noexcept
 Whether unknown control commands are accepted.
void registerControlCommand (std::string_view command, nlohmann::json schema, bool allowOverride=false)
 Register a control command JSON schema for validation.
void deregisterControlCommand (std::string_view command)
 Deregister a control command schema.
Public Member Functions inherited from dfx::Core::Port
 ENABLE_DEFAULT_MOVE_DISABLE_COPY (Port)
 Move is allowed, copy is disabled.
virtual ~Port ()
 Virtual destructor for inheritance.
NodePtr node () const noexcept
 Get the owning node.
template<DerivedFromPort T>
T & as () noexcept
 Unchecked cast to a derived port type.
template<DerivedFromPort T>
T const & as () const noexcept
 Unchecked cast to a derived port type.
Id id () const noexcept
 Get the port id.
std::string const & name () const noexcept
 Get the port name.
Mode mode () const noexcept
 Get the port mode.
Kind kind () const noexcept
 Get the port kind.
bool isInput () const noexcept
 Check is this is an input port.
bool isOutput () const noexcept
 Check is this is an output port.
std::optional< bool > allowsMimeTypePropagation () const noexcept
 Check if this node allow mime-type propagation.
void addChannel (ChannelPtr channel)
 Attach a channel to this port.
void removeChannel (ChannelPtr channel)
 Detach a channel from this port. If the channel is not present, this is a no-op.
bool hasChannel (ChannelPtr channel) const noexcept
 Check whether a channel is attached to this port.
std::size_t channelCount () const noexcept
 Number of attached channels.
ChannelPtr channel (std::size_t index) const
 Get the attached channel at the given index.
void registerHook (Hooks::Port *hook)
 Register a hook on this port.
void deregisterHook (Hooks::Port *hook)
 Deregister a hook from this port. If the hook is not registered, this is a no-op.

Additional Inherited Members

Public Types inherited from dfx::Core::Port
enum class  Mode { Input , Output }
 Port direction. More...
using Id = uint32_t
 Identifier type of a port (unique within a node by not unique accross a graph).
Static Public Member Functions inherited from dfx::Core::Port
static void validatePortName (std::string_view name)
 Validate a port name according to dfx rules.
Protected Member Functions inherited from dfx::Core::Port
 Port (Id id, NodeWPtr node, Mode mode, Kind kind, std::string name, std::optional< bool > allowsMimeTypePropagation)
 Construct a port.
Protected Attributes inherited from dfx::Core::Port
std::vector< Hooks::Port * > hooks
 Registered port hooks. Stored as raw pointers. Managed via registerHook and deregisterHook.

Detailed Description

Incoming message endpoint attached to a node.

MIME type support
The port may declare a list of supported MIME types (supportedMimeTypes).
Pending messages
The input port does not own message queues itself; it queries each attached dfx::Core::Channel for pending messages.
Runtime constraints and validation
When processing a message:
  • If the owning node is expired (weak pointer cannot be locked), processing is a no-op.
  • Asserts that the owning node is running.
  • Asserts that the message dfx::Core::Kind matches the port kind() (data/control "network" segregation).
Control command validation
For dfx::Core::Kind::Control messages (see dfx::Core::ControlMessage):
  • The command can be registered with a JSON schema via registerControlCommand.
  • If the schema exists, params are validated using dfx::Utils::JsonValidator against the schema at JSON pointer "/params".
  • If the command is not registered:
    • If isUnknownControlCommandAllowed is false, an exception is thrown listing the known commands.
    • If it is true, the command is accepted without schema validation.
Hooks and path tracking
Before the message is forwarded to the node:

Constructor & Destructor Documentation

◆ InputPort()

dfx::Core::InputPort::InputPort ( Id id,
NodeWPtr node,
std::string name,
Kind kind,
MimeTypes supportedMimeTypes = {},
std::optional< bool > allowsMimeTypePropagation = std::nullopt )

Construct an input port.

Parameters
idPort id (unique within the owning node).
nodeOwning node (weak reference).
namePort name.
kindConnectivity domain (data/control "network").
supportedMimeTypesList of accepted MIME types. If empty, accepts any.
allowsMimeTypePropagationOptional override for MIME type propagation.

Member Function Documentation

◆ deregisterControlCommand()

void dfx::Core::InputPort::deregisterControlCommand ( std::string_view command)

Deregister a control command schema.

After deregistration, receiving that command will be considered "unknown" will either throw or be allowed depending on isUnknownControlCommandAllowed.

◆ hasPendingMessage()

bool dfx::Core::InputPort::hasPendingMessage ( ) const

Check whether any attached channel has at least one pending message.

Returns
true if at least one channel reports pending messages.

◆ isMimeTypeSupported()

bool dfx::Core::InputPort::isMimeTypeSupported ( MimeType const & mimeType) const
noexcept

Check whether a MIME type is compatible with this port.

Implemented rules:

  • If mimeType is Any, returns true.
  • If supportedMimeTypes() is empty, returns true.
  • Otherwise returns true iff mimeType is contained in the list.

◆ isUnknownControlCommandAllowed()

bool dfx::Core::InputPort::isUnknownControlCommandAllowed ( ) const
inlinenoexcept

Whether unknown control commands are accepted.

◆ processAllPendingMessages()

void dfx::Core::InputPort::processAllPendingMessages ( )

Drain and process all pending messages from all attached channels.

For each attached channel, repeatedly pops messages until none remain, and forwards each message to processMessage.

◆ processMessage()

void dfx::Core::InputPort::processMessage ( MessagePtr message)

Process a single message received on this input port.

Performs:

  • Node existence check (expired node => no-op).
  • Runtime assertions: node must be running, and message kind must match port kind.
  • For control messages: optional JSON schema validation or unknown-command handling.
  • Path update and hook invocation.
  • Forwarding to Node::handleMessage(*this, message).
Parameters
messageMessage to process.

◆ registerControlCommand()

void dfx::Core::InputPort::registerControlCommand ( std::string_view command,
nlohmann::json schema,
bool allowOverride = false )

Register a control command JSON schema for validation.

The schema is registered under command, and validation checks the message params against the schema at JSON pointer "/params".

Parameters
commandCommand name.
schemaJSON schema.
allowOverrideIf true, replaces an existing schema for the same command.

◆ setAllowUnknownControlCommand()

void dfx::Core::InputPort::setAllowUnknownControlCommand ( bool allow)
inline

Allow or forbid unknown control commands.

If false (default), receiving an unregistered control command throws. If true, unregistered commands are accepted without schema validation.

◆ supportedMimeTypes()

MimeTypes dfx::Core::InputPort::supportedMimeTypes ( ) const
inlinenoexcept

Return the list of MIME types supported by this input port. An empty list means “accept anything”.


The documentation for this class was generated from the following file: