Full module system

This commit is contained in:
Ryzerth
2020-08-12 16:43:44 +02:00
parent cdea80f8c5
commit 31a95031e4
15 changed files with 174 additions and 37 deletions

View File

@@ -1,12 +1,19 @@
#include <module.h>
#include <vfo_manager.h>
#include <main_window.h>
namespace mod {
API_t API;
std::map<std::string, Module_t> modules;
std::vector<std::string> moduleNames;
ImGui::WaterFall* _wtf;
void initAPI() {
std::string api_getSelectedVFOName() {
return _wtf->selectedVFO;
}
void initAPI(ImGui::WaterFall* wtf) {
_wtf = wtf;
API.registerVFO = vfoman::create;
API.setVFOOffset = vfoman::setOffset;
API.setVFOCenterOffset = vfoman::setCenterOffset;
@@ -15,6 +22,9 @@ namespace mod {
API.getVFOOutputBlockSize = vfoman::getOutputBlockSize;
API.setVFOReference = vfoman::setReference;
API.removeVFO = vfoman::remove;
API.getSelectedVFOName = api_getSelectedVFOName;
API.bindVolumeVariable = bindVolumeVariable;
API.unbindVolumeVariable = unbindVolumeVariable;
}
void loadModule(std::string path, std::string name) {
@@ -33,7 +43,8 @@ namespace mod {
spdlog::error("Couldn't load {0}.", name);
return;
}
mod._INIT_ = (void*(*)(mod::API_t*,ImGuiContext*,std::string))GetProcAddress(mod.inst, "_INIT_");
mod._INIT_ = (void*(*)(mod::API_t*,ImGuiContext*,std::string))GetProcAddress(mod.inst, "_INIT_");
mod._NEW_FRAME_ = (void(*)(void*))GetProcAddress(mod.inst, "_NEW_FRAME_");
mod._DRAW_MENU_ = (void(*)(void*))GetProcAddress(mod.inst, "_DRAW_MENU_");
mod._HANDLE_EVENT_ = (void(*)(void*, int))GetProcAddress(mod.inst, "_HANDLE_EVENT_");
mod._STOP_ = (void(*)(void*))GetProcAddress(mod.inst, "_STOP_");
@@ -43,7 +54,8 @@ namespace mod {
spdlog::error("Couldn't load {0}.", name);
return;
}
mod._INIT_ = (void*(*)(mod::API_t*,ImGuiContext*,std::string))dlsym(mod.inst, "_INIT_");
mod._INIT_ = (void*(*)(mod::API_t*,ImGuiContext*,std::string))dlsym(mod.inst, "_INIT_");
mod._NEW_FRAME_ = (void(*)(void*))dlsym(mod.inst, "_NEW_FRAME_");
mod._DRAW_MENU_ = (void(*)(void*))dlsym(mod.inst, "_DRAW_MENU_");
mod._HANDLE_EVENT_ = (void(*)(void*, int))dlsym(mod.inst, "_HANDLE_EVENT_");
mod._STOP_ = (void(*)(void*))dlsym(mod.inst, "_STOP_");
@@ -52,6 +64,10 @@ namespace mod {
spdlog::error("Couldn't load {0} because it's missing _INIT_.", name);
return;
}
if (mod._NEW_FRAME_ == NULL) {
spdlog::error("Couldn't load {0} because it's missing _NEW_FRAME_.", name);
return;
}
if (mod._DRAW_MENU_ == NULL) {
spdlog::error("Couldn't load {0} because it's missing _DRAW_MENU_.", name);
return;
@@ -80,5 +96,26 @@ namespace mod {
mod._HANDLE_EVENT_(mod.ctx, eventId);
}
}
void loadFromList(std::string path) {
if (!std::filesystem::exists(path)) {
spdlog::error("Module list file does not exist");
return;
}
if (!std::filesystem::is_regular_file(path)) {
spdlog::error("Module list file isn't a file...");
return;
}
std::ifstream file(path.c_str());
json data;
data << file;
file.close();
std::map<std::string, std::string> list = data.get<std::map<std::string, std::string>>();
for (auto const& [name, file] : list) {
spdlog::info("Loading {0} ({1})", name, file);
loadModule(file, name);
}
}
};