dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
Channel.hpp
1// SPDX-FileCopyrightText: 2025-2026 Vincent Leroy
2// SPDX-License-Identifier: MIT
3//
4// This file is part of dfx.
5//
6// Licensed under the MIT License. See the LICENSE file in the project root
7// for full license information.
8
9#pragma once
10
11// Standard includes
12#include <memory>
13
14// Third-party includes
15#include <nlohmann/json.hpp>
16
17// Project includes
18#include "messages/Message.hpp"
19#include "transports/destinations/DestinationTransport.hpp"
20#include "transports/sources/SourceTransport.hpp"
21#include <dfx-hooks/Delivery.hpp>
23
24namespace dfx::Core
25{
58{
59 friend class SourceTransport;
60
61public:
63 using Id = uint32_t;
64
65public:
71 Channel(Id id, SourceTransportPtr source, DestinationTransportPtr destination);
72
75
77 Id id() const noexcept { return _id; }
78
80 int64_t pendingMessageCount() const;
81
82public:
84 SourceTransportPtr const & source() const noexcept { return _source; }
85
87 DestinationTransportPtr const & destination() const noexcept { return _destination; }
88
89public:
97 { _deliveryHook = hook; }
98
99protected:
125 bool transmit(MessagePtr message);
126
127private:
128 Id const _id;
129
130 SourceTransportPtr _source;
131 DestinationTransportPtr _destination;
132
133 Hooks::Delivery * _deliveryHook = nullptr;
134};
135
137using ChannelPtr = std::shared_ptr<Channel>;
138} // !namespace dfx::Core
Convenience macros to explicitly control copy and move semantics.
DFX_DISABLE_COPY_AND_MOVE(Channel)
Channel is not copiable nor movable.
uint32_t Id
Identifier type (unique within a graph instance, by convention).
Definition Channel.hpp:63
Channel(Id id, SourceTransportPtr source, DestinationTransportPtr destination)
Construct a channel linking one input port to one output port.
DestinationTransportPtr const & destination() const noexcept
Get the destination transport a.k.a. the InputPort.
Definition Channel.hpp:87
void setDeliveryHook(Hooks::Delivery *hook)
Set the optional delivery hook for this channel.
Definition Channel.hpp:96
Id id() const noexcept
Get the channel id.
Definition Channel.hpp:77
bool transmit(MessagePtr message)
Transmits a message from the source transport to the destination transport.
int64_t pendingMessageCount() const
Return the number of pending message in this channel or -1 if unknown.
SourceTransportPtr const & source() const noexcept
Get the source transport a.k.a. the OutputPort.
Definition Channel.hpp:84
Hook interface invoked around message enqueue in an dfx::Core::Channel.
Definition Delivery.hpp:39
Definition Channel.hpp:25
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:137
std::unique_ptr< SourceTransport > SourceTransportPtr
Unique ownership handle for SourceTransport.
Definition SourceTransport.hpp:48