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

Last change on this file since 4945 was 4945, checked in by mervart, 11 years ago
File size: 1.9 KB
Line 
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
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 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
26class t_connection {
27 public:
28 shared_ptr<myService> _service;
29 shared_ptr<TProcessor> _processor;
30 shared_ptr<TProtocol> _protocolInp;
31 shared_ptr<TProtocol> _protocolOut;
32 shared_ptr<TTransport> _transport;
33};
34
35class myProcessorFactory : public TProcessorFactory {
36 public:
37 myProcessorFactory() {};
38 shared_ptr<TProcessor> getProcessor(const TConnectionInfo& info) {
39 shared_ptr<myService> service(new myService());
40 shared_ptr<TProcessor> processor(new myServiceProcessor(service));
41 cout << "connection " << endl;
42
43 t_connection connection;
44 connection._service = service;
45 connection._processor = processor;
46 connection._protocolInp = info.input;
47 connection._protocolOut = info.output;
48 connection._transport = info.transport;
49
50 return processor;
51 }
52};
53
54int main(int argc, char **argv) {
55 int port = 9090;
56 shared_ptr<TServerSocket> serverTransport(new TServerSocket(port));
57 shared_ptr<myProcessorFactory> processorFactory(new myProcessorFactory());
58 shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
59 shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
60
61 TThreadedServer server(processorFactory, serverTransport,
62 transportFactory, protocolFactory);
63
64 server.serve();
65
66 return 0;
67}
68
Note: See TracBrowser for help on using the repository browser.