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

Manager for a loaded plugin shared library. More...

#include <dfx-plugins/Plugin.hpp>

Public Member Functions

 Plugin ()=default
 Default constructor for an uninitialized plugin.
 Plugin (fs::path path)
 Constructs a plugin object associated with a specific file path.
 ~Plugin ()
 Destructor. Calls the plugin's deinit function (dfx_deinit_plugin) if it exists and unloads the shared library.
 DFX_DISABLE_COPY_AND_MOVE (Plugin)
void loadAndInitPlugin (dfx_registration_api_t const &reg, std::string const &pluginConfig, fs::path const &basePath, SharedLibrary::LoadFlags loadFlags=SharedLibrary::defaultLoadFlags)
 Loads the shared library into memory and initializes the plugin.
dfx_env_api_tpluginEnv () noexcept
 Access the environment API structure provided to this plugin.
dfx_env_api_t const & pluginEnv () const noexcept
 Access the environment API structure provided to this plugin.
fs::path const & pluginPath () const noexcept
 Access the filesystem path to the plugin binary.
SharedLibraryPtr const & lib () const noexcept
 Access the pointer to the underlying shared library wrapper.
nlohmann::json const & metadata () const noexcept
 Access the metadata JSON extracted from the plugin's .dfx_metadata section.
std::string name () const
 Access the human-readable name of the plugin from metadata.
std::string version () const
 Access the version string of the plugin from metadata.
std::vector< std::string > const & registeredTransportScheme () const noexcept
 Access the list of transport schemes (e.g., "udp") registered by this plugin.
std::vector< std::string > const & registeredNodeType () const noexcept
 Access the list of node types (e.g., "camera_input") registered by this plugin.

Static Public Member Functions

static nlohmann::json readMetadataOfPluginAt (fs::path const &path)
 Static helper to read metadata from a binary without fully loading it.

Static Public Attributes

static nlohmann::json const pluginMetadataSchema
 JSON schema used to validate plugin metadata blobs.

Friends

class Registry

Detailed Description

Manager for a loaded plugin shared library.

This class handles the low-level mechanics of loading a shared library (.so/.dll), extracting its metadata, and executing its dfx_init_plugin entry point.

It maintains the dfx_env_api_t provided to the plugin and tracks which node types and transport schemes the plugin has successfully registered.

Note
Copy/Move restricted: This class passes its this pointer to the C-ABI as context; therefore, it cannot be copied or moved to ensure pointer stability.

Constructor & Destructor Documentation

◆ Plugin() [1/2]

dfx::Plugins::Plugin::Plugin ( )
explicitdefault

Default constructor for an uninitialized plugin.

◆ Plugin() [2/2]

dfx::Plugins::Plugin::Plugin ( fs::path path)
explicit

Constructs a plugin object associated with a specific file path.

The constructor doesn't load nor call any function from the file at the specified location. It only check and load its JSON metadata.

Parameters
pathPath to the shared library file.
See also
loadAndInitPlugin

◆ ~Plugin()

dfx::Plugins::Plugin::~Plugin ( )

Destructor. Calls the plugin's deinit function (dfx_deinit_plugin) if it exists and unloads the shared library.

Member Function Documentation

◆ lib()

SharedLibraryPtr const & dfx::Plugins::Plugin::lib ( ) const
inlinenoexcept

Access the pointer to the underlying shared library wrapper.

◆ loadAndInitPlugin()

void dfx::Plugins::Plugin::loadAndInitPlugin ( dfx_registration_api_t const & reg,
std::string const & pluginConfig,
fs::path const & basePath,
SharedLibrary::LoadFlags loadFlags = SharedLibrary::defaultLoadFlags )

Loads the shared library into memory and initializes the plugin.

Performs the following steps:

  1. Loads the binary using the specified loadFlags.
  2. Locates the dfx_init_plugin symbol.
  3. Invokes the initialization function with the provided registration context.
Parameters
regThe host-side registration API.
pluginConfigPlugin specific configuration.
basePathThe path that will be used as the root dir when resolving relative path.
loadFlagsOS-specific flags for library loading (e.g., RTLD_NOW).

◆ metadata()

nlohmann::json const & dfx::Plugins::Plugin::metadata ( ) const
inlinenoexcept

Access the metadata JSON extracted from the plugin's .dfx_metadata section.

◆ name()

std::string dfx::Plugins::Plugin::name ( ) const
inline

Access the human-readable name of the plugin from metadata.

◆ pluginEnv() [1/2]

dfx_env_api_t const & dfx::Plugins::Plugin::pluginEnv ( ) const
inlinenoexcept

Access the environment API structure provided to this plugin.

◆ pluginEnv() [2/2]

dfx_env_api_t & dfx::Plugins::Plugin::pluginEnv ( )
inlinenoexcept

Access the environment API structure provided to this plugin.

◆ pluginPath()

fs::path const & dfx::Plugins::Plugin::pluginPath ( ) const
inlinenoexcept

Access the filesystem path to the plugin binary.

◆ readMetadataOfPluginAt()

nlohmann::json dfx::Plugins::Plugin::readMetadataOfPluginAt ( fs::path const & path)
static

Static helper to read metadata from a binary without fully loading it.

Parameters
pathPath to the shared library.
Returns
The parsed JSON metadata.

◆ registeredNodeType()

std::vector< std::string > const & dfx::Plugins::Plugin::registeredNodeType ( ) const
inlinenoexcept

Access the list of node types (e.g., "camera_input") registered by this plugin.

◆ registeredTransportScheme()

std::vector< std::string > const & dfx::Plugins::Plugin::registeredTransportScheme ( ) const
inlinenoexcept

Access the list of transport schemes (e.g., "udp") registered by this plugin.

◆ version()

std::string dfx::Plugins::Plugin::version ( ) const
inline

Access the version string of the plugin from metadata.

Member Data Documentation

◆ pluginMetadataSchema

nlohmann::json const dfx::Plugins::Plugin::pluginMetadataSchema
static

JSON schema used to validate plugin metadata blobs.


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