added module system

This commit is contained in:
Ryzerth
2020-08-07 14:29:06 +02:00
parent 9d2b60b88e
commit 7759de96da
10 changed files with 203 additions and 20 deletions

View File

@ -10,6 +10,7 @@
#include <version.h>
#include <spdlog/spdlog.h>
#include <bandplan.h>
#include <module.h>
#ifdef _WIN32
#include <Windows.h>
@ -72,6 +73,11 @@ int main() {
spdlog::info("Loading band plans color table");
bandplan::loadColorTable("band_colors.json");
spdlog::info("Loading test module");
//mod::loadModule("../modules/demo/build/Release/demo.dll", "Demo Module 1");
//mod::loadModule("../modules/demo/build/Release/demo.dll", "Demo Module 2");
//mod::loadModule("../modules/demo/build/Release/demo.dll", "Demo Module 3");
spdlog::info("Ready.");
// Main loop

View File

@ -1,20 +1,4 @@
#include <main_window.h>
#include <imgui_plot.h>
#include <dsp/resampling.h>
#include <dsp/demodulator.h>
#include <dsp/filter.h>
#include <thread>
#include <complex>
#include <dsp/source.h>
#include <dsp/math.h>
#include <waterfall.h>
#include <frequency_select.h>
#include <fftw3.h>
#include <signal_path.h>
#include <io/soapy.h>
#include <icons.h>
#include <bandplan.h>
#include <watcher.h>
std::thread worker;
std::mutex fft_mtx;
@ -304,6 +288,15 @@ void drawWindow() {
}
}
int modCount = mod::moduleNames.size();
mod::Module_t mod;
for (int i = 0; i < modCount; i++) {
if (ImGui::CollapsingHeader(mod::moduleNames[i].c_str())) {
mod = mod::modules[mod::moduleNames[i]];
mod._DRAW_MENU_(mod.ctx);
}
}
if (ImGui::CollapsingHeader("Radio")) {
ImGui::BeginGroup();

View File

@ -5,6 +5,23 @@
#include <stdio.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <imgui_plot.h>
#include <dsp/resampling.h>
#include <dsp/demodulator.h>
#include <dsp/filter.h>
#include <thread>
#include <complex>
#include <dsp/source.h>
#include <dsp/math.h>
#include <waterfall.h>
#include <frequency_select.h>
#include <fftw3.h>
#include <signal_path.h>
#include <io/soapy.h>
#include <icons.h>
#include <bandplan.h>
#include <watcher.h>
#include <module.h>
#define WINDOW_FLAGS ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoBackground

50
src/module.cpp Normal file
View File

@ -0,0 +1,50 @@
#include <module.h>
namespace mod {
API_t API;
std::map<std::string, Module_t> modules;
std::vector<std::string> moduleNames;
void loadModule(std::string path, std::string name) {
if (!std::filesystem::exists(path)) {
spdlog::error("{0} does not exist", path);
return;
}
if (!std::filesystem::is_regular_file(path)) {
spdlog::error("{0} isn't a loadable module", path);
return;
}
Module_t mod;
#ifdef _WIN32
mod.inst = LoadLibraryA(path.c_str());
if (mod.inst == NULL) {
spdlog::error("Couldn't load {0}.", name);
return;
}
mod._INIT_ = (void*(*)(mod::API_t*,ImGuiContext*,std::string))GetProcAddress(mod.inst, "_INIT_");
mod._DRAW_MENU_ = (void(*)(void*))GetProcAddress(mod.inst, "_DRAW_MENU_");
mod._STOP_ = (void(*)(void*))GetProcAddress(mod.inst, "_STOP_");
#else
// Linux function here
#endif
if (mod._INIT_ == NULL) {
spdlog::error("Couldn't load {0} because it's missing _INIT_.", name);
return;
}
if (mod._DRAW_MENU_ == NULL) {
spdlog::error("Couldn't load {0} because it's missing _DRAW_MENU_.", 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 (mod.ctx == NULL) {
spdlog::error("{0} Failed to initialize.", name);
}
modules[name] = mod;
moduleNames.push_back(name);
}
};

38
src/module.h Normal file
View File

@ -0,0 +1,38 @@
#pragma once
#include <string>
#include <map>
#include <filesystem>
#include <stdint.h>
#include <imgui.h>
#include <spdlog/spdlog.h>
#ifdef _WIN32
#include <Windows.h>
#define MOD_EXPORT extern "C" \
__declspec(dllexport)
#else
#define MOD_EXPORT extern "C"
#endif
namespace mod {
struct API_t {
};
struct Module_t {
#ifdef _WIN32
HINSTANCE inst;
#else
void* inst;
#endif
void* (*_INIT_)(API_t*, ImGuiContext*, std::string);
void (*_DRAW_MENU_)(void*);
void (*_STOP_)(void*);
void* ctx;
};
void loadModule(std::string path, std::string name);
extern std::map<std::string, Module_t> modules;
extern std::vector<std::string> moduleNames;
};

View File

@ -1,3 +1,3 @@
#pragma once
#define VERSION_STR "0.2.4_alpha"
#define VERSION_STR "0.2.5_alpha"

View File

@ -1,6 +1,4 @@
#include <waterfall.h>
#include <algorithm>
float COLOR_MAP[][3] = {
{0x00, 0x00, 0x20},
@ -20,7 +18,6 @@ float COLOR_MAP[][3] = {
void doZoom(int offset, int width, int outWidth, std::vector<float> data, float* out) {
// NOTE: REMOVE THAT SHIT, IT'S JUST A HACKY FIX
if (offset < 0) {
offset = 0;
}

View File

@ -6,6 +6,7 @@
#include <GL/glew.h>
#include <imutils.h>
#include <bandplan.h>
#include <algorithm>
#define WATERFALL_RESOLUTION 1000000