![]() |
dfx 0.1.0
Linux-based dynamic dataflow executor
|
In-memory graph builder and mutation controller (nodes + channels) with optional connection verification. More...
#include <dfx-graph/Controller.hpp>
Public Member Functions | |
| Controller (NodeFactory &nodeFactory, TransportFactory &transportFactory) | |
| Construct an empty controller. | |
| ~Controller ()=default | |
| Destroy the controller. | |
| DFX_DISABLE_COPY_AND_MOVE (Controller) | |
| Move and copy are disallowed. | |
Node | |
| Core::Node::Id | addNode (std::string_view type, std::string_view name, nlohmann::json config={}) |
| Add a node and allocate a fresh node id. | |
| 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. | |
| bool | removeNode (Core::Node::Id id) noexcept |
| Remove a node by id. | |
| bool | removeNode (std::string_view name) noexcept |
| Remove a node by name. | |
| bool | hasNode (Core::Node::Id id) const noexcept |
| Check whether a node id exists. | |
| bool | hasNode (std::string_view name) const noexcept |
| Check whether a node name exists. | |
| bool | hasNodeType (std::string_view type) const noexcept |
| Check whether a node type is known by the factory. | |
| std::vector< std::string > | allNodeType () const |
| List all node types known by the factory. | |
| std::vector< std::string > | allNodeName () const |
| List all node names currently in the graph. | |
| std::vector< Core::Node::Id > | allNodeId () const |
| List all node ids currently in the graph. | |
| Core::NodePtr | node (Core::Node::Id id) const |
| Get a node by id. | |
| Core::NodePtr | node (std::string_view name) const |
| Get a node by name. | |
| std::vector< Core::NodePtr > | nodes () const |
| Return all nodes currently in the graph (strong pointers). | |
Channel | |
| 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. | |
| 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. | |
| bool | removeChannel (Core::Channel::Id id) noexcept |
| Remove a channel by id. | |
| bool | hasChannel (Core::Channel::Id id) const noexcept |
| Check whether a channel id exists. | |
| std::vector< Core::Channel::Id > | allChannelId () const |
| List all channel ids currently in the graph. | |
| Core::ChannelPtr | channel (Core::Channel::Id id) const |
| Get a channel by id. | |
| std::vector< Core::ChannelPtr > | channels () const |
| Return all channels currently in the graph (strong pointers). | |
Factory and validator | |
| NodeFactory & | nodeFactory () noexcept |
| Access the node factory used to create nodes. | |
| NodeFactory const & | nodeFactory () const noexcept |
| Access the node factory used to create nodes. | |
| TransportFactory & | transportFactory () noexcept |
| Access the transport factory used to create dfx::Core::Transport. | |
| TransportFactory const & | transportFactory () const noexcept |
| Access the transport factory used to create dfx::Core::Transport. | |
| ConnectionValidator & | connectionValidator () noexcept |
| Access the connection validator used to verify connections between ports. | |
| ConnectionValidator const & | connectionValidator () const noexcept |
| Access the connection validator used to verify connections between ports. | |
Hook | |
| void | registerHook (Hooks::Graph *hook) |
| Register a graph hook. | |
| void | deregisterHook (Hooks::Graph *hook) noexcept |
| Deregister a previously registered hook (no-op if not present). | |
In-memory graph builder and mutation controller (nodes + channels) with optional connection verification.
Controller owns the editable state of a dfx graph:
This is the central mutation API used to construct graphs from configuration files, and to apply runtime modifications (add/remove nodes, add/remove channels).
Node names must be unique and are validated via Core::Node::validateNodeName().
Hooks are invoked with a "safe invoke" wrapper so one misbehaving hook does not break graph operations.
| dfx::Graph::Controller::Controller | ( | NodeFactory & | nodeFactory, |
| TransportFactory & | transportFactory ) |
Construct an empty controller.
|
default |
Destroy the controller.
| Core::Channel::Id dfx::Graph::Controller::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.
When verification is enabled (default), the controller validates compatibility. See Graph channel verification (kind + mime-type compatibility) for more information.
On success:
| src | Source transport definition. |
| dst | Destination transport definition. |
| srcConfig | Additional source transport configuration. |
| dstConfig | Additional destination transport configuration. |
| errorLimit | Optional cap on number of collected errors (0 = no limit). |
| Core::Channel::Id dfx::Graph::Controller::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.
When verification is enabled (default), the controller validates compatibility. See Graph channel verification (kind + mime-type compatibility) for more information.
On success:
| src | Source transport definition. |
| dst | Destination transport definition. |
| srcConfig | Additional source transport configuration. |
| dstConfig | Additional destination transport configuration. |
| errorLimit | Optional cap on number of collected errors (0 = no limit). |
| Core::Node::Id dfx::Graph::Controller::addNode | ( | Core::Node::Id | id, |
| std::string_view | type, | ||
| std::string_view | name, | ||
| nlohmann::json | config = {} ) |
Add a node using a specific id.
Reserves id in the allocator before creation. If creation fails, the id is released. This overload is mainly intended for graph loading / replay where ids are already known.
| id | Desired node id. |
| type | Node type name (resolved by NodeFactory). |
| name | Unique node name. |
| config | Optional node configuration blob (passed to the factory). |
id). | Core::Node::Id dfx::Graph::Controller::addNode | ( | std::string_view | type, |
| std::string_view | name, | ||
| nlohmann::json | config = {} ) |
Add a node and allocate a fresh node id.
If creation fails, the allocated id is released back to the allocator so it will be reused for the next node. On success, hooks are notified via Hooks::Graph::onNodeCreated().
| type | Node type name (resolved by NodeFactory). |
| name | Unique node name. |
| config | Optional node configuration blob (passed to the factory). |
| std::vector< Core::Channel::Id > dfx::Graph::Controller::allChannelId | ( | ) | const |
List all channel ids currently in the graph.
| std::vector< Core::Node::Id > dfx::Graph::Controller::allNodeId | ( | ) | const |
List all node ids currently in the graph.
| std::vector< std::string > dfx::Graph::Controller::allNodeName | ( | ) | const |
List all node names currently in the graph.
| std::vector< std::string > dfx::Graph::Controller::allNodeType | ( | ) | const |
List all node types known by the factory.
| Core::ChannelPtr dfx::Graph::Controller::channel | ( | Core::Channel::Id | id | ) | const |
Get a channel by id.
| dfx::Utils::Exception | If the id does not exist. |
| std::vector< Core::ChannelPtr > dfx::Graph::Controller::channels | ( | ) | const |
Return all channels currently in the graph (strong pointers).
|
inlinenoexcept |
Access the connection validator used to verify connections between ports.
|
inlinenoexcept |
Access the connection validator used to verify connections between ports.
|
noexcept |
Deregister a previously registered hook (no-op if not present).
| hook | Hook instance to remove. |
| dfx::Graph::Controller::DFX_DISABLE_COPY_AND_MOVE | ( | Controller | ) |
Move and copy are disallowed.
|
noexcept |
Check whether a channel id exists.
|
noexcept |
Check whether a node id exists.
|
noexcept |
Check whether a node name exists.
|
noexcept |
Check whether a node type is known by the factory.
| Core::NodePtr dfx::Graph::Controller::node | ( | Core::Node::Id | id | ) | const |
Get a node by id.
| dfx::Utils::Exception | If the id does not exist. |
| Core::NodePtr dfx::Graph::Controller::node | ( | std::string_view | name | ) | const |
Get a node by name.
| dfx::Utils::Exception | If the name does not exist. |
|
inlinenoexcept |
Access the node factory used to create nodes.
|
inlinenoexcept |
Access the node factory used to create nodes.
| std::vector< Core::NodePtr > dfx::Graph::Controller::nodes | ( | ) | const |
Return all nodes currently in the graph (strong pointers).
| void dfx::Graph::Controller::registerHook | ( | Hooks::Graph * | hook | ) |
Register a graph hook.
The same hook pointer is not added twice.
| hook | Hook instance (must not be null). |
|
noexcept |
Remove a channel by id.
On success:
| id | Channel id. |
|
noexcept |
Remove a node by id.
Also removes all channels connected to the node before erasing it, to prevent dangling connections. Hooks are notified via Hooks::Graph::onNodeRemoved() and Hooks::Graph::onChannelRemoved().
| id | Node id. |
|
noexcept |
Remove a node by name.
Same semantics as removeNode(Core::Node::Id).
| name | Node name. |
|
inlinenoexcept |
Access the transport factory used to create dfx::Core::Transport.
|
inlinenoexcept |
Access the transport factory used to create dfx::Core::Transport.