diff options
Diffstat (limited to 'modules/remote-filesystem/c++/remote.hpp')
-rw-r--r-- | modules/remote-filesystem/c++/remote.hpp | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/modules/remote-filesystem/c++/remote.hpp b/modules/remote-filesystem/c++/remote.hpp index 42cdd03..062d7ee 100644 --- a/modules/remote-filesystem/c++/remote.hpp +++ b/modules/remote-filesystem/c++/remote.hpp @@ -6,54 +6,49 @@ namespace saw { namespace rmt { -struct FileSystem {}; +struct File {}; } template<> -class remote_address<rmt::FileSystem> { +class remote_address<rmt::File> { private: std::filesystem::path path_; public: remote_address(const std::filesystem::path& path__): path_{path__} {} -}; -template<typename Iface, typename Encoding, typename Storage> -class rpc_client<Iface, Encoding, Storage, rmt::FileSystem> { -private: - ptr<remote_address<rmt::FileSystem>> addr_; -public: - rpc_client(ptr<remote_address<rmt::FileSystem>> addr__): - addr_{addr__} - {} -}; + std::string get_path_string() const { + return path_.string(); + } -template<typename Iface, typename Encoding, typename Storage> -class rpc_server<Iface, Encoding, Storage, rmt::FileSystem> { -private: - ptr<remote_address<rmt::FileSystem>> addr_; -public: - rpc_server(ptr<remote_address<rmt::FileSystem>> addr__): - addr_{addr__} - {} + const std::filesystem::path& get_path() const { + return path_; + } }; template<> -class remote<rmt::FileSystem> { +class remote<rmt::File> { private: SAW_FORBID_COPY(remote); SAW_FORBID_MOVE(remote); - + std::map<std::string, ptr<i_data_server<rmt::File>>> registered_data_servers_; public: - error_or<own<remote_address<rmt::FileSystem>>> parse_address(const std::string_view& path_v){ - return heap<remote_address<rmt::FileSystem>>(path_v); + error_or<own<remote_address<rmt::File>>> parse_address(const std::string_view& path_v){ + return heap<remote_address<rmt::File>>(path_v); } - template<typename Iface, typename Encoding, typename Storage> - rpc_server<Iface, Encoding, Storage, rmt::FileSystem> listen(const remote_address<rmt::FileSystem>& addr, typename rpc_server<Iface,Encoding,Storage,rmt::FileSystem>::InterfaceT iface){ - return {addr, std::move(iface)}; + template<typename Schema, typename Encode> + error_or<own<data_server<Schema, Encode, rmt::File>>> data_listen(ref<remote_address<rmt::File>> addr){ + auto insert_res = registered_data_servers_.emplace(std::make_pair(addr.get_path_string(),{})); + if(!insert_res.second){ + return make_error<err::already_exists>(); + } + + auto dat_srv = heap<data_server<Schema, Encode, rmt::File>>(*this, addr); + insert_res.first->second = {dat_srv}; + return dat_srv; } }; } |