forked from solidoss/solidframe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathipc_file_messages.hpp
114 lines (87 loc) · 2.92 KB
/
ipc_file_messages.hpp
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#ifndef TUTORIAL_IPC_REQUEST_MESSAGES_HPP
#define TUTORIAL_IPC_REQUEST_MESSAGES_HPP
#include "solid/frame/ipc/ipcmessage.hpp"
#include "solid/frame/ipc/ipccontext.hpp"
#include "solid/frame/ipc/ipcprotocol_serialization_v1.hpp"
#include <vector>
#include <deque>
#include <fstream>
#include <iostream>
namespace ipc_file{
struct ListRequest: solid::frame::ipc::Message{
std::string path;
ListRequest(){}
ListRequest(std::string && _path): path(std::move(_path)){}
template <class S>
void serialize(S &_s, solid::frame::ipc::ConnectionContext &_rctx){
_s.push(path, "path");
}
};
struct ListResponse: solid::frame::ipc::Message{
std::string path;
std::deque<std::pair<std::string, uint8_t> > node_dq;
ListResponse(){}
ListResponse(const ListRequest &_rmsg):solid::frame::ipc::Message(_rmsg), path(_rmsg.path){}
template <class S>
void serialize(S &_s, solid::frame::ipc::ConnectionContext &_rctx){
_s.pushContainer(node_dq, "node_dq");
}
};
struct FileRequest: solid::frame::ipc::Message{
std::string remote_path;
std::string local_path;
FileRequest(){}
FileRequest(
std::string && _remote_path, std::string && _local_path
): remote_path(std::move(_remote_path)), local_path(std::move(_local_path)){}
template <class S>
void serialize(S &_s, solid::frame::ipc::ConnectionContext &_rctx){
_s.push(remote_path, "remote_path");
_s.push(local_path, "local_path");
}
};
struct FileResponse: solid::frame::ipc::Message{
std::string remote_path;
std::string local_path;
std::fstream fs;
int64_t remote_file_size;
FileResponse(){}
FileResponse(
const FileRequest &_rmsg
): solid::frame::ipc::Message(_rmsg), remote_path(_rmsg.remote_path),
local_path(_rmsg.local_path), remote_file_size(solid::InvalidSize()){}
template <class S>
void serialize(S &_s, solid::frame::ipc::ConnectionContext &_rctx){
_s.pushCall(
[this](S &_rs, solid::frame::ipc::ConnectionContext &_rctx, uint64_t _val, solid::ErrorConditionT &_rerr){
if(S::IsSerializer){
fs.open(remote_path.c_str());
_rs.pushStream(static_cast<std::istream*>(&fs), "fs");
if(fs){
std::streampos pos = fs.tellg();
fs.seekg(0, fs.end);
std::streampos endpos = fs.tellg();
fs.seekg(pos);
remote_file_size = endpos;
}else{
remote_file_size = solid::InvalidSize();
}
_rs.push(remote_file_size, "remote_file_size");
}else{
if(remote_file_size != solid::InvalidSize()){
fs.open(local_path.c_str(), std::fstream::out | std::fstream::binary);
}
_rs.pushStream(static_cast<std::ostream*>(&fs), "fs");
}
}, 0, "reinit"
);
if(not S::IsSerializer){
_s.push(remote_file_size, "remote_file_size");
}
_s.push(remote_path, "remote_path");
_s.push(local_path, "local_path");
}
};
using ProtoSpecT = solid::frame::ipc::serialization_v1::ProtoSpec<0, ListRequest, ListResponse, FileRequest, FileResponse>;
}//namespace ipc_file
#endif