source: ntrip/trunk/GnssCenter/thrift/test2/server.cpp@ 4942

Last change on this file since 4942 was 4942, checked in by mervart, 11 years ago
File size: 1.8 KB
Line 
1#include <iostream>
2#include <string>
3
4#include <thrift/protocol/TBinaryProtocol.h>
5#include <thrift/server/TSimpleServer.h>
6#include <thrift/transport/TServerSocket.h>
7#include <thrift/transport/TBufferTransports.h>
8
9#include "gen-cpp/myService.h"
10
11using namespace std;
12using namespace boost;
13using namespace ::apache::thrift;
14using namespace ::apache::thrift::protocol;
15using namespace ::apache::thrift::transport;
16using namespace ::apache::thrift::server;
17
18class myServiceHandler : virtual public myServiceIf {
19 public:
20 myServiceHandler() {}
21 void answer(std::string& /* answ */, const std::string& /* question */) {
22 // implemented on the client-side only
23 }
24};
25
26class myServerEventHandler : virtual public TServerEventHandler {
27 public:
28 myServerEventHandler() {};
29 virtual void* createContext(shared_ptr<TProtocol> input,
30 shared_ptr<TProtocol> output) {
31 void* context = TServerEventHandler::createContext(input, output);
32 cout << "createContext " << context << endl;
33
34 string* str = static_cast<string*>(context);
35 cout << "str = " << str << endl;
36
37 return context;
38 }
39};
40
41int main(int argc, char **argv) {
42 int port = 9090;
43 shared_ptr<myServiceHandler> handler(new myServiceHandler());
44 shared_ptr<TProcessor> processor(new myServiceProcessor(handler));
45 shared_ptr<TServerSocket> serverTransport(new TServerSocket(port));
46 shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
47 shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
48
49 TSimpleServer server(processor, serverTransport,
50 transportFactory, protocolFactory);
51
52 shared_ptr<TServerEventHandler> eventHandler(new myServerEventHandler());
53 server.setServerEventHandler(eventHandler);
54
55 server.serve();
56 return 0;
57}
58
Note: See TracBrowser for help on using the repository browser.