IxService.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. #ifdef _QX_ENABLE_QT_NETWORK
  32. #ifndef _IX_SERVICE_H_
  33. #define _IX_SERVICE_H_
  34. #ifdef _MSC_VER
  35. #pragma once
  36. #endif
  37. /*!
  38. * \file IxService.h
  39. * \author Lionel Marty
  40. * \ingroup QxService
  41. * \brief Common interface for all services defined with QxService module of QxOrm library
  42. */
  43. #include <QtCore/qdatastream.h>
  44. #ifndef _QX_NO_JSON
  45. #include <QtCore/qjsonvalue.h>
  46. #endif // _QX_NO_JSON
  47. #include <QxCommon/QxBool.h>
  48. #include <QxRegister/QxRegisterInternalHelper.h>
  49. #include <QxService/IxParameter.h>
  50. #include <QxConvert/QxConvert.h>
  51. namespace qx {
  52. namespace service {
  53. class QxTransaction;
  54. class IxService;
  55. } // namespace service
  56. } // namespace qx
  57. QX_DLL_EXPORT QDataStream & operator<< (QDataStream & stream, const qx::service::IxService & t) QX_USED;
  58. QX_DLL_EXPORT QDataStream & operator>> (QDataStream & stream, qx::service::IxService & t) QX_USED;
  59. #ifndef _QX_NO_JSON
  60. namespace qx {
  61. namespace cvt {
  62. namespace detail {
  63. template <> struct QxConvert_ToJson< qx::service::IxService >;
  64. template <> struct QxConvert_FromJson< qx::service::IxService >;
  65. QX_DLL_EXPORT QJsonValue QxConvert_ToJson_Helper(const qx::service::IxService & t, const QString & format) QX_USED;
  66. QX_DLL_EXPORT qx_bool QxConvert_FromJson_Helper(const QJsonValue & j, qx::service::IxService & t, const QString & format) QX_USED;
  67. } // namespace detail
  68. } // namespace cvt
  69. } // namespace qx
  70. #endif // _QX_NO_JSON
  71. namespace qx {
  72. namespace service {
  73. /*!
  74. * \ingroup QxService
  75. * \brief qx::service::IxService : common interface for all services defined with QxService module of QxOrm library
  76. *
  77. * <a href="https://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>
  78. */
  79. class QX_DLL_EXPORT IxService
  80. {
  81. friend QX_DLL_EXPORT QDataStream & ::operator<< (QDataStream & stream, const qx::service::IxService & t);
  82. friend QX_DLL_EXPORT QDataStream & ::operator>> (QDataStream & stream, qx::service::IxService & t);
  83. #ifndef _QX_NO_JSON
  84. friend struct qx::cvt::detail::QxConvert_ToJson< qx::service::IxService >;
  85. friend struct qx::cvt::detail::QxConvert_FromJson< qx::service::IxService >;
  86. friend QX_DLL_EXPORT QJsonValue qx::cvt::detail::QxConvert_ToJson_Helper(const qx::service::IxService & t, const QString & format);
  87. friend QX_DLL_EXPORT qx_bool qx::cvt::detail::QxConvert_FromJson_Helper(const QJsonValue & j, qx::service::IxService & t, const QString & format);
  88. #endif // _QX_NO_JSON
  89. protected:
  90. QString m_sServiceName; //!< Service name <=> class name
  91. QString m_sServiceMethodName; //!< Service method name to call
  92. IxParameter_ptr m_pInputParameter; //!< List of input parameters (request)
  93. IxParameter_ptr m_pOutputParameter; //!< List of output parameters (reply)
  94. qx_bool m_bMessageReturn; //!< Message return to indicate if an error occured
  95. std::shared_ptr<QxTransaction> m_pTransaction; //!< Current transaction after executing service method
  96. public:
  97. IxService();
  98. IxService(const QString & sServiceName);
  99. virtual ~IxService();
  100. QString getServiceName() const { return m_sServiceName; }
  101. QString getServiceMethodName() const { return m_sServiceMethodName; }
  102. IxParameter_ptr getInputParameter_BaseClass() const { return m_pInputParameter; }
  103. IxParameter_ptr getOutputParameter_BaseClass() const { return m_pOutputParameter; }
  104. qx_bool getMessageReturn() const { return m_bMessageReturn; }
  105. std::shared_ptr<QxTransaction> getTransaction() const;
  106. void setServiceName(const QString & s) { qAssert(! s.isEmpty()); m_sServiceName = s; }
  107. void setServiceMethodName(const QString & s) { qAssert(! s.isEmpty()); m_sServiceMethodName = s; }
  108. void setInputParameter(IxParameter_ptr p) { m_pInputParameter = p; }
  109. void setOutputParameter(IxParameter_ptr p) { m_pOutputParameter = p; }
  110. void setMessageReturn(const qx_bool & b) { m_bMessageReturn = b; }
  111. void setMessageReturn(long l, const QString & s) { m_bMessageReturn = qx_bool(l, s); }
  112. void setTransaction(const std::shared_ptr<QxTransaction> & p);
  113. bool isValid() const { return m_bMessageReturn.getValue(); }
  114. bool isValidWithOutput() const { return (isValid() && (m_pOutputParameter.get() != NULL)); }
  115. virtual void registerClass() const { qDebug("[QxOrm] qx::service::IxService : %s", "need to override 'registerClass()' method"); qAssert(false); }
  116. virtual void onBeforeProcess() { ; }
  117. virtual void onAfterProcess() { ; }
  118. };
  119. typedef std::shared_ptr<IxService> IxService_ptr;
  120. } // namespace service
  121. } // namespace qx
  122. QX_REGISTER_INTERNAL_HELPER_HPP(QX_DLL_EXPORT, qx::service::IxService, 0)
  123. #endif // _IX_SERVICE_H_
  124. #endif // _QX_ENABLE_QT_NETWORK