dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
Plugin.hpp
1// SPDX-FileCopyrightText: 2026 Vincent Leroy
2// SPDX-License-Identifier: MIT
3//
4// This file is part of dfx.
5//
6// Licensed under the MIT License. See the LICENSE file in the project root
7// for full license information.
8
9#pragma once
10
11// Standard includes
12#include <memory>
13
14// Third-party includes
15#include <nlohmann/json.hpp>
16
17// Project includes
18#include "SharedLibrary.hpp"
21
22namespace dfx::Plugins
23{
37class Plugin
38{
39 friend class Registry;
40
41public:
43 static nlohmann::json const pluginMetadataSchema;
44
45public:
47 explicit Plugin() = default;
48
57 explicit Plugin(fs::path path);
58
61
62 // Plugins are not copiable nor movable because they pass the this pointer to C code as context
64
65public:
78 std::string const & pluginConfig,
79 fs::path const & basePath,
80 SharedLibrary::LoadFlags loadFlags = SharedLibrary::defaultLoadFlags);
81
83 dfx_env_api_t & pluginEnv() noexcept { return _env; }
85 dfx_env_api_t const & pluginEnv() const noexcept { return _env; }
86
88 fs::path const & pluginPath() const noexcept { return _path; }
90 SharedLibraryPtr const & lib() const noexcept { return _lib; }
92 nlohmann::json const & metadata() const noexcept { return _metadata; }
93
94public:
96 std::string name() const { return _metadata.value("name", std::string()); }
98 std::string version() const { return _metadata.value("version", std::string()); }
99
101 std::vector<std::string> const & registeredTransportScheme() const noexcept { return _registeredTransportScheme; }
103 std::vector<std::string> const & registeredNodeType() const noexcept { return _registeredNodeType; }
104
105public:
111 static nlohmann::json readMetadataOfPluginAt(fs::path const & path);
112
113private:
114 dfx_env_api_t _env{};
115
116 fs::path _path;
117 fs::path _pluginDir;
118 SharedLibraryPtr _lib;
119 nlohmann::json _metadata;
120
121 decltype(&dfx_deinit_plugin) _deinitFunc = nullptr;
122
123 // These vectors are filled by the Registry
124 std::vector<std::string> _registeredTransportScheme;
125 std::vector<std::string> _registeredNodeType;
126};
127
128using PluginPtr = std::unique_ptr<Plugin>;
129} // !namespace dfx::Plugins
Convenience macros to explicitly control copy and move semantics.
#define DFX_DISABLE_COPY_AND_MOVE(ClassName)
Disable both copy and move.
Definition CopyMoveControl.hpp:37
C-ABI for the dfx framework plugin system.
DFX_PLUGIN_VISIBLE_ATTR void dfx_deinit_plugin(dfx_env_api_t const *env, size_t env_size)
Cleanup entry point called before the plugin is unloaded.
std::string name() const
Access the human-readable name of the plugin from metadata.
Definition Plugin.hpp:96
static nlohmann::json const pluginMetadataSchema
JSON schema used to validate plugin metadata blobs.
Definition Plugin.hpp:43
static nlohmann::json readMetadataOfPluginAt(fs::path const &path)
Static helper to read metadata from a binary without fully loading it.
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.
Plugin(fs::path path)
Constructs a plugin object associated with a specific file path.
Plugin()=default
Default constructor for an uninitialized plugin.
nlohmann::json const & metadata() const noexcept
Access the metadata JSON extracted from the plugin's .dfx_metadata section.
Definition Plugin.hpp:92
std::string version() const
Access the version string of the plugin from metadata.
Definition Plugin.hpp:98
SharedLibraryPtr const & lib() const noexcept
Access the pointer to the underlying shared library wrapper.
Definition Plugin.hpp:90
~Plugin()
Destructor. Calls the plugin's deinit function (dfx_deinit_plugin) if it exists and unloads the share...
fs::path const & pluginPath() const noexcept
Access the filesystem path to the plugin binary.
Definition Plugin.hpp:88
std::vector< std::string > const & registeredTransportScheme() const noexcept
Access the list of transport schemes (e.g., "udp") registered by this plugin.
Definition Plugin.hpp:101
std::vector< std::string > const & registeredNodeType() const noexcept
Access the list of node types (e.g., "camera_input") registered by this plugin.
Definition Plugin.hpp:103
dfx_env_api_t & pluginEnv() noexcept
Access the environment API structure provided to this plugin.
Definition Plugin.hpp:83
dfx_env_api_t const & pluginEnv() const noexcept
Access the environment API structure provided to this plugin.
Definition Plugin.hpp:85
static constexpr LoadFlags defaultLoadFlags
Default flags for plugin loading: immediate resolution and local visibility.
Definition SharedLibrary.hpp:46
Definition MessageApi.hpp:16
std::unique_ptr< SharedLibrary > SharedLibraryPtr
Unique ownership pointer type for SharedLibrary.
Definition SharedLibrary.hpp:102
Host environment services provided to the plugin.
Definition PluginInterface.h:190
Transient registration context used during plugin discovery.
Definition PluginInterface.h:882