summaryrefslogtreecommitdiff
path: root/modules/codec
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2024-07-04 16:32:14 +0200
committerClaudius "keldu" Holeksa <mail@keldu.de>2024-07-04 16:32:14 +0200
commit40369c781e43282992e720efaaa99fa5e60c0d20 (patch)
tree3a862e006b000adf3aec77334a62eef8eb6215f4 /modules/codec
parent596964ba245e17444baa196c16b4531c03f7a4b2 (diff)
Preparation work for loopback
Diffstat (limited to 'modules/codec')
-rw-r--r--modules/codec/c++/remote_loopback.hpp95
-rw-r--r--modules/codec/c++/remote_loopback_base.hpp7
-rw-r--r--modules/codec/c++/rpc.hpp60
-rw-r--r--modules/codec/c++/transfer_loopback.hpp20
-rw-r--r--modules/codec/tests/forst.cpp4
-rw-r--r--modules/codec/tests/remote_loopback.cpp30
6 files changed, 159 insertions, 57 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)};
+ }
+};
+}
diff --git a/modules/codec/c++/remote_loopback_base.hpp b/modules/codec/c++/remote_loopback_base.hpp
new file mode 100644
index 0000000..823c516
--- /dev/null
+++ b/modules/codec/c++/remote_loopback_base.hpp
@@ -0,0 +1,7 @@
+#pragma once
+
+namespace saw {
+namespace rmt {
+struct Loopback {};
+}
+}
diff --git a/modules/codec/c++/rpc.hpp b/modules/codec/c++/rpc.hpp
index d172ec4..6b63580 100644
--- a/modules/codec/c++/rpc.hpp
+++ b/modules/codec/c++/rpc.hpp
@@ -70,52 +70,15 @@ public:
}
};
+
/**
* Representing data on the remote
*/
template<typename T, typename Encoding, typename Storage, typename Remote>
-class remote_data {
-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);
+class remote_data;
- /**
- * Asynchronously wait for a result
- */
- conveyor<data<T, Encoding, Storage>> on_receive();
-};
-
-/**
- * Client RPC reference structure
- */
template<typename Iface, typename Encoding, typename Storage, typename Remote>
-class rpc_client {
- /**
- * 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);
- */
-};
+class rpc_client;
/**
* Implementation of a remote server on the backend
@@ -149,22 +112,5 @@ class remote_address {
template<typename Remote>
class remote {
static_assert(always_false<Remote>, "Type of backend not supported");
-
- /**
- * Resolves an address for the remote
- */
- conveyor<remote_address<Remote>> resolve_address();
-
- /**
- * Connect to a remote
- */
- template<typename Iface, typename Encode, typename Storage>
- conveyor<rpc_client<Iface, Encode, Storage, Remote>> connect(const remote_address<Remote>& addr);
-
- /**
- * Start listening
- */
- template<typename Iface, typename Encode, typename Storage>
- rpc_server<Iface, Encode, Storage, Remote> listen();
};
}
diff --git a/modules/codec/c++/transfer_loopback.hpp b/modules/codec/c++/transfer_loopback.hpp
new file mode 100644
index 0000000..ec61669
--- /dev/null
+++ b/modules/codec/c++/transfer_loopback.hpp
@@ -0,0 +1,20 @@
+#pragma once
+
+namespace saw {
+namespace rmt {
+struct Loopback {};
+}
+
+template<typename Schema, typename Encoding>
+class data_server<Schema, Encoding, rmt::Loopback> {
+private:
+public:
+};
+
+template<typename Schema, typename Encoding>
+class data_client<Schema, Encoding, rmt::Loopback> {
+private:
+public:
+};
+
+}
diff --git a/modules/codec/tests/forst.cpp b/modules/codec/tests/forst.cpp
index 96c4dd0..28501c9 100644
--- a/modules/codec/tests/forst.cpp
+++ b/modules/codec/tests/forst.cpp
@@ -26,6 +26,10 @@ SAW_TEST("Codec Forst Info"){
SAW_EXPECT(depth == 0, "Layer info is wrong");
}
{
+ uint64_t depth = impl::forst_codec_info<schema::String>::layers;
+ SAW_EXPECT(depth == 1, "Layer info is wrong");
+ }
+ {
uint64_t depth = impl::forst_codec_info<TestStruct>::layers;
SAW_EXPECT(depth == 1, "Layer info is wrong");
}
diff --git a/modules/codec/tests/remote_loopback.cpp b/modules/codec/tests/remote_loopback.cpp
new file mode 100644
index 0000000..2f6c06c
--- /dev/null
+++ b/modules/codec/tests/remote_loopback.cpp
@@ -0,0 +1,30 @@
+#include <forstio/test/suite.hpp>
+
+#include "remote_loopback.hpp"
+
+namespace {
+namespace sch {
+using namespace saw::schema;
+
+using TestInterface = Interface<
+ Member<Function<UInt32, Int64>, "foo">
+>;
+}
+
+SAW_TEST("Remote Loopback"){
+ using namespace saw;
+
+ remote<rmt::Loopback> rmt;
+
+ auto eov = rmt.parse_address();
+ SAW_EXPECT(eov.is_value(), "Didn't parse correctly");
+ auto& val = eov.get_value();
+
+ interface<sch::TestInterface, encode::Native, storage::Default> iface{
+ [](data<sch::UInt32>& foo){
+ return foo.template cast<sch::Int64>();
+ }
+ };
+ auto rpc_srv = rmt.listen(*val, std::move(iface));
+}
+}