update to new versioned plugin api

This commit is contained in:
Green Sky 2024-01-18 18:30:08 +01:00
parent 5c3784e7ce
commit 89ace56ade
No known key found for this signature in database
2 changed files with 21 additions and 46 deletions

View File

@ -7,17 +7,16 @@
#include <memory> #include <memory>
#include <iostream> #include <iostream>
#define RESOLVE_INSTANCE(x) static_cast<x*>(solana_api->resolveInstance(#x))
#define PROVIDE_INSTANCE(x, p, v) solana_api->provideInstance(#x, p, static_cast<x*>(v))
static std::unique_ptr<IRCClient1> g_ircc = nullptr; static std::unique_ptr<IRCClient1> g_ircc = nullptr;
static std::unique_ptr<IRCClientContactModel> g_ircccm = nullptr; static std::unique_ptr<IRCClientContactModel> g_ircccm = nullptr;
static std::unique_ptr<IRCClientMessageManager> g_irccmm = nullptr; static std::unique_ptr<IRCClientMessageManager> g_irccmm = nullptr;
constexpr const char* plugin_name = "IRCClient";
extern "C" { extern "C" {
SOLANA_PLUGIN_EXPORT const char* solana_plugin_get_name(void) { 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) { 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) { 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) { if (solana_api == nullptr) {
return 1; return 1;
} }
Contact3Registry* cr; try {
RegistryMessageModel* rmm = nullptr; auto* cr = PLUG_RESOLVE_INSTANCE_VERSIONED(Contact3Registry, "1");
ConfigModelI* conf = nullptr; auto* rmm = PLUG_RESOLVE_INSTANCE(RegistryMessageModel);
auto* conf = PLUG_RESOLVE_INSTANCE(ConfigModelI);
{ // make sure required types are loaded // static store, could be anywhere tho
cr = RESOLVE_INSTANCE(Contact3Registry); // construct with fetched dependencies
rmm = RESOLVE_INSTANCE(RegistryMessageModel); g_ircc = std::make_unique<IRCClient1>(*conf);
conf = RESOLVE_INSTANCE(ConfigModelI); g_ircccm = std::make_unique<IRCClientContactModel>(*cr, *conf, *g_ircc);
g_irccmm = std::make_unique<IRCClientMessageManager>(*rmm, *cr, *conf, *g_ircc, *g_ircccm);
if (cr == nullptr) { // register types
std::cerr << "PLUGIN IRCC missing Contact3Registry\n"; PLUG_PROVIDE_INSTANCE(IRCClient1, plugin_name, g_ircc.get());
return 2; PLUG_PROVIDE_INSTANCE(IRCClientContactModel, plugin_name, g_ircccm.get());
} PLUG_PROVIDE_INSTANCE(IRCClientMessageManager, plugin_name, g_irccmm.get());
} catch (const ResolveException& e) {
if (rmm == nullptr) { std::cerr << "PLUGIN " << plugin_name << " " << e.what << "\n";
std::cerr << "PLUGIN IRCC missing RegistryMessageModel\n"; return 2;
return 2;
}
if (conf == nullptr) {
std::cerr << "PLUGIN IRCC missing ConfigModelI\n";
return 2;
}
} }
// static store, could be anywhere tho
// construct with fetched dependencies
g_ircc = std::make_unique<IRCClient1>(*conf);
// register types
PROVIDE_INSTANCE(IRCClient1, "IRCClient", g_ircc.get());
g_ircccm = std::make_unique<IRCClientContactModel>(*cr, *conf, *g_ircc);
// register types
PROVIDE_INSTANCE(IRCClientContactModel, "IRCClient", g_ircccm.get());
g_irccmm = std::make_unique<IRCClientMessageManager>(*rmm, *cr, *conf, *g_ircc, *g_ircccm);
// register types
PROVIDE_INSTANCE(IRCClientMessageManager, "IRCClient", g_irccmm.get());
return 0; return 0;
} }
SOLANA_PLUGIN_EXPORT void solana_plugin_stop(void) { SOLANA_PLUGIN_EXPORT void solana_plugin_stop(void) {
std::cout << "PLUGIN IRCC STOP()\n"; std::cout << "PLUGIN " << plugin_name << " STOP()\n";
g_ircc.reset(); g_ircc.reset();
} }
SOLANA_PLUGIN_EXPORT float solana_plugin_tick(float delta) { SOLANA_PLUGIN_EXPORT float solana_plugin_tick(float delta) {
(void)delta; (void)delta;
//std::cout << "PLUGIN IRCC TICK()\n";
g_ircc->iterate(); // TODO: return interval, respect dcc etc g_ircc->iterate(); // TODO: return interval, respect dcc etc
return 1.f; // expect atleast once per sec return 1.f; // expect atleast once per sec

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "solanaceae/contact/contact_model3.hpp"
#include <solanaceae/ircclient/ircclient.hpp> #include <solanaceae/ircclient/ircclient.hpp>
#include <solanaceae/ircclient_contacts/ircclient_contact_model.hpp> #include <solanaceae/ircclient_contacts/ircclient_contact_model.hpp>
#include <solanaceae/message3/registry_message_model.hpp> #include <solanaceae/message3/registry_message_model.hpp>