]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/cpp/src/thrift/qt/TQTcpServer.h
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / lib / cpp / src / thrift / qt / TQTcpServer.h
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
20 #ifndef _THRIFT_TASYNC_QTCP_SERVER_H_
21 #define _THRIFT_TASYNC_QTCP_SERVER_H_
22
23 #include <QObject>
24 #include <QTcpServer>
25
26 #include <memory>
27
28 namespace apache {
29 namespace thrift {
30 namespace protocol {
31 class TProtocolFactory;
32 }
33 }
34 } // apache::thrift::protocol
35
36 namespace apache {
37 namespace thrift {
38 namespace async {
39
40 class TAsyncProcessor;
41
42 /**
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.
46 */
47 class TQTcpServer : public QObject {
48 Q_OBJECT
49 public:
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;
55
56 private Q_SLOTS:
57 void processIncoming();
58 void beginDecode();
59 void socketClosed();
60 void deleteConnectionContext(QTcpSocket* connection);
61
62 private:
63 Q_DISABLE_COPY(TQTcpServer)
64
65 struct ConnectionContext;
66
67 void scheduleDeleteConnectionContext(QTcpSocket* connection);
68 void finish(std::shared_ptr<ConnectionContext> ctx, bool healthy);
69
70 std::shared_ptr<QTcpServer> server_;
71 std::shared_ptr<TAsyncProcessor> processor_;
72 std::shared_ptr<apache::thrift::protocol::TProtocolFactory> pfact_;
73
74 typedef std::map<QTcpSocket*, std::shared_ptr<ConnectionContext> > ConnectionContextMap;
75 ConnectionContextMap ctxMap_;
76 };
77 }
78 }
79 } // apache::thrift::async
80
81 #endif // #ifndef _THRIFT_TASYNC_QTCP_SERVER_H_