File indexing completed on 2024-04-14 04:46:35

0001 /*
0002     SPDX-FileCopyrightText: 2021 Jean-Baptiste Mardelle <jb@kdenlive.org>
0003 
0004     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #pragma once
0008 
0009 #include "definitions.h"
0010 
0011 #include <QAtomicInt>
0012 #include <QMutex>
0013 #include <QObject>
0014 #include <QRunnable>
0015 #include <QUuid>
0016 
0017 class AbstractTask : public QObject, public QRunnable
0018 {
0019     Q_OBJECT
0020     friend class TaskManager;
0021 
0022 public:
0023     enum JOBTYPE {
0024         NOJOBTYPE = 0,
0025         PROXYJOB = 1,
0026         CUTJOB = 2,
0027         STABILIZEJOB = 3,
0028         TRANSCODEJOB = 4,
0029         FILTERCLIPJOB = 5,
0030         THUMBJOB = 6,
0031         ANALYSECLIPJOB = 7,
0032         LOADJOB = 8,
0033         AUDIOTHUMBJOB = 9,
0034         SPEEDJOB = 10,
0035         CACHEJOB = 11
0036     };
0037     AbstractTask(const ObjectId &owner, JOBTYPE type, QObject* object);
0038     ~AbstractTask() override;
0039     static void closeAll();
0040     static void setPreferredPriority(qint64 pid);
0041     const ObjectId ownerId() const;
0042     bool operator==(const AbstractTask& b);
0043 
0044 protected:
0045     ObjectId m_owner;
0046     QObject* m_object;
0047     int m_progress;
0048     QString m_description;
0049     bool m_successful;
0050     QAtomicInt m_isCanceled;
0051     QAtomicInt m_softDelete;
0052     QMutex m_runMutex;
0053     bool m_isForce;
0054     bool m_running;
0055     QUuid m_uuid;
0056     void run() override;
0057     void cleanup();
0058 
0059 private:
0060     //QString cacheKey();
0061     JOBTYPE m_type;
0062     int m_priority;
0063     void cancelJob(bool softDelete = false);
0064     bool isCanceled() const;
0065 
0066 Q_SIGNALS:
0067     void jobCanceled();
0068 };
0069 
0070 /**
0071  * @brief When destroyed, notifies the taskManager that this task is done.
0072  */
0073 class AbstractTaskDone {
0074 public:
0075     AbstractTaskDone(int cid, AbstractTask *task)
0076         : m_cid(cid)
0077         , m_task(task) {}
0078     ~AbstractTaskDone();
0079 private:
0080     int m_cid;
0081     AbstractTask *m_task;
0082 };