From 89ace56ade4bdfc36074dd5a595d26e304dde58d Mon Sep 17 00:00:00 2001 From: Green Sky Date: Thu, 18 Jan 2024 18:30:08 +0100 Subject: [PATCH] update to new versioned plugin api --- plugins/plugin_ircclient.cpp | 66 ++++++------------- .../ircclient_message_manager.hpp | 1 - 2 files changed, 21 insertions(+), 46 deletions(-) diff --git a/plugins/plugin_ircclient.cpp b/plugins/plugin_ircclient.cpp index 413f6af..0703b05 100644 --- a/plugins/plugin_ircclient.cpp +++ b/plugins/plugin_ircclient.cpp @@ -7,17 +7,16 @@ #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_ircc = nullptr; static std::unique_ptr g_ircccm = nullptr; static std::unique_ptr g_irccmm = nullptr; +constexpr const char* plugin_name = "IRCClient"; + extern "C" { SOLANA_PLUGIN_EXPORT const char* solana_plugin_get_name(void) { - return "IRCClient"; + return plugin_name; } SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_get_version(void) { @@ -25,66 +24,43 @@ 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 IRCC START()\n"; + std::cout << "PLUGIN " << plugin_name << " START()\n"; if (solana_api == nullptr) { return 1; } - Contact3Registry* cr; - RegistryMessageModel* rmm = nullptr; - ConfigModelI* conf = nullptr; + try { + auto* cr = PLUG_RESOLVE_INSTANCE_VERSIONED(Contact3Registry, "1"); + auto* rmm = PLUG_RESOLVE_INSTANCE(RegistryMessageModel); + auto* conf = PLUG_RESOLVE_INSTANCE(ConfigModelI); - { // make sure required types are loaded - cr = RESOLVE_INSTANCE(Contact3Registry); - rmm = RESOLVE_INSTANCE(RegistryMessageModel); - conf = RESOLVE_INSTANCE(ConfigModelI); + // static store, could be anywhere tho + // construct with fetched dependencies + g_ircc = std::make_unique(*conf); + g_ircccm = std::make_unique(*cr, *conf, *g_ircc); + g_irccmm = std::make_unique(*rmm, *cr, *conf, *g_ircc, *g_ircccm); - if (cr == nullptr) { - std::cerr << "PLUGIN IRCC missing Contact3Registry\n"; - return 2; - } - - if (rmm == nullptr) { - std::cerr << "PLUGIN IRCC missing RegistryMessageModel\n"; - return 2; - } - - if (conf == nullptr) { - std::cerr << "PLUGIN IRCC missing ConfigModelI\n"; - return 2; - } + // register types + PLUG_PROVIDE_INSTANCE(IRCClient1, plugin_name, g_ircc.get()); + PLUG_PROVIDE_INSTANCE(IRCClientContactModel, plugin_name, g_ircccm.get()); + PLUG_PROVIDE_INSTANCE(IRCClientMessageManager, plugin_name, g_irccmm.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_ircc = std::make_unique(*conf); - - // register types - PROVIDE_INSTANCE(IRCClient1, "IRCClient", g_ircc.get()); - - g_ircccm = std::make_unique(*cr, *conf, *g_ircc); - - // register types - PROVIDE_INSTANCE(IRCClientContactModel, "IRCClient", g_ircccm.get()); - - g_irccmm = std::make_unique(*rmm, *cr, *conf, *g_ircc, *g_ircccm); - - // register types - PROVIDE_INSTANCE(IRCClientMessageManager, "IRCClient", g_irccmm.get()); - return 0; } SOLANA_PLUGIN_EXPORT void solana_plugin_stop(void) { - std::cout << "PLUGIN IRCC STOP()\n"; + std::cout << "PLUGIN " << plugin_name << " STOP()\n"; g_ircc.reset(); } SOLANA_PLUGIN_EXPORT float solana_plugin_tick(float delta) { (void)delta; - //std::cout << "PLUGIN IRCC TICK()\n"; g_ircc->iterate(); // TODO: return interval, respect dcc etc return 1.f; // expect atleast once per sec diff --git a/src/solanaceae/ircclient_messages/ircclient_message_manager.hpp b/src/solanaceae/ircclient_messages/ircclient_message_manager.hpp index d82da89..ec2e912 100644 --- a/src/solanaceae/ircclient_messages/ircclient_message_manager.hpp +++ b/src/solanaceae/ircclient_messages/ircclient_message_manager.hpp @@ -1,6 +1,5 @@ #pragma once -#include "solanaceae/contact/contact_model3.hpp" #include #include #include