From 7611bd2aeeb5c29ccfed6a1e8d5cb0e17b8c6aac Mon Sep 17 00:00:00 2001 From: Claudius 'keldu' Holeksa Date: Mon, 12 Aug 2024 14:37:07 +0200 Subject: wip --- modules/remote/c++/transfer_loopback.hpp | 49 ++++++++++++++++++-- modules/remote/tests/remote_loopback.cpp | 77 ++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 3 deletions(-) (limited to 'modules') diff --git a/modules/remote/c++/transfer_loopback.hpp b/modules/remote/c++/transfer_loopback.hpp index 9e3c7f6..3eb6922 100644 --- a/modules/remote/c++/transfer_loopback.hpp +++ b/modules/remote/c++/transfer_loopback.hpp @@ -54,6 +54,49 @@ public: } return void_t{}; } + + error_or allocate(data::MetaSchema, Encoding> meta, id store_id){ + try{ + auto insert_res = values_.emplace(std::make_pair(store_id.get_value(), data::MetaSchema, Encoding>{std::move(meta)})); + if(!insert_res.second){ + return make_error(); + } + }catch(const std::exception&){ + return make_error(); + } + + return make_void(); + } + + error_or> receive(id store_id){ + auto find_res = values_.find(store_id.get_value()); + if(find_res == values_.end()){ + return make_error(); + } + + auto& dat = find_res->second; + // here + return dat;// boy + } + + error_or erase(id store_id){ + auto erase_res = values_.erase(store_id.get_value()); + if(erase_res == 0u){ + return make_error(); + } + + return make_void(); + } + + error_or>> find(id store_id){ + auto find_res = values_.find(store_id.get_value()); + if(find_res == values_.end()){ + return make_error(); + } + + auto& dat = find_res->second; + return ptr>{dat}; + } }; template @@ -142,7 +185,7 @@ public: if(erase_op == 0u){ return make_error(); } - return void_t{}; + return make_void(); } template @@ -224,7 +267,7 @@ public: * An exception for the Loopback backend. Here we can safely use find from * the client side. */ - error_or>> find(id dat_id){ + error_or>> find(id dat_id){ auto eov = srv_().find(dat_id); if(eov.is_error()){ auto& err = eov.get_error(); @@ -232,7 +275,7 @@ public: } auto val = eov.get_value(); - return {*val}; + return val; } }; diff --git a/modules/remote/tests/remote_loopback.cpp b/modules/remote/tests/remote_loopback.cpp index 6ecf4e0..eca107f 100644 --- a/modules/remote/tests/remote_loopback.cpp +++ b/modules/remote/tests/remote_loopback.cpp @@ -26,6 +26,83 @@ SAW_TEST("Remote Loopback Data"){ remote rmt; + using Schema = sch::Array; + + auto eov = rmt.parse_address(0u); + SAW_EXPECT(eov.is_value(), "Didn't parse correctly"); + auto& addr = eov.get_value(); + + auto eo_srv = rmt.template data_listen(*addr); + SAW_EXPECT(eo_srv.is_value(), std::string{"Couldn't listen: "} + std::string{eo_srv.get_error().get_category()}); + auto& srv = eo_srv.get_value(); + + auto cvr_client = rmt.template data_connect(*addr); + auto eo_client = cvr_client.take(); + SAW_EXPECT(eo_client.is_value(), "Couldn't connect."); + auto& client = eo_client.get_value(); + + data foo{4}; + for(uint64_t i = 0; i < foo.size(); ++i){ + foo.at(i).set(i * 2.0); + } + id sent_id = [&](){ + auto eov = client.send(foo); + SAW_EXPECT(eov.is_value(), "Failed send."); + return eov.get_value(); + }(); + + { + auto conv = client.receive(sent_id); + auto eov = conv.take(); + + SAW_EXPECT(eov.is_value(), "Failed receive."); + // SAW_EXPECT(eov.get_value() == foo, "Wrong received value."); + } + { + auto eov = client.find(sent_id); + SAW_EXPECT(eov.is_value(), "Failed find."); + auto& f_val = eov.get_value(); + // SAW_EXPECT(f_val.is_valid(), "Nullptr in find."); + // SAW_EXPECT(*f_val == foo, "Wrong received value."); + } + { + auto eov = client.erase(sent_id); + SAW_EXPECT(eov.is_value(), "Failed erase."); + } + { + auto conv = client.receive(sent_id); + auto eov = conv.take(); + SAW_EXPECT(!eov.is_value(), "Failed receive. Value should already be erased."); + } + + id alloc_id = [&](){ + auto eov = client.allocate(data>{{4}}); + SAW_EXPECT(eov.is_value(), "Failed send."); + return eov.get_value(); + }(); + { + auto eov = client.find(alloc_id); + SAW_EXPECT(eov.is_value(), "Failed find."); + auto& f_val = eov.get_value(); + // SAW_EXPECT(f_val.is_valid(), "Nullptr in find."); + // f_val->set(5u); + } + { + auto conv = client.receive(alloc_id); + auto eov = conv.take(); + SAW_EXPECT(eov.is_value(), "Failed receive."); + SAW_EXPECT(eov.get_value().size() == 4u, "Wrong received value."); + } +} + +SAW_TEST("Remote Loopback Grouped Data"){ + using namespace saw; + + event_loop loop; + wait_scope wait{loop}; + + remote rmt; + auto eov = rmt.parse_address(0u); SAW_EXPECT(eov.is_value(), "Didn't parse correctly"); auto& addr = eov.get_value(); -- cgit v1.2.3