diff --git a/aslp-cpp/include/aslp-cpp/aslp-cpp.hpp b/aslp-cpp/include/aslp-cpp/aslp-cpp.hpp index 485e334a..a0e15d6b 100644 --- a/aslp-cpp/include/aslp-cpp/aslp-cpp.hpp +++ b/aslp-cpp/include/aslp-cpp/aslp-cpp.hpp @@ -1,35 +1,41 @@ #pragma once -#include +#include #include +#include +#include -namespace httplib { +namespace httplib +{ class Client; -} // namespace httplib; +} // namespace httplib // tuple of encoding and semantics using aslp_opcode_result_t = std::tuple; class aslp_connection { + using params_t = std::multimap; + std::unique_ptr client {nullptr}; + const params_t& extra_params; public: - aslp_connection(const std::string& server_addr, int server_port); + aslp_connection(const std::string& server_addr, int server_port, const params_t& extra_params = {}); aslp_connection(aslp_connection&&) noexcept; auto get_opcode(uint32_t opcode) -> aslp_opcode_result_t; void wait_active(); ~aslp_connection(); }; - - -class aslp_client { +class aslp_client +{ private: const std::string server_addr; pid_t server_pid; int server_port; void shutdown(); + public: aslp_client(const aslp_client&) = delete; aslp_client(aslp_client&&) = delete; @@ -43,26 +49,26 @@ class aslp_client { : server_pid(pid) , server_port(port) , server_addr(std::move(addr)) - { } + { + } /** * Creates a new aslp_client with a managed server on * the default address, localhost:8000. */ - std::unique_ptr static start() { + std::unique_ptr static start() + { return start("127.0.0.1", 8000); } /** Creates a new managed aslp_client with the given address and port. */ - auto static start(const std::string& addr, int server_port) -> std::unique_ptr; + auto static start(const std::string& addr, + int server_port) -> std::unique_ptr; - /** Returns the semantics for the given opcode, as a newline-separated string. */ + /** Returns the semantics for the given opcode, as a newline-separated string. + */ auto get_opcode(uint32_t opcode) -> aslp_opcode_result_t; /** Destroys the aslp_client and terminates the managed server as well. */ - virtual ~aslp_client() { - shutdown(); - }; - + virtual ~aslp_client() { shutdown(); }; }; - diff --git a/aslp-cpp/source/aslp-cpp.cpp b/aslp-cpp/source/aslp-cpp.cpp index 598d504f..c86a817c 100644 --- a/aslp-cpp/source/aslp-cpp.cpp +++ b/aslp-cpp/source/aslp-cpp.cpp @@ -151,7 +151,10 @@ aslp_opcode_result_t aslp_connection::get_opcode(uint32_t opcode) { auto codestr = std::format("{:#x}", opcode); std::cout << codestr << "\n"; - const auto params = httplib::Params({{"opcode", codestr}}); + auto params = httplib::Params({{"opcode", codestr}}); + for (const auto& pair : extra_params) { + params.insert(pair); + } auto req = client->Get("/", params, httplib::Headers()); if (req.error() != httplib::Error::Success) { @@ -174,10 +177,11 @@ aslp_opcode_result_t aslp_connection::get_opcode(uint32_t opcode) } aslp_connection::aslp_connection(const std::string& server_addr, - int server_port) -{ - client = std::make_unique(server_addr, server_port); -} + int server_port, + const params_t& extra_params) : + extra_params{extra_params}, + client{std::make_unique(server_addr, server_port)} +{} aslp_connection::aslp_connection(aslp_connection&&) noexcept = default; aslp_connection::~aslp_connection() = default;