diff options
Diffstat (limited to 'modules/remote-filesystem/examples')
-rw-r--r-- | modules/remote-filesystem/examples/SConscript | 10 | ||||
-rw-r--r-- | modules/remote-filesystem/examples/remote_write_file.cpp | 58 |
2 files changed, 67 insertions, 1 deletions
diff --git a/modules/remote-filesystem/examples/SConscript b/modules/remote-filesystem/examples/SConscript index df8e0c6..3e039b7 100644 --- a/modules/remote-filesystem/examples/SConscript +++ b/modules/remote-filesystem/examples/SConscript @@ -18,11 +18,19 @@ examples_env.headers = sorted(glob.glob(dir_path + "/*.hpp")) env.sources += examples_env.sources; env.headers += examples_env.headers; -objects_static = [] +examples_objects = []; +examples_env.add_source_files(examples_objects, ['remote_write_file.cpp'], shared=False); +examples_env.remote_file_write = examples_env.Program('#bin/remote_write_file', [env.library_static, examples_objects]); + +examples_objects = []; +examples_env.add_source_files(examples_objects, ['remote_read_file.cpp'], shared=False); +examples_env.remote_file_read = examples_env.Program('#bin/remote_read_file', [env.library_static, examples_objects]); + # Set Alias env.examples = [ #, examples_env.echo_server + examples_env.remote_file_write ]; env.Alias('examples', env.examples); diff --git a/modules/remote-filesystem/examples/remote_write_file.cpp b/modules/remote-filesystem/examples/remote_write_file.cpp new file mode 100644 index 0000000..938b140 --- /dev/null +++ b/modules/remote-filesystem/examples/remote_write_file.cpp @@ -0,0 +1,58 @@ +#include "../c++/transfer.hpp" + +#include <forstio/codec/simple.hpp> + +#include <iostream> + +namespace sch { +using namespace saw::schema; + +using Foo = Struct< + Member<String, "a">, + Member<Int64, "b"> +>; +} + +int main(){ + using namespace saw; + + remote<rmt::File> file_remote; + + auto eo_addr = file_remote.parse_address("./example_file"); + if(eo_addr.is_error()){ + return 1; + } + auto& addr = eo_addr.get_value(); + + auto eo_dat_srv = file_remote.template data_listen<sch::Foo,encode::KelSimple>({*addr}); + if(eo_dat_srv.is_error()){ + return 2; + } + auto& dat_srv = eo_dat_srv.get_value(); + + std::string a = "blafoobla"; + int64_t b = 42; + + { + data<sch::Foo> nat_foo; + nat_foo.template get<"a">().set(a); + nat_foo.template get<"b">().set(b); + + data<sch::Foo, encode::KelSimple> smp_foo; + + codec<sch::Foo, encode::KelSimple> smp_cod; + auto eov = smp_cod.encode(nat_foo,smp_foo); + if(eov.is_error()){ + return 3; + } + + id<sch::Foo> foo_id{0u}; + auto eo_send = dat_srv->send(smp_foo, foo_id); + if(eo_send.is_error()){ + auto& err = eo_send.get_error(); + std::cerr<<"Error: "<<err.get_category()<<" - "<<err.get_message()<<std::endl; + return 4; + } + } + +} |