Changeset 4943 in ntrip for trunk/GnssCenter/thrift
- Timestamp:
- Feb 23, 2013, 3:41:59 PM (12 years ago)
- Location:
- trunk/GnssCenter/thrift/test2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GnssCenter/thrift/test2/Makefile
r4942 r4943 24 24 25 25 server: server.o $(GEN_OBJ) 26 $(CXX) $^ -o $@ -L$(LIB_DIR) -lthrift 26 $(CXX) $^ -o $@ -L$(LIB_DIR) -lthrift 27 27 28 28 client: client.o $(GEN_OBJ) 29 $(CXX) $^ -o $@ -L$(LIB_DIR) -lthrift 29 $(CXX) $^ -o $@ -L$(LIB_DIR) -lthrift 30 30 31 31 clean: -
trunk/GnssCenter/thrift/test2/server.cpp
r4942 r4943 3 3 4 4 #include <thrift/protocol/TBinaryProtocol.h> 5 #include <thrift/server/T SimpleServer.h>5 #include <thrift/server/TThreadedServer.h> 6 6 #include <thrift/transport/TServerSocket.h> 7 7 #include <thrift/transport/TBufferTransports.h> … … 19 19 public: 20 20 myServiceHandler() {} 21 void answer(std::string& /* answ */, const std::string& /* question */) {21 void answer(std::string& answ, const std::string& question) { 22 22 // implemented on the client-side only 23 23 } 24 24 }; 25 25 26 class my ServerEventHandler : virtual public TServerEventHandler{26 class myProcessorFactory : virtual public TProcessorFactory { 27 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; 28 myProcessorFactory() {}; 29 shared_ptr<TProcessor> getProcessor(const TConnectionInfo& info) { 30 shared_ptr<myServiceHandler> handler(new myServiceHandler()); 31 shared_ptr<TProcessor> processor(new myServiceProcessor(handler)); 32 return processor; 38 33 } 39 34 }; … … 41 36 int main(int argc, char **argv) { 42 37 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()); 38 shared_ptr<TServerSocket> serverTransport(new TServerSocket(port)); 39 shared_ptr<myProcessorFactory> processorFactory(new myProcessorFactory()); 40 shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory()); 41 shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory()); 48 42 49 TSimpleServer server(processor, serverTransport, 50 transportFactory, protocolFactory); 51 52 shared_ptr<TServerEventHandler> eventHandler(new myServerEventHandler()); 53 server.setServerEventHandler(eventHandler); 43 TThreadedServer server(processorFactory, serverTransport, 44 transportFactory, protocolFactory); 54 45 55 46 server.serve(); 47 56 48 return 0; 57 49 }
Note:
See TracChangeset
for help on using the changeset viewer.