From a1c8f243125b855f1f3b5f14ebfe83aec7cf0d8d Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Tue, 2 Jul 2024 13:36:57 +0200 Subject: Adding in between thread handler --- modules/thread/c++/remote.hpp | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'modules/thread/c++') diff --git a/modules/thread/c++/remote.hpp b/modules/thread/c++/remote.hpp index 37f89ad..39c64a6 100644 --- a/modules/thread/c++/remote.hpp +++ b/modules/thread/c++/remote.hpp @@ -30,6 +30,60 @@ namespace rmt { struct Thread {}; } +namespace impl { +template +class thread_rpc_communication_handler final { +private: + std::mutex mut_; + + using FunctionT = std::function(rpc_server&)>; + std::deque dispatches_; + + // TODO Need a send + receive + erase request queue + // std::deque; +public: + thread_rpc_communication_handler() = default; + + template + error_or call(id dat_id){ + std::lock_guard lock{mut_}; + + dispatches_.emplace_back([dat_id](rpc_server& srv){ + srv.template call(dat_id); + }); + } + + error_or run_next_dispatch(rpc_server& srv){ + std::lock_guard lock{mut_}; + if(dispatches_.empty()){ + return make_error("Dispatch Queue is empty"); + } + + ref front{dispatches_.front()}; + + front()(); + } +}; + +} + +template +class rpc_server { +private: + our> comms_; +public: +}; + +template +class rpc_client { +private: + our> comms_; +public: + rpc_client(our> comms__): + comms_{std::move(comms__)} + {} +}; + /** * A device representing a remote thread. Technically it's * a logical distinction and not a physical. @@ -41,6 +95,8 @@ private: bool keep_running_; std::function run_func_; + // std::vector()>> func_calls_; + std::thread thread_; void run(){ -- cgit v1.2.3