-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
61 lines (51 loc) · 1.51 KB
/
Copy pathmain.cpp
File metadata and controls
61 lines (51 loc) · 1.51 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
#include <iostream>
#include <boost/shared_ptr.hpp>
#include <thrift/transport/TSocket.h>
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/protocol/TJSONProtocol.h>
#include "calculator_types.h"
#include "Calculator.h"
using namespace std;
using namespace apache::thrift::transport;
using namespace apache::thrift::protocol;
using namespace foo::bar::baz;
using boost::shared_ptr;
int main(int argc, char** argv)
{
shared_ptr<TSocket> socket(new TSocket("localhost", 9090));
socket->open();
shared_ptr<TBinaryProtocol> inputProtocol(new TBinaryProtocol(socket));
shared_ptr<TJSONProtocol> outputProtocol(new TJSONProtocol(socket));
CalculatorClient client(inputProtocol, outputProtocol);
Operation o;
o.type = OperationType::ADD;
o.op1 = 1;
o.op2 = 1;
cout << client.perform(o) << endl;
o.type = OperationType::SUBTRACT;
o.op1 = 2;
o.op2 = 3;
cout << client.perform(o) << endl;
o.type = OperationType::MULTIPLY;
o.op1 = 5;
o.op2 = 8;
cout << client.perform(o) << endl;
o.type = OperationType::DIVIDE;
o.op1 = 13;
o.op2 = 21;
cout << client.perform(o) << endl;
try {
o.op1 = 34;
o.op2 = 0;
cout << client.perform(o) << endl;
} catch (ArithmeticException& e) {
cerr << e.message << endl;
}
try {
o.type = static_cast<OperationType::type>(4);
cout << client.perform(o) << endl;
} catch (IllegalArgumentException& e) {
cerr << e.message << endl;
}
return 0;
}