![]() |
QxOrm
1.4.5
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 _QX_ENABLE_QT_NETWORK 00033 #ifndef _QX_SERVICE_TRANSACTION_H_ 00034 #define _QX_SERVICE_TRANSACTION_H_ 00035 00036 #ifdef _MSC_VER 00037 #pragma once 00038 #endif 00039 00047 #include <QtCore/qdatastream.h> 00048 00049 #ifndef _QX_NO_JSON 00050 #include <QtCore/qjsonvalue.h> 00051 #endif // _QX_NO_JSON 00052 00053 #include <QtNetwork/qtcpsocket.h> 00054 00055 #include <QxCommon/QxBool.h> 00056 00057 #include <QxRegister/QxRegisterInternalHelper.h> 00058 00059 #include <QxService/IxService.h> 00060 #include <QxService/IxParameter.h> 00061 00062 #include <QxConvert/QxConvert.h> 00063 00064 namespace qx { 00065 namespace service { 00066 class QxTransaction; 00067 } // namespace service 00068 } // namespace qx 00069 00070 QX_DLL_EXPORT QDataStream & operator<< (QDataStream & stream, const qx::service::QxTransaction & t) QX_USED; 00071 QX_DLL_EXPORT QDataStream & operator>> (QDataStream & stream, qx::service::QxTransaction & t) QX_USED; 00072 00073 #ifndef _QX_NO_JSON 00074 namespace qx { 00075 namespace cvt { 00076 namespace detail { 00077 template <> struct QxConvert_ToJson< qx::service::QxTransaction >; 00078 template <> struct QxConvert_FromJson< qx::service::QxTransaction >; 00079 QX_DLL_EXPORT QJsonValue QxConvert_ToJson_Helper(const qx::service::QxTransaction & t, const QString & format) QX_USED; 00080 QX_DLL_EXPORT qx_bool QxConvert_FromJson_Helper(const QJsonValue & j, qx::service::QxTransaction & t, const QString & format) QX_USED; 00081 } // namespace detail 00082 } // namespace cvt 00083 } // namespace qx 00084 #endif // _QX_NO_JSON 00085 00086 namespace qx { 00087 namespace service { 00088 00095 class QX_DLL_EXPORT QxTransaction 00096 { 00097 00098 QX_REGISTER_FRIEND_CLASS(qx::service::QxTransaction) 00099 00100 friend QX_DLL_EXPORT QDataStream & ::operator<< (QDataStream & stream, const qx::service::QxTransaction & t); 00101 friend QX_DLL_EXPORT QDataStream & ::operator>> (QDataStream & stream, qx::service::QxTransaction & t); 00102 00103 #ifndef _QX_NO_JSON 00104 friend struct qx::cvt::detail::QxConvert_ToJson< qx::service::QxTransaction >; 00105 friend struct qx::cvt::detail::QxConvert_FromJson< qx::service::QxTransaction >; 00106 friend QX_DLL_EXPORT QJsonValue qx::cvt::detail::QxConvert_ToJson_Helper(const qx::service::QxTransaction & t, const QString & format); 00107 friend QX_DLL_EXPORT qx_bool qx::cvt::detail::QxConvert_FromJson_Helper(const QJsonValue & j, qx::service::QxTransaction & t, const QString & format); 00108 #endif // _QX_NO_JSON 00109 00110 protected: 00111 00112 QString m_sTransactionId; 00113 quint32 m_uiInputTransactionSize; 00114 quint32 m_uiOutputTransactionSize; 00115 QDateTime m_dtTransactionBegin; 00116 QDateTime m_dtTransactionRequestSent; 00117 QDateTime m_dtTransactionRequestReceived; 00118 QDateTime m_dtTransactionReplySent; 00119 QDateTime m_dtTransactionReplyReceived; 00120 QDateTime m_dtTransactionEnd; 00121 QString m_sIpSource; 00122 QString m_sIpTarget; 00123 long m_lPortSource; 00124 long m_lPortTarget; 00125 QString m_sServiceName; 00126 QString m_sServiceMethod; 00127 qx_bool m_bMessageReturn; 00128 IxParameter_ptr m_pInputParameter; 00129 IxParameter_ptr m_pOutputParameter; 00130 IxService_ptr m_pServiceInstance; 00131 00132 public: 00133 00134 QxTransaction() : m_uiInputTransactionSize(0), m_uiOutputTransactionSize(0), m_lPortSource(0), m_lPortTarget(0) { ; } 00135 virtual ~QxTransaction() { ; } 00136 00137 QString getTransactionId() const { return m_sTransactionId; } 00138 quint32 getInputTransactionSize() const { return m_uiInputTransactionSize; } 00139 quint32 getOutputTransactionSize() const { return m_uiOutputTransactionSize; } 00140 QDateTime getTransactionBegin() const { return m_dtTransactionBegin; } 00141 QDateTime getTransactionRequestSent() const { return m_dtTransactionRequestSent; } 00142 QDateTime getTransactionRequestReceived() const { return m_dtTransactionRequestReceived; } 00143 QDateTime getTransactionReplySent() const { return m_dtTransactionReplySent; } 00144 QDateTime getTransactionReplyReceived() const { return m_dtTransactionReplyReceived; } 00145 QDateTime getTransactionEnd() const { return m_dtTransactionEnd; } 00146 QString getIpSource() const { return m_sIpSource; } 00147 QString getIpTarget() const { return m_sIpTarget; } 00148 long getPortSource() const { return m_lPortSource; } 00149 long getPortTarget() const { return m_lPortTarget; } 00150 QString getServiceName() const { return m_sServiceName; } 00151 QString getServiceMethod() const { return m_sServiceMethod; } 00152 qx_bool getMessageReturn() const { return m_bMessageReturn; } 00153 IxParameter_ptr getInputParameter() const { return m_pInputParameter; } 00154 IxParameter_ptr getOutputParameter() const { return m_pOutputParameter; } 00155 00156 void setTransactionId(const QString & s) { m_sTransactionId = s; } 00157 void setInputTransactionSize(quint32 ui) { m_uiInputTransactionSize = ui; } 00158 void setOutputTransactionSize(quint32 ui) { m_uiOutputTransactionSize = ui; } 00159 void setTransactionBegin(const QDateTime & dt) { m_dtTransactionBegin = dt; } 00160 void setTransactionRequestSent(const QDateTime & dt) { m_dtTransactionRequestSent = dt; } 00161 void setTransactionRequestReceived(const QDateTime & dt) { m_dtTransactionRequestReceived = dt; } 00162 void setTransactionReplySent(const QDateTime & dt) { m_dtTransactionReplySent = dt; } 00163 void setTransactionReplyReceived(const QDateTime & dt) { m_dtTransactionReplyReceived = dt; } 00164 void setTransactionEnd(const QDateTime & dt) { m_dtTransactionEnd = dt; } 00165 void setIpSource(const QString & s) { m_sIpSource = s; } 00166 void setIpTarget(const QString & s) { m_sIpTarget = s; } 00167 void setPortSource(long l) { m_lPortSource = l; } 00168 void setPortTarget(long l) { m_lPortTarget = l; } 00169 void setServiceName(const QString & s) { m_sServiceName = s; } 00170 void setServiceMethod(const QString & s) { m_sServiceMethod = s; } 00171 void setMessageReturn(const qx_bool & b) { m_bMessageReturn = b; } 00172 void setInputParameter(IxParameter_ptr p) { m_pInputParameter = p; } 00173 void setOutputParameter(IxParameter_ptr p) { m_pOutputParameter = p; } 00174 00175 public: 00176 00177 void executeServer(); 00178 void executeClient(IxService * pService, const QString & sMethod); 00179 00180 QString getInfos() const; 00181 00182 protected: 00183 00184 qx_bool writeSocket(QTcpSocket & socket); 00185 qx_bool readSocket(QTcpSocket & socket); 00186 00187 }; 00188 00189 typedef std::shared_ptr<QxTransaction> QxTransaction_ptr; 00190 QX_DLL_EXPORT void execute_client(IxService * pService, const QString & sMethod); 00191 00192 } // namespace service 00193 } // namespace qx 00194 00195 QX_REGISTER_INTERNAL_HELPER_HPP(QX_DLL_EXPORT, qx::service::QxTransaction, 0) 00196 00197 #endif // _QX_SERVICE_TRANSACTION_H_ 00198 #endif // _QX_ENABLE_QT_NETWORK