| 1 | /**************************************************************************** |
|---|---|
| 2 | ** |
| 3 | ** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt3D module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #include "qaspectjob.h" |
| 41 | #include "qaspectjob_p.h" |
| 42 | |
| 43 | #include <QtCore/QByteArray> |
| 44 | |
| 45 | QT_BEGIN_NAMESPACE |
| 46 | |
| 47 | namespace Qt3DCore { |
| 48 | |
| 49 | namespace { |
| 50 | |
| 51 | bool isDependencyNull(const QWeakPointer<QAspectJob> &dep) |
| 52 | { |
| 53 | return dep.isNull(); |
| 54 | } |
| 55 | |
| 56 | } // anonymous |
| 57 | |
| 58 | QAspectJobPrivate::QAspectJobPrivate() |
| 59 | : m_jobName(QLatin1String("UnknowJob")) |
| 60 | { |
| 61 | } |
| 62 | |
| 63 | QAspectJobPrivate::~QAspectJobPrivate() = default; |
| 64 | |
| 65 | QAspectJobPrivate *QAspectJobPrivate::get(QAspectJob *job) |
| 66 | { |
| 67 | return job->d_func(); |
| 68 | } |
| 69 | |
| 70 | bool QAspectJobPrivate::isRequired() const |
| 71 | { |
| 72 | return true; |
| 73 | } |
| 74 | |
| 75 | void QAspectJobPrivate::postFrame(QAspectManager *aspectManager) |
| 76 | { |
| 77 | Q_UNUSED(aspectManager) |
| 78 | } |
| 79 | |
| 80 | QAspectJob::QAspectJob() |
| 81 | : d_ptr(new QAspectJobPrivate) |
| 82 | { |
| 83 | } |
| 84 | |
| 85 | /*! |
| 86 | * \class Qt3DCore::QAspectJob |
| 87 | * \inheaderfile Qt3DCore/QAspectJob |
| 88 | * \inmodule Qt3DCore |
| 89 | * \brief The base class for jobs executed in an aspect. |
| 90 | */ |
| 91 | |
| 92 | /*! |
| 93 | * \fn void Qt3DCore::QAspectJob::run() |
| 94 | * Executes the job. |
| 95 | */ |
| 96 | |
| 97 | /*! |
| 98 | * \internal |
| 99 | */ |
| 100 | QAspectJob::QAspectJob(QAspectJobPrivate &dd) |
| 101 | : d_ptr(&dd) |
| 102 | { |
| 103 | } |
| 104 | |
| 105 | QAspectJob::~QAspectJob() |
| 106 | { |
| 107 | delete d_ptr; |
| 108 | } |
| 109 | |
| 110 | /*! |
| 111 | * Adds \a dependency to the aspect job. |
| 112 | */ |
| 113 | void QAspectJob::addDependency(QWeakPointer<QAspectJob> dependency) |
| 114 | { |
| 115 | Q_D(QAspectJob); |
| 116 | d->m_dependencies.append(t: dependency); |
| 117 | #ifdef QT3DCORE_ASPECT_JOB_DEBUG |
| 118 | static int threshold = qMax(1, qgetenv("QT3DCORE_ASPECT_JOB_DEPENDENCY_THRESHOLD").toInt()); |
| 119 | if (d->m_dependencies.count() > threshold) |
| 120 | qWarning() << "Suspicious number of job dependencies found"; |
| 121 | #endif |
| 122 | } |
| 123 | |
| 124 | /*! |
| 125 | * Removes the given \a dependency from aspect job. |
| 126 | */ |
| 127 | void QAspectJob::removeDependency(QWeakPointer<QAspectJob> dependency) |
| 128 | { |
| 129 | Q_D(QAspectJob); |
| 130 | if (!dependency.isNull()) { |
| 131 | d->m_dependencies.removeAll(t: dependency); |
| 132 | } else { |
| 133 | d->m_dependencies.erase(abegin: std::remove_if(first: d->m_dependencies.begin(), |
| 134 | last: d->m_dependencies.end(), |
| 135 | pred: isDependencyNull), |
| 136 | aend: d->m_dependencies.end()); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | /*! |
| 141 | * \return the dependencies of the aspect job. |
| 142 | */ |
| 143 | QVector<QWeakPointer<QAspectJob> > QAspectJob::dependencies() const |
| 144 | { |
| 145 | Q_D(const QAspectJob); |
| 146 | return d->m_dependencies; |
| 147 | } |
| 148 | |
| 149 | void QAspectJob::postFrame(QAspectManager *aspectManager) |
| 150 | { |
| 151 | Q_D(QAspectJob); |
| 152 | if (aspectManager) |
| 153 | d->postFrame(aspectManager); |
| 154 | } |
| 155 | |
| 156 | } // namespace Qt3DCore |
| 157 | |
| 158 | QT_END_NAMESPACE |
| 159 |
