From 40369c781e43282992e720efaaa99fa5e60c0d20 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Thu, 4 Jul 2024 16:32:14 +0200 Subject: Preparation work for loopback --- modules/codec/c++/remote_loopback.hpp | 95 ++++++++++++++++++++++++++++++ modules/codec/c++/remote_loopback_base.hpp | 7 +++ modules/codec/c++/rpc.hpp | 60 +------------------ modules/codec/c++/transfer_loopback.hpp | 20 +++++++ modules/codec/tests/forst.cpp | 4 ++ modules/codec/tests/remote_loopback.cpp | 30 ++++++++++ modules/core/c++/common.hpp | 26 ++++++++ modules/io_codec/c++/remote.hpp | 55 +++++++++++++++++ 8 files changed, 240 insertions(+), 57 deletions(-) create mode 100644 modules/codec/c++/remote_loopback.hpp create mode 100644 modules/codec/c++/remote_loopback_base.hpp create mode 100644 modules/codec/c++/transfer_loopback.hpp create mode 100644 modules/codec/tests/remote_loopback.cpp create mode 100644 modules/io_codec/c++/remote.hpp diff --git a/modules/codec/c++/remote_loopback.hpp b/modules/codec/c++/remote_loopback.hpp new file mode 100644 index 0000000..22ca15f --- /dev/null +++ b/modules/codec/c++/remote_loopback.hpp @@ -0,0 +1,95 @@ +#pragma once + +#include + +#include + +#include "transfer_loopback.hpp" + +namespace saw { + +template +class remote_data { +private: + id id_; +public: + remote_data(const id& id): + id_{id} + {} + + /** + * Wait until data arrives + */ + error_or> wait(wait_scope& wait); + + /** + * Asynchronously wait for a result + */ + conveyor> on_receive(); +}; + +/** + * Client RPC reference structure + */ +template +class rpc_client { + /** + * request the data from the remote + */ + template + remote_data request_data(id data); + + /** @todo + * Determine type based on Name + */ + /* + template + error_or< + id< + typename schema_member_type::type + > + > call(data_or_id inp); + */ +}; + +template<> +class remote_address { +}; + +template +class rpc_server { +public: + using InterfaceT = interface; +private: + const remote_address* addr_; + InterfaceT iface_; +public: + rpc_server(const remode_address& addr__, InterfaceT iface__): + addr_{&addr__}, + iface_{std::move(iface__)} + {} +}; + +template<> +class remote { + + /** + * Resolves an address for the remote + */ + conveyor> resolve_address(); + + /** + * Connect to a remote + */ + template + conveyor> connect(const remote_address& addr); + + /** + * Start listening + */ + template + rpc_server listen(const remote_address& addr, typename rpc_server::InterfaceT iface){ + return {addr, std::move(iface)}; + } +}; +} diff --git a/modules/codec/c++/remote_loopback_base.hpp b/modules/codec/c++/remote_loopback_base.hpp new file mode 100644 index 0000000..823c516 --- /dev/null +++ b/modules/codec/c++/remote_loopback_base.hpp @@ -0,0 +1,7 @@ +#pragma once + +namespace saw { +namespace rmt { +struct Loopback {}; +} +} diff --git a/modules/codec/c++/rpc.hpp b/modules/codec/c++/rpc.hpp index d172ec4..6b63580 100644 --- a/modules/codec/c++/rpc.hpp +++ b/modules/codec/c++/rpc.hpp @@ -70,52 +70,15 @@ public: } }; + /** * Representing data on the remote */ template -class remote_data { -private: - id id_; -public: - remote_data(const id& id): - id_{id} - {} - - /** - * Wait until data arrives - */ - error_or> wait(wait_scope& wait); +class remote_data; - /** - * Asynchronously wait for a result - */ - conveyor> on_receive(); -}; - -/** - * Client RPC reference structure - */ template -class rpc_client { - /** - * request the data from the remote - */ - template - remote_data request_data(id data); - - /** @todo - * Determine type based on Name - */ - /* - template - error_or< - id< - typename schema_member_type::type - > - > call(data_or_id inp); - */ -}; +class rpc_client; /** * Implementation of a remote server on the backend @@ -149,22 +112,5 @@ class remote_address { template class remote { static_assert(always_false, "Type of backend not supported"); - - /** - * Resolves an address for the remote - */ - conveyor> resolve_address(); - - /** - * Connect to a remote - */ - template - conveyor> connect(const remote_address& addr); - - /** - * Start listening - */ - template - rpc_server listen(); }; } diff --git a/modules/codec/c++/transfer_loopback.hpp b/modules/codec/c++/transfer_loopback.hpp new file mode 100644 index 0000000..ec61669 --- /dev/null +++ b/modules/codec/c++/transfer_loopback.hpp @@ -0,0 +1,20 @@ +#pragma once + +namespace saw { +namespace rmt { +struct Loopback {}; +} + +template +class data_server { +private: +public: +}; + +template +class data_client { +private: +public: +}; + +} diff --git a/modules/codec/tests/forst.cpp b/modules/codec/tests/forst.cpp index 96c4dd0..28501c9 100644 --- a/modules/codec/tests/forst.cpp +++ b/modules/codec/tests/forst.cpp @@ -25,6 +25,10 @@ SAW_TEST("Codec Forst Info"){ uint64_t depth = impl::forst_codec_info::layers; SAW_EXPECT(depth == 0, "Layer info is wrong"); } + { + uint64_t depth = impl::forst_codec_info::layers; + SAW_EXPECT(depth == 1, "Layer info is wrong"); + } { uint64_t depth = impl::forst_codec_info::layers; SAW_EXPECT(depth == 1, "Layer info is wrong"); diff --git a/modules/codec/tests/remote_loopback.cpp b/modules/codec/tests/remote_loopback.cpp new file mode 100644 index 0000000..2f6c06c --- /dev/null +++ b/modules/codec/tests/remote_loopback.cpp @@ -0,0 +1,30 @@ +#include + +#include "remote_loopback.hpp" + +namespace { +namespace sch { +using namespace saw::schema; + +using TestInterface = Interface< + Member, "foo"> +>; +} + +SAW_TEST("Remote Loopback"){ + using namespace saw; + + remote rmt; + + auto eov = rmt.parse_address(); + SAW_EXPECT(eov.is_value(), "Didn't parse correctly"); + auto& val = eov.get_value(); + + interface iface{ + [](data& foo){ + return foo.template cast(); + } + }; + auto rpc_srv = rmt.listen(*val, std::move(iface)); +} +} diff --git a/modules/core/c++/common.hpp b/modules/core/c++/common.hpp index 40b2c43..ebca498 100644 --- a/modules/core/c++/common.hpp +++ b/modules/core/c++/common.hpp @@ -40,6 +40,32 @@ template using our = std::shared_ptr; template using lent = std::weak_ptr; +template +class ptr { +private: + T* ptr_; + +public: + ptr(T& ptr__): + ptr_{&ptr__} + {} + + SAW_DEFAULT_COPY(ptr); + SAW_DEFAULT_MOVE(ptr); + + T& operator()(){ + return *ptr_; + } + + const T& operator()() const { + return *ptr_; + } + + bool is_valid() const { + return ptr_ != nullptr; + } +}; + /** * Reference class for easier distinction * of references and its referenced types. diff --git a/modules/io_codec/c++/remote.hpp b/modules/io_codec/c++/remote.hpp new file mode 100644 index 0000000..3ff5822 --- /dev/null +++ b/modules/io_codec/c++/remote.hpp @@ -0,0 +1,55 @@ +#pragma once + +#include + +namespace saw { +namespace rmt { +struct FileSystem {}; +} + +template<> +class remote_address { +private: + std::filesystem::path path_; +public: + remote_address(const std::filesystem::path& path__): + path_{path__} + {} +}; + +template +class rpc_client { +private: + ptr> addr_; +public: + rpc_client(ptr> addr__): + addr_{addr__} + {} +}; + +template +class rpc_server { +private: + ptr> addr_; +public: + rpc_server(ptr> addr__): + addr_{addr__} + {} +}; + +template<> +class remote { +private: + SAW_FORBID_COPY(remote); + SAW_FORBID_MOVE(remote); +public: + error_or>> parse_address(const std::string_view& path_v){ + return heap>(path_v); + } + + template + rpc_server listen(const remote_address& addr, typename rpc_server::InterfaceT iface){ + return {addr, std::move(iface)}; + } +}; +} -- cgit v1.2.3