![]() |
dfx 0.1.0
Linux-based dynamic dataflow executor
|
Abstract base class for all nodes in the dfx runtime. More...
#include <dfx-core/Node.hpp>
Public Types | |
| enum class | ExecutionFlowPolicy { AlwaysDispatch , InlineIfAvailable } |
| Policy controlling how execution is chained after message delivery. More... | |
| using | Id = uint32_t |
| Node identifier type (unique and stable within a graph instance). | |
Public Member Functions | |
| Node (std::string type, Id id, std::string name) | |
| Construct a node instance. | |
| virtual | ~Node ()=0 |
| Virtual destructor. Pure virtual to ensure Node is abstract, but defined out-of-line. | |
| void | setName (std::string newName) |
| Rename the node. | |
| template<DerivedFromNode T> | |
| bool | is () const noexcept |
| Check whether this node is of a given derived type. | |
| template<DerivedFromNode T> | |
| T & | as () noexcept |
| Cast this node to a derived type (unchecked). | |
| template<DerivedFromNode T> | |
| T const & | as () const noexcept |
| Cast this node to a derived type (unchecked). | |
Introspection | |
| std::string const & | type () const noexcept |
| Get the node type. | |
| std::string const & | name () const noexcept |
| Get the node name. | |
| Id | id () const noexcept |
| Get the node id. | |
| nlohmann::json const & | config () const noexcept |
| Get the node configuration. | |
| ExecutionFlowPolicy | executionFlowPolicy () const noexcept |
| Get the node execution policy. | |
| bool | isRunning () const noexcept |
| Check of the node is currently running. | |
| bool | allowsMimeTypePropagation () const noexcept |
| Whether this node allows mime-type propagation through its ports. | |
Lifecycle | |
| void | start () |
| Start the node. | |
| void | stop () |
| Stop the node. | |
| void | waitForStopped () |
| Block the current thread until the node is stopped. | |
| bool | stopRequested () const noexcept |
| Check if stop has already been called or not. | |
Ports | |
| InputPortContainer const & | inputPorts () const noexcept |
| Get all input ports of all Kind. | |
| OutputPortContainer const & | outputPorts () const noexcept |
| Get all output ports of all Kind. | |
| bool | hasInputPort (std::string_view portName) const noexcept |
| Check whether an input port exists by name. | |
| bool | hasOutputPort (std::string_view portName) const noexcept |
| Check whether an output port exists by name. | |
| bool | hasInputPort (Port::Id id) const noexcept |
| Check whether an input port exists by id. | |
| bool | hasOutputPort (Port::Id id) const noexcept |
| Check whether an output port exists by id. | |
| InputPort const & | inputPort (std::string_view portName) const |
| Get an input port by name. | |
| OutputPort const & | outputPort (std::string_view portName) const |
| Get an output port by name. | |
| InputPort & | inputPort (std::string_view portName) |
| Get an input port by name (mutable). | |
| OutputPort & | outputPort (std::string_view portName) |
| Get an output port by name (mutable). | |
| InputPort const & | inputPort (Port::Id id) const |
| Get an input port by id. | |
| OutputPort const & | outputPort (Port::Id id) const |
| Get an output port by id. | |
| InputPort & | inputPort (Port::Id id) |
| Get an input port by id (mutable). | |
| OutputPort & | outputPort (Port::Id id) |
| Get an output port by id (mutable). | |
Sending messages | |
| void | sendMessage (Port::Id id, MessagePtr message) |
| Send a message on an output port by id. | |
| void | sendMessage (std::string_view portName, MessagePtr message) |
| Send a message on an output port by name. | |
| void | sendMessage (OutputPort &port, MessagePtr message) |
| Send a message on the provided output port. | |
Lockable interface | |
| void | lock () |
| Lock the node's internal recursive mutex. | |
| void | unlock () |
| Unlock the node's internal recursive mutex. | |
| bool | try_lock () noexcept |
| Try to lock the node's internal recursive mutex. | |
Metadata | |
| virtual nlohmann::json | configSchema () const =0 |
| Return the JSON schema describing the node configuration. Used by the dfx::Graph::NodeFactory / tooling / UI to validate and edit configuration. | |
| virtual nlohmann::json | metadata () const =0 |
| Return node metadata (description, categories, ports, etc.). Intended for UI/tooling and discovery. | |
Static Public Member Functions | |
| static void | validateNodeName (std::string_view name) |
| Validate a node name. | |
Protected Member Functions | |
| void | initialize (nlohmann::json config) |
| Initialize the node with its configuration. | |
| void | setAllowsMimeTypePropagation (bool allowed) |
| Enable/disable global mime-type propagation for this node. This affects how the runtime may propagate mime types through connected ports. | |
| virtual void | setExecutionFlowPolicy (ExecutionFlowPolicy policy) |
| Set the execution flow policy used by the runtime scheduler. | |
| virtual void | handleMessage (InputPort const &port, MessagePtr message)=0 |
| Handle an incoming message on an input port. | |
Lifecycle hooks for derived classes | |
| virtual void | startImpl () |
| Called by start before the node is marked running. | |
| virtual void | stopImpl () |
| Called by stop before the node is marked stopped. | |
| virtual void | initializeImpl (nlohmann::json config)=0 |
Called by initialize; derived nodes must parse config here. | |
| void | onNodeStopped () |
| Must be called by classes that re-implement the stopImpl function. | |
Port registration helpers (for derived classes) | |
| OutputPort & | registerOutputPort (std::string name, MimeType mimeType=MimeType::Any, std::optional< bool > allowsMimeTypePropagation=std::nullopt) |
| Register a data output port. | |
| InputPort & | registerInputPort (std::string name, MimeTypes supportedMimeTypes={}, std::optional< bool > allowsMimeTypePropagation=std::nullopt) |
| Register a data input port. | |
| OutputPort & | registerControlOutputPort (std::string name) |
| Register a control output port. | |
| InputPort & | registerControlInputPort (std::string name) |
| Register a control input port. | |
Friends | |
| class | Graph::NodeFactory |
| class | InputPort |
Runtime integration | |
| void | setReactor (Runtime::Api::NodeReactor *reactor) |
| Attach the runtime reactor used by this node. | |
| Runtime::Api::NodeReactor * | reactor () const noexcept |
| Get the currently attached reactor (may be null if not set). | |
| FdWatch::Poller & | poller () |
| Access a poller instance associated with this node. | |
| template<typename T = Runtime::Api::NodeTaskExecutor> | |
| T * | customExecutor () const noexcept |
| Access the customer executor of this node if any. | |
| void | assignTaskExecutor (Runtime::Api::NodeTaskExecutorPtr executor) |
| Assigns a custom task executor to this node. | |
| void | revokeTaskExecutor () noexcept |
| Revokes a custom task executor, returning this node to the default execution model. | |
Abstract base class for all nodes in the dfx runtime.
Thread-safety of higher-level operations still depends on the rest of the runtime (reactor/poller and port/message delivery).
| using dfx::Core::Node::Id = uint32_t |
Node identifier type (unique and stable within a graph instance).
|
strong |
Policy controlling how execution is chained after message delivery.
This value is read by the runtime to decide whether the next node execution should be enqueued or can run inline on the current thread.
| Enumerator | |
|---|---|
| AlwaysDispatch | Always enqueue next task for deferred execution. |
| InlineIfAvailable | Run inline on the current thread when possible. |
| dfx::Core::Node::Node | ( | std::string | type, |
| Id | id, | ||
| std::string | name ) |
Construct a node instance.
| type | Node type name (typically stable across versions and used by factories/UI). |
| id | Unique node identifier within the graph. |
| name | Human-readable node name (must satisfy validateNodeName). |
|
pure virtual |
Virtual destructor. Pure virtual to ensure Node is abstract, but defined out-of-line.
|
inlinenoexcept |
Whether this node allows mime-type propagation through its ports.
This is used during graph validation at node creation time. See Graph channel verification (kind + mime-type compatibility) for more information. Nodes may change this behavior during initialization via setAllowsMimeTypePropagation.
|
inlinenoexcept |
|
inlinenoexcept |
|
protected |
Assigns a custom task executor to this node.
The custom executor is saved in this class and will be automatically set to the reactor when it is set or changed.
|
inlinenoexcept |
Get the node configuration.
|
pure virtual |
Return the JSON schema describing the node configuration. Used by the dfx::Graph::NodeFactory / tooling / UI to validate and edit configuration.
Implemented in dfx::Plugins::CNode.
|
inlinenoexcept |
Access the customer executor of this node if any.
| T | The type of the underlying executor |
|
inlinenoexcept |
Get the node execution policy.
|
protectedpure virtual |
Handle an incoming message on an input port.
This is the core callback invoked by dfx::Core::InputPort when messages are delivered to this node.
| port | The input port that received the message. |
| message | The delivered message. |
Implemented in dfx::Node::Base64, dfx::Node::Delay, dfx::Node::FileSink, dfx::Node::FileSource, dfx::Node::Log, dfx::Node::MimeTypeRouter, dfx::Node::NullSink, dfx::Node::Process, dfx::Node::Switch, dfx::Node::Testing::Configurable, dfx::Node::ThreadBased, and dfx::Plugins::CNode.
|
inlinenoexcept |
Check whether an input port exists by id.
|
inlinenoexcept |
Check whether an input port exists by name.
|
inlinenoexcept |
Check whether an output port exists by id.
|
inlinenoexcept |
Check whether an output port exists by name.
|
inlinenoexcept |
Get the node id.
|
protected |
Initialize the node with its configuration.
Calls initializeImpl and then stores the resulting configuration in config().
|
protectedpure virtual |
Called by initialize; derived nodes must parse config here.
Implemented in dfx::Node::Base64, dfx::Node::Delay, dfx::Node::FileSink, dfx::Node::FileSource, dfx::Node::Generator, dfx::Node::Log, dfx::Node::MimeTypeRouter, dfx::Node::NullSink, dfx::Node::Process, dfx::Node::Switch, dfx::Node::Testing::Configurable, and dfx::Plugins::CNode.
Get an input port by id (mutable).
| dfx::Utils::Exception | Throws if the port does not exist. |
Get an input port by id.
| dfx::Utils::Exception | Throws if the port does not exist. |
| InputPort & dfx::Core::Node::inputPort | ( | std::string_view | portName | ) |
Get an input port by name (mutable).
| dfx::Utils::Exception | Throws if the port does not exist. |
| InputPort const & dfx::Core::Node::inputPort | ( | std::string_view | portName | ) | const |
Get an input port by name.
| dfx::Utils::Exception | Throws if the port does not exist. |
|
inlinenoexcept |
Get all input ports of all Kind.
|
inlinenoexcept |
Check whether this node is of a given derived type.
| T | A type derived from Node. |
|
inlinenoexcept |
Check of the node is currently running.
|
inline |
Lock the node's internal recursive mutex.
|
pure virtual |
Return node metadata (description, categories, ports, etc.). Intended for UI/tooling and discovery.
Implemented in dfx::Plugins::CNode.
|
inlinenoexcept |
Get the node name.
|
protected |
Must be called by classes that re-implement the stopImpl function.
Informs the node that it has actually stop since some node may take a while to stop.
| OutputPort & dfx::Core::Node::outputPort | ( | Port::Id | id | ) |
Get an output port by id (mutable).
| dfx::Utils::Exception | Throws if the port does not exist. |
| OutputPort const & dfx::Core::Node::outputPort | ( | Port::Id | id | ) | const |
Get an output port by id.
| dfx::Utils::Exception | Throws if the port does not exist. |
| OutputPort & dfx::Core::Node::outputPort | ( | std::string_view | portName | ) |
Get an output port by name (mutable).
| dfx::Utils::Exception | Throws if the port does not exist. |
| OutputPort const & dfx::Core::Node::outputPort | ( | std::string_view | portName | ) | const |
Get an output port by name.
| dfx::Utils::Exception | Throws if the port does not exist. |
|
inlinenoexcept |
Get all output ports of all Kind.
| FdWatch::Poller & dfx::Core::Node::poller | ( | ) |
Access a poller instance associated with this node.
The poller is provided through a lazy-created dfx::Runtime::Api::PollerProxy that forwards registration requests to the runtime reactor.
| dfx::Utils::Exception | Throws if called without a reactor. |
|
inlinenoexcept |
Get the currently attached reactor (may be null if not set).
|
protected |
Register a control input port.
Control ports are used for runtime control messages and use dfx::Core::MimeType::DfxControl.
|
protected |
Register a control output port.
Control ports are used for runtime control messages and use dfx::Core::MimeType::DfxControl.
|
protected |
Register a data input port.
| name | Input port name (unique within the node). |
| supportedMimeTypes | Mime types accepted by the port. |
| allowsMimeTypePropagation | Optional override for propagation behavior. |
|
protected |
Register a data output port.
| name | Output port name (unique within the node). |
| mimeType | Default mime type advertised by the port. |
| allowsMimeTypePropagation | Optional override for propagation behavior. |
|
protectednoexcept |
Revokes a custom task executor, returning this node to the default execution model.
| void dfx::Core::Node::sendMessage | ( | OutputPort & | port, |
| MessagePtr | message ) |
Send a message on the provided output port.
This is the lowest-level overload; it simply forwards to dfx::Core::OutputPort::sendMessage.
| void dfx::Core::Node::sendMessage | ( | Port::Id | id, |
| MessagePtr | message ) |
Send a message on an output port by id.
| id | Output port id. |
| message | Message to send. |
| dfx::Utils::Exception | Throws if the port does not exist. |
| void dfx::Core::Node::sendMessage | ( | std::string_view | portName, |
| MessagePtr | message ) |
Send a message on an output port by name.
| portName | Output port name. |
| message | Message to send. |
| dfx::Utils::Exception | Throws if the port does not exist. |
|
inlineprotected |
Enable/disable global mime-type propagation for this node. This affects how the runtime may propagate mime types through connected ports.
|
inlineprotectedvirtual |
Set the execution flow policy used by the runtime scheduler.
Derived nodes may choose a policy depending on their semantics (e.g. nodes that do heavy work might prefer AlwaysDispatch).
Reimplemented in dfx::Node::ThreadBased.
| void dfx::Core::Node::setName | ( | std::string | newName | ) |
Rename the node.
| newName | New node name (must satisfy validateNodeName). |
| dfx::Utils::Exception | An exception (wrapped with context) if the node is running or the name is invalid. |
| void dfx::Core::Node::setReactor | ( | Runtime::Api::NodeReactor * | reactor | ) |
Attach the runtime reactor used by this node.
Setting a new reactor clears the cached poller proxy; poller will recreate it lazily when needed.
The custom executor, if any, is revoked from the previous reactor and assign to the new one.
| void dfx::Core::Node::start | ( | ) |
Start the node.
If the node is already running, this is a no-op.
First start all transport attached to this node, then calls startImpl and finally marks the node as running.
After starting, any messages that were received while the node was stopped are processed by asking each input port to flush its pending queue.
|
inlineprotectedvirtual |
Called by start before the node is marked running.
Reimplemented in dfx::Node::FileSink, dfx::Node::FileSource, dfx::Node::Process, dfx::Node::ThreadBased, and dfx::Plugins::CNode.
| void dfx::Core::Node::stop | ( | ) |
Stop the node.
If the node is not running, this is a no-op.
First stop all transport attached to this node, then calls stopImpl and finally marks the node as not running.
|
inlineprotectedvirtual |
Called by stop before the node is marked stopped.
When re-implementing this function, onNodeStopped must be called synchronously or not to inform the system that this node is now stopped.
Reimplemented in dfx::Node::FileSource, dfx::Node::Process, dfx::Node::ThreadBased, and dfx::Plugins::CNode.
|
inlinenoexcept |
Check if stop has already been called or not.
|
inlinenoexcept |
Try to lock the node's internal recursive mutex.
|
inlinenoexcept |
Get the node type.
|
inline |
Unlock the node's internal recursive mutex.
|
static |
Validate a node name.
Rules enforced by the implementation:
| name | Name to validate. |
| dfx::Utils::Exception | if the name is invalid |
| void dfx::Core::Node::waitForStopped | ( | ) |
Block the current thread until the node is stopped.
This function will return immediately if the node is already stopped