dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
dfx::Plugins::CNode Class Reference

Host-side proxy for a Node implemented via the C-ABI. More...

#include <dfx-plugins/bridges/node/CNode.hpp>

Inheritance diagram for dfx::Plugins::CNode:
[legend]
Collaboration diagram for dfx::Plugins::CNode:
[legend]

Public Member Functions

 CNode (std::string type, Id id, std::string name, Plugin const &plugin, dfx_node_interface_t interface)
 Constructs a new CNode proxy.
 DFX_DISABLE_COPY_AND_MOVE (CNode)
 ~CNode ()
 Destructor. Invokes the plugin's dfx_node_interface_t::destroy function.
nlohmann::json configSchema () const override
 Return the JSON schema describing the node configuration. Used by the dfx::Graph::NodeFactory / tooling / UI to validate and edit configuration.
nlohmann::json metadata () const override
 Return node metadata (description, categories, ports, etc.). Intended for UI/tooling and discovery.
Public Member Functions inherited from dfx::Core::Node
 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).
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.
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.
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.
InputPortinputPort (std::string_view portName)
 Get an input port by name (mutable).
OutputPortoutputPort (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.
InputPortinputPort (Port::Id id)
 Get an input port by id (mutable).
OutputPortoutputPort (Port::Id id)
 Get an output port by id (mutable).
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.
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.
void setReactor (Runtime::Api::NodeReactor *reactor)
 Attach the runtime reactor used by this node.
Runtime::Api::NodeReactorreactor () const noexcept
 Get the currently attached reactor (may be null if not set).
FdWatch::Pollerpoller ()
 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.

Protected Member Functions

void startImpl () override
 Signals the plugin to start processing.
void stopImpl () override
 Signals the plugin to stop processing.
void initializeImpl (nlohmann::json config) override
 Initializes the plugin-side instance.
void handleMessage (Core::InputPort const &port, Core::MessagePtr message) override
 Dispatches an incoming C++ message to the C-ABI.
Protected Member Functions inherited from dfx::Core::Node
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.
void onNodeStopped ()
 Must be called by classes that re-implement the stopImpl function.
OutputPortregisterOutputPort (std::string name, MimeType mimeType=MimeType::Any, std::optional< bool > allowsMimeTypePropagation=std::nullopt)
 Register a data output port.
InputPortregisterInputPort (std::string name, MimeTypes supportedMimeTypes={}, std::optional< bool > allowsMimeTypePropagation=std::nullopt)
 Register a data input port.
OutputPortregisterControlOutputPort (std::string name)
 Register a control output port.
InputPortregisterControlInputPort (std::string name)
 Register a control input port.
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.

Additional Inherited Members

Public Types inherited from dfx::Core::Node
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).
Static Public Member Functions inherited from dfx::Core::Node
static void validateNodeName (std::string_view name)
 Validate a node name.

Detailed Description

Host-side proxy for a Node implemented via the C-ABI.

CNode is a concrete implementation of Core::Node that delegates its core functionality to an external plugin through the dfx_node_interface_t vtable.

It manages the lifecycle of the plugin-side node instance, handles the conversion between native C++ message objects and the dfx_message_api_t, and provides the node with access to host services like the poller and port registration.

Constructor & Destructor Documentation

◆ CNode()

dfx::Plugins::CNode::CNode ( std::string type,
Id id,
std::string name,
Plugin const & plugin,
dfx_node_interface_t interface )

Constructs a new CNode proxy.

Parameters
typeThe registered node type string.
idThe unique instance ID within the graph.
nameThe user-defined instance name.
pluginReference to the owning plugin handle (for resource tracking).
interfaceThe vtable containing the plugin's function implementations.

◆ ~CNode()

dfx::Plugins::CNode::~CNode ( )

Destructor. Invokes the plugin's dfx_node_interface_t::destroy function.

Member Function Documentation

◆ configSchema()

nlohmann::json dfx::Plugins::CNode::configSchema ( ) const
inlineoverridevirtual

Return the JSON schema describing the node configuration. Used by the dfx::Graph::NodeFactory / tooling / UI to validate and edit configuration.

See also
DFX_NODE

Implements dfx::Core::Node.

◆ handleMessage()

void dfx::Plugins::CNode::handleMessage ( Core::InputPort const & port,
Core::MessagePtr message )
overrideprotectedvirtual

Dispatches an incoming C++ message to the C-ABI.

Wraps the native message in a dfx_message_api_t and invokes dfx_node_interface_t::on_message.

Parameters
portThe native input port the message arrived on.
messageThe message pointer.

Implements dfx::Core::Node.

◆ initializeImpl()

void dfx::Plugins::CNode::initializeImpl ( nlohmann::json config)
overrideprotectedvirtual

Initializes the plugin-side instance.

Calls dfx_node_interface_t::build with the provided JSON configuration.

Parameters
configThe validated JSON configuration for this node instance.

Implements dfx::Core::Node.

◆ metadata()

nlohmann::json dfx::Plugins::CNode::metadata ( ) const
inlineoverridevirtual

Return node metadata (description, categories, ports, etc.). Intended for UI/tooling and discovery.

See also
DFX_NODE

Implements dfx::Core::Node.

◆ startImpl()

void dfx::Plugins::CNode::startImpl ( )
overrideprotectedvirtual

Signals the plugin to start processing.

Invokes dfx_node_interface_t::start and provides the dfx_poller_api_t to the plugin.

Reimplemented from dfx::Core::Node.

◆ stopImpl()

void dfx::Plugins::CNode::stopImpl ( )
overrideprotectedvirtual

Signals the plugin to stop processing.

Invokes dfx_node_interface_t::stop. The node is expected to call dfx_node_api_t::notify_stopped once background tasks are joined.

Reimplemented from dfx::Core::Node.


The documentation for this class was generated from the following file: