diff options
author | Claudius "keldu" Holeksa <mail@keldu.de> | 2024-07-21 22:42:22 +0200 |
---|---|---|
committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2024-07-21 22:42:22 +0200 |
commit | e5bf2f231e5ebaa13baf0742149d71fc8777e823 (patch) | |
tree | 24a7fd45869b86358c9424c438889e7c98e4a203 /modules/remote | |
parent | 498acb5ee9db90aaf01049ae44e098169219398d (diff) |
Added preallocation to remote
Diffstat (limited to 'modules/remote')
-rw-r--r-- | modules/remote/c++/transfer_loopback.hpp | 20 | ||||
-rw-r--r-- | modules/remote/tests/remote_loopback.cpp | 13 |
2 files changed, 30 insertions, 3 deletions
diff --git a/modules/remote/c++/transfer_loopback.hpp b/modules/remote/c++/transfer_loopback.hpp index 9f6dddd..abea83f 100644 --- a/modules/remote/c++/transfer_loopback.hpp +++ b/modules/remote/c++/transfer_loopback.hpp @@ -36,11 +36,10 @@ public: * */ template<typename Sch> - error_or<void> allocate(data<typename meta_schema<Sch>::type, Encoding> meta, id<Sch> store_id){ + error_or<void> allocate(data<typename meta_schema<Sch>::MetaSchema, Encoding> meta, id<Sch> store_id){ auto& vals = std::get<std::unordered_map<uint64_t, data<Sch,Encoding>>>(values_); - try { - auto insert_res = vals.emplace(std::make_pair(store_id.get_value(), {std::move(meta)})); + auto insert_res = vals.emplace(std::make_pair(store_id.get_value(), data<typename meta_schema<Sch>::MetaSchema, Encoding>{std::move(meta)})); if(!insert_res.second){ return make_error<err::already_exists>(); } @@ -125,6 +124,21 @@ public: ++next_id_; return dat_id; } + + /** + * Preallocate data + */ + template<typename Sch> + error_or<id<Sch>> allocate(const data<typename meta_schema<Sch>::MetaSchema, Encoding>& meta){ + id<Sch> dat_id{next_id_}; + auto eov = srv_->allocate(meta, dat_id); + if(eov.is_error()){ + auto& err = eov.get_error(); + return std::move(err); + } + ++next_id_; + return dat_id; + } /** * Receive data diff --git a/modules/remote/tests/remote_loopback.cpp b/modules/remote/tests/remote_loopback.cpp index 2895ee7..e78f646 100644 --- a/modules/remote/tests/remote_loopback.cpp +++ b/modules/remote/tests/remote_loopback.cpp @@ -69,5 +69,18 @@ SAW_TEST("Remote Loopback Data"){ auto eov = conv.take(); SAW_EXPECT(!eov.is_value(), "Failed receive. Value should already be erased."); } + + id<sch::UInt64> alloc_id = [&](){ + auto eov = client.allocate<sch::UInt64>(data<sch::Void>{}); + 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, "Nullptr in find."); + f_val->set(5u); + } } } |