first commit

This commit is contained in:
bing
2026-04-03 11:32:07 +08:00
commit 003be19522
1142 changed files with 185854 additions and 0 deletions

View File

@@ -0,0 +1,146 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifdef _QX_ENABLE_QT_NETWORK
#ifndef _IX_SERVICE_PARAMETER_H_
#define _IX_SERVICE_PARAMETER_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file IxParameter.h
* \author XDL Team
* \ingroup QxService
* \brief Common interface for all parameters transfered by QxService module of QxOrm library
*/
#include <QtCore/qdatastream.h>
#ifndef _QX_NO_JSON
#include <QtCore/qjsonvalue.h>
#endif // _QX_NO_JSON
#include <QxRegister/QxRegisterInternalHelper.h>
namespace qx
{
namespace service
{
class IxParameter;
} // namespace service
} // namespace qx
QX_DLL_EXPORT QDataStream &operator<<(QDataStream &stream, const qx::service::IxParameter &t) QX_USED;
QX_DLL_EXPORT QDataStream &operator>>(QDataStream &stream, qx::service::IxParameter &t) QX_USED;
namespace qx
{
namespace service
{
/*!
* \ingroup QxService
* \brief qx::service::IxParameter : common interface for all parameters transfered by QxService module of QxOrm library
*
* <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>
*/
class QX_DLL_EXPORT IxParameter
{
friend QX_DLL_EXPORT QDataStream & ::operator<<(QDataStream &stream, const qx::service::IxParameter &t);
friend QX_DLL_EXPORT QDataStream & ::operator>>(QDataStream &stream, qx::service::IxParameter &t);
public:
IxParameter();
virtual ~IxParameter();
// Need to override these methods only if you are using 'qx::service::QxConnect::serialization_qt' type (based on QDataStream) or 'qx::service::QxConnect::serialization_json' type (based on QJson engine)
// You can use QX_SERVICE_IX_PARAMETER_SERIALIZATION_HPP and QX_SERVICE_IX_PARAMETER_SERIALIZATION_CPP macro to override
virtual void registerClass() const;
virtual QString getClassName() const;
virtual void save(QDataStream &stream) const;
virtual void load(QDataStream &stream);
#ifndef _QX_NO_JSON
virtual QJsonValue saveToJson() const;
virtual qx_bool loadFromJson(const QJsonValue &val);
#endif // _QX_NO_JSON
};
typedef std::shared_ptr<IxParameter> IxParameter_ptr;
} // namespace service
} // namespace qx
QX_REGISTER_INTERNAL_HELPER_HPP(QX_DLL_EXPORT, qx::service::IxParameter, 0)
#define QX_SERVICE_IX_PARAMETER_QDATASTREAM_HPP(className) \
public: \
virtual void save(QDataStream &stream) const; \
virtual void load(QDataStream &stream);
#define QX_SERVICE_IX_PARAMETER_QDATASTREAM_CPP(className) \
void className::save(QDataStream &stream) const { qx::QxSerializeRegistered<className>::save(stream, (*this)); } \
void className::load(QDataStream &stream) { qx::QxSerializeRegistered<className>::load(stream, (*this)); }
#ifndef _QX_NO_JSON
#define QX_SERVICE_IX_PARAMETER_QJSON_HPP(className) \
public: \
virtual QJsonValue saveToJson() const; \
virtual qx_bool loadFromJson(const QJsonValue &val);
#define QX_SERVICE_IX_PARAMETER_QJSON_CPP(className) \
QJsonValue className::saveToJson() const { return qx::cvt::detail::QxSerializeJsonRegistered<className>::save((*this), ""); } \
qx_bool className::loadFromJson(const QJsonValue &val) { return qx::cvt::detail::QxSerializeJsonRegistered<className>::load(val, (*this), ""); }
#else // _QX_NO_JSON
#define QX_SERVICE_IX_PARAMETER_QJSON_HPP(className) /* Nothing */
#define QX_SERVICE_IX_PARAMETER_QJSON_CPP(className) /* Nothing */
#endif // _QX_NO_JSON
#define QX_SERVICE_IX_PARAMETER_SERIALIZATION_HPP(className) \
QX_SERVICE_IX_PARAMETER_QDATASTREAM_HPP(className) \
QX_SERVICE_IX_PARAMETER_QJSON_HPP(className) \
public: \
virtual void registerClass() const; \
virtual QString getClassName() const;
#define QX_SERVICE_IX_PARAMETER_SERIALIZATION_CPP(className) \
QX_SERVICE_IX_PARAMETER_QDATASTREAM_CPP(className) \
QX_SERVICE_IX_PARAMETER_QJSON_CPP(className) \
void className::registerClass() const { qx::QxClass<className>::getSingleton(); } \
QString className::getClassName() const { return #className; }
#endif // _IX_SERVICE_PARAMETER_H_
#endif // _QX_ENABLE_QT_NETWORK

View File

@@ -0,0 +1,171 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifdef _QX_ENABLE_QT_NETWORK
#ifndef _IX_SERVICE_H_
#define _IX_SERVICE_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file IxService.h
* \author XDL Team
* \ingroup QxService
* \brief Common interface for all services defined with QxService module of QxOrm library
*/
#include <QtCore/qdatastream.h>
#ifndef _QX_NO_JSON
#include <QtCore/qjsonvalue.h>
#endif // _QX_NO_JSON
#include <QxCommon/QxBool.h>
#include <QxRegister/QxRegisterInternalHelper.h>
#include <QxService/IxParameter.h>
#include <QxConvert/QxConvert.h>
namespace qx
{
namespace service
{
class QxTransaction;
class IxService;
} // namespace service
} // namespace qx
QX_DLL_EXPORT QDataStream &operator<<(QDataStream &stream, const qx::service::IxService &t) QX_USED;
QX_DLL_EXPORT QDataStream &operator>>(QDataStream &stream, qx::service::IxService &t) QX_USED;
#ifndef _QX_NO_JSON
namespace qx
{
namespace cvt
{
namespace detail
{
template <>
struct QxConvert_ToJson<qx::service::IxService>;
template <>
struct QxConvert_FromJson<qx::service::IxService>;
QX_DLL_EXPORT QJsonValue QxConvert_ToJson_Helper(const qx::service::IxService &t, const QString &format) QX_USED;
QX_DLL_EXPORT qx_bool QxConvert_FromJson_Helper(const QJsonValue &j, qx::service::IxService &t, const QString &format) QX_USED;
} // namespace detail
} // namespace cvt
} // namespace qx
#endif // _QX_NO_JSON
namespace qx
{
namespace service
{
/*!
* \ingroup QxService
* \brief qx::service::IxService : common interface for all services defined with QxService module of QxOrm library
*
* <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>
*/
class QX_DLL_EXPORT IxService
{
friend QX_DLL_EXPORT QDataStream & ::operator<<(QDataStream &stream, const qx::service::IxService &t);
friend QX_DLL_EXPORT QDataStream & ::operator>>(QDataStream &stream, qx::service::IxService &t);
#ifndef _QX_NO_JSON
friend struct qx::cvt::detail::QxConvert_ToJson<qx::service::IxService>;
friend struct qx::cvt::detail::QxConvert_FromJson<qx::service::IxService>;
friend QX_DLL_EXPORT QJsonValue qx::cvt::detail::QxConvert_ToJson_Helper(const qx::service::IxService &t, const QString &format);
friend QX_DLL_EXPORT qx_bool qx::cvt::detail::QxConvert_FromJson_Helper(const QJsonValue &j, qx::service::IxService &t, const QString &format);
#endif // _QX_NO_JSON
protected:
QString m_sServiceName; //!< Service name <=> class name
QString m_sServiceMethodName; //!< Service method name to call
IxParameter_ptr m_pInputParameter; //!< List of input parameters (request)
IxParameter_ptr m_pOutputParameter; //!< List of output parameters (reply)
qx_bool m_bMessageReturn; //!< Message return to indicate if an error occured
std::shared_ptr<QxTransaction> m_pTransaction; //!< Current transaction after executing service method
public:
IxService();
IxService(const QString &sServiceName);
virtual ~IxService();
QString getServiceName() const { return m_sServiceName; }
QString getServiceMethodName() const { return m_sServiceMethodName; }
IxParameter_ptr getInputParameter_BaseClass() const { return m_pInputParameter; }
IxParameter_ptr getOutputParameter_BaseClass() const { return m_pOutputParameter; }
qx_bool getMessageReturn() const { return m_bMessageReturn; }
std::shared_ptr<QxTransaction> getTransaction() const;
void setServiceName(const QString &s)
{
qAssert(!s.isEmpty());
m_sServiceName = s;
}
void setServiceMethodName(const QString &s)
{
qAssert(!s.isEmpty());
m_sServiceMethodName = s;
}
void setInputParameter(IxParameter_ptr p) { m_pInputParameter = p; }
void setOutputParameter(IxParameter_ptr p) { m_pOutputParameter = p; }
void setMessageReturn(const qx_bool &b) { m_bMessageReturn = b; }
void setMessageReturn(long l, const QString &s) { m_bMessageReturn = qx_bool(l, s); }
void setTransaction(const std::shared_ptr<QxTransaction> &p);
bool isValid() const { return m_bMessageReturn.getValue(); }
bool isValidWithOutput() const { return (isValid() && (m_pOutputParameter.get() != NULL)); }
virtual void registerClass() const
{
qDebug("[QxOrm] qx::service::IxService : %s", "need to override 'registerClass()' method");
qAssert(false);
}
virtual void onBeforeProcess() { ; }
virtual void onAfterProcess() { ; }
};
typedef std::shared_ptr<IxService> IxService_ptr;
} // namespace service
} // namespace qx
QX_REGISTER_INTERNAL_HELPER_HPP(QX_DLL_EXPORT, qx::service::IxService, 0)
#endif // _IX_SERVICE_H_
#endif // _QX_ENABLE_QT_NETWORK

View File

@@ -0,0 +1,97 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifdef _QX_ENABLE_QT_NETWORK
#ifndef _QX_SERVICE_CLIENT_ASYNC_H_
#define _QX_SERVICE_CLIENT_ASYNC_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxClientAsync.h
* \author XDL Team
* \ingroup QxService
* \brief Provide a class helper to easily execute an asynchronous transaction using a multi-thread process
*/
#include <QxService/IxService.h>
#include <QxService/QxTransaction.h>
namespace qx
{
namespace service
{
/*!
* \ingroup QxService
* \brief qx::service::QxClientAsync : class helper to easily execute an asynchronous transaction using a multi-thread process
*
* <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>
*/
class QxClientAsync : public QThread
{
protected:
IxService_ptr m_pService; //!< Service to execute in thread
QString m_sServiceMethod; //!< Service method to call
public:
QxClientAsync() : QThread() { ; }
virtual ~QxClientAsync()
{
if (isRunning())
{
qDebug("[QxOrm] qx::service::QxClientAsync thread is running : %s", "wait thread finished");
wait();
}
}
IxService_ptr getService() const { return m_pService; }
void setService(IxService_ptr service, const QString &method)
{
qAssert(!isRunning());
m_pService = service;
m_sServiceMethod = method;
}
protected:
virtual void run() { qx::service::execute_client(m_pService.get(), m_sServiceMethod); }
};
typedef std::shared_ptr<QxClientAsync> QxClientAsync_ptr;
} // namespace service
} // namespace qx
#endif // _QX_SERVICE_CLIENT_ASYNC_H_
#endif // _QX_ENABLE_QT_NETWORK

View File

@@ -0,0 +1,156 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifdef _QX_ENABLE_QT_NETWORK
#ifndef _QX_SERVICE_CONNECT_H_
#define _QX_SERVICE_CONNECT_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxConnect.h
* \author XDL Team
* \ingroup QxService
* \brief Define connection parameters used by QxService module of QxOrm library
*/
#ifndef QT_NO_SSL
#include <QtNetwork/qsslsocket.h>
#include <QtNetwork/qsslconfiguration.h>
#include <QtNetwork/qsslcertificate.h>
#include <QtNetwork/qsslerror.h>
#include <QtNetwork/qsslkey.h>
#endif // QT_NO_SSL
#ifndef Q_MOC_RUN
#include <QxSingleton/QxSingleton.h>
#endif // Q_MOC_RUN
namespace qx
{
namespace service
{
/*!
* \ingroup QxService
* \brief qx::service::QxConnect : define connection parameters used by QxService module of QxOrm library (this class is a singleton)
*
* <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>
*/
class QX_DLL_EXPORT QxConnect : public qx::QxSingleton<QxConnect>
{
friend class qx::QxSingleton<QxConnect>;
public:
enum serialization_type
{
serialization_binary,
serialization_xml,
serialization_text,
serialization_portable_binary,
serialization_wide_binary,
serialization_wide_xml,
serialization_wide_text,
serialization_polymorphic_binary,
serialization_polymorphic_xml,
serialization_polymorphic_text,
serialization_qt,
serialization_json
};
private:
struct QxConnectImpl;
std::unique_ptr<QxConnectImpl> m_pImpl; //!< Private implementation idiom
QxConnect();
virtual ~QxConnect();
public:
QString getIp();
long getPort();
serialization_type getSerializationType();
long getThreadCount();
int getMaxWait();
bool getCompressData();
bool getEncryptData();
quint64 getEncryptKey();
long getKeepAlive();
bool getModeHTTP();
qlonglong getSessionTimeOut();
#ifndef QT_NO_SSL
bool getSSLEnabled();
QSslConfiguration getSSLConfiguration();
QList<QSslCertificate> getSSLCACertificates();
QSslCertificate getSSLLocalCertificate();
QSslKey getSSLPrivateKey();
QList<QSslError> getSSLIgnoreErrors();
QSsl::SslProtocol getSSLProtocol();
QString getSSLPeerVerifyName();
QSslSocket::PeerVerifyMode getSSLPeerVerifyMode();
int getSSLPeerVerifyDepth();
#endif // QT_NO_SSL
void setIp(const QString &s);
void setPort(long l);
void setSerializationType(serialization_type e);
void setThreadCount(long l);
void setMaxWait(int i);
void setCompressData(bool b);
void setEncryptData(bool b, quint64 key = 0);
void setKeepAlive(long l);
void setModeHTTP(bool b);
void setSessionTimeOut(qlonglong l);
#ifndef QT_NO_SSL
void setSSLEnabled(bool b);
void setSSLConfiguration(QSslConfiguration cfg);
void setSSLCACertificates(QList<QSslCertificate> lst);
void setSSLLocalCertificate(QSslCertificate cert);
void setSSLPrivateKey(QSslKey key);
void setSSLIgnoreErrors(QList<QSslError> lst);
void setSSLProtocol(QSsl::SslProtocol e);
void setSSLPeerVerifyName(const QString &s);
void setSSLPeerVerifyMode(QSslSocket::PeerVerifyMode e);
void setSSLPeerVerifyDepth(int i);
#endif // QT_NO_SSL
};
} // namespace service
} // namespace qx
QX_DLL_EXPORT_QX_SINGLETON_HPP(qx::service::QxConnect)
#endif // _QX_SERVICE_CONNECT_H_
#endif // _QX_ENABLE_QT_NETWORK

View File

@@ -0,0 +1,88 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifdef _QX_ENABLE_QT_NETWORK
#ifndef _QX_SERVICE_SERVER_H_
#define _QX_SERVICE_SERVER_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxServer.h
* \author XDL Team
* \ingroup QxService
* \brief Server side to manage a thread pool of incoming connections (new request from client)
*/
#include <QtNetwork/qtcpserver.h>
namespace qx
{
namespace service
{
class QxThreadPool;
class QxThread;
/*!
* \ingroup QxService
* \brief qx::service::QxServer : server side to manage a thread pool of incoming connections (new request from client)
*
* <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>
*/
class QX_DLL_EXPORT QxServer : public QTcpServer
{
protected:
QxThreadPool *m_pThreadPool; //!< Parent thread pool to prevent from incoming connection
QMutex m_mutex; //!< Mutex => 'QxServer' is thread-safe
public:
QxServer(QxThreadPool *pool) : QTcpServer(), m_pThreadPool(pool) { qAssert(m_pThreadPool); }
virtual ~QxServer() { ; }
protected:
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
virtual void incomingConnection(qintptr socketDescriptor);
#else // (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
virtual void incomingConnection(int socketDescriptor);
#endif // (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
QxThread *getAvailable() const;
};
} // namespace service
} // namespace qx
#endif // _QX_SERVICE_SERVER_H_
#endif // _QX_ENABLE_QT_NETWORK

View File

@@ -0,0 +1,109 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifdef _QX_ENABLE_QT_NETWORK
#ifndef _QX_SERVICE_H_
#define _QX_SERVICE_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxService.h
* \author XDL Team
* \ingroup QxService
* \brief Concrete service class defined with QxService module of QxOrm library
*/
#include <QxRegister/QxClass.h>
#include <QxService/IxService.h>
namespace qx
{
namespace service
{
/*!
* \ingroup QxService
* \brief qx::service::QxService<INPUT, OUTPUT> : concrete service class with INPUT parameters and OUTPUT parameters
*
* <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>
*/
template <class INPUT, class OUTPUT>
class QxService : public IxService
{
protected:
enum
{
is_input_parameter = std::is_base_of<IxParameter, INPUT>::value
};
enum
{
is_output_parameter = std::is_base_of<IxParameter, OUTPUT>::value
};
enum
{
is_input_registered = qx::trait::is_qx_registered<INPUT>::value
};
enum
{
is_output_registered = qx::trait::is_qx_registered<OUTPUT>::value
};
enum
{
is_valid_parameter = (is_input_parameter && is_output_parameter && is_input_registered && is_output_registered)
};
typedef std::shared_ptr<INPUT> INPUT_ptr;
typedef std::shared_ptr<OUTPUT> OUTPUT_ptr;
public:
QxService(const QString &sServiceName) : IxService(sServiceName) { static_assert(is_valid_parameter, "is_valid_parameter"); }
virtual ~QxService() { ; }
INPUT_ptr getInputParameter() const { return std::static_pointer_cast<INPUT>(m_pInputParameter); }
OUTPUT_ptr getOutputParameter() const { return std::static_pointer_cast<OUTPUT>(m_pOutputParameter); }
virtual void registerClass() const
{
qx::QxClass<INPUT>::getSingleton();
qx::QxClass<OUTPUT>::getSingleton();
}
};
} // namespace service
} // namespace qx
#endif // _QX_SERVICE_H_
#endif // _QX_ENABLE_QT_NETWORK

View File

@@ -0,0 +1,166 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifdef Q_MOC_RUN
#include <QxCommon/QxConfig.h> // Need to include this file for the 'moc' process
#endif // Q_MOC_RUN
#ifdef _QX_ENABLE_QT_NETWORK
#ifndef _QX_SERVICE_THREAD_H_
#define _QX_SERVICE_THREAD_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxThread.h
* \author XDL Team
* \ingroup QxService
* \brief Thread to execute a transaction of QxService module
*/
#ifdef _QX_NO_PRECOMPILED_HEADER
#ifndef Q_MOC_RUN
#include <QxPrecompiled.h> // Need to include precompiled header for the generated moc file
#endif // Q_MOC_RUN
#endif // _QX_NO_PRECOMPILED_HEADER
#ifdef QT_NO_OPENSSL
#ifndef QT_NO_SSL
#define QT_NO_SSL /* Nothing */
#endif // QT_NO_SSL
#endif // QT_NO_OPENSSL
#include <QtNetwork/qtcpsocket.h>
#ifndef QT_NO_SSL
#include <QtNetwork/qsslsocket.h>
#include <QtNetwork/qsslconfiguration.h>
#include <QtNetwork/qsslcertificate.h>
#include <QtNetwork/qsslerror.h>
#include <QtNetwork/qsslkey.h>
#endif // QT_NO_SSL
#ifndef Q_MOC_RUN
#include <QxService/QxTransaction.h>
#endif // Q_MOC_RUN
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
#define QX_TYPE_SOCKET_DESC qintptr
#else // (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
#define QX_TYPE_SOCKET_DESC int
#endif // (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
namespace qx
{
namespace service
{
class QxThreadPool;
/*!
* \ingroup QxService
* \brief qx::service::QxThread : thread to execute a transaction of QxService module
*
* <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>
*/
class QX_DLL_EXPORT QxThread : public QObject
{
Q_OBJECT
protected:
QX_TYPE_SOCKET_DESC m_iSocketDescriptor; //!< Socket descriptor to retrieve 'QTcpSocket'
QxThreadPool *m_pThreadPool; //!< Parent thread pool to set available
QThread *m_pThread; //!< Thread where this worker is executed
QxTransaction_ptr m_pTransaction; //!< Current service transaction
bool m_bIsStopped; //!< Set this flag to 'true' to terminate thread
bool m_bIsDisconnected; //!< Socket has been disconnected
QMutex m_mutex; //!< Mutex => 'QxThread' is thread-safe
public:
QxThread(QxThreadPool *pool, QThread *thread) : QObject(), m_iSocketDescriptor(0), m_pThreadPool(pool), m_pThread(thread), m_bIsStopped(false), m_bIsDisconnected(false)
{
qAssert(m_pThreadPool);
qAssert(m_pThread);
}
virtual ~QxThread() { clearData(); }
void init();
void stop();
void wait();
bool isAvailable();
void execute(QX_TYPE_SOCKET_DESC socketDescriptor);
protected:
void quit();
void clearData();
bool hasBeenStopped();
void doProcess(QTcpSocket &socket);
bool checkKeepAlive(QTcpSocket &socket);
QX_TYPE_SOCKET_DESC getSocketDescriptor();
#ifndef QT_NO_SSL
bool checkSocketSSLEncrypted(QTcpSocket *socket);
QSslSocket *initSocketSSL();
#endif // QT_NO_SSL
Q_SIGNALS:
void error(const QString &err, qx::service::QxTransaction_ptr transaction);
void transactionStarted(qx::service::QxTransaction_ptr transaction);
void transactionFinished(qx::service::QxTransaction_ptr transaction);
void customRequestHandler(qx::service::QxTransaction_ptr transaction);
void incomingConnection();
void finished();
private Q_SLOTS:
void onCustomRequestHandler();
void onIncomingConnection();
void onSocketDisconnected();
void onSocketReadyRead();
#ifndef QT_NO_SSL
#ifndef QT_NO_OPENSSL
void onSocketSSLEncrypted();
void onSocketSSLErrors(const QList<QSslError> &errors);
void onSocketSSLPeerVerifyError(const QSslError &error);
#endif // QT_NO_OPENSSL
#endif // QT_NO_SSL
};
} // namespace service
} // namespace qx
#endif // _QX_SERVICE_THREAD_H_
#endif // _QX_ENABLE_QT_NETWORK

View File

@@ -0,0 +1,129 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifdef Q_MOC_RUN
#include <QxCommon/QxConfig.h> // Need to include this file for the 'moc' process
#endif // Q_MOC_RUN
#ifdef _QX_ENABLE_QT_NETWORK
#ifndef _QX_SERVICE_THREAD_POOL_H_
#define _QX_SERVICE_THREAD_POOL_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxThreadPool.h
* \author XDL Team
* \ingroup QxService
* \brief Thread pool to manage list of threads for executing all transactions of QxService module
*/
#ifdef _QX_NO_PRECOMPILED_HEADER
#ifndef Q_MOC_RUN
#include <QxPrecompiled.h> // Need to include precompiled header for the generated moc file
#endif // Q_MOC_RUN
#endif // _QX_NO_PRECOMPILED_HEADER
#include <QtCore/qqueue.h>
#ifndef Q_MOC_RUN
#include <QxService/QxTransaction.h>
#include <QxService/QxServer.h>
#endif // Q_MOC_RUN
namespace qx
{
namespace service
{
class QxThread;
/*!
* \ingroup QxService
* \brief qx::service::QxThreadPool : thread-safe thread pool to manage list of threads for executing all transactions of QxService module
*
* <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>
*/
class QX_DLL_EXPORT QxThreadPool : public QThread
{
Q_OBJECT
protected:
QList<QxThread *> m_lstAllServices; //!< List of all services created by 'QxThreadPool'
QQueue<QxThread *> m_lstAvailable; //!< List of services available to execute process
bool m_bIsStopped; //!< Flag to indicate if thread has been stopped
QMutex m_mutex; //!< Mutex => 'QxThreadPool' is thread-safe
public:
QxThreadPool() : QThread(), m_bIsStopped(false) { ; }
virtual ~QxThreadPool()
{
if (isRunning())
{
qDebug("[QxOrm] qx::service::QxThreadPool thread is running : %s", "quit and wait");
quit();
wait();
}
}
bool isStopped() const;
QxThread *getAvailable();
void setAvailable(QxThread *p);
void raiseError(const QString &err, QxTransaction_ptr transaction);
static void sleepThread(unsigned long msecs) { QThread::msleep(msecs); }
protected:
virtual void run();
void runServer();
void initServices();
void clearServices();
Q_SIGNALS:
void error(const QString &err, qx::service::QxTransaction_ptr transaction);
void transactionStarted(qx::service::QxTransaction_ptr transaction);
void transactionFinished(qx::service::QxTransaction_ptr transaction);
void customRequestHandler(qx::service::QxTransaction_ptr transaction);
void serverIsRunning(bool bIsRunning, qx::service::QxServer *pServer);
};
typedef std::shared_ptr<QxThreadPool> QxThreadPool_ptr;
} // namespace service
} // namespace qx
#endif // _QX_SERVICE_THREAD_POOL_H_
#endif // _QX_ENABLE_QT_NETWORK

View File

@@ -0,0 +1,72 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifdef _QX_ENABLE_QT_NETWORK
#ifndef _QX_SERVICE_TOOLS_H_
#define _QX_SERVICE_TOOLS_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxTools.h
* \author XDL Team
* \ingroup QxService
* \brief Provide some tools to read/write on socket all datas transfered by QxService module of QxOrm library
*/
#include <QxService/QxTransaction.h>
namespace qx
{
namespace service
{
/*!
* \ingroup QxService
* \brief qx::service::QxTools : provide some tools to read/write on socket all datas transfered by QxService module of QxOrm library
*
* <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>
*/
class QX_DLL_EXPORT QxTools
{
public:
static qx_bool readSocket(QTcpSocket &socket, QxTransaction &transaction, quint32 &size);
static qx_bool writeSocket(QTcpSocket &socket, QxTransaction &transaction, quint32 &size);
};
} // namespace service
} // namespace qx
#endif // _QX_SERVICE_TOOLS_H_
#endif // _QX_ENABLE_QT_NETWORK

View File

@@ -0,0 +1,242 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifdef Q_MOC_RUN
#include <QxCommon/QxConfig.h> // Need to include this file for the 'moc' process
#endif // Q_MOC_RUN
#ifdef _QX_ENABLE_QT_NETWORK
#ifndef _QX_SERVICE_TRANSACTION_H_
#define _QX_SERVICE_TRANSACTION_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxTransaction.h
* \author XDL Team
* \ingroup QxService
* \brief Transaction of QxService module (contains request from client and reply from server)
*/
#ifdef _QX_NO_PRECOMPILED_HEADER
#ifndef Q_MOC_RUN
#include <QxPrecompiled.h> // Need to include precompiled header for the generated moc file
#endif // Q_MOC_RUN
#endif // _QX_NO_PRECOMPILED_HEADER
#include <QtCore/qdatastream.h>
#ifndef _QX_NO_JSON
#include <QtCore/qjsonvalue.h>
#endif // _QX_NO_JSON
#include <QtNetwork/qtcpsocket.h>
#ifndef QT_NO_SSL
#include <QtNetwork/qsslsocket.h>
#include <QtNetwork/qsslconfiguration.h>
#include <QtNetwork/qsslcertificate.h>
#include <QtNetwork/qsslerror.h>
#include <QtNetwork/qsslkey.h>
#endif // QT_NO_SSL
#ifndef Q_MOC_RUN
#include <QxCommon/QxBool.h>
#include <QxRegister/QxRegisterInternalHelper.h>
#include <QxService/IxService.h>
#include <QxService/IxParameter.h>
#include <QxConvert/QxConvert.h>
#endif // Q_MOC_RUN
namespace qx
{
namespace service
{
class QxTransaction;
} // namespace service
} // namespace qx
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;
#ifndef _QX_NO_JSON
namespace qx
{
namespace cvt
{
namespace detail
{
template <>
struct QxConvert_ToJson<qx::service::QxTransaction>;
template <>
struct QxConvert_FromJson<qx::service::QxTransaction>;
QX_DLL_EXPORT QJsonValue QxConvert_ToJson_Helper(const qx::service::QxTransaction &t, const QString &format) QX_USED;
QX_DLL_EXPORT qx_bool QxConvert_FromJson_Helper(const QJsonValue &j, qx::service::QxTransaction &t, const QString &format) QX_USED;
} // namespace detail
} // namespace cvt
} // namespace qx
#endif // _QX_NO_JSON
namespace qx
{
namespace service
{
/*!
* \ingroup QxService
* \brief qx::service::QxTransaction : transaction of QxService module (contains request from client and reply from server)
*
* <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>
*/
class QX_DLL_EXPORT QxTransaction : public QObject
{
Q_OBJECT
QX_REGISTER_FRIEND_CLASS(qx::service::QxTransaction)
friend QX_DLL_EXPORT QDataStream & ::operator<<(QDataStream &stream, const qx::service::QxTransaction &t);
friend QX_DLL_EXPORT QDataStream & ::operator>>(QDataStream &stream, qx::service::QxTransaction &t);
#ifndef _QX_NO_JSON
friend struct qx::cvt::detail::QxConvert_ToJson<qx::service::QxTransaction>;
friend struct qx::cvt::detail::QxConvert_FromJson<qx::service::QxTransaction>;
friend QX_DLL_EXPORT QJsonValue qx::cvt::detail::QxConvert_ToJson_Helper(const qx::service::QxTransaction &t, const QString &format);
friend QX_DLL_EXPORT qx_bool qx::cvt::detail::QxConvert_FromJson_Helper(const QJsonValue &j, qx::service::QxTransaction &t, const QString &format);
#endif // _QX_NO_JSON
public:
enum connection_status
{
conn_none,
conn_keep_alive,
conn_close
};
protected:
QString m_sTransactionId; //!< Transaction id (GUID)
quint32 m_uiInputTransactionSize; //!< Input transaction size
quint32 m_uiOutputTransactionSize; //!< Output transaction size
QDateTime m_dtTransactionBegin; //!< Date-time transaction begin
QDateTime m_dtTransactionRequestSent; //!< Date-time transaction request sent
QDateTime m_dtTransactionRequestReceived; //!< Date-time transaction request received
QDateTime m_dtTransactionReplySent; //!< Date-time transaction reply sent
QDateTime m_dtTransactionReplyReceived; //!< Date-time transaction reply received
QDateTime m_dtTransactionEnd; //!< Date-time transaction end
QString m_sIpSource; //!< Ip address source (request)
QString m_sIpTarget; //!< Ip address target (reply)
long m_lPortSource; //!< Port number source (request)
long m_lPortTarget; //!< Port number target (reply)
QString m_sServiceName; //!< Service name to create using 'QxFactory'
QString m_sServiceMethod; //!< Service method to call to execute transaction
qx_bool m_bMessageReturn; //!< Message return to indicate if an error occured
IxParameter_ptr m_pInputParameter; //!< List of input parameters (request)
IxParameter_ptr m_pOutputParameter; //!< List of output parameters (reply)
IxService_ptr m_pServiceInstance; //!< Service instance created by 'm_sServiceName' property
connection_status m_eForceConnectionStatus; //!< Sometimes we have to force connection status
public:
QxTransaction() : QObject(), m_uiInputTransactionSize(0), m_uiOutputTransactionSize(0), m_lPortSource(0), m_lPortTarget(0), m_eForceConnectionStatus(conn_none) { ; }
virtual ~QxTransaction() { ; }
virtual void clear();
QString getTransactionId() const { return m_sTransactionId; }
quint32 getInputTransactionSize() const { return m_uiInputTransactionSize; }
quint32 getOutputTransactionSize() const { return m_uiOutputTransactionSize; }
QDateTime getTransactionBegin() const { return m_dtTransactionBegin; }
QDateTime getTransactionRequestSent() const { return m_dtTransactionRequestSent; }
QDateTime getTransactionRequestReceived() const { return m_dtTransactionRequestReceived; }
QDateTime getTransactionReplySent() const { return m_dtTransactionReplySent; }
QDateTime getTransactionReplyReceived() const { return m_dtTransactionReplyReceived; }
QDateTime getTransactionEnd() const { return m_dtTransactionEnd; }
QString getIpSource() const { return m_sIpSource; }
QString getIpTarget() const { return m_sIpTarget; }
long getPortSource() const { return m_lPortSource; }
long getPortTarget() const { return m_lPortTarget; }
QString getServiceName() const { return m_sServiceName; }
QString getServiceMethod() const { return m_sServiceMethod; }
qx_bool getMessageReturn() const { return m_bMessageReturn; }
IxParameter_ptr getInputParameter() const { return m_pInputParameter; }
IxParameter_ptr getOutputParameter() const { return m_pOutputParameter; }
connection_status getForceConnectionStatus() const { return m_eForceConnectionStatus; }
void setTransactionId(const QString &s) { m_sTransactionId = s; }
void setInputTransactionSize(quint32 ui) { m_uiInputTransactionSize = ui; }
void setOutputTransactionSize(quint32 ui) { m_uiOutputTransactionSize = ui; }
void setTransactionBegin(const QDateTime &dt) { m_dtTransactionBegin = dt; }
void setTransactionRequestSent(const QDateTime &dt) { m_dtTransactionRequestSent = dt; }
void setTransactionRequestReceived(const QDateTime &dt) { m_dtTransactionRequestReceived = dt; }
void setTransactionReplySent(const QDateTime &dt) { m_dtTransactionReplySent = dt; }
void setTransactionReplyReceived(const QDateTime &dt) { m_dtTransactionReplyReceived = dt; }
void setTransactionEnd(const QDateTime &dt) { m_dtTransactionEnd = dt; }
void setIpSource(const QString &s) { m_sIpSource = s; }
void setIpTarget(const QString &s) { m_sIpTarget = s; }
void setPortSource(long l) { m_lPortSource = l; }
void setPortTarget(long l) { m_lPortTarget = l; }
void setServiceName(const QString &s) { m_sServiceName = s; }
void setServiceMethod(const QString &s) { m_sServiceMethod = s; }
void setMessageReturn(const qx_bool &b) { m_bMessageReturn = b; }
void setInputParameter(IxParameter_ptr p) { m_pInputParameter = p; }
void setOutputParameter(IxParameter_ptr p) { m_pOutputParameter = p; }
void setForceConnectionStatus(connection_status e) { m_eForceConnectionStatus = e; }
virtual void executeServer();
virtual qx_bool writeSocketServer(QTcpSocket &socket);
virtual qx_bool readSocketServer(QTcpSocket &socket);
virtual void executeClient(IxService *pService, const QString &sMethod);
virtual qx_bool writeSocketClient(QTcpSocket &socket);
virtual qx_bool readSocketClient(QTcpSocket &socket);
QString getInfos() const;
protected:
#ifndef QT_NO_SSL
QSslSocket *initSocketSSL();
bool checkSocketSSLEncrypted(QTcpSocket *socket);
#endif // QT_NO_SSL
Q_SIGNALS:
void onCustomRequestHandler();
};
typedef std::shared_ptr<QxTransaction> QxTransaction_ptr;
QX_DLL_EXPORT void execute_client(IxService *pService, const QString &sMethod);
} // namespace service
} // namespace qx
QX_REGISTER_INTERNAL_HELPER_HPP(QX_DLL_EXPORT, qx::service::QxTransaction, 0)
#endif // _QX_SERVICE_TRANSACTION_H_
#endif // _QX_ENABLE_QT_NETWORK