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

Abstract message channel connecting exactly one output port to one input port. More...

#include <dfx-core/channels/Channel.hpp>

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

Public Types

using Id = uint32_t
 Identifier type (unique within a graph instance, by convention).

Public Member Functions

 Channel (Id id, InputPort &inputPort, OutputPort &outputPort)
 Construct a channel linking one input port to one output port.
 DISABLE_COPY_AND_MOVE (Channel)
 Channel is not copiable nor movable.
virtual ~Channel ()=default
 Virtual destructor.
Id id () const noexcept
 Get the channel id.
template<DerivedFromChannel T>
bool is () const noexcept
 Check whether this channel is of a given derived type.
template<DerivedFromChannel T>
T & as () noexcept
 Cast this channel to a derived type (unchecked).
template<DerivedFromChannel T>
T const & as () const noexcept
 Cast this channel to a derived type (unchecked).
InputPortinputPort () const noexcept
 Destination (consumer) endpoint of this channel.
OutputPortoutputPort () const noexcept
 Source (producer) endpoint of this channel.
void setDeliveryHook (Hooks::Delivery *hook)
 Set the optional delivery hook for this channel.
Queue-like interface
virtual bool pushMessage (MessagePtr msg)=0
 Push a message into the channel from the producer side.
virtual bool hasPendingMessage () const =0
 Whether at least one message is pending in this channel.
virtual std::size_t pendingMessageCount () const =0
 Number of messages currently pending in this channel.
virtual std::optional< MessagePtrpop ()=0
 Pop the next message from the channel.

Protected Attributes

InputPort_inputPort
 Destination port (consumer).
OutputPort_outputPort
 Source port (producer).
Hooks::Delivery_deliveryHook = nullptr
 Optional delivery hook (non-owning).

Detailed Description

Abstract message channel connecting exactly one output port to one input port.

A channel is a directed edge in the graph:

Ownership and lifetime
The channel stores references to both endpoints. It therefore assumes both ports outlive the channel (typically: the graph owns nodes/ports and channels together).

The class is explicitly non-copyable and non-movable.

Delivery hook
A channel can optionally be configured with a dfx::Hooks::Delivery hook via setDeliveryHook. The base class only stores the pointer; it is the job of concrete implementations to invoke it at the appropriate points (enqueue/dequeue, pre/post delivery, etc.).
Note
pushMessage returns a boolean to allow implementations to reject messages (e.g. bounded queues, backpressure, shutdown).

Member Typedef Documentation

◆ Id

using dfx::Core::Channel::Id = uint32_t

Identifier type (unique within a graph instance, by convention).

Constructor & Destructor Documentation

◆ Channel()

dfx::Core::Channel::Channel ( Id id,
InputPort & inputPort,
OutputPort & outputPort )

Construct a channel linking one input port to one output port.

Parameters
idChannel id.
inputPortDestination port (consumer).
outputPortSource port (producer).

◆ ~Channel()

virtual dfx::Core::Channel::~Channel ( )
virtualdefault

Virtual destructor.

Member Function Documentation

◆ as() [1/2]

template<DerivedFromChannel T>
T const & dfx::Core::Channel::as ( ) const
inlinenoexcept

Cast this channel to a derived type (unchecked).

Template Parameters
TA type derived from Channel.
Warning
This uses static_cast. Only call after checking with is.

◆ as() [2/2]

template<DerivedFromChannel T>
T & dfx::Core::Channel::as ( )
inlinenoexcept

Cast this channel to a derived type (unchecked).

Template Parameters
TA type derived from Channel.
Warning
This uses static_cast. Only call after checking with is.

◆ DISABLE_COPY_AND_MOVE()

dfx::Core::Channel::DISABLE_COPY_AND_MOVE ( Channel )

Channel is not copiable nor movable.

◆ hasPendingMessage()

virtual bool dfx::Core::Channel::hasPendingMessage ( ) const
pure virtual

Whether at least one message is pending in this channel.

Implemented in dfx::Core::SPSCChannel.

◆ id()

Id dfx::Core::Channel::id ( ) const
inlinenoexcept

Get the channel id.

◆ inputPort()

InputPort & dfx::Core::Channel::inputPort ( ) const
inlinenoexcept

Destination (consumer) endpoint of this channel.

◆ is()

template<DerivedFromChannel T>
bool dfx::Core::Channel::is ( ) const
inlinenoexcept

Check whether this channel is of a given derived type.

Template Parameters
TA type derived from Channel.

◆ outputPort()

OutputPort & dfx::Core::Channel::outputPort ( ) const
inlinenoexcept

Source (producer) endpoint of this channel.

◆ pendingMessageCount()

virtual std::size_t dfx::Core::Channel::pendingMessageCount ( ) const
pure virtual

Number of messages currently pending in this channel.

Implemented in dfx::Core::SPSCChannel.

◆ pop()

virtual std::optional< MessagePtr > dfx::Core::Channel::pop ( )
pure virtual

Pop the next message from the channel.

Returns
The next message if available, or std::nullopt if the channel is empty.

Implemented in dfx::Core::SPSCChannel.

◆ pushMessage()

virtual bool dfx::Core::Channel::pushMessage ( MessagePtr msg)
pure virtual

Push a message into the channel from the producer side.

Parameters
msgMessage to enqueue.
Returns
true on success, false if the message could not be enqueued.

Implemented in dfx::Core::SPSCChannel.

◆ setDeliveryHook()

void dfx::Core::Channel::setDeliveryHook ( Hooks::Delivery * hook)
inline

Set the optional delivery hook for this channel.

The hook pointer is stored as-is; it is not owned by the channel. Concrete implementations may call the hook around enqueue/dequeue/delivery.

Parameters
hookHook pointer, or null to disable.

Member Data Documentation

◆ _deliveryHook

Hooks::Delivery* dfx::Core::Channel::_deliveryHook = nullptr
protected

Optional delivery hook (non-owning).

◆ _inputPort

InputPort& dfx::Core::Channel::_inputPort
protected

Destination port (consumer).

◆ _outputPort

OutputPort& dfx::Core::Channel::_outputPort
protected

Source port (producer).


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