PageRenderTime 54ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 1ms

/QxOrm.1.3.2/QxOrm/include/QxService/QxTransaction.h

https://gitlab.com/Sarahma/Installation-Requirements
C Header | 156 lines | 89 code | 25 blank | 42 comment | 0 complexity | 59dc1e67ad90ce75b36edef8fe38bb9d MD5 | raw file
  1. /****************************************************************************
  2. **
  3. ** http://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. #if _QX_ENABLE_QT_NETWORK_DEPENDENCY
  32. #ifndef _QX_SERVICE_TRANSACTION_H_
  33. #define _QX_SERVICE_TRANSACTION_H_
  34. #ifdef _MSC_VER
  35. #pragma once
  36. #endif
  37. /*!
  38. * \file QxTransaction.h
  39. * \author Lionel Marty
  40. * \ingroup QxService
  41. * \brief Transaction of QxService module (contains request from client and reply from server)
  42. */
  43. #include <QtNetwork/qtcpsocket.h>
  44. #include <QxCommon/QxBool.h>
  45. #include <QxRegister/QxRegisterInternalHelper.h>
  46. #include <QxService/IxService.h>
  47. #include <QxService/IxParameter.h>
  48. namespace qx {
  49. namespace service {
  50. /*!
  51. * \ingroup QxService
  52. * \brief qx::service::QxTransaction : transaction of QxService module (contains request from client and reply from server)
  53. *
  54. * <a href="http://www.qxorm.com/qxorm_en/tutorial_2.html" target="_blank">Click here to access to a tutorial to explain how to work with QxService module.</a>
  55. */
  56. class QX_DLL_EXPORT QxTransaction
  57. {
  58. QX_REGISTER_FRIEND_CLASS(qx::service::QxTransaction)
  59. protected:
  60. QString m_sTransactionId; //!< Transaction id (GUID)
  61. quint32 m_uiInputTransactionSize; //!< Input transaction size
  62. quint32 m_uiOutputTransactionSize; //!< Output transaction size
  63. QDateTime m_dtTransactionBegin; //!< Date-time transaction begin
  64. QDateTime m_dtTransactionRequestSent; //!< Date-time transaction request sent
  65. QDateTime m_dtTransactionRequestReceived; //!< Date-time transaction request received
  66. QDateTime m_dtTransactionReplySent; //!< Date-time transaction reply sent
  67. QDateTime m_dtTransactionReplyReceived; //!< Date-time transaction reply received
  68. QDateTime m_dtTransactionEnd; //!< Date-time transaction end
  69. QString m_sIpSource; //!< Ip address source (request)
  70. QString m_sIpTarget; //!< Ip address target (reply)
  71. long m_lPortSource; //!< Port number source (request)
  72. long m_lPortTarget; //!< Port number target (reply)
  73. QString m_sServiceName; //!< Service name to create using 'QxFactory'
  74. QString m_sServiceMethod; //!< Service method to call to execute transaction
  75. qx_bool m_bMessageReturn; //!< Message return to indicate if an error occured
  76. IxParameter_ptr m_pInputParameter; //!< List of input parameters (request)
  77. IxParameter_ptr m_pOutputParameter; //!< List of output parameters (reply)
  78. IxService_ptr m_pServiceInstance; //!< Service instance created by 'm_sServiceName' property
  79. public:
  80. QxTransaction() : m_uiInputTransactionSize(0), m_uiOutputTransactionSize(0), m_lPortSource(0), m_lPortTarget(0) { ; }
  81. virtual ~QxTransaction() { ; }
  82. QString getTransactionId() const { return m_sTransactionId; }
  83. quint32 getInputTransactionSize() const { return m_uiInputTransactionSize; }
  84. quint32 getOutputTransactionSize() const { return m_uiOutputTransactionSize; }
  85. QDateTime getTransactionBegin() const { return m_dtTransactionBegin; }
  86. QDateTime getTransactionRequestSent() const { return m_dtTransactionRequestSent; }
  87. QDateTime getTransactionRequestReceived() const { return m_dtTransactionRequestReceived; }
  88. QDateTime getTransactionReplySent() const { return m_dtTransactionReplySent; }
  89. QDateTime getTransactionReplyReceived() const { return m_dtTransactionReplyReceived; }
  90. QDateTime getTransactionEnd() const { return m_dtTransactionEnd; }
  91. QString getIpSource() const { return m_sIpSource; }
  92. QString getIpTarget() const { return m_sIpTarget; }
  93. long getPortSource() const { return m_lPortSource; }
  94. long getPortTarget() const { return m_lPortTarget; }
  95. QString getServiceName() const { return m_sServiceName; }
  96. QString getServiceMethod() const { return m_sServiceMethod; }
  97. qx_bool getMessageReturn() const { return m_bMessageReturn; }
  98. IxParameter_ptr getInputParameter() const { return m_pInputParameter; }
  99. IxParameter_ptr getOutputParameter() const { return m_pOutputParameter; }
  100. void setTransactionId(const QString & s) { m_sTransactionId = s; }
  101. void setInputTransactionSize(quint32 ui) { m_uiInputTransactionSize = ui; }
  102. void setOutputTransactionSize(quint32 ui) { m_uiOutputTransactionSize = ui; }
  103. void setTransactionBegin(const QDateTime & dt) { m_dtTransactionBegin = dt; }
  104. void setTransactionRequestSent(const QDateTime & dt) { m_dtTransactionRequestSent = dt; }
  105. void setTransactionRequestReceived(const QDateTime & dt) { m_dtTransactionRequestReceived = dt; }
  106. void setTransactionReplySent(const QDateTime & dt) { m_dtTransactionReplySent = dt; }
  107. void setTransactionReplyReceived(const QDateTime & dt) { m_dtTransactionReplyReceived = dt; }
  108. void setTransactionEnd(const QDateTime & dt) { m_dtTransactionEnd = dt; }
  109. void setIpSource(const QString & s) { m_sIpSource = s; }
  110. void setIpTarget(const QString & s) { m_sIpTarget = s; }
  111. void setPortSource(long l) { m_lPortSource = l; }
  112. void setPortTarget(long l) { m_lPortTarget = l; }
  113. void setServiceName(const QString & s) { m_sServiceName = s; }
  114. void setServiceMethod(const QString & s) { m_sServiceMethod = s; }
  115. void setMessageReturn(const qx_bool & b) { m_bMessageReturn = b; }
  116. void setInputParameter(IxParameter_ptr p) { m_pInputParameter = p; }
  117. void setOutputParameter(IxParameter_ptr p) { m_pOutputParameter = p; }
  118. public:
  119. void executeServer();
  120. void executeClient(IxService * pService, const QString & sMethod);
  121. protected:
  122. qx_bool writeSocket(QTcpSocket & socket);
  123. qx_bool readSocket(QTcpSocket & socket);
  124. };
  125. typedef boost::shared_ptr<QxTransaction> QxTransaction_ptr;
  126. QX_DLL_EXPORT void execute_client(IxService * pService, const QString & sMethod);
  127. } // namespace service
  128. } // namespace qx
  129. QX_REGISTER_INTERNAL_HELPER_HPP(QX_DLL_EXPORT, qx::service::QxTransaction, 0)
  130. #endif // _QX_SERVICE_TRANSACTION_H_
  131. #endif // _QX_ENABLE_QT_NETWORK_DEPENDENCY