update to new versioned plugin api
This commit is contained in:
parent
5c3784e7ce
commit
89ace56ade
@ -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
|
|
||||||
cr = RESOLVE_INSTANCE(Contact3Registry);
|
|
||||||
rmm = RESOLVE_INSTANCE(RegistryMessageModel);
|
|
||||||
conf = RESOLVE_INSTANCE(ConfigModelI);
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// static store, could be anywhere tho
|
// static store, could be anywhere tho
|
||||||
// construct with fetched dependencies
|
// construct with fetched dependencies
|
||||||
g_ircc = std::make_unique<IRCClient1>(*conf);
|
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);
|
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);
|
g_irccmm = std::make_unique<IRCClientMessageManager>(*rmm, *cr, *conf, *g_ircc, *g_ircccm);
|
||||||
|
|
||||||
// register types
|
// register types
|
||||||
PROVIDE_INSTANCE(IRCClientMessageManager, "IRCClient", g_irccmm.get());
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
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
|
||||||
|
@ -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>
|
||||||
|
Loading…
Reference in New Issue
Block a user