update to new versioned plugin api

This commit is contained in:
Green Sky 2024-01-18 18:24:52 +01:00
parent a488a255ff
commit 998794a6dd
No known key found for this signature in database
4 changed files with 55 additions and 130 deletions

View File

@ -13,7 +13,7 @@ endif()
if (NOT TARGET imgui) if (NOT TARGET imgui)
FetchContent_Declare(imgui FetchContent_Declare(imgui
GIT_REPOSITORY https://github.com/ocornut/imgui.git GIT_REPOSITORY https://github.com/ocornut/imgui.git
GIT_TAG d4ddc46e7 GIT_TAG d6cb3c9 # v1.90.1
EXCLUDE_FROM_ALL EXCLUDE_FROM_ALL
) )

View File

@ -2,21 +2,19 @@
#include <solanaceae/crdtnotes/crdtnotes.hpp> #include <solanaceae/crdtnotes/crdtnotes.hpp>
#include <solanaceae/crdtnotes/crdtnotes_sync.hpp> #include <solanaceae/crdtnotes/crdtnotes_sync.hpp>
//#include <solanaceae/util/config_model.hpp>
#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<CRDTNotes> g_crdtn = nullptr; static std::unique_ptr<CRDTNotes> g_crdtn = nullptr;
static std::unique_ptr<CRDTNotesSync> g_crdtns = nullptr; static std::unique_ptr<CRDTNotesSync> g_crdtns = nullptr;
constexpr const char* plugin_name = "CRDTNotes";
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 "CRDTNotes"; return plugin_name;
} }
SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_get_version(void) { SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_get_version(void) {
@ -24,29 +22,14 @@ 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 CRDTN START()\n"; std::cout << "PLUGIN " << plugin_name << " START()\n";
if (solana_api == nullptr) { if (solana_api == nullptr) {
return 1; return 1;
} }
//ConfigModelI* conf = nullptr; try {
Contact3Registry* cr = nullptr; auto* cr = PLUG_RESOLVE_INSTANCE_VERSIONED(Contact3Registry, "1");
{ // make sure required types are loaded
//conf = RESOLVE_INSTANCE(ConfigModelI);
cr = RESOLVE_INSTANCE(Contact3Registry);
//if (conf == nullptr) {
//std::cerr << "PLUGIN CRDTN missing ConfigModelI\n";
//return 2;
//}
if (cr == nullptr) {
std::cerr << "PLUGIN CRDTNTS missing Contact3Registry\n";
return 2;
}
}
// static store, could be anywhere tho // static store, could be anywhere tho
// construct with fetched dependencies // construct with fetched dependencies
@ -54,14 +37,18 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api)
g_crdtns = std::make_unique<CRDTNotesSync>(*g_crdtn, *cr); g_crdtns = std::make_unique<CRDTNotesSync>(*g_crdtn, *cr);
// register types // register types
PROVIDE_INSTANCE(CRDTNotesSync, "CRDTNotes", g_crdtns.get()); PLUG_PROVIDE_INSTANCE(CRDTNotesSync, plugin_name, g_crdtns.get());
PROVIDE_INSTANCE(CRDTNotesEventI, "CRDTNotes", g_crdtns.get()); PLUG_PROVIDE_INSTANCE(CRDTNotesEventI, plugin_name, g_crdtns.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 CRDTN STOP()\n"; std::cout << "PLUGIN " << plugin_name << " STOP()\n";
g_crdtn.reset(); g_crdtn.reset();
g_crdtns.reset(); g_crdtns.reset();

View File

@ -1,22 +1,20 @@
#include <solanaceae/plugin/solana_plugin_v1.h> #include <solanaceae/plugin/solana_plugin_v1.h>
#include <solanaceae/crdtnotes_imgui/crdtnotes_imgui.hpp> #include <solanaceae/crdtnotes_imgui/crdtnotes_imgui.hpp>
//#include <solanaceae/util/config_model.hpp>
#include <imgui.h> #include <imgui.h>
#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<CRDTNotesImGui> g_crdtn_imgui = nullptr; static std::unique_ptr<CRDTNotesImGui> g_crdtn_imgui = nullptr;
constexpr const char* plugin_name = "CRDTNotesImGui";
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 "CRDTNIMGUIotesImGui"; return plugin_name;
} }
SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_get_version(void) { SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_get_version(void) {
@ -24,43 +22,16 @@ 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 CRDTNIMGUI START()\n"; std::cout << "PLUGIN " << plugin_name << " START()\n";
if (solana_api == nullptr) { if (solana_api == nullptr) {
return 1; return 1;
} }
//ConfigModelI* conf = nullptr; try {
CRDTNotesSync* crdtns = nullptr; auto* crdtns = PLUG_RESOLVE_INSTANCE(CRDTNotesSync);
Contact3Registry* cr = nullptr; auto* cr = PLUG_RESOLVE_INSTANCE_VERSIONED(Contact3Registry, "1");
ImGuiContext* imguic = nullptr; auto* imguic = PLUG_RESOLVE_INSTANCE_VERSIONED(ImGuiContext, ImGui::GetVersion());
{ // make sure required types are loaded
//conf = RESOLVE_INSTANCE(ConfigModelI);
crdtns = RESOLVE_INSTANCE(CRDTNotesSync);
cr = RESOLVE_INSTANCE(Contact3Registry);
imguic = RESOLVE_INSTANCE(ImGuiContext);
//if (conf == nullptr) {
//std::cerr << "PLUGIN CRDTNIMGUI missing ConfigModelI\n";
//return 2;
//}
if (crdtns == nullptr) {
std::cerr << "PLUGIN CRDTNIMGUI missing CRDTNotesSync\n";
return 2;
}
if (cr == nullptr) {
std::cerr << "PLUGIN CRDTNIMGUI missing Contact3Registry\n";
return 2;
}
if (imguic == nullptr) {
std::cerr << "PLUGIN CRDTNIMGUI missing ImGuiContext\n";
return 2;
}
}
ImGui::SetCurrentContext(imguic); ImGui::SetCurrentContext(imguic);
@ -69,13 +40,17 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api)
g_crdtn_imgui = std::make_unique<CRDTNotesImGui>(*crdtns, *cr); g_crdtn_imgui = std::make_unique<CRDTNotesImGui>(*crdtns, *cr);
// register types // register types
PROVIDE_INSTANCE(CRDTNotesImGui, "CRDTNotesImGui", g_crdtn_imgui.get()); PLUG_PROVIDE_INSTANCE(CRDTNotesImGui, plugin_name, g_crdtn_imgui.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 CRDTNIMGUI STOP()\n"; std::cout << "PLUGIN " << plugin_name << " STOP()\n";
g_crdtn_imgui.reset(); g_crdtn_imgui.reset();
} }

