diff --git a/external/solanaceae_util b/external/solanaceae_util index 92eee15..17d2baf 160000 --- a/external/solanaceae_util +++ b/external/solanaceae_util @@ -1 +1 @@ -Subproject commit 92eee153f2c14f97e50f44b10e2a0aeb5f8b190d +Subproject commit 17d2baf7365c3499172dc5afd71171cb3a138d99 diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 3c7aba4..409dc26 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -4,6 +4,10 @@ add_library(plugin_clamav SHARED ./plugin_clamav_module.cpp ) target_compile_features(plugin_clamav PUBLIC cxx_std_17) +set_target_properties(plugin_clamav PROPERTIES + C_VISIBILITY_PRESET hidden + POSITION_INDEPENDENT_CODE ON +) target_link_libraries(plugin_clamav PUBLIC solanaceae_clamav solanaceae_plugin diff --git a/plugins/plugin_clamav_module.cpp b/plugins/plugin_clamav_module.cpp index 604085b..12a7a5b 100644 --- a/plugins/plugin_clamav_module.cpp +++ b/plugins/plugin_clamav_module.cpp @@ -4,17 +4,17 @@ #include #include +#include #include -#define RESOLVE_INSTANCE(x) static_cast(solana_api->resolveInstance(#x)) -#define PROVIDE_INSTANCE(x, p, v) solana_api->provideInstance(#x, p, static_cast(v)) - static std::unique_ptr g_cavm = nullptr; +constexpr const char* plugin_name = "ClamAVModule"; + extern "C" { SOLANA_PLUGIN_EXPORT const char* solana_plugin_get_name(void) { - return "ClamAVModule"; + return plugin_name; } SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_get_version(void) { @@ -22,43 +22,40 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_get_version(void) { } SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api) { - std::cout << "PLUGIN CAVM START()\n"; + std::cout << "PLUGIN " << plugin_name << " START()\n"; if (solana_api == nullptr) { return 1; } - ConfigModelI* conf = nullptr; + try { + auto* conf = PLUG_RESOLVE_INSTANCE(ConfigModelI); - { // make sure required types are loaded - conf = RESOLVE_INSTANCE(ConfigModelI); + // static store, could be anywhere tho + // construct with fetched dependencies + g_cavm = std::make_unique(*conf); - if (conf == nullptr) { - std::cerr << "PLUGIN CAVM missing ConfigModelI\n"; - return 2; - } + // register types + PLUG_PROVIDE_INSTANCE(ClamAVModule, plugin_name, g_cavm.get()); + } catch (const ResolveException& e) { + std::cerr << "PLUGIN " << plugin_name << " " << e.what << "\n"; + return 2; } - // static store, could be anywhere tho - // construct with fetched dependencies - g_cavm = std::make_unique(*conf); - - // register types - PROVIDE_INSTANCE(ClamAVModule, "ClamAVModule", g_cavm.get()); - return 0; } SOLANA_PLUGIN_EXPORT void solana_plugin_stop(void) { - std::cout << "PLUGIN CAVM STOP()\n"; + std::cout << "PLUGIN " << plugin_name << " STOP()\n"; g_cavm.reset(); } -SOLANA_PLUGIN_EXPORT void solana_plugin_tick(float delta) { +SOLANA_PLUGIN_EXPORT float solana_plugin_tick(float delta) { (void)delta; //std::cout << "PLUGIN CAVM TICK()\n"; //g_cavm->iterate(); + return std::numeric_limits::max(); } } // extern C