1 | #include <iostream>
|
---|
2 | #include <string>
|
---|
3 |
|
---|
4 | #include <thrift/protocol/TBinaryProtocol.h>
|
---|
5 | #include <thrift/server/TThreadedServer.h>
|
---|
6 | #include <thrift/transport/TServerSocket.h>
|
---|
7 | #include <thrift/transport/TBufferTransports.h>
|
---|
8 |
|
---|
9 | #include "gen-cpp/myService.h"
|
---|
10 |
|
---|
11 | using namespace std;
|
---|
12 | using namespace boost;
|
---|
13 | using namespace ::apache::thrift;
|
---|
14 | using namespace ::apache::thrift::protocol;
|
---|
15 | using namespace ::apache::thrift::transport;
|
---|
16 | using namespace ::apache::thrift::server;
|
---|
17 |
|
---|
18 | class myService : virtual public myServiceIf {
|
---|
19 | public:
|
---|
20 | myService() {}
|
---|
21 | void answer(std::string& answ, const std::string& question) {
|
---|
22 | // implemented on the client-side only
|
---|
23 | }
|
---|
24 | };
|
---|
25 |
|
---|
26 | class myProcessorFactory : virtual public TProcessorFactory {
|
---|
27 | public:
|
---|
28 | myProcessorFactory() {};
|
---|
29 | shared_ptr<TProcessor> getProcessor(const TConnectionInfo& info) {
|
---|
30 | shared_ptr<myService> service(new myService());
|
---|
31 | shared_ptr<TProcessor> processor(new myServiceProcessor(service));
|
---|
32 | cout << "connection " << endl;
|
---|
33 | return processor;
|
---|
34 | }
|
---|
35 | };
|
---|
36 |
|
---|
37 | int main(int argc, char **argv) {
|
---|
38 | int port = 9090;
|
---|
39 | shared_ptr<TServerSocket> serverTransport(new TServerSocket(port));
|
---|
40 | shared_ptr<myProcessorFactory> processorFactory(new myProcessorFactory());
|
---|
41 | shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
|
---|
42 | shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
|
---|
43 |
|
---|
44 | TThreadedServer server(processorFactory, serverTransport,
|
---|
45 | transportFactory, protocolFactory);
|
---|
46 |
|
---|
47 | server.serve();
|
---|
48 |
|
---|
49 | return 0;
|
---|
50 | }
|
---|
51 |
|
---|