container: plugins: root: example: support Pluggable entrypoint
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
// docker-finance | modern accounting for the power-user
|
// 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
|
// 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
|
// 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
|
//! \since docker-finance 1.1.0
|
||||||
namespace example
|
namespace example
|
||||||
{
|
{
|
||||||
//! \brief Example auto-loader
|
//! \brief Pluggable entrypoint
|
||||||
//! \param arg String to pass to auto-loader (use-case is plugin-implementation defined)
|
//! \ingroup cpp_plugin_impl
|
||||||
void load(const std::string& arg = {})
|
//! \since docker-finance 1.1.0
|
||||||
|
class example_cc
|
||||||
{
|
{
|
||||||
namespace plugin = ::dfi::plugin;
|
public:
|
||||||
namespace common = ::dfi::common;
|
example_cc() = default;
|
||||||
|
~example_cc() = default;
|
||||||
|
|
||||||
// Any code can follow here: run example functions, etc.
|
example_cc(const example_cc&) = default;
|
||||||
//
|
example_cc& operator=(const example_cc&) = default;
|
||||||
// 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
|
|
||||||
|
|
||||||
plugin::common::PluginPath path("repo/example/internal/example.cc");
|
example_cc(example_cc&&) = default;
|
||||||
common::load(path.absolute());
|
example_cc& operator=(example_cc&&) = default;
|
||||||
|
|
||||||
// For this example, expect and pass a line of code to the interpreter after loading
|
public:
|
||||||
// NOTE: the following arg code can utilize any code that was loaded/interpreted in load()
|
//! \brief Example auto-loader
|
||||||
if (!arg.empty())
|
//! \param arg String to pass to auto-loader (use-case is plugin-implementation defined)
|
||||||
common::line(arg);
|
static void load(const std::string& arg = {})
|
||||||
}
|
{
|
||||||
|
namespace plugin = ::dfi::plugin;
|
||||||
|
namespace common = ::dfi::common;
|
||||||
|
|
||||||
//! \brief Example auto-unloader
|
// Any code can follow here: run example functions, etc.
|
||||||
//! \param arg String to pass to auto-unloader (use-case is plugin-implementation defined)
|
//
|
||||||
void unload(const std::string& arg = {})
|
// For this example:
|
||||||
{
|
//
|
||||||
namespace plugin = ::dfi::plugin;
|
// 1. Load needed requirements for this plugin's impl
|
||||||
namespace common = ::dfi::common;
|
// 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.
|
plugin::common::PluginPath path("repo/example/internal/example.cc");
|
||||||
// NOTE: the following arg code can utilize any code that was previously loaded/interpreted
|
common::load(path.absolute());
|
||||||
if (!arg.empty())
|
|
||||||
common::line(arg);
|
|
||||||
|
|
||||||
// Any code can follow here: run example functions, etc.
|
// 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()
|
||||||
// For this example:
|
if (!arg.empty())
|
||||||
//
|
common::line(arg);
|
||||||
// 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");
|
//! \brief Example auto-unloader
|
||||||
common::unload(path.absolute());
|
//! \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 example
|
||||||
} // namespace dfi::plugin
|
} // namespace dfi::plugin
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user