From 24d83f549a6fba7b23a0c048e1512d00ed704e0d Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Mon, 15 Apr 2024 15:24:40 +0200 Subject: codec, io_codec: Fixed some type issues with functions and moved rpc to io_codec due to dependency issues --- modules/codec/c++/interface.hpp | 43 ++++++++------ modules/codec/c++/rpc.hpp | 102 -------------------------------- modules/io_codec/.nix/derivation.nix | 2 +- modules/io_codec/SConstruct | 8 ++- modules/io_codec/c++/rpc.hpp | 109 +++++++++++++++++++++++++++-------- 5 files changed, 119 insertions(+), 145 deletions(-) delete mode 100644 modules/codec/c++/rpc.hpp (limited to 'modules') diff --git a/modules/codec/c++/interface.hpp b/modules/codec/c++/interface.hpp index 59401ca..19dc145 100644 --- a/modules/codec/c++/interface.hpp +++ b/modules/codec/c++/interface.hpp @@ -1,18 +1,21 @@ #pragma once +#include + #include #include "schema.hpp" #include "data.hpp" namespace saw { -template +template class function; -template -class function, Encode, Func> { +template +class function, Encode> { private: - Func func_; + std::function(data)> func_; public: + template function(Func func): func_{std::move(func)} {} @@ -22,15 +25,25 @@ public: } }; +template +class i_interface { +public: + virtual ~i_interface() = default; + + +}; + template class interface; -template -class interface, Names>...>, Encode, Funcs...> { +template +class interface, Names>...>, Encode> { +public: + using Schema = schema::Interface,Names>...>; private: - std::tuple, Encode, Funcs>...> funcs_; + std::tuple, Encode>...> funcs_; public: - interface(function, Encode, Funcs>... funcs): + interface(function, Encode>... funcs): funcs_{std::move(funcs)...} {} @@ -54,12 +67,6 @@ public: > , Encode - , - typename parameter_pack_type< - parameter_key_pack_index< - Lit, Names... - >::value - , Funcs...>::type >& get(){ return std::get::value>(funcs_); } @@ -89,16 +96,16 @@ public: template struct function_factory { template - static function create(Func func){ - return function{std::move(func)}; + static function create(Func func){ + return function{std::move(func)}; } }; template struct interface_factory { template - static interface create(Func... func){ - return interface{std::move(func)...}; + static interface create(Func... func){ + return interface{std::move(func)...}; } }; } diff --git a/modules/codec/c++/rpc.hpp b/modules/codec/c++/rpc.hpp deleted file mode 100644 index 5a24034..0000000 --- a/modules/codec/c++/rpc.hpp +++ /dev/null @@ -1,102 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace saw { - -/** - * 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); - - /** - * 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); - - /** - * Determine type based on Name - */ - template - error_or< - id< - typename schema_member_type::type - > - > call(data_or_id inp); -}; - -/** - * Implementation of a remote server on the backend - */ -template -class rpc_server { -private: - interface iface_; -public: - rpc_server(interface iface): - iface_{std::move(iface)} - {} -}; - -/** - * Representation of a remote. - * Partially similar to a network address - */ -template -class remote_address { - static_assert(always_false, "Type of remote not supported"); - - -}; - -/** - * Reference Backend structure - */ -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/io_codec/.nix/derivation.nix b/modules/io_codec/.nix/derivation.nix index 7cd55a8..aa5deb8 100644 --- a/modules/io_codec/.nix/derivation.nix +++ b/modules/io_codec/.nix/derivation.nix @@ -24,7 +24,7 @@ in stdenv.mkDerivation { forstio.core forstio.async forstio.io - forstio.codec + forstio.codec ]; outputs = ["out" "dev"]; diff --git a/modules/io_codec/SConstruct b/modules/io_codec/SConstruct index 429656a..f4b8164 100644 --- a/modules/io_codec/SConstruct +++ b/modules/io_codec/SConstruct @@ -46,7 +46,13 @@ env_vars.Add('prefix', env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[], CPPDEFINES=['SAW_UNIX'], CXXFLAGS=['-std=c++20','-g','-Wall','-Wextra'], - LIBS=['forstio-io']) + LIBS=[ + 'forstio-core', + 'forstio-async', + 'forstio-io', + 'forstio-codec' + ] +); env.__class__.add_source_files = add_kel_source_files env.Tool('compilation_db'); env.cdb = env.CompilationDatabase('compile_commands.json'); diff --git a/modules/io_codec/c++/rpc.hpp b/modules/io_codec/c++/rpc.hpp index cdade00..3caa808 100644 --- a/modules/io_codec/c++/rpc.hpp +++ b/modules/io_codec/c++/rpc.hpp @@ -1,43 +1,106 @@ #pragma once -#include +#include +#include +#include + +#include namespace saw { -namespace rmt { -struct Network {}; -} -template<> -class remote { +/** + * Representing data on the remote + */ +template +class remote_data { private: - std::string addr_str_; + id id_; public: - remote(std::string addr_str); + remote_data(const id& id): + id_{id} + {} - template - conveyor> connect(); + /** + * Wait until data arrives + */ + error_or> wait(wait_scope& wait); - template - conveyor> listen(network& net){ + /** + * 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 rpc_server { +/** + * Implementation of a remote server on the backend + */ +template +class rpc_server { private: + interface iface_; public: + rpc_server(interface iface): + iface_{std::move(iface)} + {} +}; + +/** + * Representation of a remote. + * Partially similar to a network address + */ +template +class remote_address { + static_assert(always_false, "Type of remote not supported"); + }; -template