diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 2a02711..eb5be15 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -9,3 +9,13 @@ target_link_libraries(plugin_zox_ngc PUBLIC solanaceae_zox ) +######################################## + +add_library(plugin_zox_ngc_hs SHARED + ./plugin_zox_ngc_hs.cpp +) + +target_link_libraries(plugin_zox_ngc_hs PUBLIC + solanaceae_plugin + solanaceae_zox +) diff --git a/plugins/plugin_zox_ngc_hs.cpp b/plugins/plugin_zox_ngc_hs.cpp new file mode 100644 index 0000000..b995862 --- /dev/null +++ b/plugins/plugin_zox_ngc_hs.cpp @@ -0,0 +1,103 @@ +#include + +#include +#include + +#include +#include + +// fwd +struct ContactModelI; +class RegistryMessageModel; + +#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_zngchs = nullptr; + +extern "C" { + +SOLANA_PLUGIN_EXPORT const char* solana_plugin_get_name(void) { + return "ZoxNGCHistorySync"; +} + +SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_get_version(void) { + return SOLANA_PLUGIN_VERSION; +} + +SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api) { + std::cout << "PLUGIN ZNGCHS START()\n"; + + if (solana_api == nullptr) { + return 1; + } + + ToxI* tox_i = nullptr; + ToxEventProviderI* tox_event_provider_i = nullptr; + ZoxNGCEventProviderI* zox_ngc_event_provider_i = nullptr; + Contact3Registry* cr = nullptr; + ToxContactModel2* tcm = nullptr; + RegistryMessageModel* rmm = nullptr; + + { // make sure required types are loaded + tox_i = RESOLVE_INSTANCE(ToxI); + tox_event_provider_i = RESOLVE_INSTANCE(ToxEventProviderI); + zox_ngc_event_provider_i = RESOLVE_INSTANCE(ZoxNGCEventProviderI); + cr = RESOLVE_INSTANCE(Contact3Registry); + tcm = RESOLVE_INSTANCE(ToxContactModel2); + rmm = RESOLVE_INSTANCE(RegistryMessageModel); + + if (tox_i == nullptr) { + std::cerr << "PLUGIN ZNGCHS missing ToxI\n"; + return 2; + } + + if (tox_event_provider_i == nullptr) { + std::cerr << "PLUGIN ZNGCHS missing ToxEventProviderI\n"; + return 2; + } + + if (zox_ngc_event_provider_i == nullptr) { + std::cerr << "PLUGIN ZNGCHS missing ZoxNGCEventProviderI\n"; + return 2; + } + + if (cr == nullptr) { + std::cerr << "PLUGIN ZNGCHS missing ContactModelI\n"; + return 2; + } + + if (tcm == nullptr) { + std::cerr << "PLUGIN ZNGCHS missing ToxContactModel2\n"; + return 2; + } + + if (rmm == nullptr) { + std::cerr << "PLUGIN ZNGCHS missing RegistryMessageModel\n"; + return 2; + } + } + + // static store, could be anywhere tho + // construct with fetched dependencies + g_zngchs = std::make_unique(*tox_event_provider_i, *zox_ngc_event_provider_i, *tox_i, *cr, *tcm, *rmm); + + // register types + PROVIDE_INSTANCE(ZoxNGCHistorySync, "ZoxNGCHistorySync", g_zngchs.get()); + + return 0; +} + +SOLANA_PLUGIN_EXPORT void solana_plugin_stop(void) { + std::cout << "PLUGIN ZNGCHS STOP()\n"; + + g_zngchs.reset(); +} + +SOLANA_PLUGIN_EXPORT void solana_plugin_tick(float delta) { + //std::cout << "PLUGIN ZNGCHS TICK()\n"; + g_zngchs->tick(delta); +} + +} // extern C +