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_TRANSACTION_H_ 00038 #define _QX_SERVICE_TRANSACTION_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 #include <QtCore/qdatastream.h> 00058 00059 #ifndef _QX_NO_JSON 00060 #include <QtCore/qjsonvalue.h> 00061 #endif // _QX_NO_JSON 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 <QxCommon/QxBool.h> 00075 #include <QxRegister/QxRegisterInternalHelper.h> 00076 #include <QxService/IxService.h> 00077 #include <QxService/IxParameter.h> 00078 #include <QxConvert/QxConvert.h> 00079 #endif // Q_MOC_RUN 00080 00081 namespace qx { 00082 namespace service { 00083 class QxTransaction; 00084 } // namespace service 00085 } // namespace qx 00086 00087 QX_DLL_EXPORT QDataStream & operator<< (QDataStream & stream, const qx::service::QxTransaction & t) QX_USED; 00088 QX_DLL_EXPORT QDataStream & operator>> (QDataStream & stream, qx::service::QxTransaction & t) QX_USED; 00089 00090 #ifndef _QX_NO_JSON 00091 namespace qx { 00092 namespace cvt { 00093 namespace detail { 00094 template <> struct QxConvert_ToJson< qx::service::QxTransaction >; 00095 template <> struct QxConvert_FromJson< qx::service::QxTransaction >; 00096 QX_DLL_EXPORT QJsonValue QxConvert_ToJson_Helper(const qx::service::QxTransaction & t, const QString & format) QX_USED; 00097 QX_DLL_EXPORT qx_bool QxConvert_FromJson_Helper(const QJsonValue & j, qx::service::QxTransaction & t, const QString & format) QX_USED; 00098 } // namespace detail 00099 } // namespace cvt 00100 } // namespace qx 00101 #endif // _QX_NO_JSON 00102 00103 namespace qx { 00104 namespace service { 00105 00112 class QX_DLL_EXPORT QxTransaction : public QObject 00113 { 00114 00115 Q_OBJECT 00116 QX_REGISTER_FRIEND_CLASS(qx::service::QxTransaction) 00117 00118 friend QX_DLL_EXPORT QDataStream & ::operator<< (QDataStream & stream, const qx::service::QxTransaction & t); 00119 friend QX_DLL_EXPORT QDataStream & ::operator>> (QDataStream & stream, qx::service::QxTransaction & t); 00120 00121 #ifndef _QX_NO_JSON 00122 friend struct qx::cvt::detail::QxConvert_ToJson< qx::service::QxTransaction >; 00123 friend struct qx::cvt::detail::QxConvert_FromJson< qx::service::QxTransaction >; 00124 friend QX_DLL_EXPORT QJsonValue qx::cvt::detail::QxConvert_ToJson_Helper(const qx::service::QxTransaction & t, const QString & format); 00125 friend QX_DLL_EXPORT qx_bool qx::cvt::detail::QxConvert_FromJson_Helper(const QJsonValue & j, qx::service::QxTransaction & t, const QString & format); 00126 #endif // _QX_NO_JSON 00127 00128 public: 00129 00130 enum connection_status { conn_none, conn_keep_alive, conn_close }; 00131 00132 protected: 00133 00134 QString m_sTransactionId; 00135 quint32 m_uiInputTransactionSize; 00136 quint32 m_uiOutputTransactionSize; 00137 QDateTime m_dtTransactionBegin; 00138 QDateTime m_dtTransactionRequestSent; 00139 QDateTime m_dtTransactionRequestReceived; 00140 QDateTime m_dtTransactionReplySent; 00141 QDateTime m_dtTransactionReplyReceived; 00142 QDateTime m_dtTransactionEnd; 00143 QString m_sIpSource; 00144 QString m_sIpTarget; 00145 long m_lPortSource; 00146 long m_lPortTarget; 00147 QString m_sServiceName; 00148 QString m_sServiceMethod; 00149 qx_bool m_bMessageReturn; 00150 IxParameter_ptr m_pInputParameter; 00151 IxParameter_ptr m_pOutputParameter; 00152 IxService_ptr m_pServiceInstance; 00153 connection_status m_eForceConnectionStatus; 00154 00155 public: 00156 00157 QxTransaction() : QObject(), m_uiInputTransactionSize(0), m_uiOutputTransactionSize(0), m_lPortSource(0), m_lPortTarget(0), m_eForceConnectionStatus(conn_none) { ; } 00158 virtual ~QxTransaction() { ; } 00159 virtual void clear(); 00160 00161 QString getTransactionId() const { return m_sTransactionId; } 00162 quint32 getInputTransactionSize() const { return m_uiInputTransactionSize; } 00163 quint32 getOutputTransactionSize() const { return m_uiOutputTransactionSize; } 00164 QDateTime getTransactionBegin() const { return m_dtTransactionBegin; } 00165 QDateTime getTransactionRequestSent() const { return m_dtTransactionRequestSent; } 00166 QDateTime getTransactionRequestReceived() const { return m_dtTransactionRequestReceived; } 00167 QDateTime getTransactionReplySent() const { return m_dtTransactionReplySent; } 00168 QDateTime getTransactionReplyReceived() const { return m_dtTransactionReplyReceived; } 00169 QDateTime getTransactionEnd() const { return m_dtTransactionEnd; } 00170 QString getIpSource() const { return m_sIpSource; } 00171 QString getIpTarget() const { return m_sIpTarget; } 00172 long getPortSource() const { return m_lPortSource; } 00173 long getPortTarget() const { return m_lPortTarget; } 00174 QString getServiceName() const { return m_sServiceName; } 00175 QString getServiceMethod() const { return m_sServiceMethod; } 00176 qx_bool getMessageReturn() const { return m_bMessageReturn; } 00177 IxParameter_ptr getInputParameter() const { return m_pInputParameter; } 00178 IxParameter_ptr getOutputParameter() const { return m_pOutputParameter; } 00179 connection_status getForceConnectionStatus() const { return m_eForceConnectionStatus; } 00180 00181 void setTransactionId(const QString & s) { m_sTransactionId = s; } 00182 void setInputTransactionSize(quint32 ui) { m_uiInputTransactionSize = ui; } 00183 void setOutputTransactionSize(quint32 ui) { m_uiOutputTransactionSize = ui; } 00184 void setTransactionBegin(const QDateTime & dt) { m_dtTransactionBegin = dt; } 00185 void setTransactionRequestSent(const QDateTime & dt) { m_dtTransactionRequestSent = dt; } 00186 void setTransactionRequestReceived(const QDateTime & dt) { m_dtTransactionRequestReceived = dt; } 00187 void setTransactionReplySent(const QDateTime & dt) { m_dtTransactionReplySent = dt; } 00188 void setTransactionReplyReceived(const QDateTime & dt) { m_dtTransactionReplyReceived = dt; } 00189 void setTransactionEnd(const QDateTime & dt) { m_dtTransactionEnd = dt; } 00190 void setIpSource(const QString & s) { m_sIpSource = s; } 00191 void setIpTarget(const QString & s) { m_sIpTarget = s; } 00192 void setPortSource(long l) { m_lPortSource = l; } 00193 void setPortTarget(long l) { m_lPortTarget = l; } 00194 void setServiceName(const QString & s) { m_sServiceName = s; } 00195 void setServiceMethod(const QString & s) { m_sServiceMethod = s; } 00196 void setMessageReturn(const qx_bool & b) { m_bMessageReturn = b; } 00197 void setInputParameter(IxParameter_ptr p) { m_pInputParameter = p; } 00198 void setOutputParameter(IxParameter_ptr p) { m_pOutputParameter = p; } 00199 void setForceConnectionStatus(connection_status e) { m_eForceConnectionStatus = e; } 00200 00201 virtual void executeServer(); 00202 virtual qx_bool writeSocketServer(QTcpSocket & socket); 00203 virtual qx_bool readSocketServer(QTcpSocket & socket); 00204 00205 virtual void executeClient(IxService * pService, const QString & sMethod); 00206 virtual qx_bool writeSocketClient(QTcpSocket & socket); 00207 virtual qx_bool readSocketClient(QTcpSocket & socket); 00208 00209 QString getInfos() const; 00210 00211 protected: 00212 00213 #ifndef QT_NO_SSL 00214 QSslSocket * initSocketSSL(); 00215 bool checkSocketSSLEncrypted(QTcpSocket * socket); 00216 #endif // QT_NO_SSL 00217 00218 Q_SIGNALS: 00219 00220 void onCustomRequestHandler(); 00221 00222 }; 00223 00224 typedef std::shared_ptr<QxTransaction> QxTransaction_ptr; 00225 QX_DLL_EXPORT void execute_client(IxService * pService, const QString & sMethod); 00226 00227 } // namespace service 00228 } // namespace qx 00229 00230 QX_REGISTER_INTERNAL_HELPER_HPP(QX_DLL_EXPORT, qx::service::QxTransaction, 0) 00231 00232 #endif // _QX_SERVICE_TRANSACTION_H_ 00233 #endif // _QX_ENABLE_QT_NETWORK