QxOrm
1.5.0
C++ Object Relational Mapping library
|
00001 /**************************************************************************** 00002 ** 00003 ** https://www.qxorm.com/ 00004 ** Copyright (C) 2013 Lionel Marty (contact@qxorm.com) 00005 ** 00006 ** This file is part of the QxOrm library 00007 ** 00008 ** This software is provided 'as-is', without any express or implied 00009 ** warranty. In no event will the authors be held liable for any 00010 ** damages arising from the use of this software 00011 ** 00012 ** Commercial Usage 00013 ** Licensees holding valid commercial QxOrm licenses may use this file in 00014 ** accordance with the commercial license agreement provided with the 00015 ** Software or, alternatively, in accordance with the terms contained in 00016 ** a written agreement between you and Lionel Marty 00017 ** 00018 ** GNU General Public License Usage 00019 ** Alternatively, this file may be used under the terms of the GNU 00020 ** General Public License version 3.0 as published by the Free Software 00021 ** Foundation and appearing in the file 'license.gpl3.txt' included in the 00022 ** packaging of this file. Please review the following information to 00023 ** ensure the GNU General Public License version 3.0 requirements will be 00024 ** met : http://www.gnu.org/copyleft/gpl.html 00025 ** 00026 ** If you are unsure which license is appropriate for your use, or 00027 ** if you have questions regarding the use of this file, please contact : 00028 ** contact@qxorm.com 00029 ** 00030 ****************************************************************************/ 00031 00032 #ifdef Q_MOC_RUN 00033 #include <QxCommon/QxConfig.h> // Need to include this file for the 'moc' process 00034 #endif // Q_MOC_RUN 00035 00036 #ifdef _QX_ENABLE_QT_NETWORK 00037 #ifndef _QX_SERVICE_THREAD_H_ 00038 #define _QX_SERVICE_THREAD_H_ 00039 00040 #ifdef _MSC_VER 00041 #pragma once 00042 #endif 00043 00051 #ifdef _QX_NO_PRECOMPILED_HEADER 00052 #ifndef Q_MOC_RUN 00053 #include <QxPrecompiled.h> // Need to include precompiled header for the generated moc file 00054 #endif // Q_MOC_RUN 00055 #endif // _QX_NO_PRECOMPILED_HEADER 00056 00057 #ifdef QT_NO_OPENSSL 00058 #ifndef QT_NO_SSL 00059 #define QT_NO_SSL /* Nothing */ 00060 #endif // QT_NO_SSL 00061 #endif // QT_NO_OPENSSL 00062 00063 #include <QtNetwork/qtcpsocket.h> 00064 00065 #ifndef QT_NO_SSL 00066 #include <QtNetwork/qsslsocket.h> 00067 #include <QtNetwork/qsslconfiguration.h> 00068 #include <QtNetwork/qsslcertificate.h> 00069 #include <QtNetwork/qsslerror.h> 00070 #include <QtNetwork/qsslkey.h> 00071 #endif // QT_NO_SSL 00072 00073 #ifndef Q_MOC_RUN 00074 #include <QxService/QxTransaction.h> 00075 #endif // Q_MOC_RUN 00076 00077 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) 00078 #define QX_TYPE_SOCKET_DESC qintptr 00079 #else // (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) 00080 #define QX_TYPE_SOCKET_DESC int 00081 #endif // (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) 00082 00083 namespace qx { 00084 namespace service { 00085 00086 class QxThreadPool; 00087 00094 class QX_DLL_EXPORT QxThread : public QObject 00095 { 00096 00097 Q_OBJECT 00098 00099 protected: 00100 00101 QX_TYPE_SOCKET_DESC m_iSocketDescriptor; 00102 QxThreadPool * m_pThreadPool; 00103 QThread * m_pThread; 00104 QxTransaction_ptr m_pTransaction; 00105 bool m_bIsStopped; 00106 bool m_bIsDisconnected; 00107 QMutex m_mutex; 00108 00109 public: 00110 00111 QxThread(QxThreadPool * pool, QThread * thread) : QObject(), m_iSocketDescriptor(0), m_pThreadPool(pool), m_pThread(thread), m_bIsStopped(false), m_bIsDisconnected(false) { qAssert(m_pThreadPool); qAssert(m_pThread); } 00112 virtual ~QxThread() { clearData(); } 00113 00114 void init(); 00115 void stop(); 00116 void wait(); 00117 bool isAvailable(); 00118 void execute(QX_TYPE_SOCKET_DESC socketDescriptor); 00119 00120 protected: 00121 00122 void quit(); 00123 void clearData(); 00124 bool hasBeenStopped(); 00125 void doProcess(QTcpSocket & socket); 00126 bool checkKeepAlive(QTcpSocket & socket); 00127 QX_TYPE_SOCKET_DESC getSocketDescriptor(); 00128 00129 #ifndef QT_NO_SSL 00130 bool checkSocketSSLEncrypted(QTcpSocket * socket); 00131 QSslSocket * initSocketSSL(); 00132 #endif // QT_NO_SSL 00133 00134 Q_SIGNALS: 00135 00136 void error(const QString & err, qx::service::QxTransaction_ptr transaction); 00137 void transactionStarted(qx::service::QxTransaction_ptr transaction); 00138 void transactionFinished(qx::service::QxTransaction_ptr transaction); 00139 void customRequestHandler(qx::service::QxTransaction_ptr transaction); 00140 void incomingConnection(); 00141 void finished(); 00142 00143 private Q_SLOTS: 00144 00145 void onCustomRequestHandler(); 00146 void onIncomingConnection(); 00147 void onSocketDisconnected(); 00148 void onSocketReadyRead(); 00149 00150 #ifndef QT_NO_SSL 00151 #ifndef QT_NO_OPENSSL 00152 void onSocketSSLEncrypted(); 00153 void onSocketSSLErrors(const QList<QSslError> & errors); 00154 void onSocketSSLPeerVerifyError(const QSslError & error); 00155 #endif // QT_NO_OPENSSL 00156 #endif // QT_NO_SSL 00157 00158 }; 00159 00160 } // namespace service 00161 } // namespace qx 00162 00163 #endif // _QX_SERVICE_THREAD_H_ 00164 #endif // _QX_ENABLE_QT_NETWORK