summaryrefslogtreecommitdiff
path: root/modules/remote/c++/remote_loopback.hpp
blob: 10ac79c1ed1f7fe87f7209153f64915c1d91ba42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#pragma once

#include <variant>

#include <forstio/codec/interface.hpp>

#include "remote.hpp"
#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, rmt::Loopback> 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> {
private:
	data<schema::UInt64> addr_id_;
public:
	remote_address(data<schema::UInt64> addr_id__):
		addr_id_{addr_id__}
	{}

	const data<schema::UInt64>& get_address_id() const {
		return addr_id_;
	}
};

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 remote_address<rmt::Loopback>& addr__, InterfaceT iface__):
		addr_{&addr__},
		iface_{std::move(iface__)}
	{}

	// error_or<id<>>
};

template<>
class remote<rmt::Loopback> {
private:
public:
	/**
	 * Resolves an address for the remote
	 */
	error_or<own<remote_address<rmt::Loopback>>> parse_address(data<schema::UInt64> id){
		return heap<remote_address<rmt::Loopback>>(id);
	}

	/**
	 * 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)};
	}
};
}