![]() |
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 ()=default | |
| Construct an empty controller. | |
| ~Controller () | |
| Destroy the controller. | |
| ENABLE_DEFAULT_MOVE_DISABLE_COPY (Controller) | |
| Move is allowed, copy is disabled. | |
| 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) |
| Remove a node by id. | |
| bool | removeNode (std::string_view name) |
| Remove a node by name. | |
| bool | hasNode (Core::Node::Id id) const |
| Check whether a node id exists. | |
| bool | hasNode (std::string_view name) const |
| Check whether a node name exists. | |
| bool | hasNodeType (std::string_view type) const |
| 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). | |
| 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. | |
| bool | removeChannel (Core::Channel::Id id) |
| Remove a channel by id. | |
| bool | hasChannel (Core::Channel::Id id) const |
| 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). | |
| NodeFactory & | nodeFactory () noexcept |
| Access the node factory used to create nodes. | |
| NodeFactory const & | nodeFactory () const noexcept |
| Access the node factory used to create nodes. | |
| bool | isChannelVerificationEnabled () const noexcept |
| Whether channel verification is enabled. | |
| void | setChannelVerification (bool enabled) |
| Enable/disable channel verification. | |
| void | registerHook (Hooks::Graph *hook) |
| Register a graph hook. | |
| void | deregisterHook (Hooks::Graph *hook) |
| 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().
The verification logic is intentionally conservative: when ports declare any mime-type, the controller can infer possible mime-types by walking existing connections and applying propagation rules (node-level and port-level).
When verification fails:
errors vector is provided to addChannel(), it is filled and the call returns {}.Hooks are invoked with a "safe invoke" wrapper so one misbehaving hook does not break graph operations.
|
default |
Construct an empty controller.
| dfx::Graph::Controller::~Controller | ( | ) |
Destroy the controller.
| Core::Channel::Id dfx::Graph::Controller::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.
When verification is enabled (default), the controller validates compatibility. See Graph channel verification (kind + mime-type compatibility) for more information.
On success:
| src | Source output port. |
| dst | Destination input port. |
| errors | Optional output list of human-readable validation errors. |
| errorLimit | Optional cap on number of collected errors (0 = no limit). |
errors is provided.| dfx::Utils::Exception |
|
| 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).
| void dfx::Graph::Controller::deregisterHook | ( | Hooks::Graph * | hook | ) |
Deregister a previously registered hook (no-op if not present).
| hook | Hook instance to remove. |
| dfx::Graph::Controller::ENABLE_DEFAULT_MOVE_DISABLE_COPY | ( | Controller | ) |
Move is allowed, copy is disabled.
| bool dfx::Graph::Controller::hasChannel | ( | Core::Channel::Id | id | ) | const |
Check whether a channel id exists.
| bool dfx::Graph::Controller::hasNode | ( | Core::Node::Id | id | ) | const |
Check whether a node id exists.
| bool dfx::Graph::Controller::hasNode | ( | std::string_view | name | ) | const |
Check whether a node name exists.
| bool dfx::Graph::Controller::hasNodeType | ( | std::string_view | type | ) | const |
Check whether a node type is known by the factory.
|
inlinenoexcept |
Whether channel verification is enabled.
| 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). |
| bool dfx::Graph::Controller::removeChannel | ( | Core::Channel::Id | id | ) |
Remove a channel by id.
On success:
| id | Channel id. |
| bool dfx::Graph::Controller::removeNode | ( | Core::Node::Id | id | ) |
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. |
| bool dfx::Graph::Controller::removeNode | ( | std::string_view | name | ) |
Remove a node by name.
Same semantics as removeNode(Core::Node::Id).
| name | Node name. |
|
inline |
Enable/disable channel verification.
When disabled, addChannel() skips compatibility checks entirely. This is mainly intended for debugging or for scenarios where compatibility is enforced elsewhere.