-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.h
70 lines (63 loc) · 1.78 KB
/
process.h
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
#ifndef PROCESS_H
#define PROCESS_H
#include "version.h"
#include <functional>
#include "commSingleton.h"
class Process
{
using comm_func = std::function<Response(Request)>;
public:
Process(){
std::cout << __PRETTY_FUNCTION__ << std::endl;
}
~Process(){
std::cout << __PRETTY_FUNCTION__ << std::endl;
// CommSingleton::deleteCommSingleton();
}
//version-4
#if VERSION_4
Response sendData(const Data& data, CommWrapper& comm){
std::cout << __PRETTY_FUNCTION__ << std::endl;
Request req;
// transfer data into the request
req.setData(data);
return comm(std::move(req));
}
// compatiable with oldest version
Response sendData(const Data& data){
std::cout << __PRETTY_FUNCTION__ << std::endl;
return sendData(data, getDefaultComm() );
}
#endif //VERSION_4
// version-3
#if VERSION_3
Response sendData(const Data& data, comm_func comm = std::ref(Service::comm)){
std::cout << __PRETTY_FUNCTION__ << std::endl;
Request req;
// transfer data into the request
req.setData(data);
return comm(std::move(req));
}
#endif
#if VERSION_2
// version-2
Response sendData(const Data& data, CommWrapper& comm = Service::comm){
std::cout << __PRETTY_FUNCTION__ << std::endl;
Request req;
// transfer data into the request
req.setData(data);
return comm.send(req);
}
#endif // VERSION_2
// oldest version
#if VERSION_1
Response sendData(const Data& data){
std::cout << __PRETTY_FUNCTION__ << std::endl;
Request req;
// transfer data into the request
req.setData(data);
return CommSingleton::instance()->send(req);// hidden dependency
}
#endif
};
#endif // PROCESS_H