diff options
-rw-r--r-- | modules/thread/c++/remote.hpp | 56 |
1 files changed, 56 insertions, 0 deletions
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<typename Iface, typename Encoding, typename Storage> +class thread_rpc_communication_handler final { +private: + std::mutex mut_; + + using FunctionT = std::function<error_or<void>(rpc_server<Iface, Encoding, Storage, rmt::Thread>&)>; + std::deque<FunctionT> dispatches_; + + // TODO Need a send + receive + erase request queue + // std::deque<int>; +public: + thread_rpc_communication_handler() = default; + + template<string_literal Lit> + error_or<void> call(id<Void> dat_id){ + std::lock_guard lock{mut_}; + + dispatches_.emplace_back([dat_id](rpc_server<Iface, Encoding, Storage, rmt::Thread>& srv){ + srv.template call<Lit>(dat_id); + }); + } + + error_or<void> run_next_dispatch(rpc_server<Iface, Encoding, Storage, rmt::Thread>& srv){ + std::lock_guard lock{mut_}; + if(dispatches_.empty()){ + return make_error<err::recoverable>("Dispatch Queue is empty"); + } + + ref<FunctionT> front{dispatches_.front()}; + + front()(); + } +}; + +} + +template<Iface, Encoding, Storage> +class rpc_server<Iface, Encoding, Storage, rmt::Thread> { +private: + our<impl::thread_rpc_communication_handler<Iface, Encoding, Storage>> comms_; +public: +}; + +template<Iface, Encoding, Storage> +class rpc_client<Iface, Encoding, Storage, rmt::Thread> { +private: + our<impl::thread_rpc_communication_handler<Iface, Encoding, Storage>> comms_; +public: + rpc_client(our<impl::thread_rpc_communication_handler<Iface, Encoding, Storage>> 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<void()> run_func_; + // std::vector<std::function<error_or<void>()>> func_calls_; + std::thread thread_; void run(){ |