From 44f6a2ec37e35cf96419885be27afeab9ea84ec5 Mon Sep 17 00:00:00 2001 From: Claudius 'keldu' Holeksa Date: Mon, 29 Jul 2024 14:53:48 +0200 Subject: wip --- modules/codec/c++/data.hpp | 4 +- modules/codec/c++/schema_hash.hpp | 27 ++++++++++++- modules/core/c++/templates.hpp | 4 +- modules/remote/c++/remote_loopback.hpp | 34 ---------------- modules/remote/c++/remote_loopback_base.hpp | 63 +++++++++++++++++++++++++++++ modules/remote/c++/transfer.hpp | 6 ++- modules/remote/c++/transfer_loopback.hpp | 19 +++++++-- 7 files changed, 116 insertions(+), 41 deletions(-) diff --git a/modules/codec/c++/data.hpp b/modules/codec/c++/data.hpp index a17f123..8e92622 100644 --- a/modules/codec/c++/data.hpp +++ b/modules/codec/c++/data.hpp @@ -21,7 +21,9 @@ struct Default {}; } namespace encode { -struct Native {}; +struct Native { + static constexpr string_literal name = "encode::Native"; +}; } template class codec; diff --git a/modules/codec/c++/schema_hash.hpp b/modules/codec/c++/schema_hash.hpp index 4b537e1..d653bf4 100644 --- a/modules/codec/c++/schema_hash.hpp +++ b/modules/codec/c++/schema_hash.hpp @@ -15,7 +15,9 @@ struct hash_literal { template struct schema_hash_seed { - static_assert(always_false, "Not schema_hashable"); + static constexpr uint32_t apply(uint32_t seed){ + return hash_literal::apply(seed); + } }; template<> @@ -125,6 +127,29 @@ struct schema_hash_seed> { } }; +template +struct schema_hash_seed> { + template + static constexpr uint32_t apply_ele(uint32_t seed){ + using Type = typename parameter_pack_type::type; + + seed = schema_hash_seed::apply(seed); + if constexpr ( (i+1u) < sizeof...(T) ){ + return apply_ele(seed); + } + + return seed; + } + + static constexpr uint32_t apply(uint32_t seed){ + seed = hash_literal::name>::apply(seed); + if constexpr (sizeof...(T)>0u){ + seed = apply_ele<0u>(seed); + } + return seed; + } +}; + template struct schema_hash_seed> { using Schema = schema::Member; diff --git a/modules/core/c++/templates.hpp b/modules/core/c++/templates.hpp index 70836ae..9f629da 100644 --- a/modules/core/c++/templates.hpp +++ b/modules/core/c++/templates.hpp @@ -9,7 +9,9 @@ namespace saw { * This type is meant for grouping of template types */ template -struct tmpl_group {}; +struct tmpl_group { + static constexpr string_literal name = "tmpl_group"; +}; template struct tmpl_concat; diff --git a/modules/remote/c++/remote_loopback.hpp b/modules/remote/c++/remote_loopback.hpp index ea4eb8e..400a076 100644 --- a/modules/remote/c++/remote_loopback.hpp +++ b/modules/remote/c++/remote_loopback.hpp @@ -83,38 +83,4 @@ public: // error_or> }; -template<> -class remote { -private: - std::map> registered_data_servers_; -public: - /** - * Resolves an address for the remote - */ - error_or>> parse_address(data id){ - return heap>(id); - } - - /** - * 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)}; - } - - /** - * Start data server - */ - template - data_server data_listen(const remote_address& addr){ - return {addr,*this}; - } -}; } diff --git a/modules/remote/c++/remote_loopback_base.hpp b/modules/remote/c++/remote_loopback_base.hpp index 823c516..660180d 100644 --- a/modules/remote/c++/remote_loopback_base.hpp +++ b/modules/remote/c++/remote_loopback_base.hpp @@ -1,7 +1,70 @@ #pragma once +#include "remote.hpp" + +#include + namespace saw { namespace rmt { struct Loopback {}; } + +template<> +class remote { +private: + std::map>> registered_data_servers_; +public: + /** + * Resolves an address for the remote + */ + error_or>> parse_address(data id){ + return heap>(id); + } + + /** + * 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)}; + } + + /** + * Start data server + */ + template + error_or>> data_listen(const remote_address& addr){ + auto find = registered_data_servers_.find(addr.get_address_id()); + if(find == registered_data_servers_.end()){ + return make_error("Server already bound to this address"); + } + return {addr,*this}; + } + + /** + * Connect to a data server + */ + template + conveyor> data_connect(const remote_address& addr){ + + } + + /** + * Internal function + */ + error_or register_data_server(const remote_address& addr, i_data_server& srv){ + + auto insert = registered_data_servers_.emplace(std::make_pair(addr.get_address_id(), {srv})); + if(insert.second){ + return make_error("Server already bound to this address"); + } + + } +}; } diff --git a/modules/remote/c++/transfer.hpp b/modules/remote/c++/transfer.hpp index ea61d56..32416de 100644 --- a/modules/remote/c++/transfer.hpp +++ b/modules/remote/c++/transfer.hpp @@ -1,10 +1,14 @@ #pragma once +#include + namespace saw { template class i_data_server { protected: - virtual ~i_data_server() = default; + ~i_data_server() = default; +public: + virtual std::pair get_class_id() const = 0; }; template diff --git a/modules/remote/c++/transfer_loopback.hpp b/modules/remote/c++/transfer_loopback.hpp index 2e01509..d205776 100644 --- a/modules/remote/c++/transfer_loopback.hpp +++ b/modules/remote/c++/transfer_loopback.hpp @@ -9,24 +9,37 @@ namespace rmt { struct Loopback {}; } +template<> +class remote; + template -class data_server, Encoding, rmt::Loopback> { +class data_server, Encoding, rmt::Loopback> final : public i_data_server { private: typename impl::data_server_redux>::type>::type values_; ptr> remote_; public: data_server(remote_address& addr){ - remote->register_server(addr); + remote_().register_server(addr); } ~data_server(){ - remote->deregister_server(addr); + remote_().deregister_server(addr); } SAW_FORBID_COPY(data_server); SAW_FORBID_MOVE(data_server); + /** + * Return the schema id + */ + std::pair get_class_id() const override { + uint32_t schema_hash = schema_hash>::apply(); + uint32_t encode_hash = schema_hash::apply(); + + return std::make_pair(schema_hash, encode_hash); + } + /** * Get data from client */ -- cgit v1.2.3