Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-17 08:35:02

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one
0003  * or more contributor license agreements. See the NOTICE file
0004  * distributed with this work for additional information
0005  * regarding copyright ownership. The ASF licenses this file
0006  * to you under the Apache License, Version 2.0 (the
0007  * "License"); you may not use this file except in compliance
0008  * with the License. You may obtain a copy of the License at
0009  *
0010  *   http://www.apache.org/licenses/LICENSE-2.0
0011  *
0012  * Unless required by applicable law or agreed to in writing,
0013  * software distributed under the License is distributed on an
0014  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0015  * KIND, either express or implied. See the License for the
0016  * specific language governing permissions and limitations
0017  * under the License.
0018  */
0019 
0020 #ifndef _THRIFT_TASYNC_QTCP_SERVER_H_
0021 #define _THRIFT_TASYNC_QTCP_SERVER_H_
0022 
0023 #include <QObject>
0024 #include <QTcpServer>
0025 
0026 #include <memory>
0027 
0028 namespace apache {
0029 namespace thrift {
0030 namespace protocol {
0031 class TProtocolFactory;
0032 }
0033 }
0034 } // apache::thrift::protocol
0035 
0036 namespace apache {
0037 namespace thrift {
0038 namespace async {
0039 
0040 class TAsyncProcessor;
0041 
0042 /**
0043  *  Server that uses Qt to listen for connections.
0044  *  Simply give it a QTcpServer that is listening, along with an async
0045  *  processor and a protocol factory, and then run the Qt event loop.
0046  */
0047 class TQTcpServer : public QObject {
0048   Q_OBJECT
0049 public:
0050   TQTcpServer(std::shared_ptr<QTcpServer> server,
0051               std::shared_ptr<TAsyncProcessor> processor,
0052               std::shared_ptr<apache::thrift::protocol::TProtocolFactory> protocolFactory,
0053               QObject* parent = nullptr);
0054   ~TQTcpServer() override;
0055 
0056 private Q_SLOTS:
0057   void processIncoming();
0058   void beginDecode();
0059   void socketClosed();
0060   void deleteConnectionContext(QTcpSocket* connection);
0061 
0062 private:
0063   Q_DISABLE_COPY(TQTcpServer)
0064 
0065   struct ConnectionContext;
0066 
0067   void scheduleDeleteConnectionContext(QTcpSocket* connection);
0068   void finish(std::shared_ptr<ConnectionContext> ctx, bool healthy);
0069 
0070   std::shared_ptr<QTcpServer> server_;
0071   std::shared_ptr<TAsyncProcessor> processor_;
0072   std::shared_ptr<apache::thrift::protocol::TProtocolFactory> pfact_;
0073 
0074   typedef std::map<QTcpSocket*, std::shared_ptr<ConnectionContext> > ConnectionContextMap;
0075   ConnectionContextMap ctxMap_;
0076 };
0077 }
0078 }
0079 } // apache::thrift::async
0080 
0081 #endif // #ifndef _THRIFT_TASYNC_QTCP_SERVER_H_