QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
QxTransaction.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** https://www.qxorm.com/
4** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
5**
6** This file is part of the QxOrm library
7**
8** This software is provided 'as-is', without any express or implied
9** warranty. In no event will the authors be held liable for any
10** damages arising from the use of this software
11**
12** Commercial Usage
13** Licensees holding valid commercial QxOrm licenses may use this file in
14** accordance with the commercial license agreement provided with the
15** Software or, alternatively, in accordance with the terms contained in
16** a written agreement between you and Lionel Marty
17**
18** GNU General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU
20** General Public License version 3.0 as published by the Free Software
21** Foundation and appearing in the file 'license.gpl3.txt' included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU General Public License version 3.0 requirements will be
24** met : http://www.gnu.org/copyleft/gpl.html
25**
26** If you are unsure which license is appropriate for your use, or
27** if you have questions regarding the use of this file, please contact :
28** contact@qxorm.com
29**
30****************************************************************************/
31
32#ifdef Q_MOC_RUN
33#include <QxCommon/QxConfig.h> // Need to include this file for the 'moc' process
34#endif // Q_MOC_RUN
35
36#ifdef _QX_ENABLE_QT_NETWORK
37#ifndef _QX_SERVICE_TRANSACTION_H_
38#define _QX_SERVICE_TRANSACTION_H_
39
40#ifdef _MSC_VER
41#pragma once
42#endif
43
51#ifdef _QX_NO_PRECOMPILED_HEADER
52#ifndef Q_MOC_RUN
53#include <QxPrecompiled.h> // Need to include precompiled header for the generated moc file
54#endif // Q_MOC_RUN
55#endif // _QX_NO_PRECOMPILED_HEADER
56
57#include <QtCore/qdatastream.h>
58
59#ifndef _QX_NO_JSON
60#include <QtCore/qjsonvalue.h>
61#endif // _QX_NO_JSON
62
63#include <QtNetwork/qtcpsocket.h>
64
65#ifndef QT_NO_SSL
66#include <QtNetwork/qsslsocket.h>
67#include <QtNetwork/qsslconfiguration.h>
68#include <QtNetwork/qsslcertificate.h>
69#include <QtNetwork/qsslerror.h>
70#include <QtNetwork/qsslkey.h>
71#endif // QT_NO_SSL
72
73#ifndef Q_MOC_RUN
74#include <QxCommon/QxBool.h>
76#include <QxService/IxService.h>
78#include <QxConvert/QxConvert.h>
79#endif // Q_MOC_RUN
80
81namespace qx {
82namespace service {
83class QxTransaction;
84} // namespace service
85} // namespace qx
86
87QX_DLL_EXPORT QDataStream & operator<< (QDataStream & stream, const qx::service::QxTransaction & t) QX_USED;
88QX_DLL_EXPORT QDataStream & operator>> (QDataStream & stream, qx::service::QxTransaction & t) QX_USED;
89
90#ifndef _QX_NO_JSON
91namespace qx {
92namespace cvt {
93namespace detail {
94template <> struct QxConvert_ToJson< qx::service::QxTransaction >;
95template <> struct QxConvert_FromJson< qx::service::QxTransaction >;
96QX_DLL_EXPORT QJsonValue QxConvert_ToJson_Helper(const qx::service::QxTransaction & t, const QString & format) QX_USED;
97QX_DLL_EXPORT qx_bool QxConvert_FromJson_Helper(const QJsonValue & j, qx::service::QxTransaction & t, const QString & format) QX_USED;
98} // namespace detail
99} // namespace cvt
100} // namespace qx
101#endif // _QX_NO_JSON
102
103namespace qx {
104namespace service {
105
112class QX_DLL_EXPORT QxTransaction : public QObject
113{
114
115 Q_OBJECT
117
118 friend QX_DLL_EXPORT QDataStream & ::operator<< (QDataStream & stream, const qx::service::QxTransaction & t);
119 friend QX_DLL_EXPORT QDataStream & ::operator>> (QDataStream & stream, qx::service::QxTransaction & t);
120
121#ifndef _QX_NO_JSON
123 friend struct qx::cvt::detail::QxConvert_FromJson< qx::service::QxTransaction >;
124 friend QX_DLL_EXPORT QJsonValue qx::cvt::detail::QxConvert_ToJson_Helper(const qx::service::QxTransaction & t, const QString & format);
125 friend QX_DLL_EXPORT qx_bool qx::cvt::detail::QxConvert_FromJson_Helper(const QJsonValue & j, qx::service::QxTransaction & t, const QString & format);
126#endif // _QX_NO_JSON
127
128public:
129
130 enum connection_status { conn_none, conn_keep_alive, conn_close };
131
132protected:
133
143 QString m_sIpSource;
144 QString m_sIpTarget;
154
155public:
156
157 QxTransaction() : QObject(), m_uiInputTransactionSize(0), m_uiOutputTransactionSize(0), m_lPortSource(0), m_lPortTarget(0), m_eForceConnectionStatus(conn_none) { ; }
158 virtual ~QxTransaction() { ; }
159 virtual void clear();
160
161 QString getTransactionId() const { return m_sTransactionId; }
162 quint32 getInputTransactionSize() const { return m_uiInputTransactionSize; }
163 quint32 getOutputTransactionSize() const { return m_uiOutputTransactionSize; }
164 QDateTime getTransactionBegin() const { return m_dtTransactionBegin; }
165 QDateTime getTransactionRequestSent() const { return m_dtTransactionRequestSent; }
166 QDateTime getTransactionRequestReceived() const { return m_dtTransactionRequestReceived; }
167 QDateTime getTransactionReplySent() const { return m_dtTransactionReplySent; }
168 QDateTime getTransactionReplyReceived() const { return m_dtTransactionReplyReceived; }
169 QDateTime getTransactionEnd() const { return m_dtTransactionEnd; }
170 QString getIpSource() const { return m_sIpSource; }
171 QString getIpTarget() const { return m_sIpTarget; }
172 long getPortSource() const { return m_lPortSource; }
173 long getPortTarget() const { return m_lPortTarget; }
174 QString getServiceName() const { return m_sServiceName; }
175 QString getServiceMethod() const { return m_sServiceMethod; }
176 qx_bool getMessageReturn() const { return m_bMessageReturn; }
177 IxParameter_ptr getInputParameter() const { return m_pInputParameter; }
178 IxParameter_ptr getOutputParameter() const { return m_pOutputParameter; }
179 connection_status getForceConnectionStatus() const { return m_eForceConnectionStatus; }
180
181 void setTransactionId(const QString & s) { m_sTransactionId = s; }
182 void setInputTransactionSize(quint32 ui) { m_uiInputTransactionSize = ui; }
183 void setOutputTransactionSize(quint32 ui) { m_uiOutputTransactionSize = ui; }
184 void setTransactionBegin(const QDateTime & dt) { m_dtTransactionBegin = dt; }
185 void setTransactionRequestSent(const QDateTime & dt) { m_dtTransactionRequestSent = dt; }
186 void setTransactionRequestReceived(const QDateTime & dt) { m_dtTransactionRequestReceived = dt; }
187 void setTransactionReplySent(const QDateTime & dt) { m_dtTransactionReplySent = dt; }
188 void setTransactionReplyReceived(const QDateTime & dt) { m_dtTransactionReplyReceived = dt; }
189 void setTransactionEnd(const QDateTime & dt) { m_dtTransactionEnd = dt; }
190 void setIpSource(const QString & s) { m_sIpSource = s; }
191 void setIpTarget(const QString & s) { m_sIpTarget = s; }
192 void setPortSource(long l) { m_lPortSource = l; }
193 void setPortTarget(long l) { m_lPortTarget = l; }
194 void setServiceName(const QString & s) { m_sServiceName = s; }
195 void setServiceMethod(const QString & s) { m_sServiceMethod = s; }
196 void setMessageReturn(const qx_bool & b) { m_bMessageReturn = b; }
197 void setInputParameter(IxParameter_ptr p) { m_pInputParameter = p; }
198 void setOutputParameter(IxParameter_ptr p) { m_pOutputParameter = p; }
199 void setForceConnectionStatus(connection_status e) { m_eForceConnectionStatus = e; }
200
201 virtual void executeServer();
202 virtual qx_bool writeSocketServer(QTcpSocket & socket);
203 virtual qx_bool readSocketServer(QTcpSocket & socket);
204
205 virtual void executeClient(IxService * pService, const QString & sMethod);
206 virtual qx_bool writeSocketClient(QTcpSocket & socket);
207 virtual qx_bool readSocketClient(QTcpSocket & socket);
208
209 QString getInfos() const;
210
211protected:
212
213#ifndef QT_NO_SSL
214 QSslSocket * initSocketSSL();
215 bool checkSocketSSLEncrypted(QTcpSocket * socket);
216#endif // QT_NO_SSL
217
218Q_SIGNALS:
219
221
222};
223
224typedef std::shared_ptr<QxTransaction> QxTransaction_ptr;
225QX_DLL_EXPORT void execute_client(IxService * pService, const QString & sMethod);
226
227} // namespace service
228} // namespace qx
229
231
232#endif // _QX_SERVICE_TRANSACTION_H_
233#endif // _QX_ENABLE_QT_NETWORK
Common interface for all parameters transfered by QxService module of QxOrm library.
Common interface for all services defined with QxService module of QxOrm library.
qx_bool : QxOrm library boolean type with code and description message when an error occured
List of parameters to compile and build QxOrm library.
qx::cvt : namespace to provide global functions to convert any kind of objects to/from QString and QV...
#define QX_USED
Definition QxMacro.h:244
#define QX_DLL_EXPORT
Definition QxMacro.h:182
#define QX_REGISTER_FRIEND_CLASS(className)
Definition QxRegister.h:291
#define QX_REGISTER_INTERNAL_HELPER_HPP(dllImportExport, className, version)
QX_DLL_EXPORT QDataStream & operator<<(QDataStream &stream, const qx::service::QxTransaction &t) QX_USED
QX_DLL_EXPORT QDataStream & operator>>(QDataStream &stream, qx::service::QxTransaction &t) QX_USED
qx_bool : boolean type with code and description message when an error occured
Definition QxBool.h:71
qx::service::IxService : common interface for all services defined with QxService module of QxOrm lib...
Definition IxService.h:94
qx::service::QxTransaction : transaction of QxService module (contains request from client and reply ...
virtual void executeServer()
QDateTime getTransactionRequestReceived() const
quint32 getOutputTransactionSize() const
connection_status m_eForceConnectionStatus
Sometimes we have to force connection status.
qx_bool m_bMessageReturn
Message return to indicate if an error occured.
quint32 m_uiOutputTransactionSize
Output transaction size.
QString m_sIpSource
Ip address source (request)
void setOutputParameter(IxParameter_ptr p)
quint32 getInputTransactionSize() const
IxParameter_ptr m_pInputParameter
List of input parameters (request)
bool checkSocketSSLEncrypted(QTcpSocket *socket)
void setInputParameter(IxParameter_ptr p)
QString m_sIpTarget
Ip address target (reply)
void setOutputTransactionSize(quint32 ui)
QDateTime m_dtTransactionEnd
Date-time transaction end.
void setIpSource(const QString &s)
void setServiceMethod(const QString &s)
QDateTime getTransactionReplyReceived() const
void setServiceName(const QString &s)
long m_lPortSource
Port number source (request)
void setMessageReturn(const qx_bool &b)
virtual void executeClient(IxService *pService, const QString &sMethod)
void setTransactionEnd(const QDateTime &dt)
long m_lPortTarget
Port number target (reply)
void setIpTarget(const QString &s)
connection_status getForceConnectionStatus() const
quint32 m_uiInputTransactionSize
Input transaction size.
virtual qx_bool readSocketServer(QTcpSocket &socket)
QDateTime getTransactionReplySent() const
QString getServiceMethod() const
void setTransactionId(const QString &s)
IxService_ptr m_pServiceInstance
Service instance created by 'm_sServiceName' property.
void setTransactionRequestSent(const QDateTime &dt)
QDateTime m_dtTransactionRequestReceived
Date-time transaction request received.
void setTransactionRequestReceived(const QDateTime &dt)
QString getInfos() const
void setTransactionReplySent(const QDateTime &dt)
IxParameter_ptr getInputParameter() const
QString m_sServiceMethod
Service method to call to execute transaction.
virtual qx_bool writeSocketClient(QTcpSocket &socket)
QDateTime getTransactionRequestSent() const
QString m_sTransactionId
Transaction id (GUID)
QString getTransactionId() const
qx_bool getMessageReturn() const
QString m_sServiceName
Service name to create using 'QxFactory'.
void setTransactionReplyReceived(const QDateTime &dt)
IxParameter_ptr m_pOutputParameter
List of output parameters (reply)
virtual qx_bool readSocketClient(QTcpSocket &socket)
QDateTime m_dtTransactionReplyReceived
Date-time transaction reply received.
void setInputTransactionSize(quint32 ui)
QDateTime m_dtTransactionRequestSent
Date-time transaction request sent.
QDateTime getTransactionBegin() const
IxParameter_ptr getOutputParameter() const
QDateTime m_dtTransactionReplySent
Date-time transaction reply sent.
QDateTime m_dtTransactionBegin
Date-time transaction begin.
virtual qx_bool writeSocketServer(QTcpSocket &socket)
void setForceConnectionStatus(connection_status e)
void setTransactionBegin(const QDateTime &dt)
QString getServiceName() const
QDateTime getTransactionEnd() const
QSslSocket * initSocketSSL()
QX_DLL_EXPORT QJsonValue QxConvert_ToJson_Helper(const qx::dao::detail::IxSqlElement &t, const QString &format) QX_USED
QX_DLL_EXPORT qx_bool QxConvert_FromJson_Helper(const QJsonValue &j, qx::dao::detail::IxSqlElement &t, const QString &format) QX_USED
std::shared_ptr< IxParameter > IxParameter_ptr
Definition IxParameter.h:98
std::shared_ptr< QxTransaction > QxTransaction_ptr
std::shared_ptr< IxService > IxService_ptr
Definition IxService.h:145
QX_DLL_EXPORT void execute_client(IxService *pService, const QString &sMethod)
Root namespace for all QxOrm library features.