Roger Meier | 7699b40 | 2012-04-08 18:18:44 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | |
Roger Meier | 86e8986 | 2012-02-10 19:53:20 +0000 | [diff] [blame] | 20 | #ifndef _THRIFT_TASYNC_QTCP_SERVER_H_ |
| 21 | #define _THRIFT_TASYNC_QTCP_SERVER_H_ |
| 22 | |
| 23 | #include <QObject> |
| 24 | #include <QTcpServer> |
| 25 | |
| 26 | #include <boost/shared_ptr.hpp> |
| 27 | |
Roger Meier | 86e8986 | 2012-02-10 19:53:20 +0000 | [diff] [blame] | 28 | namespace apache { namespace thrift { namespace protocol { |
Roger Meier | 86e8986 | 2012-02-10 19:53:20 +0000 | [diff] [blame] | 29 | class TProtocolFactory; |
| 30 | }}} // apache::thrift::protocol |
| 31 | |
| 32 | namespace apache { namespace thrift { namespace async { |
| 33 | |
| 34 | class TAsyncProcessor; |
| 35 | |
Roger Meier | 19a9915 | 2012-02-11 19:09:30 +0000 | [diff] [blame] | 36 | /** |
| 37 | * Server that uses Qt to listen for connections. |
| 38 | * Simply give it a QTcpServer that is listening, along with an async |
| 39 | * processor and a protocol factory, and then run the Qt event loop. |
| 40 | */ |
Roger Meier | 86e8986 | 2012-02-10 19:53:20 +0000 | [diff] [blame] | 41 | class TQTcpServer : public QObject { |
| 42 | Q_OBJECT |
| 43 | public: |
| 44 | TQTcpServer(boost::shared_ptr<QTcpServer> server, |
| 45 | boost::shared_ptr<TAsyncProcessor> processor, |
| 46 | boost::shared_ptr<apache::thrift::protocol::TProtocolFactory> protocolFactory, |
| 47 | QT_PREPEND_NAMESPACE(QObject)* parent = NULL); |
| 48 | virtual ~TQTcpServer(); |
| 49 | |
| 50 | private Q_SLOTS: |
| 51 | void processIncoming(); |
| 52 | void beginDecode(); |
| 53 | void socketClosed(); |
| 54 | |
| 55 | private: |
Roger Meier | 19a9915 | 2012-02-11 19:09:30 +0000 | [diff] [blame] | 56 | TQTcpServer(const TQTcpServer&); |
| 57 | TQTcpServer& operator=(const TQTcpServer&); |
| 58 | |
Roger Meier | 86e8986 | 2012-02-10 19:53:20 +0000 | [diff] [blame] | 59 | class ConnectionContext; |
| 60 | |
| 61 | void finish(boost::shared_ptr<ConnectionContext> ctx, bool healthy); |
| 62 | |
| 63 | boost::shared_ptr<QTcpServer> server_; |
| 64 | boost::shared_ptr<TAsyncProcessor> processor_; |
| 65 | boost::shared_ptr<apache::thrift::protocol::TProtocolFactory> pfact_; |
| 66 | |
| 67 | std::map<QT_PREPEND_NAMESPACE(QTcpSocket)*, boost::shared_ptr<ConnectionContext> > ctxMap_; |
| 68 | }; |
| 69 | |
| 70 | }}} // apache::thrift::async |
| 71 | |
| 72 | #endif // #ifndef _THRIFT_TASYNC_QTCP_SERVER_H_ |