1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#pragma once
#include "common.hpp"
#include "data.hpp"
#include "device.hpp"
#include <forstio/error.hpp>
#include <forstio/reduce_templates.hpp>
#include <forstio/remote/transfer.hpp>
#include <forstio/codec/schema_hash.hpp>
namespace saw {
template<typename Schema, typename Encoding>
class data_server<Schema, Encoding, rmt::Hip> final : public i_data_server<rmt::Hip> {
private:
our<device<rmt::Hip>> device_;
std::map<uint64_t, data<Schema, encode::Hip<Encoding>>> values_;
public:
static constexpr std::pair<uint32_t,uint32_t> class_id{schema_hash<Schema>::apply(), schema_hash<Encoding>::apply()};
std::pair<uint32_t,uint32_t> get_class_id() const override {
return class_id;
}
data_server(our<device<rmt::Hip>> device__):
device_{std::move(device__)}
{}
error_or<void> send(data<Schema,Encoding>& dat, id<Schema> store_id){
data<Schema, encode::Hip<Encoding>> hip_dat;
{
auto eov = device_->copy_to_device(dat, hip_dat);
if(eov.is_error()){
return eov;
}
}
auto ins = values_.emplace(std::make_pair(store_id.get_value(), hip_dat));
if(!ins.second){
return make_error<err::already_exists>();
}
return make_void();
}
error_or<void> allocate(const data<typename meta_schema<Schema>::MetaSchema, Encoding>& dat, id<Schema> store_id){
return make_error<err::not_implemented>("Allocate not implemented");
return make_void();
}
error_or<data<Schema,Encoding>> receive(id<Schema> store_id){
return make_error<err::not_implemented>("Receive not implemented");
}
error_or<void> erase(id<Schema> store_id){
return make_error<err::not_implemented>("Erase not implemented");
return make_void();
}
error_or<ptr<data<Schema, encode::Hip<Encoding>>>> find(id<Schema> store_id){
auto find_res = values_.find(store_id.get_value());
if(find_res == values_.end()){
return make_error<err::not_found>();
}
return {(find_res.second)};
}
};
}
|