12#include <unordered_map>
15#include <nlohmann/json.hpp>
18#include "ConnectionValidator.hpp"
19#include "NodeFactory.hpp"
20#include "TransportFactory.hpp"
21#include <dfx-hooks/Graph.hpp>
23#include <dfx-utilities/RecyclableIdAllocator.hpp>
87 nlohmann::json config = {});
101 std::string_view type, std::string_view name,
102 nlohmann::json config = {});
126 bool hasNode(std::string_view name)
const noexcept;
144 std::vector<Core::NodePtr>
nodes()
const;
168 nlohmann::json srcConfig = {}, nlohmann::json dstConfig = {},
169 std::size_t errorLimit = 0);
188 nlohmann::json srcConfig = {}, nlohmann::json dstConfig = {},
189 std::size_t errorLimit = 0);
259 void _addNode(
Core::Node::Id nodeId, std::string_view type, std::string_view name,
260 nlohmann::json config);
261 void _removeNode(std::unordered_map<Core::Node::Id, Core::NodePtr>::iterator itr)
noexcept;
270 std::unordered_map<Core::Node::Id, Core::NodePtr> _nodes;
271 std::unordered_map<Core::Channel::Id, Core::ChannelPtr> _channels;
277 std::vector<Hooks::Graph *> _hooks;
Convenience macros to explicitly control copy and move semantics.
uint32_t Id
Identifier type (unique within a graph instance, by convention).
Definition Channel.hpp:63
uint32_t Id
Node identifier type (unique and stable within a graph instance).
Definition Node.hpp:116
Class used to validate is a channel can be created between 2 ports.
Definition ConnectionValidator.hpp:181
~Controller()=default
Destroy the controller.
bool removeNode(std::string_view name) noexcept
Remove a node by name.
TransportFactory & transportFactory() noexcept
Access the transport factory used to create dfx::Core::Transport.
Definition Controller.hpp:228
bool hasNode(std::string_view name) const noexcept
Check whether a node name exists.
Core::ChannelPtr channel(Core::Channel::Id id) const
Get a channel by id.
bool hasNode(Core::Node::Id id) const noexcept
Check whether a node id exists.
std::vector< Core::Node::Id > allNodeId() const
List all node ids currently in the graph.
Controller(NodeFactory &nodeFactory, TransportFactory &transportFactory)
Construct an empty controller.
DFX_DISABLE_COPY_AND_MOVE(Controller)
Move and copy are disallowed.
Core::Node::Id addNode(Core::Node::Id id, std::string_view type, std::string_view name, nlohmann::json config={})
Add a node using a specific id.
Core::NodePtr node(Core::Node::Id id) const
Get a node by id.
NodeFactory & nodeFactory() noexcept
Access the node factory used to create nodes.
Definition Controller.hpp:222
bool removeChannel(Core::Channel::Id id) noexcept
Remove a channel by id.
void deregisterHook(Hooks::Graph *hook) noexcept
Deregister a previously registered hook (no-op if not present).
Core::NodePtr node(std::string_view name) const
Get a node by name.
bool hasChannel(Core::Channel::Id id) const noexcept
Check whether a channel id exists.
bool hasNodeType(std::string_view type) const noexcept
Check whether a node type is known by the factory.
std::vector< Core::ChannelPtr > channels() const
Return all channels currently in the graph (strong pointers).
std::vector< std::string > allNodeName() const
List all node names currently in the graph.
void registerHook(Hooks::Graph *hook)
Register a graph hook.
ConnectionValidator const & connectionValidator() const noexcept
Access the connection validator used to verify connections between ports.
Definition Controller.hpp:237
ConnectionValidator & connectionValidator() noexcept
Access the connection validator used to verify connections between ports.
Definition Controller.hpp:234
bool removeNode(Core::Node::Id id) noexcept
Remove a node by id.
std::vector< std::string > allNodeType() const
List all node types known by the factory.
std::vector< Core::NodePtr > nodes() const
Return all nodes currently in the graph (strong pointers).
Core::Channel::Id addChannel(std::string_view src, std::string_view dst, nlohmann::json srcConfig={}, nlohmann::json dstConfig={}, std::size_t errorLimit=0)
Create a channel between an output and an input port.
NodeFactory const & nodeFactory() const noexcept
Access the node factory used to create nodes.
Definition Controller.hpp:225
TransportFactory const & transportFactory() const noexcept
Access the transport factory used to create dfx::Core::Transport.
Definition Controller.hpp:231
Core::Channel::Id addChannel(Core::Endpoint::Descriptor src, Core::Endpoint::Descriptor dst, nlohmann::json srcConfig={}, nlohmann::json dstConfig={}, std::size_t errorLimit=0)
Create a channel between an output and an input port.
std::vector< Core::Channel::Id > allChannelId() const
List all channel ids currently in the graph.
Core::Node::Id addNode(std::string_view type, std::string_view name, nlohmann::json config={})
Add a node and allocate a fresh node id.
Runtime node instantiation and validation facility (builders + config/metadata schemas).
Definition NodeFactory.hpp:60
Registry and factory for creating Source and Destination transports.
Definition TransportFactory.hpp:40
Hooks related to the lifecycle of graph objects (nodes and channels).
Definition Graph.hpp:54
ID allocator that can recycle released identifiers.
Definition RecyclableIdAllocator.hpp:78
std::shared_ptr< Node > NodePtr
Shared ownership pointer type for Nodes..
Definition Endpoint.hpp:21
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
Parsed metadata for an endpoint, used for routing and graph introspection.
Definition Endpoint.hpp:61