-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththrift_client.cpp
42 lines (37 loc) · 1.02 KB
/
thrift_client.cpp
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
#include "thrift_client.h"
#include <iostream>
using namespace facebook::thrift;
using namespace facebook::thrift::protocol;
using namespace facebook::thrift::transport;
using namespace boost;
using namespace simple;
using namespace std;
Thrift_Client::Thrift_Client() {
shared_ptr<TTransport> socket(new TSocket("localhost", 9091));
shared_ptr<TTransport> transport(new TBufferedTransport(socket));
shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
client = new MemoryHierarchyClient(protocol);
cout << "Thrift client invoked!" << endl;
try {
transport->open();
cout << "Transport opened" << endl;
}
catch (TException &tx) {
printf("Exception triggered\n");
}
}
Thrift_Client::~Thrift_Client() {
}
void Thrift_Client::step() {
}
void Thrift_Client::operate(int cpuid, int type, int addr) {
Work work;
work.cpuid = cpuid;
work.type = (MemOp)type;
work.addr = addr;
try {
client->operate(work);
} catch (TException &tx) {
cout << "InvalidOperation" << endl;
}
}