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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
20 #ifndef _THRIFT_TASYNC_QTCP_SERVER_H_
21 #define _THRIFT_TASYNC_QTCP_SERVER_H_
31 class TProtocolFactory
;
34 } // apache::thrift::protocol
40 class TAsyncProcessor
;
43 * Server that uses Qt to listen for connections.
44 * Simply give it a QTcpServer that is listening, along with an async
45 * processor and a protocol factory, and then run the Qt event loop.
47 class TQTcpServer
: public QObject
{
50 TQTcpServer(std::shared_ptr
<QTcpServer
> server
,
51 std::shared_ptr
<TAsyncProcessor
> processor
,
52 std::shared_ptr
<apache::thrift::protocol::TProtocolFactory
> protocolFactory
,
53 QObject
* parent
= nullptr);
54 ~TQTcpServer() override
;
57 void processIncoming();
60 void deleteConnectionContext(QTcpSocket
* connection
);
63 Q_DISABLE_COPY(TQTcpServer
)
65 struct ConnectionContext
;
67 void scheduleDeleteConnectionContext(QTcpSocket
* connection
);
68 void finish(std::shared_ptr
<ConnectionContext
> ctx
, bool healthy
);
70 std::shared_ptr
<QTcpServer
> server_
;
71 std::shared_ptr
<TAsyncProcessor
> processor_
;
72 std::shared_ptr
<apache::thrift::protocol::TProtocolFactory
> pfact_
;
74 typedef std::map
<QTcpSocket
*, std::shared_ptr
<ConnectionContext
> > ConnectionContextMap
;
75 ConnectionContextMap ctxMap_
;
79 } // apache::thrift::async
81 #endif // #ifndef _THRIFT_TASYNC_QTCP_SERVER_H_