xbmc
Job.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 class CJob;
12 
13 #include <stddef.h>
14 
15 #define kJobTypeMediaFlags "mediaflags"
16 #define kJobTypeCacheImage "cacheimage"
17 #define kJobTypeDDSCompress "ddscompress"
18 
32 {
33 public:
39  virtual ~IJobCallback() = default;
40 
53  virtual void OnJobComplete(unsigned int jobID, bool success, CJob *job)=0;
54 
66  virtual void OnJobAbort(unsigned int jobID, CJob* job) {}
67 
80  virtual void OnJobProgress(unsigned int jobID,
81  unsigned int progress,
82  unsigned int total,
83  const CJob* job)
84  {
85  }
86 };
87 
88 class CJobManager;
89 
109 class CJob
110 {
111 public:
116  enum PRIORITY {
117  PRIORITY_LOW_PAUSABLE = 0,
118  PRIORITY_LOW,
119  PRIORITY_NORMAL,
120  PRIORITY_HIGH,
121  PRIORITY_DEDICATED, // will create a new worker if no worker is available at queue time
122  };
123  CJob() { m_callback = NULL; }
124 
134  virtual ~CJob() = default;
135 
144  virtual bool DoWork() = 0; // function to do the work
145 
156  virtual const char* GetType() const { return ""; }
157 
158  virtual bool operator==(const CJob* job) const
159  {
160  return false;
161  }
162 
175  virtual bool ShouldCancel(unsigned int progress, unsigned int total) const;
176 private:
177  friend class CJobManager;
178  CJobManager *m_callback;
179 };
virtual void OnJobProgress(unsigned int jobID, unsigned int progress, unsigned int total, const CJob *job)
An optional callback function that a job may call while processing.
Definition: Job.h:80
Base class for jobs that are executed asynchronously.
Definition: Job.h:109
Job Manager class for scheduling asynchronous jobs.
Definition: JobManager.h:205
virtual void OnJobComplete(unsigned int jobID, bool success, CJob *job)=0
The callback used when a job completes.
Callback interface for asynchronous jobs.
Definition: Job.h:31
virtual const char * GetType() const
Function that returns the type of job.
Definition: Job.h:156
virtual void OnJobAbort(unsigned int jobID, CJob *job)
An optional callback function used when a job will be aborted.
Definition: Job.h:66
PRIORITY
Priority levels for jobs, specified by clients when adding jobs to the CJobManager.
Definition: Job.h:116
virtual ~IJobCallback()=default
Destructor for job call back objects.