File indexing completed on 2024-04-21 04:01:27

0001 /* -*- C++ -*-
0002     Base class for job decorators in ThreadWeaver.
0003 
0004     SPDX-FileCopyrightText: 2005-2013 Mirko Boehm <mirko@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #ifndef THREADWEAVER_IDDECORATOR_H
0010 #define THREADWEAVER_IDDECORATOR_H
0011 
0012 #include <QObject>
0013 
0014 #include "jobinterface.h"
0015 #include "threadweaver_export.h"
0016 
0017 namespace ThreadWeaver
0018 {
0019 class Collection;
0020 class Sequence;
0021 
0022 /** @brief IdDecorator decorates a job without changing it's behaviour.
0023  *
0024  *  It is supposed to be used as the base class for actual decorators that do change the behaviour of jobs. */
0025 class THREADWEAVER_EXPORT IdDecorator : public JobInterface
0026 {
0027 public:
0028     explicit IdDecorator(JobInterface *job, bool autoDelete = true);
0029     ~IdDecorator() override;
0030     /** Retrieve the decorated job. */
0031     const JobInterface *job() const;
0032     /** Retrieve the decorated job. */
0033     JobInterface *job();
0034     /** Auto-delete the decoratee or not. */
0035     void setAutoDelete(bool onOff);
0036     /** Will the decoratee be auto-deleted? */
0037     bool autoDelete() const;
0038     /** Retrieve the decorated job as a Collection.
0039      *  If the decorated Job is not a Collection, 0 is returned. */
0040     const Collection *collection() const;
0041     /** Retrieve the decorated job as a Collection.
0042      *  If the decorated Job is not a Collection, 0 is returned. */
0043     Collection *collection();
0044     /** Retrieve the decorated job as a Sequence.
0045      *  If the decorated Job is not a Sequence, 0 is returned. */
0046     const Sequence *sequence() const;
0047     /** Retrieve the decorated job as a Sequence.
0048      *  If the decorated Job is not a Sequence, 0 is returned. */
0049     Sequence *sequence();
0050 
0051     void execute(const JobPointer &job, Thread *) override;
0052     void blockingExecute() override;
0053     Executor *setExecutor(Executor *executor) override;
0054     Executor *executor() const override;
0055     int priority() const override;
0056     void setStatus(Status) override;
0057     Status status() const override;
0058     bool success() const override;
0059     void requestAbort() override;
0060     void aboutToBeQueued(QueueAPI *api) override;
0061     void aboutToBeQueued_locked(QueueAPI *api) override;
0062     void aboutToBeDequeued(QueueAPI *api) override;
0063     void aboutToBeDequeued_locked(QueueAPI *api) override;
0064     bool isFinished() const override;
0065     void assignQueuePolicy(QueuePolicy *) override;
0066     void removeQueuePolicy(QueuePolicy *) override;
0067     QList<QueuePolicy *> queuePolicies() const override;
0068     QMutex *mutex() const override;
0069 
0070 protected:
0071     void run(JobPointer self, Thread *thread) override;
0072     void defaultBegin(const JobPointer &job, Thread *thread) override;
0073     void defaultEnd(const JobPointer &job, Thread *thread) override;
0074 
0075 private:
0076     class Private1;
0077     Private1 *const d1;
0078     class Private2;
0079     Private2 *d2;
0080 };
0081 
0082 }
0083 
0084 #endif // THREADWEAVER_IDDECORATOR_H