| QxOrm 1.3.2 C++ Object Relational Mapping library

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

QxThread.h
Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** http://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 #include <QxCommon/QxConfig.h> // Need to include this file for the 'moc' process
    00033
    00034 #if _QX_ENABLE_QT_NETWORK_DEPENDENCY
    00035 #ifndef _QX_SERVICE_THREAD_H_
    00036 #define _QX_SERVICE_THREAD_H_
    00037
    00038 #ifdef _MSC_VER
    00039 #pragma once
    00040 #endif
    00041
    00049 #ifdef _QX_NO_PRECOMPILED_HEADER
    00050 #ifndef Q_MOC_RUN
    00051 #include <QxPrecompiled.h> // Need to include precompiled header for the generated moc file
    00052 #endif // Q_MOC_RUN
    00053 #endif // _QX_NO_PRECOMPILED_HEADER
    00054
    00055 #include <QtNetwork/qtcpsocket.h>
    00056
    00057 #ifndef Q_MOC_RUN
    00058 #include <QxService/QxTransaction.h>
    00059 #endif // Q_MOC_RUN
    00060
    00061 #if (QT_VERSION >= 0x050000)
    00062 #define QX_TYPE_SOCKET_DESC qintptr
    00063 #else // (QT_VERSION >= 0x050000)
    00064 #define QX_TYPE_SOCKET_DESC int
    00065 #endif // (QT_VERSION >= 0x050000)
    00066
    00067 namespace qx {
    00068 namespace service {
    00069
    00070 class QxThreadPool;
    00071
    00078 class QX_DLL_EXPORT QxThread : public QThread
    00079 { Q_OBJECT
    00080
    00081 protected:
    00082
    00083    QX_TYPE_SOCKET_DESC m_iSocketDescriptor;
    00084    QxThreadPool * m_pThreadPool;
    00085    QxTransaction_ptr m_pTransaction;
    00086    bool m_bIsRunning;
    00087    QMutex m_mutex;
    00088
    00089 public:
    00090
    00091    QxThread(QxThreadPool * pool) : QThread(), m_iSocketDescriptor(0), m_pThreadPool(pool), m_bIsRunning(false) { qAssert(m_pThreadPool); }
    00092    virtual ~QxThread() { clearData(); }
    00093
    00094    bool isAvailable();
    00095    void stop();
    00096    void execute(QX_TYPE_SOCKET_DESC socketDescriptor);
    00097
    00098    static void sleepCurrentThread(unsigned long msecs) { QThread::msleep(msecs); }
    00099
    00100 protected:
    00101
    00102    virtual void run();
    00103
    00104    void clearData();
    00105    void doProcess(QTcpSocket & socket);
    00106    qx_bool readSocket(QTcpSocket & socket);
    00107    qx_bool writeSocket(QTcpSocket & socket);
    00108
    00109 Q_SIGNALS:
    00110
    00111    void error(const QString & err, qx::service::QxTransaction_ptr transaction);
    00112    void transactionStarted(qx::service::QxTransaction_ptr transaction);
    00113    void transactionFinished(qx::service::QxTransaction_ptr transaction);
    00114
    00115 };
    00116
    00117 } // namespace service
    00118 } // namespace qx
    00119
    00120 #endif // _QX_SERVICE_THREAD_H_
    00121 #endif // _QX_ENABLE_QT_NETWORK_DEPENDENCY