init
This commit is contained in:
commit
a6b54fac0e
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
build
|
||||
.cache
|
31
CMakeLists.txt
Normal file
31
CMakeLists.txt
Normal file
@ -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})
|
14
inc/graph/plugins/plugin.h
Normal file
14
inc/graph/plugins/plugin.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
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;
|
18
inc/graph/server/plugin.h
Normal file
18
inc/graph/server/plugin.h
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <graph/plugins/plugin.h>
|
||||
#include <string>
|
||||
|
||||
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
|
22
inc/graph/server/spec.h
Normal file
22
inc/graph/server/spec.h
Normal file
@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
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;
|
||||
};
|
||||
};
|
||||
};
|
1
src/graph/plugins/CMakeLists.txt
Normal file
1
src/graph/plugins/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
||||
add_subdirectory("./http")
|
2
src/graph/plugins/http/CMakeLists.txt
Normal file
2
src/graph/plugins/http/CMakeLists.txt
Normal file
@ -0,0 +1,2 @@
|
||||
file(GLOB_RECURSE HTTP_SOURCES "./*.cpp")
|
||||
add_library(http SHARED ${HTTP_SOURCES})
|
15
src/graph/plugins/http/http.cpp
Normal file
15
src/graph/plugins/http/http.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
#include <graph/plugins/plugin.h>
|
||||
#include <iostream>
|
||||
|
||||
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};
|
||||
}
|
9
src/graph/server/main.cpp
Normal file
9
src/graph/server/main.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
#include <graph/server/plugin.h>
|
||||
#include <dlfcn.h>
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
Graph::Plugin plugin("src/graph/plugins/http/libhttp.so");
|
||||
plugin.init((update_callback_t)1);
|
||||
return 0;
|
||||
}
|
31
src/graph/server/plugin.cpp
Normal file
31
src/graph/server/plugin.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
#include <dlfcn.h>
|
||||
#include <graph/server/plugin.h>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
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
|
Loading…
Reference in New Issue
Block a user