diff options
Diffstat (limited to 'modules/codec/c++/remote_loopback.hpp')
-rw-r--r-- | modules/codec/c++/remote_loopback.hpp | 95 |
1 files changed, 95 insertions, 0 deletions
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 <forstio/codec/interface.hpp> + +#include <variant> + +#include "transfer_loopback.hpp" + +namespace saw { + +template<typename T, typename Encoding, typename Storage> +class remote_data<T, Encoding, Storage, rmt::Loopback> { +private: + id<T> id_; +public: + remote_data(const id<T>& id): + id_{id} + {} + + /** + * Wait until data arrives + */ + error_or<data<T, Encoding, Storage>> wait(wait_scope& wait); + + /** + * Asynchronously wait for a result + */ + conveyor<data<T, Encoding, Storage>> on_receive(); +}; + +/** + * Client RPC reference structure + */ +template<typename Iface, typename Encoding, typename Storage> +class rpc_client<Iface, Encoding, Storage, rmt::Loopback> { + /** + * request the data from the remote + */ + template<typename IdT> + remote_data<IdT, Encoding, Storage, Remote> request_data(id<IdT> data); + + /** @todo + * Determine type based on Name + */ + /* + template<string_literal Name> + error_or< + id< + typename schema_member_type<Name, Iface>::type + > + > call(data_or_id<Input> inp); + */ +}; + +template<> +class remote_address<rmt::Loopback> { +}; + +template<typename Iface, typename Encode, typename Storage> +class rpc_server<Iface, Encode, Storage, rmt::Loopback> { +public: + using InterfaceT = interface<Iface, Encode, Storage>; +private: + const remote_address<rmt::Loopback>* addr_; + InterfaceT iface_; +public: + rpc_server(const remode_address<rmt::Loopback>& addr__, InterfaceT iface__): + addr_{&addr__}, + iface_{std::move(iface__)} + {} +}; + +template<> +class remote<rmt::Loopback> { + + /** + * Resolves an address for the remote + */ + conveyor<remote_address<rmt::Loopback>> resolve_address(); + + /** + * Connect to a remote + */ + template<typename Iface, typename Encode, typename Storage> + conveyor<rpc_client<Iface, Encode, Storage, rmt::Loopback>> connect(const remote_address<rmt::Loopback>& addr); + + /** + * Start listening + */ + template<typename Iface, typename Encode, typename Storage> + rpc_server<Iface, Encode, Storage, rmt::Loopback> listen(const remote_address<rmt::Loopback>& addr, typename rpc_server<Iface,Encode,Storage,rmt::Loopback>::InterfaceT iface){ + return {addr, std::move(iface)}; + } +}; +} |