File indexing completed on 2025-01-19 03:57:56

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2010-09-03
0007  * Description : Integrated, multithread face detection / recognition
0008  *
0009  * SPDX-FileCopyrightText: 2010-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "parallelpipes.h"
0016 
0017 // Local includes
0018 
0019 #include "digikam_debug.h"
0020 
0021 namespace Digikam
0022 {
0023 
0024 ParallelPipes::ParallelPipes()
0025     : m_currentIndex(0)
0026 {
0027 }
0028 
0029 ParallelPipes::~ParallelPipes()
0030 {
0031     Q_FOREACH (WorkerObject* const object, m_workers)
0032     {
0033         delete object;
0034     }
0035 }
0036 
0037 void ParallelPipes::schedule()
0038 {
0039     Q_FOREACH (WorkerObject* const object, m_workers)
0040     {
0041         object->schedule();
0042     }
0043 }
0044 
0045 void ParallelPipes::deactivate(WorkerObject::DeactivatingMode mode)
0046 {
0047     Q_FOREACH (WorkerObject* const object, m_workers)
0048     {
0049         object->deactivate(mode);
0050     }
0051 }
0052 
0053 void ParallelPipes::wait()
0054 {
0055     Q_FOREACH (WorkerObject* const object, m_workers)
0056     {
0057         object->wait();
0058     }
0059 }
0060 
0061 void ParallelPipes::setPriority(QThread::Priority priority)
0062 {
0063     Q_FOREACH (WorkerObject* const object, m_workers)
0064     {
0065         object->setPriority(priority);
0066     }
0067 }
0068 
0069 void ParallelPipes::add(WorkerObject* const worker)
0070 {
0071     QByteArray normalizedSignature = QMetaObject::normalizedSignature("process(FacePipelineExtendedPackage::Ptr)");
0072     int methodIndex                = worker->metaObject()->indexOfMethod(normalizedSignature.constData());
0073 
0074     if (methodIndex == -1)
0075     {
0076         qCDebug(DIGIKAM_GENERAL_LOG) << "Object" << worker << "does not have a slot"
0077                                      << normalizedSignature << " - cannot use for processing.";
0078         return;
0079     }
0080 
0081     m_workers << worker;
0082     m_methods << worker->metaObject()->method(methodIndex);
0083 
0084     // collect the worker's signals and bundle them to our single signal, which is further connected
0085 
0086     connect(worker, SIGNAL(processed(FacePipelineExtendedPackage::Ptr)),
0087             this, SIGNAL(processed(FacePipelineExtendedPackage::Ptr)));
0088 }
0089 
0090 void ParallelPipes::process(const FacePipelineExtendedPackage::Ptr& package)
0091 {
0092     // Here, we send the package to one of the workers, in turn
0093 
0094     m_methods.at(m_currentIndex).invoke(m_workers.at(m_currentIndex), Qt::QueuedConnection,
0095                                         Q_ARG(FacePipelineExtendedPackage::Ptr, package));
0096 
0097     if (++m_currentIndex == m_workers.size())
0098     {
0099         m_currentIndex = 0;
0100     }
0101 }
0102 
0103 } // namespace Digikam
0104 
0105 #include "moc_parallelpipes.cpp"