From c2dca2e8f812302d9465186bf001442a29919088 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 30 Dec 2024 22:57:48 +0100 Subject: Start on rpc, open existing instances ui when trying to launch gsr-ui a second time --- include/Rpc.hpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 include/Rpc.hpp (limited to 'include') diff --git a/include/Rpc.hpp b/include/Rpc.hpp new file mode 100644 index 0000000..d6db218 --- /dev/null +++ b/include/Rpc.hpp @@ -0,0 +1,34 @@ +#pragma once + +#include +#include +#include +#include + +typedef struct _IO_FILE FILE; + +namespace gsr { + using RpcCallback = std::function; + + class Rpc { + public: + Rpc() = default; + Rpc(const Rpc&) = delete; + Rpc& operator=(const Rpc&) = delete; + ~Rpc(); + + bool create(const char *name); + bool open(const char *name); + bool write(const char *str, size_t size); + void poll(); + + bool add_handler(const std::string &name, RpcCallback callback); + private: + bool open_filepath(const char *filepath); + private: + int fd = 0; + FILE *file = nullptr; + std::string fifo_filepath; + std::unordered_map handlers_by_name; + }; +} \ No newline at end of file -- cgit v1.2.3