12#include <unordered_map>
15#include <nlohmann/json.hpp>
18#include "NodeFactory.hpp"
19#include <dfx-hooks/Graph.hpp>
21#include <dfx-utilities/RecyclableIdAllocator.hpp>
234 nlohmann::json config = {});
248 std::string_view type, std::string_view name,
249 nlohmann::json config = {});
291 std::vector<Core::NodePtr>
nodes()
const;
314 std::vector<std::string> * errors =
nullptr,
315 std::size_t errorLimit = 0);
372 std::vector<std::string> * errors =
nullptr,
373 std::size_t errorLimit = 0)
const;
375 void _addNode(
Core::Node::Id nodeId, std::string_view type, std::string_view name,
376 nlohmann::json config);
377 void _removeNode(std::unordered_map<Core::Node::Id, Core::NodePtr>::iterator itr);
382 std::unordered_map<Core::Node::Id, Core::NodePtr> _nodes;
383 std::unordered_map<Core::Channel::Id, Core::ChannelPtr> _channels;
388 bool _channelVerificationEnabled =
true;
391 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:57
uint32_t Id
Node identifier type (unique and stable within a graph instance).
Definition Node.hpp:113
Outgoing message endpoint attached to a node.
Definition OutputPort.hpp:47
Core::ChannelPtr channel(Core::Channel::Id id) const
Get a channel by id.
Core::Channel::Id addChannel(Core::OutputPort &src, Core::InputPort &dst, std::vector< std::string > *errors=nullptr, std::size_t errorLimit=0)
Create a channel between an output and an input port.
std::vector< Core::Node::Id > allNodeId() const
List all node ids currently in the graph.
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:342
Core::NodePtr node(std::string_view name) const
Get a node by name.
void setChannelVerification(bool enabled)
Enable/disable channel verification.
Definition Controller.hpp:356
Controller()=default
Construct an empty controller.
bool removeChannel(Core::Channel::Id id)
Remove a channel by id.
std::vector< Core::ChannelPtr > channels() const
Return all channels currently in the graph (strong pointers).
ENABLE_DEFAULT_MOVE_DISABLE_COPY(Controller)
Move is allowed, copy is disabled.
std::vector< std::string > allNodeName() const
List all node names currently in the graph.
void deregisterHook(Hooks::Graph *hook)
Deregister a previously registered hook (no-op if not present).
bool hasChannel(Core::Channel::Id id) const
Check whether a channel id exists.
~Controller()
Destroy the controller.
void registerHook(Hooks::Graph *hook)
Register a graph hook.
bool removeNode(Core::Node::Id id)
Remove a node by id.
bool isChannelVerificationEnabled() const noexcept
Whether channel verification is enabled.
Definition Controller.hpp:349
std::vector< std::string > allNodeType() const
List all node types known by the factory.
bool hasNode(Core::Node::Id id) const
Check whether a node id exists.
bool removeNode(std::string_view name)
Remove a node by name.
std::vector< Core::NodePtr > nodes() const
Return all nodes currently in the graph (strong pointers).
bool hasNodeType(std::string_view type) const
Check whether a node type is known by the factory.
NodeFactory const & nodeFactory() const noexcept
Access the node factory used to create nodes.
Definition Controller.hpp:345
bool hasNode(std::string_view name) const
Check whether a node name exists.
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
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 Node.hpp:61
std::shared_ptr< Channel > ChannelPtr
Shared ownership handle for channels.
Definition Channel.hpp:147