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

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

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

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

Public Member Functions

 OutputPort (Id id, NodeWPtr node, std::string name, Kind kind, MimeType mimeType=MimeType::Any, std::optional< bool > allowsMimeTypePropagation=std::nullopt)
 Construct an output port.
MimeType const & mimeType () const noexcept
 Declared MIME type emitted by this port.
bool isMimeTypeSupported (MimeType const &mimeType) const noexcept
 Test whether a MIME type is compatible with this port.
void sendMessage (MessagePtr msg)
 Send a message through this output port.
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

Outgoing message endpoint attached to a node.

Mime type
The port has a single MIME type declared (mimeType()).
Delivery to multiple channels
Messages are delivered to every attached channel:
  • For N channels, the message is cloned N-1 times.
  • The last channel receives the original message via move.

This minimizes cloning while keeping each channel independent (each delivery gets a distinct message object).

Hooks
Before pushing a message to a channel, the port calls all registered dfx::Hooks::Port hooks with onMessageSent(*this, *message). Hook invocation is guarded using dfx::Utils::safeInvoke, so exceptions raised by hooks are contained.
Runtime constraints
  • If the owning node has expired (weak pointer cannot be locked), sending is a no-op.
  • Sending asserts that the owning node is running (node->isRunning()).
  • If no channel is attached, sending is a no-op.
Path tracking
On send, the port appends "nodeName.portName" to the message path using Message::addToPathTaken, which can later be used for debugging/tracing.

Constructor & Destructor Documentation

◆ OutputPort()

dfx::Core::OutputPort::OutputPort ( Id id,
NodeWPtr node,
std::string name,
Kind kind,
MimeType mimeType = MimeType::Any,
std::optional< bool > allowsMimeTypePropagation = std::nullopt )

Construct an output port.

Parameters
idPort id (unique within the owning node).
nodeOwning node (weak reference).
namePort name.
kindConnectivity domain (data/control "network").
mimeTypeDeclared MIME type emitted by this port (defaults to MimeType::Any).
allowsMimeTypePropagationOptional override for MIME type propagation.

Member Function Documentation

◆ isMimeTypeSupported()

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

Test whether a MIME type is compatible with this port.

Compatibility rules implemented:

  • If mimeType is Any, returns true.
  • If this port MIME type is Any, returns true.
  • Otherwise returns mimeType == this->mimeType().

◆ mimeType()

MimeType const & dfx::Core::OutputPort::mimeType ( ) const
inlinenoexcept

Declared MIME type emitted by this port.

◆ sendMessage()

void dfx::Core::OutputPort::sendMessage ( MessagePtr msg)

Send a message through this output port.

Delivery behavior:

  • If the node is expired: no-op.
  • Throw if the node is not running.
  • If there are no channels: no-op.
  • If the message has no MIME type and the port MIME type is not Any, sets the message MIME type to the port MIME type.
  • Appends "node.port" to the message path.
  • For each channel:
    • Calls all registered dfx::Hooks::Port hooks via onMessageSent.
    • Pushes the message to the channel (Channel::pushMessage).
    • If push fails, logs a warning containing both endpoints when available.
  • Uses clone() for all channels except the last to avoid unnecessary cloning.
Parameters
msgMessage to broadcast to all connected channels.

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