From 35bf05b3e1b21bb75f0804a3422eefc8dfe3b834 Mon Sep 17 00:00:00 2001 From: faumaray Date: Tue, 28 Jul 2026 23:04:26 +0300 Subject: [PATCH] Plugin: publish reloadable module contract --- .gitignore | 2 ++ CMakeLists.txt | 3 +++ abi/module.json | 14 ++++++++++++++ src/Plugin.cpp | 42 ++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 abi/module.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2b6299e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build*/ +.cache/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 0666629..2172cb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,9 +41,12 @@ add_library(EchoionUrlShortenerInternalPlugin MODULE target_include_directories(EchoionUrlShortenerInternalPlugin PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include") target_compile_features(EchoionUrlShortenerInternalPlugin PRIVATE cxx_std_26) +target_compile_definitions(EchoionUrlShortenerInternalPlugin PRIVATE + "ECHOION_COMPONENT_VERSION=\"${PROJECT_VERSION}\"") target_link_libraries(EchoionUrlShortenerInternalPlugin PRIVATE Echoion::ApiPlugin Echoion::ApiConfig + Echoion::ApiModuleAbi Echoion::ApiPluginSdk Void::ShortUrl Void::Data diff --git a/abi/module.json b/abi/module.json new file mode 100644 index 0000000..1791932 --- /dev/null +++ b/abi/module.json @@ -0,0 +1,14 @@ +{ + "schemaVersion": 1, + "contractId": "echoion.plugin.url-shortener-internal", + "descriptor": "Void::Plugin::ModuleDescriptor", + "moduleId": "url-shortener-internal", + "activationPolicy": "reloadable", + "services": [ + { + "id": "void.short-url", + "version": 1, + "type": "Void::ShortUrl::IShortener" + } + ] +} diff --git a/src/Plugin.cpp b/src/Plugin.cpp index 96f64fa..bb33ccc 100644 --- a/src/Plugin.cpp +++ b/src/Plugin.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -23,7 +24,7 @@ namespace Echoion::Plugins::ShortUrl namespace { constexpr std::string_view kPluginId{"url-shortener-internal"}; - constexpr std::string_view kPluginVersion{"1.0.0"}; + constexpr std::string_view kPluginVersion{ECHOION_COMPONENT_VERSION}; [[nodiscard]] const Void::Json::Value& settingsObject(const Void::Json::Value& root) noexcept @@ -372,10 +373,47 @@ namespace Echoion::Plugins::ShortUrl std::unique_ptr store_; }; + std::unique_ptr createModule() + { + return std::make_unique(); + } + + const Void::Plugin::ModuleDescriptor& moduleDescriptor() + { + static const Void::Plugin::ModuleDescriptor descriptor{ + .module_id = "url-shortener-internal", + .component_version = {.major = 2, .minor = 0, .patch = 0}, + .abi_hash = + "sha256:68e338e9fd65bfad73364587af7e1c95f6ce98fe2ab08922113d9d240a4c8a39", + .abi_contract = Void::Json::object({ + {"schemaVersion", 1}, + {"contractId", "echoion.plugin.url-shortener-internal"}, + {"descriptor", "Void::Plugin::ModuleDescriptor"}, + }), + .dependencies = + { + { + .module_id = "EchoionApi", + .version_range = "^2.0.0", + .abi_hash = + "sha256:336492a52097dd12f222bb6d9acab19e8eb6a502eab45bb78127bce6d733fbd3", + }, + }, + .activation_policy = Void::Plugin::ActivationPolicy::Reloadable, + .create = createModule, + }; + return descriptor; + } + } // namespace Echoion::Plugins::ShortUrl extern "C" { +const Void::Plugin::ModuleDescriptor* echoion_module_query() +{ + return &Echoion::Plugins::ShortUrl::moduleDescriptor(); +} + void* void_plugin_create() { return std::make_unique< @@ -395,7 +433,7 @@ Void::Plugin::PluginInfo void_plugin_info() return { .abi_version = Void::Plugin::ABI_VERSION, .name = "url-shortener-internal", - .plugin_version = "1.0.0", + .plugin_version = ECHOION_COMPONENT_VERSION, .description = "Persistent Echoion-hosted URL shortener", }; }