update for new plugin api

This commit is contained in:
Green Sky 2024-01-18 18:22:33 +01:00
parent 158860e1b0
commit d9ee8f9dc4
No known key found for this signature in database
2 changed files with 25 additions and 39 deletions

View File

@ -2,19 +2,20 @@
#include "../src/bridge.hpp" #include "../src/bridge.hpp"
#include <solanaceae/util/config_model.hpp>
#include <memory> #include <memory>
#include <limits> #include <limits>
#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<Bridge> g_bridge = nullptr; static std::unique_ptr<Bridge> g_bridge = nullptr;
constexpr const char* plugin_name = "Bridge";
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 "Bridge"; return plugin_name;
} }
SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_get_version(void) { SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_get_version(void) {
@ -22,59 +23,42 @@ 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 Bridge START()\n"; std::cout << "PLUGIN " << plugin_name << " START()\n";
if (solana_api == nullptr) { if (solana_api == nullptr) {
return 1; return 1;
} }
Contact3Registry* cr = nullptr; try {
RegistryMessageModel* rmm = nullptr; auto* cr = PLUG_RESOLVE_INSTANCE_VERSIONED(Contact3Registry, "1");
ConfigModelI* conf = nullptr; auto* rmm = PLUG_RESOLVE_INSTANCE(RegistryMessageModel);
MessageCommandDispatcher* mcd = nullptr; auto* conf = PLUG_RESOLVE_INSTANCE(ConfigModelI);
{ // make sure required types are loaded // optional dep
cr = RESOLVE_INSTANCE(Contact3Registry); auto* mcd = PLUG_RESOLVE_INSTANCE_OPT(MessageCommandDispatcher);
rmm = RESOLVE_INSTANCE(RegistryMessageModel);
conf = RESOLVE_INSTANCE(ConfigModelI);
mcd = RESOLVE_INSTANCE(MessageCommandDispatcher);
if (cr == nullptr) {
std::cerr << "PLUGIN Bridge missing Contact3Registry\n";
return 2;
}
if (rmm == nullptr) {
std::cerr << "PLUGIN Bridge missing RegistryMessageModel\n";
return 2;
}
if (conf == nullptr) {
std::cerr << "PLUGIN Bridge missing ConfigModelI\n";
return 2;
}
// missing mcd is no error
}
// static store, could be anywhere tho // static store, could be anywhere tho
// construct with fetched dependencies // construct with fetched dependencies
g_bridge = std::make_unique<Bridge>(*cr, *rmm, *conf, mcd); g_bridge = std::make_unique<Bridge>(*cr, *rmm, *conf, mcd);
// register types // register types
PROVIDE_INSTANCE(Bridge, "Bridge", g_bridge.get()); PLUG_PROVIDE_INSTANCE(Bridge, plugin_name, g_bridge.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 Bridge STOP()\n"; std::cout << "PLUGIN " << plugin_name << " STOP()\n";
g_bridge.reset(); g_bridge.reset();
} }
SOLANA_PLUGIN_EXPORT float solana_plugin_tick(float delta) { SOLANA_PLUGIN_EXPORT float solana_plugin_tick(float time_delta) {
g_bridge->iterate(delta); g_bridge->iterate(time_delta);
return std::numeric_limits<float>::max(); return std::numeric_limits<float>::max();
} }

View File

@ -34,6 +34,8 @@ class Bridge : public RegistryMessageModelEventI {
float _iterate_timer {0.f}; float _iterate_timer {0.f};
public: public:
static constexpr const char* version {"1"};
Bridge( Bridge(
Contact3Registry& cr, Contact3Registry& cr,
RegistryMessageModel& rmm, RegistryMessageModel& rmm,