#include #include #include #include #include #include #include "gen-cpp/myService.h" using namespace std; using namespace boost; using namespace ::apache::thrift; using namespace ::apache::thrift::protocol; using namespace ::apache::thrift::transport; using namespace ::apache::thrift::server; class myServiceHandler : virtual public myServiceIf { public: myServiceHandler() {} void answer(std::string& /* answ */, const std::string& /* question */) { // implemented on the client-side only } }; class myServerEventHandler : virtual public TServerEventHandler { public: myServerEventHandler() {}; virtual void* createContext(shared_ptr input, shared_ptr output) { void* context = TServerEventHandler::createContext(input, output); cout << "createContext " << context << endl; string* str = static_cast(context); cout << "str = " << str << endl; return context; } }; int main(int argc, char **argv) { int port = 9090; shared_ptr handler(new myServiceHandler()); shared_ptr processor(new myServiceProcessor(handler)); shared_ptr serverTransport(new TServerSocket(port)); shared_ptr transportFactory(new TBufferedTransportFactory()); shared_ptr protocolFactory(new TBinaryProtocolFactory()); TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory); shared_ptr eventHandler(new myServerEventHandler()); server.setServerEventHandler(eventHandler); server.serve(); return 0; }