summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/codec/c++/interface.hpp43
-rw-r--r--modules/codec/c++/rpc.hpp102
-rw-r--r--modules/io_codec/.nix/derivation.nix2
-rw-r--r--modules/io_codec/SConstruct8
-rw-r--r--modules/io_codec/c++/rpc.hpp109
5 files changed, 119 insertions, 145 deletions
diff --git a/modules/codec/c++/interface.hpp b/modules/codec/c++/interface.hpp
index 59401ca..19dc145 100644
--- a/modules/codec/c++/interface.hpp
+++ b/modules/codec/c++/interface.hpp
@@ -1,18 +1,21 @@
#pragma once
+#include <functional>
+
#include <forstio/error.hpp>
#include "schema.hpp"
#include "data.hpp"
namespace saw {
-template<typename SchemaFunc, typename Encode, typename Func>
+template<typename SchemaFunc, typename Encode>
class function;
-template<typename Request, typename Response, typename Encode, typename Func>
-class function<schema::Function<Request, Response>, Encode, Func> {
+template<typename Request, typename Response, typename Encode>
+class function<schema::Function<Request, Response>, Encode> {
private:
- Func func_;
+ std::function<data<Response, Encode>(data<Request, Encode>)> func_;
public:
+ template<typename Func>
function(Func func):
func_{std::move(func)}
{}
@@ -22,15 +25,25 @@ public:
}
};
+template<typename Iface, typename Encode>
+class i_interface {
+public:
+ virtual ~i_interface() = default;
+
+
+};
+
template<typename T, typename Encode, typename... Funcs>
class interface;
-template<typename... Requests, typename... Responses, string_literal... Names, typename Encode, typename... Funcs>
-class interface<schema::Interface<schema::Member<schema::Function<Requests, Responses>, Names>...>, Encode, Funcs...> {
+template<typename... Requests, typename... Responses, string_literal... Names, typename Encode>
+class interface<schema::Interface<schema::Member<schema::Function<Requests, Responses>, Names>...>, Encode> {
+public:
+ using Schema = schema::Interface<schema::Member<schema::Function<Requests, Responses>,Names>...>;
private:
- std::tuple<function<schema::Function<Requests, Responses>, Encode, Funcs>...> funcs_;
+ std::tuple<function<schema::Function<Requests, Responses>, Encode>...> funcs_;
public:
- interface(function<schema::Function<Requests, Responses>, Encode, Funcs>... funcs):
+ interface(function<schema::Function<Requests, Responses>, Encode>... funcs):
funcs_{std::move(funcs)...}
{}
@@ -54,12 +67,6 @@ public:
>
,
Encode
- ,
- typename parameter_pack_type<
- parameter_key_pack_index<
- Lit, Names...
- >::value
- , Funcs...>::type
>& get(){
return std::get<parameter_key_pack_index<Lit, Names...>::value>(funcs_);
}
@@ -89,16 +96,16 @@ public:
template<typename T, typename Encode>
struct function_factory {
template<typename Func>
- static function<T,Encode, Func> create(Func func){
- return function<T,Encode,Func>{std::move(func)};
+ static function<T,Encode> create(Func func){
+ return function<T,Encode>{std::move(func)};
}
};
template<typename T, typename Encode>
struct interface_factory {
template<typename... Func>
- static interface<T,Encode, Func...> create(Func... func){
- return interface<T,Encode, Func...>{std::move(func)...};
+ static interface<T,Encode> create(Func... func){
+ return interface<T,Encode>{std::move(func)...};
}
};
}
diff --git a/modules/codec/c++/rpc.hpp b/modules/codec/c++/rpc.hpp
deleted file mode 100644
index 5a24034..0000000
--- a/modules/codec/c++/rpc.hpp
+++ /dev/null
@@ -1,102 +0,0 @@
-#pragma once
-
-#include <forstio/id.hpp>
-#include <forstio/codec/data.hpp>
-#include <forstio/io/io.hpp>
-
-namespace saw {
-
-/**
- * Representing data on the remote
- */
-template<typename T, 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>> wait(wait_scope& wait);
-
- /**
- * Asynchronously wait for a result
- */
- conveyor<data<T>> on_receive();
-};
-
-/**
- * Client RPC reference structure
- */
-template<typename T, typename Iface>
-class rpc_client {
- /**
- * request the data from the remote
- */
- template<typename IdT>
- remote_data<IdT> request_data(id<IdT> data);
-
- /**
- * 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);
-};
-
-/**
- * Implementation of a remote server on the backend
- */
-template<typename T, typename Iface>
-class rpc_server {
-private:
- interface<Iface> iface_;
-public:
- rpc_server(interface<Iface> iface):
- iface_{std::move(iface)}
- {}
-};
-
-/**
- * Representation of a remote.
- * Partially similar to a network address
- */
-template<typename T>
-class remote_address {
- static_assert(always_false<T>, "Type of remote not supported");
-
-
-};
-
-/**
- * Reference Backend structure
- */
-template<typename T>
-class remote {
- static_assert(always_false<T>, "Type of backend not supported");
-
- /**
- * Resolves an address for the remote
- */
- conveyor<remote_address<T>> resolve_address();
-
- /**
- * Connect to a remote
- */
- template<typename Iface>
- conveyor<rpc_client<T,Iface>> connect(const remote_address<T>& addr);
-
- /**
- * Start listening
- */
- template<typename Iface>
- rpc_server<T,Iface> listen();
-};
-}
diff --git a/modules/io_codec/.nix/derivation.nix b/modules/io_codec/.nix/derivation.nix
index 7cd55a8..aa5deb8 100644
--- a/modules/io_codec/.nix/derivation.nix
+++ b/modules/io_codec/.nix/derivation.nix
@@ -24,7 +24,7 @@ in stdenv.mkDerivation {
forstio.core
forstio.async
forstio.io
- forstio.codec
+ forstio.codec
];
outputs = ["out" "dev"];
diff --git a/modules/io_codec/SConstruct b/modules/io_codec/SConstruct
index 429656a..f4b8164 100644
--- a/modules/io_codec/SConstruct
+++ b/modules/io_codec/SConstruct
@@ -46,7 +46,13 @@ env_vars.Add('prefix',
env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[],
CPPDEFINES=['SAW_UNIX'],
CXXFLAGS=['-std=c++20','-g','-Wall','-Wextra'],
- LIBS=['forstio-io'])
+ LIBS=[
+ 'forstio-core',
+ 'forstio-async',
+ 'forstio-io',
+ 'forstio-codec'
+ ]
+);
env.__class__.add_source_files = add_kel_source_files
env.Tool('compilation_db');
env.cdb = env.CompilationDatabase('compile_commands.json');
diff --git a/modules/io_codec/c++/rpc.hpp b/modules/io_codec/c++/rpc.hpp
index cdade00..3caa808 100644
--- a/modules/io_codec/c++/rpc.hpp
+++ b/modules/io_codec/c++/rpc.hpp
@@ -1,43 +1,106 @@
#pragma once
-#include <forstio/codec/rpc.hpp>
+#include <forstio/id.hpp>
+#include <forstio/codec/data.hpp>
+#include <forstio/async/async.hpp>
+
+#include <forstio/codec/interface.hpp>
namespace saw {
-namespace rmt {
-struct Network {};
-}
-template<>
-class remote<rmt::Network> {
+/**
+ * Representing data on the remote
+ */
+template<typename T, typename Remote>
+class remote_data {
private:
- std::string addr_str_;
+ id<T> id_;
public:
- remote(std::string addr_str);
+ remote_data(const id<T>& id):
+ id_{id}
+ {}
- template<typename Interface>
- conveyor<rpc_client<rmt::Network, Interface>> connect();
+ /**
+ * Wait until data arrives
+ */
+ error_or<data<T>> wait(wait_scope& wait);
- template<typename Interface>
- conveyor<rpc_server<rmt::Network, Interface>> listen(network& net){
+ /**
+ * Asynchronously wait for a result
+ */
+ conveyor<data<T>> on_receive();
+};
- }
+/**
+ * Client RPC reference structure
+ */
+template<typename Iface, typename Remote>
+class rpc_client {
+ /**
+ * request the data from the remote
+ */
+ template<typename IdT>
+ remote_data<IdT, 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<typename Interface>
-class rpc_server<rmt::Network, Interface> {
+/**
+ * Implementation of a remote server on the backend
+ */
+template<typename Iface, typename Remote>
+class rpc_server {
private:
+ interface<Iface> iface_;
public:
+ rpc_server(interface<Iface> iface):
+ iface_{std::move(iface)}
+ {}
+};
+
+/**
+ * Representation of a remote.
+ * Partially similar to a network address
+ */
+template<typename Remote>
+class remote_address {
+ static_assert(always_false<Remote>, "Type of remote not supported");
+
};
-template<template Interface>
-class rpc_client<rmt::Network, Interface> {
-private:
- own<async_io_stream> stream_;
-public:
- rpc_client(own<async_io_stream> stream);
+/**
+ * Reference Backend structure
+ */
+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>
+ conveyor<rpc_client<Iface, Remote>> connect(const remote_address<Remote>& addr);
- template<typename T>
- remote_result<typename response<T>::type> call(typename request<T>::type req);
+ /**
+ * Start listening
+ */
+ template<typename Iface>
+ rpc_server<Iface, Remote> listen();
};
}