Abstract message channel connecting exactly one output port to one input port.
More...
#include <dfx-core/channels/Channel.hpp>
|
| using | Id = uint32_t |
| | Identifier type (unique within a graph instance, by convention).
|
|
| | 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).
|
| InputPort & | inputPort () const noexcept |
| | Destination (consumer) endpoint of this channel.
|
| OutputPort & | outputPort () const noexcept |
| | Source (producer) endpoint of this channel.
|
| void | setDeliveryHook (Hooks::Delivery *hook) |
| | Set the optional delivery hook for this channel.
|
| 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< MessagePtr > | pop ()=0 |
| | Pop the next message from the channel.
|
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).
◆ Id
Identifier type (unique within a graph instance, by convention).
◆ Channel()
Construct a channel linking one input port to one output port.
- Parameters
-
| id | Channel id. |
| inputPort | Destination port (consumer). |
| outputPort | Source port (producer). |
◆ ~Channel()
| virtual dfx::Core::Channel::~Channel |
( |
| ) |
|
|
virtualdefault |
◆ as() [1/2]
template<DerivedFromChannel T>
| T const & dfx::Core::Channel::as |
( |
| ) |
const |
|
inlinenoexcept |
Cast this channel to a derived type (unchecked).
- Template Parameters
-
- 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
-
- 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 |
◆ id()
| Id dfx::Core::Channel::id |
( |
| ) |
const |
|
inlinenoexcept |
◆ 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
-
◆ 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 |
◆ 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
-
- Returns
- true on success, false if the message could not be enqueued.
Implemented in dfx::Core::SPSCChannel.
◆ setDeliveryHook()
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
-
| hook | Hook pointer, or null to disable. |
◆ _deliveryHook
Optional delivery hook (non-owning).
◆ _inputPort
Destination port (consumer).
◆ _outputPort
The documentation for this class was generated from the following file: