| QxOrm 1.2.6 C++ Object Relational Mapping library

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

- File List
- File Members

QxThreadPool.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_POOL_H_
    00036 #define _QX_SERVICE_THREAD_POOL_H_
    00037
    00038 #ifdef _MSC_VER
    00039 #pragma once
    00040 #endif
    00041
    00049 #include <QtCore/qqueue.h>
    00050
    00051 #ifndef Q_MOC_RUN
    00052 #include <QxService/QxTransaction.h>
    00053 #include <QxService/QxServer.h>
    00054 #endif // Q_MOC_RUN
    00055
    00056 namespace qx {
    00057 namespace service {
    00058
    00059 class QxThread;
    00060
    00067 class QX_DLL_EXPORT QxThreadPool : public QThread
    00068 { Q_OBJECT
    00069
    00070 protected:
    00071
    00072    QList<QxThread *> m_lstAllServices;
    00073    QQueue<QxThread *> m_lstAvailable;
    00074    bool m_bIsRunning;
    00075    QMutex m_mutex;
    00076
    00077 public:
    00078
    00079    QxThreadPool() : QThread(), m_bIsRunning(false) { ; }
    00080    virtual ~QxThreadPool() { if (isRunning()) { qDebug("[QxOrm] qx::service::QxThreadPool thread is running : %s", "quit and wait"); quit(); wait(); } }
    00081
    00082    QxThread * getAvailable();
    00083    void setAvailable(QxThread * p);
    00084    void raiseError(const QString & err, QxTransaction_ptr transaction);
    00085
    00086    void sleepThread(unsigned long msecs) { QThread::msleep(msecs); }
    00087
    00088 protected:
    00089
    00090    virtual void run();
    00091
    00092    void runServer();
    00093    void initServices();
    00094    void clearServices();
    00095
    00096 Q_SIGNALS:
    00097
    00098    void error(const QString & err, qx::service::QxTransaction_ptr transaction);
    00099    void transactionStarted(qx::service::QxTransaction_ptr transaction);
    00100    void transactionFinished(qx::service::QxTransaction_ptr transaction);
    00101    void serverIsRunning(bool bIsRunning, qx::service::QxServer * pServer);
    00102
    00103 };
    00104
    00105 typedef boost::shared_ptr<QxThreadPool> QxThreadPool_ptr;
    00106
    00107 } // namespace service
    00108 } // namespace qx
    00109
    00110 #endif // _QX_SERVICE_THREAD_POOL_H_
    00111 #endif // _QX_ENABLE_QT_NETWORK_DEPENDENCY