Ignore:
Timestamp:
Feb 23, 2013, 3:41:59 PM (9 years ago)
Author:
mervart
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GnssCenter/thrift/test2/server.cpp

    r4942 r4943  
    33
    44#include <thrift/protocol/TBinaryProtocol.h>
    5 #include <thrift/server/TSimpleServer.h>
     5#include <thrift/server/TThreadedServer.h>
    66#include <thrift/transport/TServerSocket.h>
    77#include <thrift/transport/TBufferTransports.h>
     
    1919 public:
    2020  myServiceHandler() {}
    21   void answer(std::string& /* answ */, const std::string& /* question */) {
     21  void answer(std::string& answ, const std::string& question) {
    2222    // implemented on the client-side only
    2323  }
    2424};
    2525
    26 class myServerEventHandler : virtual public TServerEventHandler {
     26class myProcessorFactory : virtual public TProcessorFactory {
    2727 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;
    3833  }
    3934};
     
    4136int main(int argc, char **argv) {
    4237  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());
    4842
    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);
    5445
    5546  server.serve();
     47
    5648  return 0;
    5749}
Note: See TracChangeset for help on using the changeset viewer.