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