commit a6b54fac0e47a02ca6e3f878b7ce90f967dfb905 Author: Benedek László Date: Mon May 13 23:41:20 2024 +0200 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d835f77 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build +.cache \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..fa5ed8a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,31 @@ +cmake_minimum_required(VERSION 3.22) +project(graph) + +include(CMakePrintHelpers) + +set(CMAKE_C_COMPILER clang) +set(CMAKE_CXX_COMPILER clang++) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-variable") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-variable") + +if(DEBUG) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -DDEBUG") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DDEBUG") +endif() + +set(CMAKE_EXPORT_COMPILE_COMMANDS true) + +include_directories("${CMAKE_SOURCE_DIR}/inc") +add_subdirectory("${CMAKE_SOURCE_DIR}/src/graph/plugins") + +find_package(Qt6 REQUIRED COMPONENTS Widgets) +qt_standard_project_setup() +file(GLOB_RECURSE SERVER_SOURCES "${CMAKE_SOURCE_DIR}/src/graph/server/*.cpp") +file(GLOB_RECURSE SERVER_RES "${CMAKE_SOURCE_DIR}/src/graph/server/*.ui") +qt_add_executable(server ${SERVER_SOURCES} ${SERVER_RES}) +target_link_libraries(server PRIVATE dl Qt6::Widgets) + + +# add_executable(server ${SERVER_SOURCES}) diff --git a/inc/graph/plugins/plugin.h b/inc/graph/plugins/plugin.h new file mode 100644 index 0000000..8d5499d --- /dev/null +++ b/inc/graph/plugins/plugin.h @@ -0,0 +1,14 @@ +#pragma once + +#include + +typedef bool (*init_t)(); +typedef void (*destroy_t)(); +typedef void (*update_callback_t)(); + +typedef struct { + uint32_t version; + init_t init_method; + destroy_t destroy_method; + update_callback_t update_callback; +} plugin_t; \ No newline at end of file diff --git a/inc/graph/server/plugin.h b/inc/graph/server/plugin.h new file mode 100644 index 0000000..3f494a5 --- /dev/null +++ b/inc/graph/server/plugin.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include + +namespace Graph { + +class Plugin { +private: + plugin_t *plugin; + const void* handle; +public: + Plugin(const std::string& path); + ~Plugin(); + + bool init(update_callback_t callback); +}; +} // namespace Graph diff --git a/inc/graph/server/spec.h b/inc/graph/server/spec.h new file mode 100644 index 0000000..9ea7702 --- /dev/null +++ b/inc/graph/server/spec.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include + +struct graph_spec_t { + std::string title; + bool grid = false; + bool legend = false; + struct axis { + struct x { + std::string label; + uint64_t limit = UINT64_MAX; + }; + struct y { + std::string label; + bool auto_limit = true; + double min; + double max; + }; + }; +}; \ No newline at end of file diff --git a/src/graph/plugins/CMakeLists.txt b/src/graph/plugins/CMakeLists.txt new file mode 100644 index 0000000..a27923c --- /dev/null +++ b/src/graph/plugins/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory("./http") \ No newline at end of file diff --git a/src/graph/plugins/http/CMakeLists.txt b/src/graph/plugins/http/CMakeLists.txt new file mode 100644 index 0000000..23b5415 --- /dev/null +++ b/src/graph/plugins/http/CMakeLists.txt @@ -0,0 +1,2 @@ +file(GLOB_RECURSE HTTP_SOURCES "./*.cpp") +add_library(http SHARED ${HTTP_SOURCES}) \ No newline at end of file diff --git a/src/graph/plugins/http/http.cpp b/src/graph/plugins/http/http.cpp new file mode 100644 index 0000000..98d4ec7 --- /dev/null +++ b/src/graph/plugins/http/http.cpp @@ -0,0 +1,15 @@ +#include +#include + +extern "C" { + +bool init() { + std::cout << "init" << std::endl; + return true; +} + +void destroy() { std::cout << "destory" << std::endl; } + +plugin_t plugin = { + .version = 1, .init_method = &init, .destroy_method = &destroy}; +} diff --git a/src/graph/server/main.cpp b/src/graph/server/main.cpp new file mode 100644 index 0000000..637710f --- /dev/null +++ b/src/graph/server/main.cpp @@ -0,0 +1,9 @@ +#include +#include +#include + +int main(int argc, char** argv) { + Graph::Plugin plugin("src/graph/plugins/http/libhttp.so"); + plugin.init((update_callback_t)1); + return 0; +} \ No newline at end of file diff --git a/src/graph/server/plugin.cpp b/src/graph/server/plugin.cpp new file mode 100644 index 0000000..5e62c49 --- /dev/null +++ b/src/graph/server/plugin.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +namespace Graph { +Plugin::Plugin(const std::string &path) { + this->handle = dlopen(path.c_str(), RTLD_LAZY); + if (!this->handle) + throw std::runtime_error(dlerror()); + + this->plugin = (plugin_t*)dlsym((void*)this->handle, "plugin"); + if (!this->plugin) + throw std::runtime_error(dlerror()); + + this->plugin->update_callback = nullptr; +} + +Plugin::~Plugin() { + if (this->plugin->update_callback) + this->plugin->destroy_method(); + + if (this->handle) + dlclose((void*)this->handle); +} + +bool Plugin::init(update_callback_t callback) { + this->plugin->update_callback = callback; + return this->plugin->init_method(); +} +} // namespace Graph \ No newline at end of file