update to versioned plugin interface
This commit is contained in:
		@@ -5,15 +5,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<SDBot> g_sdbot = nullptr;
 | 
					static std::unique_ptr<SDBot> g_sdbot = nullptr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					constexpr const char* plugin_name = "SDBot-webui";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
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 "SDBot-webui";
 | 
						return plugin_name;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_get_version(void) {
 | 
					SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_get_version(void) {
 | 
				
			||||||
@@ -21,56 +20,39 @@ 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 SDB 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 SDB missing Contact3Registry\n";
 | 
					 | 
				
			||||||
			return 2;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (rmm == nullptr) {
 | 
					 | 
				
			||||||
			std::cerr << "PLUGIN SDB missing RegistryMessageModel\n";
 | 
					 | 
				
			||||||
			return 2;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (conf == nullptr) {
 | 
					 | 
				
			||||||
			std::cerr << "PLUGIN SDB 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_sdbot = std::make_unique<SDBot>(*cr, *rmm, *conf);
 | 
							g_sdbot = std::make_unique<SDBot>(*cr, *rmm, *conf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// register types
 | 
							// register types
 | 
				
			||||||
	PROVIDE_INSTANCE(SDBot, "SDBot", g_sdbot.get());
 | 
							PLUG_PROVIDE_INSTANCE(SDBot, plugin_name, g_sdbot.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 SDB STOP()\n";
 | 
						std::cout << "PLUGIN " << plugin_name << " STOP()\n";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	g_sdbot.reset();
 | 
						g_sdbot.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 SDB TICK()\n";
 | 
					 | 
				
			||||||
	return g_sdbot->iterate();
 | 
						return g_sdbot->iterate();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user