aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2023-09-10 15:51:03 +0200
committerJan200101 <sentrycraft123@gmail.com>2023-09-10 15:51:03 +0200
commit35f1402ad5d7f142bb3932238422188455bbb9df (patch)
treeb41a8fbb7abcf7af09779779cd99ccb54369cc2b /src
downloadSouthRPC-35f1402ad5d7f142bb3932238422188455bbb9df.tar.gz
SouthRPC-35f1402ad5d7f142bb3932238422188455bbb9df.zip
create base code
from this a lot can be branched
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt18
-rw-r--r--src/init.cpp12
-rw-r--r--src/internal/logging.h45
-rw-r--r--src/plugin.h14
4 files changed, 89 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..44ae5d4
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,18 @@
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+
+find_package(spdlog REQUIRED)
+
+plugin_manifest(SouthRPC name "South-RPC")
+plugin_manifest(SouthRPC displayname "South RPC")
+plugin_manifest(SouthRPC description "Implements JSON-RPC Bridge for Northstar over TCP/IP")
+plugin_manifest(SouthRPC run_on_server OFF)
+plugin_manifest(SouthRPC run_on_client ON)
+
+add_library(SouthRPC SHARED
+ ${CMAKE_CURRENT_SOURCE_DIR}/init.cpp
+)
+
+target_precompile_headers(SouthRPC PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/plugin.h)
+
+plugin_link(SouthRPC)
diff --git a/src/init.cpp b/src/init.cpp
new file mode 100644
index 0000000..856af41
--- /dev/null
+++ b/src/init.cpp
@@ -0,0 +1,12 @@
+// Needed to bootstrap plugin abi
+#include "plugin.h"
+#include "internal/logging.h"
+
+extern "C" __declspec(dllexport)
+void PLUGIN_INIT(PluginInitFuncs* funcs, PluginNorthstarData* data)
+{
+ spdlog::default_logger()->sinks().pop_back();
+ spdlog::default_logger()->sinks().push_back(std::make_shared<PluginSink>(funcs->logger));
+
+ spdlog::info(PLUGIN_NAME " succesfully initialised!");
+}
diff --git a/src/internal/logging.h b/src/internal/logging.h
new file mode 100644
index 0000000..ad6de6b
--- /dev/null
+++ b/src/internal/logging.h
@@ -0,0 +1,45 @@
+#ifndef LOGGING_H
+#define LOGGING_H
+
+#include <iostream>
+
+#include "plugin.h"
+#include "spdlog/sinks/base_sink.h"
+
+using spdlog_base_sink = spdlog::sinks::base_sink<std::mutex>;
+
+class PluginSink : public spdlog_base_sink
+{
+public:
+
+ PluginSink(loggerfunc_t logger): spdlog_base_sink()
+ {
+ this->ns_logger_ = logger;
+ }
+
+ void sink_it_(const spdlog::details::log_msg& in_msg) override
+ {
+ LogMsg msg{};
+ std::string payload(in_msg.payload.data(), in_msg.payload.size());
+ msg.level = (int)in_msg.level;
+ msg.msg = payload.c_str();
+ msg.timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(in_msg.time.time_since_epoch()).count();
+ msg.source.file = in_msg.source.filename;
+ msg.source.func = in_msg.source.funcname;
+ msg.source.line = in_msg.source.line;
+ this->ns_logger_(&msg);
+ }
+
+ void flush_() override
+ {
+ std::cout << std::flush;
+ }
+
+protected:
+ loggerfunc_t ns_logger_;
+
+ // sink log level - default is all
+ spdlog::level_t level_{ spdlog::level::trace };
+};
+
+#endif \ No newline at end of file
diff --git a/src/plugin.h b/src/plugin.h
new file mode 100644
index 0000000..c346cee
--- /dev/null
+++ b/src/plugin.h
@@ -0,0 +1,14 @@
+#ifndef PLUGIN_H
+#define PLUGIN_H
+
+// Needed to bootstrap plugin abi
+#include <windef.h>
+#include <mutex>
+#include <optional>
+#include <map>
+#include <unordered_map>
+#include "spdlog/spdlog.h"
+
+#include "plugin_abi.h"
+
+#endif