aboutsummaryrefslogtreecommitdiff
path: root/src/rpc_server.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/rpc_server.h')
-rw-r--r--src/rpc_server.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/rpc_server.h b/src/rpc_server.h
new file mode 100644
index 0000000..afa72fe
--- /dev/null
+++ b/src/rpc_server.h
@@ -0,0 +1,46 @@
+#ifndef RPC_SERVER
+#define RPC_SERVER
+
+#include <map>
+#include <string>
+
+#include <rapidjson/document.h>
+
+#include "http_server.h"
+
+class RPCRequest {
+ private:
+ HTTPRequest* request;
+
+ rapidjson::Document body;
+
+ rapidjson::Value id;
+ std::string method;
+ rapidjson::Value params;
+
+ void response(rapidjson::Value& result);
+
+ public:
+ RPCRequest(HTTPRequest* request);
+ ~RPCRequest();
+
+ rapidjson::MemoryPoolAllocator<>& get_allocator() { return this->body.GetAllocator(); };
+ std::string get_method() { return this->method; }
+ rapidjson::Value& get_params() { return this->params; }
+
+ void result(rapidjson::Value result);
+ void error(rapidjson::Value error);
+ void close();
+};
+
+class RPCServer {
+ private:
+ HTTPServer http_server;
+
+ public:
+ RPCServer(unsigned long addr, unsigned short port);
+
+ RPCRequest* receive_request();
+};
+
+#endif