View File

@ -3,7 +3,6 @@
#include <solanaceae/crdtnotes/crdtnotes.hpp> #include <solanaceae/crdtnotes/crdtnotes.hpp>
#include <solanaceae/crdtnotes/crdtnotes_sync.hpp> #include <solanaceae/crdtnotes/crdtnotes_sync.hpp>
#include <solanaceae/crdtnotes_toxsync/crdtnotes_toxsync.hpp> #include <solanaceae/crdtnotes_toxsync/crdtnotes_toxsync.hpp>
//#include <solanaceae/util/config_model.hpp>
#include <solanaceae/contact/contact_model3.hpp> #include <solanaceae/contact/contact_model3.hpp>
#include <solanaceae/toxcore/tox_interface.hpp> #include <solanaceae/toxcore/tox_interface.hpp>
#include <solanaceae/toxcore/tox_event_interface.hpp> #include <solanaceae/toxcore/tox_event_interface.hpp>
@ -12,15 +11,14 @@
#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<CRDTNotesToxSync> g_crdtn_ts = nullptr; static std::unique_ptr<CRDTNotesToxSync> g_crdtn_ts = nullptr;
constexpr const char* plugin_name = "CRDTNotesToxSync";
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 "CRDTNotesToxSync"; return plugin_name;
} }
SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_get_version(void) { SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_get_version(void) {
@ -28,70 +26,35 @@ 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 CRDTNTS START()\n"; std::cout << "PLUGIN " << plugin_name << " START()\n";
if (solana_api == nullptr) { if (solana_api == nullptr) {
return 1; return 1;
} }
//ConfigModelI* conf = nullptr; try {
CRDTNotesEventI* notes_sync = nullptr; auto* notes_sync = PLUG_RESOLVE_INSTANCE(CRDTNotesEventI);
Contact3Registry* cr = nullptr; auto* cr = PLUG_RESOLVE_INSTANCE_VERSIONED(Contact3Registry, "1");
ToxI* t = nullptr; auto* t = PLUG_RESOLVE_INSTANCE(ToxI);
ToxEventProviderI* tep = nullptr; auto* tep = PLUG_RESOLVE_INSTANCE(ToxEventProviderI);
ToxContactModel2* tcm = nullptr; auto* tcm = PLUG_RESOLVE_INSTANCE(ToxContactModel2);
{ // make sure required types are loaded
//conf = RESOLVE_INSTANCE(ConfigModelI);
notes_sync = RESOLVE_INSTANCE(CRDTNotesEventI);
cr = RESOLVE_INSTANCE(Contact3Registry);
t = RESOLVE_INSTANCE(ToxI);
tep = RESOLVE_INSTANCE(ToxEventProviderI);
tcm = RESOLVE_INSTANCE(ToxContactModel2);
//if (conf == nullptr) {
//std::cerr << "PLUGIN CRDTN missing ConfigModelI\n";
//return 2;
//}
if (notes_sync == nullptr) {
std::cerr << "PLUGIN CRDTNTS missing CRDTNotesEventI\n";
return 2;
}
if (cr == nullptr) {
std::cerr << "PLUGIN CRDTNTS missing Contact3Registry\n";
return 2;
}
if (t == nullptr) {
std::cerr << "PLUGIN CRDTNTS missing ToxI\n";
return 2;
}
if (tep == nullptr) {
std::cerr << "PLUGIN CRDTNTS missing ToxEventProviderI\n";
return 2;
}
if (tcm == nullptr) {
std::cerr << "PLUGIN CRDTNTS missing ToxContactModel2\n";
return 2;
}
}
// static store, could be anywhere tho // static store, could be anywhere tho
// construct with fetched dependencies // construct with fetched dependencies
g_crdtn_ts = std::make_unique<CRDTNotesToxSync>(*notes_sync, *cr, *t, *tep, *tcm); g_crdtn_ts = std::make_unique<CRDTNotesToxSync>(*notes_sync, *cr, *t, *tep, *tcm);
// register types // register types
PROVIDE_INSTANCE(CRDTNotesToxSync, "CRDTNotesToxSync", g_crdtn_ts.get()); PLUG_PROVIDE_INSTANCE(CRDTNotesToxSync, plugin_name, g_crdtn_ts.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 CRDTNTS STOP()\n"; std::cout << "PLUGIN " << plugin_name << " STOP()\n";
g_crdtn_ts.reset(); g_crdtn_ts.reset();
} }