// Copyright (c) 2006- Facebook // Distributed under the Thrift Software License // // See accompanying file LICENSE or visit the Thrift site at: // http://developers.facebook.com/thrift/ #ifndef THRIFT_TASYNCPROCESSOR_H #define THRIFT_TASYNCPROCESSOR_H 1 #include #include #include "thrift/lib/cpp/TProcessor.h" #include "thrift/lib/cpp/server/TConnectionContext.h" #include "thrift/lib/cpp/protocol/TProtocol.h" using apache::thrift::server::TConnectionContext; namespace apache { namespace thrift { namespace async { /** * Async version of a TProcessor. It is not expected to complete by the time * the call to process returns. Instead, it calls a cob to signal completion. * * @author David Reiss */ class TEventServer; // forward declaration class TAsyncProcessor : public TProcessorBase { public: virtual ~TAsyncProcessor() {} virtual void process(std::tr1::function _return, boost::shared_ptr in, boost::shared_ptr out, TConnectionContext* context = NULL) = 0; void process(std::tr1::function _return, boost::shared_ptr io) { return process(_return, io, io); } const TEventServer* getAsyncServer() { return asyncServer_; } protected: TAsyncProcessor() {} const TEventServer* asyncServer_; private: friend class TEventServer; void setAsyncServer(const TEventServer* server) { asyncServer_ = server; } }; class TAsyncProcessorFactory { public: virtual ~TAsyncProcessorFactory() {} /** * Get the TAsyncProcessor to use for a particular connection. */ virtual boost::shared_ptr getProcessor( server::TConnectionContext* ctx) = 0; }; class TAsyncSingletonProcessorFactory : public TAsyncProcessorFactory { public: explicit TAsyncSingletonProcessorFactory( const boost::shared_ptr& processor) : processor_(processor) {} boost::shared_ptr getProcessor(server::TConnectionContext*) { return processor_; } private: boost::shared_ptr processor_; }; }}} // apache::thrift::async // XXX I'm lazy for now namespace apache { namespace thrift { using apache::thrift::async::TAsyncProcessor; }} #endif // #ifndef THRIFT_TASYNCPROCESSOR_H