mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-06-25 12:07:49 +02:00
New module system
This commit is contained in:
@ -72,7 +72,6 @@ void windowInit() {
|
||||
sigpath::signalPath.start();
|
||||
|
||||
spdlog::info("Loading modules");
|
||||
mod::initAPI(&gui::waterfall);
|
||||
mod::loadFromList(ROOT_DIR "/module_list.json");
|
||||
|
||||
sourecmenu::init();
|
||||
@ -231,7 +230,6 @@ void drawWindow() {
|
||||
gui::waterfall.selectedVFOChanged = false;
|
||||
gui::freqSelect.setFrequency(vfo->generalOffset + gui::waterfall.getCenterFrequency());
|
||||
gui::freqSelect.frequencyChanged = false;
|
||||
mod::broadcastEvent(mod::EVENT_SELECTED_VFO_CHANGED);
|
||||
audioStreamName = audio::getNameFromVFO(gui::waterfall.selectedVFO);
|
||||
if (audioStreamName != "") {
|
||||
volume = &audio::streams[audioStreamName]->volume;
|
||||
@ -279,13 +277,6 @@ void drawWindow() {
|
||||
int width = vMax.x - vMin.x;
|
||||
int height = vMax.y - vMin.y;
|
||||
|
||||
int modCount = mod::moduleNames.size();
|
||||
mod::Module_t mod;
|
||||
for (int i = 0; i < modCount; i++) {
|
||||
mod = mod::modules[mod::moduleNames[i]];
|
||||
mod._NEW_FRAME_(mod.ctx);
|
||||
}
|
||||
|
||||
// To Bar
|
||||
if (ImGui::ImageButton(icons::MENU, ImVec2(40, 40), ImVec2(0, 0), ImVec2(1, 1), 0)) {
|
||||
showMenu = !showMenu;
|
||||
@ -384,14 +375,6 @@ void drawWindow() {
|
||||
|
||||
gui::menu.draw();
|
||||
|
||||
for (int i = 0; i < modCount; i++) {
|
||||
if (ImGui::CollapsingHeader(mod::moduleNames[i].c_str(), ImGuiTreeNodeFlags_DefaultOpen)) {
|
||||
mod = mod::modules[mod::moduleNames[i]];
|
||||
mod._DRAW_MENU_(mod.ctx);
|
||||
ImGui::Spacing();
|
||||
}
|
||||
}
|
||||
|
||||
if(ImGui::CollapsingHeader("Debug")) {
|
||||
ImGui::Text("Frame time: %.3f ms/frame", 1000.0f / ImGui::GetIO().Framerate);
|
||||
ImGui::Text("Framerate: %.1f FPS", ImGui::GetIO().Framerate);
|
||||
|
@ -4,37 +4,10 @@
|
||||
#include <signal_path/audio.h>
|
||||
|
||||
namespace mod {
|
||||
API_t API;
|
||||
std::map<std::string, Module_t> modules;
|
||||
std::vector<std::string> moduleNames;
|
||||
ImGui::WaterFall* _wtf;
|
||||
|
||||
std::string api_getSelectedVFOName() {
|
||||
return _wtf->selectedVFO;
|
||||
}
|
||||
|
||||
void initAPI(ImGui::WaterFall* wtf) {
|
||||
_wtf = wtf;
|
||||
|
||||
// GUI
|
||||
API.getSelectedVFOName = api_getSelectedVFOName;
|
||||
API.bindVolumeVariable = bindVolumeVariable;
|
||||
API.unbindVolumeVariable = unbindVolumeVariable;
|
||||
|
||||
// Audio
|
||||
API.registerMonoStream = audio::registerMonoStream;
|
||||
API.registerStereoStream = audio::registerStereoStream;
|
||||
API.startStream = audio::startStream;
|
||||
API.stopStream = audio::stopStream;
|
||||
API.removeStream = audio::removeStream;
|
||||
API.bindToStreamMono = audio::bindToStreamMono;
|
||||
API.bindToStreamStereo = audio::bindToStreamStereo;
|
||||
API.setBlockSize = audio::setBlockSize;
|
||||
API.unbindFromStreamMono = audio::unbindFromStreamMono;
|
||||
API.unbindFromStreamStereo = audio::unbindFromStreamStereo;
|
||||
API.getStreamNameList = audio::getStreamNameList;
|
||||
}
|
||||
|
||||
void loadModule(std::string path, std::string name) {
|
||||
if (!std::filesystem::exists(path)) {
|
||||
spdlog::error("{0} does not exist", path);
|
||||
@ -51,10 +24,10 @@ namespace mod {
|
||||
spdlog::error("Couldn't load {0}.", name);
|
||||
return;
|
||||
}
|
||||
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._INIT_ = (void(*)())GetProcAddress(mod.inst, "_INIT_");
|
||||
mod._CREATE_INSTANCE_ = (void*(*)(std::string))GetProcAddress(mod.inst, "_CREATE_INSTANCE_");
|
||||
mod._DELETE_INSTANCE_ = (void(*)(void*))GetProcAddress(mod.inst, "_DELETE_INSTANCE_");
|
||||
mod._STOP_ = (void(*)(void*))GetProcAddress(mod.inst, "_STOP_");
|
||||
#else
|
||||
mod.inst = dlopen(path.c_str(), RTLD_LAZY);
|
||||
@ -62,49 +35,41 @@ namespace mod {
|
||||
spdlog::error("Couldn't load {0}.", name);
|
||||
return;
|
||||
}
|
||||
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_");
|
||||
mod._INIT_ = (void(*)())dlsym(mod.inst, "_INIT_");
|
||||
mod._CREATE_INSTANCE_ = (void*(*)(std::string))dlsym(mod.inst, "_CREATE_INSTANCE_");
|
||||
mod._DELETE_INSTANCE_ = (void(*)(void*))dlsym(mod.inst, "_DELETE_INSTANCE_");
|
||||
mod._STOP_ = (void(*)())dlsym(mod.inst, "_STOP_");
|
||||
#endif
|
||||
if (mod._INIT_ == NULL) {
|
||||
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);
|
||||
if (mod._CREATE_INSTANCE_ == NULL) {
|
||||
spdlog::error("Couldn't load {0} because it's missing _CREATE_INSTANCE_.", name);
|
||||
return;
|
||||
}
|
||||
if (mod._DRAW_MENU_ == NULL) {
|
||||
spdlog::error("Couldn't load {0} because it's missing _DRAW_MENU_.", name);
|
||||
return;
|
||||
}
|
||||
if (mod._HANDLE_EVENT_ == NULL) {
|
||||
spdlog::error("Couldn't load {0} because it's missing _HANDLE_EVENT_.", name);
|
||||
if (mod._DELETE_INSTANCE_ == NULL) {
|
||||
spdlog::error("Couldn't load {0} because it's missing _DELETE_INSTANCE_.", name);
|
||||
return;
|
||||
}
|
||||
if (mod._STOP_ == NULL) {
|
||||
spdlog::error("Couldn't load {0} because it's missing _STOP_.", name);
|
||||
return;
|
||||
}
|
||||
mod.ctx = mod._INIT_(&API, ImGui::GetCurrentContext(), name);
|
||||
|
||||
if (!isLoaded(mod.inst)) {
|
||||
mod._INIT_();
|
||||
}
|
||||
|
||||
mod.ctx = mod._CREATE_INSTANCE_(name);
|
||||
if (mod.ctx == NULL) {
|
||||
spdlog::error("{0} Failed to initialize.", name);
|
||||
}
|
||||
|
||||
modules[name] = mod;
|
||||
moduleNames.push_back(name);
|
||||
}
|
||||
|
||||
void broadcastEvent(int eventId) {
|
||||
if (eventId < 0 || eventId >= _EVENT_COUNT) {
|
||||
return;
|
||||
}
|
||||
for (auto const& [name, mod] : modules) {
|
||||
mod._HANDLE_EVENT_(mod.ctx, eventId);
|
||||
}
|
||||
}
|
||||
|
||||
void loadFromList(std::string path) {
|
||||
if (!std::filesystem::exists(path)) {
|
||||
spdlog::error("Module list file does not exist");
|
||||
@ -125,5 +90,14 @@ namespace mod {
|
||||
loadModule(file, name);
|
||||
}
|
||||
}
|
||||
|
||||
bool isLoaded(void* handle) {
|
||||
for (auto const& [name, module] : modules) {
|
||||
if (module.inst == handle) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -37,23 +37,22 @@ namespace mod {
|
||||
void* inst;
|
||||
#endif
|
||||
void (*_INIT_)();
|
||||
void* (*_CREATE_INSTANCE)(std::string);
|
||||
void (*_DELETE_INSTANCE)();
|
||||
void* (*_CREATE_INSTANCE_)(std::string name);
|
||||
void (*_DELETE_INSTANCE_)(void* instance);
|
||||
void (*_STOP_)();
|
||||
void* ctx;
|
||||
};
|
||||
|
||||
struct ModuleInfo_t {
|
||||
char* name;
|
||||
char* description;
|
||||
char* author;
|
||||
char* version;
|
||||
const char* name;
|
||||
const char* description;
|
||||
const char* author;
|
||||
const char* version;
|
||||
};
|
||||
|
||||
void initAPI(ImGui::WaterFall* wtf);
|
||||
void loadModule(std::string path, std::string name);
|
||||
void broadcastEvent(int eventId);
|
||||
void loadFromList(std::string path);
|
||||
bool isLoaded(void* handle);
|
||||
|
||||
extern std::map<std::string, Module_t> modules;
|
||||
extern std::vector<std::string> moduleNames;
|
||||
|
@ -48,7 +48,7 @@ int VFOManager::VFO::getOutputBlockSize() {
|
||||
|
||||
|
||||
VFOManager::VFOManager() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
VFOManager::VFO* VFOManager::createVFO(std::string name, int reference, float offset, float bandwidth, float sampleRate, int blockSize) {
|
||||
|
Reference in New Issue
Block a user