Roger Meier | 86e8986 | 2012-02-10 19:53:20 +0000 | [diff] [blame] | 1 | #ifndef _THRIFT_TASYNC_QTCP_SERVER_H_ |
| 2 | #define _THRIFT_TASYNC_QTCP_SERVER_H_ |
| 3 | |
| 4 | #include <QObject> |
| 5 | #include <QTcpServer> |
| 6 | |
| 7 | #include <boost/shared_ptr.hpp> |
| 8 | |
Roger Meier | 86e8986 | 2012-02-10 19:53:20 +0000 | [diff] [blame] | 9 | namespace apache { namespace thrift { namespace protocol { |
Roger Meier | 86e8986 | 2012-02-10 19:53:20 +0000 | [diff] [blame] | 10 | class TProtocolFactory; |
| 11 | }}} // apache::thrift::protocol |
| 12 | |
| 13 | namespace apache { namespace thrift { namespace async { |
| 14 | |
| 15 | class TAsyncProcessor; |
| 16 | |
Roger Meier | 19a9915 | 2012-02-11 19:09:30 +0000 | [diff] [blame^] | 17 | /** |
| 18 | * Server that uses Qt to listen for connections. |
| 19 | * Simply give it a QTcpServer that is listening, along with an async |
| 20 | * processor and a protocol factory, and then run the Qt event loop. |
| 21 | */ |
Roger Meier | 86e8986 | 2012-02-10 19:53:20 +0000 | [diff] [blame] | 22 | class TQTcpServer : public QObject { |
| 23 | Q_OBJECT |
| 24 | public: |
| 25 | TQTcpServer(boost::shared_ptr<QTcpServer> server, |
| 26 | boost::shared_ptr<TAsyncProcessor> processor, |
| 27 | boost::shared_ptr<apache::thrift::protocol::TProtocolFactory> protocolFactory, |
| 28 | QT_PREPEND_NAMESPACE(QObject)* parent = NULL); |
| 29 | virtual ~TQTcpServer(); |
| 30 | |
| 31 | private Q_SLOTS: |
| 32 | void processIncoming(); |
| 33 | void beginDecode(); |
| 34 | void socketClosed(); |
| 35 | |
| 36 | private: |
Roger Meier | 19a9915 | 2012-02-11 19:09:30 +0000 | [diff] [blame^] | 37 | TQTcpServer(const TQTcpServer&); |
| 38 | TQTcpServer& operator=(const TQTcpServer&); |
| 39 | |
Roger Meier | 86e8986 | 2012-02-10 19:53:20 +0000 | [diff] [blame] | 40 | class ConnectionContext; |
| 41 | |
| 42 | void finish(boost::shared_ptr<ConnectionContext> ctx, bool healthy); |
| 43 | |
| 44 | boost::shared_ptr<QTcpServer> server_; |
| 45 | boost::shared_ptr<TAsyncProcessor> processor_; |
| 46 | boost::shared_ptr<apache::thrift::protocol::TProtocolFactory> pfact_; |
| 47 | |
| 48 | std::map<QT_PREPEND_NAMESPACE(QTcpSocket)*, boost::shared_ptr<ConnectionContext> > ctxMap_; |
| 49 | }; |
| 50 | |
| 51 | }}} // apache::thrift::async |
| 52 | |
| 53 | #endif // #ifndef _THRIFT_TASYNC_QTCP_SERVER_H_ |