17#include "../messages/Message.hpp"
18#include <dfx-hooks/Delivery.hpp>
74 Id id() const noexcept {
return _id; }
95 virtual std::optional<MessagePtr>
pop() = 0;
102 template<DerivedFromChannel T>
103 bool is() const noexcept {
return dynamic_cast<T
const *
>(
this) !=
nullptr; }
109 template<DerivedFromChannel T>
110 T &
as() noexcept {
return static_cast<T &
>(*this); }
116 template<DerivedFromChannel T>
117 T
const &
as() const noexcept {
return static_cast<T
const &
>(*this); }
Convenience macros to explicitly control copy and move semantics.
Abstract message channel connecting exactly one output port to one input port.
Definition Channel.hpp:54
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.
Channel(Id id, InputPort &inputPort, OutputPort &outputPort)
Construct a channel linking one input port to one output port.
InputPort & inputPort() const noexcept
Destination (consumer) endpoint of this channel.
Definition Channel.hpp:121
uint32_t Id
Identifier type (unique within a graph instance, by convention).
Definition Channel.hpp:57
OutputPort & _outputPort
Source port (producer).
Definition Channel.hpp:138
bool is() const noexcept
Check whether this channel is of a given derived type.
Definition Channel.hpp:103
T & as() noexcept
Cast this channel to a derived type (unchecked).
Definition Channel.hpp:110
DISABLE_COPY_AND_MOVE(Channel)
Channel is not copiable nor movable.
InputPort & _inputPort
Destination port (consumer).
Definition Channel.hpp:137
virtual std::optional< MessagePtr > pop()=0
Pop the next message from the channel.
void setDeliveryHook(Hooks::Delivery *hook)
Set the optional delivery hook for this channel.
Definition Channel.hpp:133
Id id() const noexcept
Get the channel id.
Definition Channel.hpp:74
virtual ~Channel()=default
Virtual destructor.
T const & as() const noexcept
Cast this channel to a derived type (unchecked).
Definition Channel.hpp:117
virtual bool pushMessage(MessagePtr msg)=0
Push a message into the channel from the producer side.
Hooks::Delivery * _deliveryHook
Optional delivery hook (non-owning).
Definition Channel.hpp:140
OutputPort & outputPort() const noexcept
Source (producer) endpoint of this channel.
Definition Channel.hpp:124
Outgoing message endpoint attached to a node.
Definition OutputPort.hpp:47
Hook interface invoked around message enqueue in an dfx::Core::Channel.
Definition Delivery.hpp:50
Concept used by dfx::Core::Channel::is() and dfx::Core::Channel::as() to constrain types.
Definition Channel.hpp:29
Definition Channel.hpp:22
std::unique_ptr< Message > MessagePtr
Unique ownership handle for messages.
Definition Message.hpp:27
std::shared_ptr< Channel > ChannelPtr
Shared ownership handle for channels.
Definition Channel.hpp:147