89 lines
1.7 KiB
C++
89 lines
1.7 KiB
C++
#include "Configurable.hpp"
|
|
|
|
#include <Void/Plugin/Plugin.hpp>
|
|
|
|
#include <string>
|
|
|
|
// A plugin that records what the host passes through the optional
|
|
// void_plugin_configure entry point, and when (relative to on_load).
|
|
|
|
namespace
|
|
{
|
|
class ConfigurablePlugin final : public VoidTest::IConfigurable
|
|
{
|
|
public:
|
|
|
|
[[nodiscard]] std::string_view name() const noexcept override
|
|
{
|
|
return "ConfigurablePlugin";
|
|
}
|
|
|
|
void on_load() override { loaded_ = true; }
|
|
|
|
[[nodiscard]] std::string_view last_config() const override
|
|
{
|
|
return config_;
|
|
}
|
|
|
|
[[nodiscard]] int configure_calls() const override
|
|
{
|
|
return calls_;
|
|
}
|
|
|
|
[[nodiscard]] bool configured_before_on_load() const override
|
|
{
|
|
return before_on_load_;
|
|
}
|
|
|
|
void apply_config(const char* config)
|
|
{
|
|
config_ = config != nullptr ? config : "";
|
|
++calls_;
|
|
if (!loaded_) {
|
|
before_on_load_ = true;
|
|
}
|
|
}
|
|
|
|
[[nodiscard]] bool ready() const noexcept
|
|
{
|
|
return config_ != "reject";
|
|
}
|
|
|
|
private:
|
|
|
|
std::string config_;
|
|
int calls_{0};
|
|
bool loaded_{false};
|
|
bool before_on_load_{false};
|
|
};
|
|
} // namespace
|
|
|
|
extern "C" {
|
|
void* void_plugin_create() { return new ConfigurablePlugin; }
|
|
|
|
void void_plugin_destroy(void* p)
|
|
{
|
|
delete static_cast<ConfigurablePlugin*>(p);
|
|
}
|
|
|
|
Void::Plugin::PluginInfo void_plugin_info()
|
|
{
|
|
return {
|
|
.abi_version = Void::Plugin::ABI_VERSION,
|
|
.name = "ConfigurablePlugin",
|
|
.plugin_version = "1.0.0",
|
|
.description = "Configure entry-point test plugin",
|
|
};
|
|
}
|
|
|
|
void void_plugin_configure(void* instance, const char* config)
|
|
{
|
|
static_cast<ConfigurablePlugin*>(instance)->apply_config(config);
|
|
}
|
|
|
|
int void_plugin_ready(void* instance)
|
|
{
|
|
return static_cast<ConfigurablePlugin*>(instance)->ready() ? 0 : -1;
|
|
}
|
|
}
|