-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathmain_server.cpp
More file actions
executable file
·96 lines (78 loc) · 1.89 KB
/
Copy pathmain_server.cpp
File metadata and controls
executable file
·96 lines (78 loc) · 1.89 KB
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
#include <string>
#include <iostream>
#include "buttonrpc.hpp"
#define buttont_assert(exp) { \
if (!(exp)) {\
std::cout << "ERROR: "; \
std::cout << "function: " << __FUNCTION__ << ", line: " << __LINE__ << std::endl; \
system("pause"); \
}\
}\
// 测试例子
void foo_1() {
}
void foo_2(int arg1) {
buttont_assert(arg1 == 10);
}
int foo_3(int arg1) {
buttont_assert(arg1 == 10);
return arg1 * arg1;
}
int foo_4(int arg1, std::string arg2, int arg3, float arg4) {
buttont_assert(arg1 == 10);
buttont_assert(arg2 == "buttonrpc");
buttont_assert(arg3 == 100);
buttont_assert((arg4 > 10.0) && (arg4 < 11.0));
return arg1 * arg3;
}
class ClassMem
{
public:
int bar(int arg1, std::string arg2, int arg3) {
buttont_assert(arg1 == 10);
buttont_assert(arg2 == "buttonrpc");
buttont_assert(arg3 == 100);
return arg1 * arg3;
}
};
struct PersonInfo
{
int age;
std::string name;
float height;
// must implement
friend Serializer& operator >> (Serializer& in, PersonInfo& d) {
in >> d.age >> d.name >> d.height;
return in;
}
friend Serializer& operator << (Serializer& out, PersonInfo d) {
out << d.age << d.name << d.height;
return out;
}
};
PersonInfo foo_5(PersonInfo d, int weigth)
{
buttont_assert(d.age == 10);
buttont_assert(d.name == "buttonrpc");
buttont_assert(d.height == 170);
PersonInfo ret;
ret.age = d.age + 10;
ret.name = d.name + " is good";
ret.height = d.height + 10;
return ret;
}
int main()
{
buttonrpc server;
server.as_server(5555);
server.bind("foo_1", foo_1);
server.bind("foo_2", foo_2);
server.bind("foo_3", std::function<int(int)>(foo_3));
server.bind("foo_4", foo_4);
server.bind("foo_5", foo_5);
ClassMem s;
server.bind("foo_6", &ClassMem::bar, &s);
std::cout << "run rpc server on: " << 5555 << std::endl;
server.run();
return 0;
}