summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/codec/c++/schema.hpp28
-rw-r--r--modules/core/c++/templates.hpp6
-rw-r--r--modules/io-tls/tls.cpp2
-rw-r--r--modules/io-tls/tls.hpp2
-rw-r--r--modules/io/c++/io.hpp7
-rw-r--r--modules/io/c++/io_unix.cpp8
-rw-r--r--modules/lang/c++/c_common.hpp49
-rw-r--r--modules/lang/c++/c_language.hpp7
-rw-r--r--modules/lang/c++/c_transfer.hpp39
-rw-r--r--modules/lang/c++/c_types.hpp4
-rw-r--r--modules/lang/examples/SConscript4
-rw-r--r--modules/lang/examples/c_example.cpp17
12 files changed, 163 insertions, 10 deletions
diff --git a/modules/codec/c++/schema.hpp b/modules/codec/c++/schema.hpp
index 40dfe39..4bd544b 100644
--- a/modules/codec/c++/schema.hpp
+++ b/modules/codec/c++/schema.hpp
@@ -2,6 +2,7 @@
#include <forstio/common.hpp>
#include <forstio/templates.hpp>
+#include <forstio/reduce_templates.hpp>
#include <forstio/string_literal.hpp>
namespace saw {
@@ -322,4 +323,31 @@ template <typename T, size_t N> struct is_primitive<schema::Primitive<T,N>> {
template <typename TI, typename TS> struct is_primitive<schema::MixedPrecision<TI,TS>> {
constexpr static bool value = true;
};
+
+template<typename Iface>
+struct schema_iface_type_group {
+ static_assert(always_false<Iface>, "Expecting an Interface Type");
+
+ using Type = tmpl_group<>;
+};
+
+namespace impl {
+template<typename... Funcs>
+struct schema_func_list_helper {
+ using Type = tmpl_group<>;
+};
+
+template<typename F0, typename... Funcs>
+struct schema_func_list_helper<F0,Funcs...> {
+ using Type = typename tmpl_concat<
+ tmpl_group<typename F0::Request, typename F0::Response>,
+ typename schema_func_list_helper<Funcs...>::Type
+ >::type;
+};
+}
+
+template<typename... Funcs>
+struct schema_iface_type_group<schema::Interface<Funcs...>> {
+ using Type = typename tmpl_reduce<typename impl::schema_func_list_helper<Funcs...>::Type>::type;
+};
} // namespace saw
diff --git a/modules/core/c++/templates.hpp b/modules/core/c++/templates.hpp
index 9f629da..fc9d368 100644
--- a/modules/core/c++/templates.hpp
+++ b/modules/core/c++/templates.hpp
@@ -13,6 +13,9 @@ struct tmpl_group {
static constexpr string_literal name = "tmpl_group";
};
+/**
+ * Concats two tmpl_group into one
+ */
template<typename T, typename U>
struct tmpl_concat;
@@ -21,6 +24,9 @@ struct tmpl_concat<tmpl_group<T...>, tmpl_group<U...>> {
using type = tmpl_group<T..., U...>;
};
+/**
+ * Returns the position of the parameter type in the parameter pack
+ */
template <class T, class... TL> struct parameter_pack_index;
template <class T, class... TL> struct parameter_pack_index<T, T, TL...> {
diff --git a/modules/io-tls/tls.cpp b/modules/io-tls/tls.cpp
index 981aa08..c9c71f4 100644
--- a/modules/io-tls/tls.cpp
+++ b/modules/io-tls/tls.cpp
@@ -292,7 +292,7 @@ conveyor<own<network_address>> tls_network::resolve_address(const std::string &a
return internal.resolve_address(addr, port);
}
-std::optional<own<tls_network>> setup_tls_network(network &network) {
+error_or<own<network<net::Tls>>> setup_tls_network(network &network) {
return std::nullopt;
}
} // namespace saw
diff --git a/modules/io-tls/tls.hpp b/modules/io-tls/tls.hpp
index a04598d..93ec180 100644
--- a/modules/io-tls/tls.hpp
+++ b/modules/io-tls/tls.hpp
@@ -37,6 +37,6 @@ private:
options options_;
};
-std::optional<own<tls_network>> setup_tls_network(network &network);
+error_or<own<network>> setup_tls_network(network &network);
} // namespace saw
diff --git a/modules/io/c++/io.hpp b/modules/io/c++/io.hpp
index 43ef7f0..390ddcc 100644
--- a/modules/io/c++/io.hpp
+++ b/modules/io/c++/io.hpp
@@ -8,6 +8,10 @@
#include <variant>
namespace saw {
+namespace net {
+struct Os {};
+}
+
/**
* Set of error common in io
*/
@@ -166,6 +170,7 @@ public:
network_address::child_variant representation() override { return this; }
};
+template<typename T = net::Os>
class network {
public:
virtual ~network() = default;
@@ -209,7 +214,7 @@ public:
virtual own<input_stream> wrap_input_fd(int fd) = 0;
- virtual network &get_network() = 0;
+ virtual network<net::Os> &get_network() = 0;
};
struct async_io_context {
diff --git a/modules/io/c++/io_unix.cpp b/modules/io/c++/io_unix.cpp
index a715535..73e8e3b 100644
--- a/modules/io/c++/io_unix.cpp
+++ b/modules/io/c++/io_unix.cpp
@@ -430,7 +430,7 @@ public:
size_t unix_address_size() const;
};
-class unix_network final : public network {
+class unix_network final : public network<net::Os> {
private:
unix_event_port &event_port_;
@@ -462,7 +462,7 @@ private:
public:
unix_io_provider(unix_event_port &port_ref, own<event_port> port);
- class network &get_network() override;
+ class network<net::Os> &get_network() override;
own<input_stream> wrap_input_fd(int fd) override;
@@ -895,8 +895,8 @@ own<input_stream> unix_io_provider::wrap_input_fd(int fd) {
return heap<unix_io_stream>(event_port_, fd, 0, EPOLLIN);
}
-class network &unix_io_provider::get_network() {
- return static_cast<class network &>(unix_network_);
+class network<net::Os> &unix_io_provider::get_network() {
+ return static_cast<class network<net::Os> &>(unix_network_);
}
class event_loop &unix_io_provider::event_loop() {
diff --git a/modules/lang/c++/c_common.hpp b/modules/lang/c++/c_common.hpp
index 6999126..968c4c0 100644
--- a/modules/lang/c++/c_common.hpp
+++ b/modules/lang/c++/c_common.hpp
@@ -4,4 +4,53 @@ namespace saw {
namespace lang {
struct RemoteC {};
}
+
+namespace lang_c {
+struct config {
+ std::string prefix;
+};
+
+struct transfer_binding_state {
+ struct info {
+ std::string type;
+ };
+
+ std::map<uint32_t, binding_state::info> hashes;
+
+ struct transpiled_element {
+ uint32_t crc32;
+ std::string header;
+ std::string source;
+ };
+
+ std::vector<transfer_binding_state::transpiled_element> tp_elements;
+
+ error_or<uint64_t> find_id_by_crc32(uint32_t hash){
+ for(uint64_t iter = 0; iter < tp_elements.size(); ++iter){
+ if(tp_elements.at(iter).crc32 == hash){
+ return iter;
+ }
+ }
+
+ return make_error<err::not_found>();
+ }
+
+ error_or<uint64_t> add_tp_element(uint32_t hash){
+ uint64_t id{};
+
+ try {
+ language_binding_state::transpiled_element ele;
+
+ ele.crc32 = hash;
+
+ id = tp_elements.size();
+ tp_elements.emplace_back(std::move(ele));
+ }catch(const std::exception&){
+ return make_error<err::out_of_memory>();
+ }
+
+ return id;
+ }
+};
+}
}
diff --git a/modules/lang/c++/c_language.hpp b/modules/lang/c++/c_language.hpp
index c4b1d48..db3c97e 100644
--- a/modules/lang/c++/c_language.hpp
+++ b/modules/lang/c++/c_language.hpp
@@ -1,7 +1,7 @@
#pragma once
-#include "c_transfer.hpp"
#include "c_helper.hpp"
+#include "c_transfer.hpp"
#include "c_rpc.hpp"
namespace saw {
@@ -12,6 +12,11 @@ public:
std::string prefix;
};
public:
+ error_or<void> generate_transfer(const config& cfg){
+
+ return make_error<err::not_implemented>();
+ }
+
error_or<void> generate_rpc(const config& cfg){
return make_error<err::not_implemented>();
}
diff --git a/modules/lang/c++/c_transfer.hpp b/modules/lang/c++/c_transfer.hpp
index 5de204c..953f732 100644
--- a/modules/lang/c++/c_transfer.hpp
+++ b/modules/lang/c++/c_transfer.hpp
@@ -4,4 +4,43 @@
#include "c_types.hpp"
namespace saw {
+namespace impl {
+template<typename T, typename Enc>
+struct c_transfer_generater;
+
+template<typename T, typename Enc>
+struct c_transfer_generater<T,Enc> {
+public:
+ static error_or<void> apply (const lang_c::config& cfg, lang_c::transfer_binding_state& state){
+
+ return make_error<err::not_implemented>();
+ }
+};
+
+template<typename... TransTypes, typename Enc>
+struct c_transfer_generater<tmpl_group<TransTypes...>, Enc> {
+private:
+ // Not used currently
+ using ReducedTmplGroup = typename tmpl_reduce<tmpl_group<TransTypes...>>::type;
+private:
+ template<uint64_t i>
+ static error_or<void> apply_ele(const lang_c::config& cfg, lang_c::transfer_binding_state& state){
+ if constexpr ( i < sizeof...(TransTypes)){
+ {
+ using pType = typename parameter_pack_type<i, TransTypes...>::type;
+ auto eov = c_transfer_generater<pType, Enc>::apply(cfg,state);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ return apply_ele<i+1u>(cfg,state);
+ }
+ return make_void();
+ }
+public:
+ static error_or<void> apply(const lang_c::config& cfg, lang_c::transfer_binding_state& state){
+ return apply_ele<0u>(cfg, state);
+ }
+};
+}
}
diff --git a/modules/lang/c++/c_types.hpp b/modules/lang/c++/c_types.hpp
index ff3f5a8..16829f4 100644
--- a/modules/lang/c++/c_types.hpp
+++ b/modules/lang/c++/c_types.hpp
@@ -18,6 +18,10 @@ struct c_is_primitive<schema::Primitive<T,N>> {
static constexpr bool value = true;
};
+/**
+ * Returns the string of the name and type of the primitive in C
+ * The name value provides information on how that element should be named.
+ */
template<typename Schema>
struct c_primitive_string {
static_assert(always_false<Schema>, "Not supported");
diff --git a/modules/lang/examples/SConscript b/modules/lang/examples/SConscript
index 99561e7..684d410 100644
--- a/modules/lang/examples/SConscript
+++ b/modules/lang/examples/SConscript
@@ -19,10 +19,10 @@ env.sources += examples_env.sources;
env.headers += examples_env.headers;
objects_static = []
-examples_env.cli_mod = examples_env.Program('#bin/cli_mod_example', ['cli_mod.cpp', env.library_static]);
+examples_env.c_example = examples_env.Program('#bin/c_example', ['c_example.cpp', env.library_static]);
# Set Alias
-env.examples = [examples_env.cli_mod];
+env.examples = [examples_env.c_example];
env.Alias('examples', env.examples);
if env["build_examples"]:
diff --git a/modules/lang/examples/c_example.cpp b/modules/lang/examples/c_example.cpp
new file mode 100644
index 0000000..f15db93
--- /dev/null
+++ b/modules/lang/examples/c_example.cpp
@@ -0,0 +1,17 @@
+#include <forstio/error.hpp>
+
+saw::error_or<void> real_main(int argc, char** argv){
+ using namespace saw;
+ return make_void();
+}
+
+int main(int argc, char** argv){
+ auto eov = real_main(argc, argv);
+ if(eov.is_error()){
+ auto& err = eov.get_error();
+ std::cerr<<"Error: "<<err.get_category()<<" - "<<err.get_message();
+ return err.get_id();
+ }
+
+ return 0;
+}