From 31054b86ea5e9a38929a493d55b119158e8ab59f Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Thu, 8 Jan 2026 14:26:09 -0800 Subject: [PATCH] container: plugins: root: example: support Pluggable entrypoint --- container/plugins/root/example/example.cc | 113 ++++++++++++---------- 1 file changed, 64 insertions(+), 49 deletions(-) diff --git a/container/plugins/root/example/example.cc b/container/plugins/root/example/example.cc index 3fee883..f89ddbf 100644 --- a/container/plugins/root/example/example.cc +++ b/container/plugins/root/example/example.cc @@ -1,6 +1,6 @@ // docker-finance | modern accounting for the power-user // -// Copyright (C) 2024-2025 Aaron Fiore (Founder, Evergreen Crypto LLC) +// Copyright (C) 2024-2026 Aaron Fiore (Founder, Evergreen Crypto LLC) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -41,64 +41,79 @@ namespace dfi::plugin //! \since docker-finance 1.1.0 namespace example { -//! \brief Example auto-loader -//! \param arg String to pass to auto-loader (use-case is plugin-implementation defined) -void load(const std::string& arg = {}) +//! \brief Pluggable entrypoint +//! \ingroup cpp_plugin_impl +//! \since docker-finance 1.1.0 +class example_cc { - namespace plugin = ::dfi::plugin; - namespace common = ::dfi::common; + public: + example_cc() = default; + ~example_cc() = default; - // Any code can follow here: run example functions, etc. - // - // For this example: - // - // 1. Load needed requirements for this plugin's impl - // 2. Get absolute path of plugin's impl and then load - // - const std::string src{common::get_root_path() + "src/"}; - common::load(src + "hash.hh"); - common::load(src + "random.hh"); - // ...add as needed + example_cc(const example_cc&) = default; + example_cc& operator=(const example_cc&) = default; - plugin::common::PluginPath path("repo/example/internal/example.cc"); - common::load(path.absolute()); + example_cc(example_cc&&) = default; + example_cc& operator=(example_cc&&) = default; - // For this example, expect and pass a line of code to the interpreter after loading - // NOTE: the following arg code can utilize any code that was loaded/interpreted in load() - if (!arg.empty()) - common::line(arg); -} + public: + //! \brief Example auto-loader + //! \param arg String to pass to auto-loader (use-case is plugin-implementation defined) + static void load(const std::string& arg = {}) + { + namespace plugin = ::dfi::plugin; + namespace common = ::dfi::common; -//! \brief Example auto-unloader -//! \param arg String to pass to auto-unloader (use-case is plugin-implementation defined) -void unload(const std::string& arg = {}) -{ - namespace plugin = ::dfi::plugin; - namespace common = ::dfi::common; + // Any code can follow here: run example functions, etc. + // + // For this example: + // + // 1. Load needed requirements for this plugin's impl + // 2. Get absolute path of plugin's impl and then load + // + const std::string src{common::get_root_path() + "src/"}; + common::load(src + "hash.hh"); + common::load(src + "random.hh"); + // ...add as needed - // For this example, expect and pass a line of code to the interpreter before unloading. - // NOTE: the following arg code can utilize any code that was previously loaded/interpreted - if (!arg.empty()) - common::line(arg); + plugin::common::PluginPath path("repo/example/internal/example.cc"); + common::load(path.absolute()); - // Any code can follow here: run example functions, etc. - // - // For this example: - // - // 1. Unload needed requirements for this plugin's impl - // 2. Get absolute path of plugin's impl and then unload - // - const std::string src{common::get_root_path() + "src/"}; - common::unload(src + "hash.hh"); - common::unload(src + "random.hh"); - // ...add as needed + // For this example, expect and pass a line of code to the interpreter after loading + // NOTE: the following arg code can utilize any code that was loaded/interpreted in load() + if (!arg.empty()) + common::line(arg); + } - plugin::common::PluginPath path("repo/example/internal/example.cc"); - common::unload(path.absolute()); -} + //! \brief Example auto-unloader + //! \param arg String to pass to auto-unloader (use-case is plugin-implementation defined) + static void unload(const std::string& arg = {}) + { + namespace plugin = ::dfi::plugin; + namespace common = ::dfi::common; -// NOTE: to auto-reload this plugin, load()/unload() here or utilize one of the `dfi::plugin::reload()` functions. + // For this example, expect and pass a line of code to the interpreter before unloading. + // NOTE: the following arg code can utilize any code that was previously loaded/interpreted + if (!arg.empty()) + common::line(arg); + // Any code can follow here: run example functions, etc. + // + // For this example: + // + // 1. Unload needed requirements for this plugin's impl + // 2. Get absolute path of plugin's impl and then unload + // + const std::string src{common::get_root_path() + "src/"}; + common::unload(src + "hash.hh"); + common::unload(src + "random.hh"); + // ...add as needed + + plugin::common::PluginPath path("repo/example/internal/example.cc"); + common::unload(path.absolute()); + } + // NOTE: to auto-reload this plugin, load()/unload() here or utilize one of the `dfi::plugin::reload()` functions. +}; } // namespace example } // namespace dfi::plugin