blob: 12a450f1145f06452f3b837b48264676f3e6b794 [file] [log] [blame]
Roger Meier7699b402012-04-08 18:18:44 +00001/*
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 Meier86e89862012-02-10 19:53:20 +000020#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 Meier86e89862012-02-10 19:53:20 +000028namespace apache { namespace thrift { namespace protocol {
Roger Meier86e89862012-02-10 19:53:20 +000029class TProtocolFactory;
30}}} // apache::thrift::protocol
31
32namespace apache { namespace thrift { namespace async {
33
34class TAsyncProcessor;
35
Roger Meier19a99152012-02-11 19:09:30 +000036/**
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 Meier86e89862012-02-10 19:53:20 +000041class 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 Meier19a99152012-02-11 19:09:30 +000056 TQTcpServer(const TQTcpServer&);
57 TQTcpServer& operator=(const TQTcpServer&);
58
Roger Meier86e89862012-02-10 19:53:20 +000059 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_