From 5e8455c8a24b305de24329614c8c9aed97c26e30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedek=20L=C3=A1szl=C3=B3?= Date: Wed, 15 May 2024 00:57:38 +0200 Subject: [PATCH] plugin prep --- inc/graph/plugins/http/http.h | 10 ++++++++++ inc/graph/plugins/plugin.h | 1 + src/graph/plugins/http/http.cpp | 22 ++++++++++++++++++---- src/graph/server/gui/mainwindow.cpp | 4 +++- src/graph/server/main.cpp | 6 ------ 5 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 inc/graph/plugins/http/http.h diff --git a/inc/graph/plugins/http/http.h b/inc/graph/plugins/http/http.h new file mode 100644 index 0000000..cc9fa78 --- /dev/null +++ b/inc/graph/plugins/http/http.h @@ -0,0 +1,10 @@ +#pragma once + +#include + +extern "C" { + extern plugin_t plugin; + + bool init(); + void destroy(); +} \ No newline at end of file diff --git a/inc/graph/plugins/plugin.h b/inc/graph/plugins/plugin.h index 95760f9..d36851f 100644 --- a/inc/graph/plugins/plugin.h +++ b/inc/graph/plugins/plugin.h @@ -4,6 +4,7 @@ #include #else #include +#include #endif typedef struct { diff --git a/src/graph/plugins/http/http.cpp b/src/graph/plugins/http/http.cpp index 98d4ec7..9d96ab2 100644 --- a/src/graph/plugins/http/http.cpp +++ b/src/graph/plugins/http/http.cpp @@ -1,15 +1,29 @@ +#include #include +#include #include +#define PI 3.1415 +#define to_rad(x) (x/180/3.1415) + extern "C" { +plugin_t plugin = {.version = 1, .init_method = &init, .destroy_method = &destroy}; + bool init() { std::cout << "init" << std::endl; + point_t points[100]; + for (int i = 0; i < 100; i++) { + double deg = i*360/100.0; + points[i].x = deg; + points[i].y = sin(to_rad(deg)); + } + + plugin.update_callback(0, "1st", points); return true; } -void destroy() { std::cout << "destory" << std::endl; } - -plugin_t plugin = { - .version = 1, .init_method = &init, .destroy_method = &destroy}; +void destroy() { + std::cout << "destory" << std::endl; } +} \ No newline at end of file diff --git a/src/graph/server/gui/mainwindow.cpp b/src/graph/server/gui/mainwindow.cpp index 0e320ae..4243a72 100644 --- a/src/graph/server/gui/mainwindow.cpp +++ b/src/graph/server/gui/mainwindow.cpp @@ -63,7 +63,9 @@ void MainWindow::on_action_Load_triggered() { return; try { - pluginModel->add(new Plugin(file.toStdString())); + Plugin* plugin = new Plugin(file.toStdString()); + // plugin->init(update_callback); + pluginModel->add(plugin); } catch (std::runtime_error e) { std::cout << e.what() << std::endl; QMessageBox::critical(this, "Error", "Failed to load plugin.", QMessageBox::StandardButton::Ignore); diff --git a/src/graph/server/main.cpp b/src/graph/server/main.cpp index 02e25b2..8ed8875 100644 --- a/src/graph/server/main.cpp +++ b/src/graph/server/main.cpp @@ -1,13 +1,7 @@ -#include #include -#include #include -#include int main(int argc, char** argv) { - // Graph::Plugin plugin("plugins/libhttp.so"); - // plugin.init((update_callback_t)1); - QApplication app(argc, argv); Graph::GUI::MainWindow window; window.show();