1/* -*- C++ -*-
2 Base class for job decorators in ThreadWeaver.
3
4 SPDX-FileCopyrightText: 2005-2013 Mirko Boehm <mirko@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#ifndef THREADWEAVER_IDDECORATOR_H
10#define THREADWEAVER_IDDECORATOR_H
11
12#include <QObject>
13
14#include "jobinterface.h"
15#include "threadweaver_export.h"
16
17namespace ThreadWeaver
18{
19class Collection;
20class Sequence;
21
22/** @brief IdDecorator decorates a job without changing it's behaviour.
23 *
24 * It is supposed to be used as the base class for actual decorators that do change the behaviour of jobs. */
25class THREADWEAVER_EXPORT IdDecorator : public JobInterface
26{
27public:
28 explicit IdDecorator(JobInterface *job, bool autoDelete = true);
29 ~IdDecorator() override;
30 /** Retrieve the decorated job. */
31 const JobInterface *job() const;
32 /** Retrieve the decorated job. */
33 JobInterface *job();
34 /** Auto-delete the decoratee or not. */
35 void setAutoDelete(bool onOff);
36 /** Will the decoratee be auto-deleted? */
37 bool autoDelete() const;
38 /** Retrieve the decorated job as a Collection.
39 * If the decorated Job is not a Collection, 0 is returned. */
40 const Collection *collection() const;
41 /** Retrieve the decorated job as a Collection.
42 * If the decorated Job is not a Collection, 0 is returned. */
43 Collection *collection();
44 /** Retrieve the decorated job as a Sequence.
45 * If the decorated Job is not a Sequence, 0 is returned. */
46 const Sequence *sequence() const;
47 /** Retrieve the decorated job as a Sequence.
48 * If the decorated Job is not a Sequence, 0 is returned. */
49 Sequence *sequence();
50
51 void execute(const JobPointer &job, Thread *) override;
52 void blockingExecute() override;
53 Executor *setExecutor(Executor *executor) override;
54 Executor *executor() const override;
55 int priority() const override;
56 void setStatus(Status) override;
57 Status status() const override;
58 bool success() const override;
59 void requestAbort() override;
60 void aboutToBeQueued(QueueAPI *api) override;
61 void aboutToBeQueued_locked(QueueAPI *api) override;
62 void aboutToBeDequeued(QueueAPI *api) override;
63 void aboutToBeDequeued_locked(QueueAPI *api) override;
64 bool isFinished() const override;
65 void assignQueuePolicy(QueuePolicy *) override;
66 void removeQueuePolicy(QueuePolicy *) override;
67 QList<QueuePolicy *> queuePolicies() const override;
68 QMutex *mutex() const override;
69
70protected:
71 void run(JobPointer self, Thread *thread) override;
72 void defaultBegin(const JobPointer &job, Thread *thread) override;
73 void defaultEnd(const JobPointer &job, Thread *thread) override;
74
75private:
76 class Private1;
77 Private1 *const d1;
78 class Private2;
79 Private2 *d2;
80};
81
82}
83
84#endif // THREADWEAVER_IDDECORATOR_H
85

source code of threadweaver/src/iddecorator.h