summaryrefslogtreecommitdiff
path: root/modules/remote/c++
diff options
context:
space:
mode:
Diffstat (limited to 'modules/remote/c++')
-rw-r--r--modules/remote/c++/remote_loopback.hpp34
-rw-r--r--modules/remote/c++/remote_loopback_base.hpp63
-rw-r--r--modules/remote/c++/transfer.hpp6
-rw-r--r--modules/remote/c++/transfer_loopback.hpp19
4 files changed, 84 insertions, 38 deletions
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<id<>>
};
-template<>
-class remote<rmt::Loopback> {
-private:
- std::map<uint64_t, i_data_server<>> 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 Encode>
- data_server<Encode> data_listen(const remote_address<rmt::Loopback>& 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 <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");
+ }
+
+ }
+};
}
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 <map>
+
namespace saw {
template<typename Remote>
class i_data_server {
protected:
- virtual ~i_data_server() = default;
+ ~i_data_server() = default;
+public:
+ virtual std::pair<uint32_t,uint32_t> get_class_id() const = 0;
};
template<typename Schema, typename Encoding, typename Remote>
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,25 +9,38 @@ namespace rmt {
struct Loopback {};
}
+template<>
+class remote<rmt::Loopback>;
+
template<typename... Schema, typename Encoding>
-class data_server<tmpl_group<Schema...>, Encoding, rmt::Loopback> {
+class data_server<tmpl_group<Schema...>, Encoding, rmt::Loopback> final : public i_data_server<rmt::Loopback> {
private:
typename impl::data_server_redux<Encoding, storage::Default, typename tmpl_reduce<tmpl_group<Schema...>>::type>::type values_;
ptr<remote<rmt::Loopback>> remote_;
public:
data_server(remote_address<rmt::Loopback>& 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<uint32_t,uint32_t> get_class_id() const override {
+ uint32_t schema_hash = schema_hash<tmpl_group<Schema...>>::apply();
+ uint32_t encode_hash = schema_hash<Encoding>::apply();
+
+ return std::make_pair(schema_hash, encode_hash);
+ }
+
+ /**
* Get data from client
*/
template<typename Sch>