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
|
#pragma once
#include "remote.hpp"
#include <map>
namespace saw {
namespace rmt {
struct Loopback {};
}
template<>
class remote<rmt::Loopback> {
private:
std::map<uint64_t, ptr<i_data_server<rmt::Loopback>>> registered_data_servers_;
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)};
}
/**
* Start data server
*/
template<typename Schema, typename Encode>
error_or<own<data_server<Schema, Encode, rmt::Loopback>>> data_listen(const remote_address<rmt::Loopback>& addr){
auto find = registered_data_servers_.find(addr.get_address_id());
if(find == registered_data_servers_.end()){
return make_error<err::already_exists>("Server already bound to this address");
}
return {addr,*this};
}
/**
* Connect to a data server
*/
template<typename Schema, typename Encode>
conveyor<data_client<Schema, Encode, rmt::Loopback>> data_connect(const remote_address<rmt::Loopback>& addr){
}
/**
* Internal function
*/
error_or<void> register_data_server(const remote_address<rmt::Loopback>& addr, i_data_server<rmt::Loopback>& srv){
auto insert = registered_data_servers_.emplace(std::make_pair(addr.get_address_id(), {srv}));
if(insert.second){
return make_error<err::already_exists>("Server already bound to this address");
}
}
};
}
|