Kodi Documentation 22.0
Kodi is an open source media player and entertainment hub.
|
Job Manager class for scheduling asynchronous jobs. More...
#include <JobManager.h>
Public Member Functions | |
CJobManager () | |
unsigned int | AddJob (CJob *job, IJobCallback *callback, CJob::PRIORITY priority=CJob::PRIORITY_LOW) |
Add a job to the threaded job manager. On completion or abort of the job or in case the job could not be added successfully, the CJob object will be destroyed. | |
template<typename F > | |
void | Submit (F &&f, CJob::PRIORITY priority=CJob::PRIORITY_LOW) |
Add a function f to this job manager for asynchronously execution. | |
template<typename F > | |
void | Submit (F &&f, IJobCallback *callback, CJob::PRIORITY priority=CJob::PRIORITY_LOW) |
Add a function f to this job manager for asynchronously execution. | |
void | CancelJob (unsigned int jobID) |
Cancel a job with the given id. | |
void | CancelJobs () |
Cancel all remaining jobs, preparing for shutdown Should be called prior to destroying any objects that may be being used as callbacks. | |
void | Restart () |
Re-start accepting jobs again Called after calling CancelJobs() to allow this manager to accept more jobs. | |
int | IsProcessing (const std::string &type) const |
Checks to see if any jobs of a specific type are currently processing. | |
void | PauseJobs () |
Suspends queueing of jobs with priority PRIORITY_LOW_PAUSABLE until unpaused Useful to (for ex) stop queuing thumb jobs during video start/playback. Does not affect currently processing jobs, use IsProcessing to see if any need to be waited on. | |
void | UnPauseJobs () |
Resumes queueing of (previously paused) jobs with priority PRIORITY_LOW_PAUSABLE. | |
bool | IsProcessing (const CJob::PRIORITY &priority) const |
Checks to see if any jobs with specific priority are currently processing. | |
Protected Member Functions | |
CJob * | GetNextJob () |
Get a new job to process. Blocks until a new job is available, or a timeout has occurred. | |
void | OnJobComplete (bool success, CJob *job) |
Callback from CJobWorker after a job has completed. Calls IJobCallback::OnJobComplete(), and then destroys job. | |
bool | OnJobProgress (unsigned int progress, unsigned int total, const CJob *job) const |
Callback from CJob to report progress and check for cancellation. Checks for cancellation, and calls IJobCallback::OnJobProgress(). | |
Friends | |
class | CJobWorker |
class | CJob |
class | CJobQueue |
Job Manager class for scheduling asynchronous jobs.
Controls asynchronous job execution, by allowing clients to add and cancel jobs. Should be accessed via CServiceBroker::GetJobManager(). Jobs are allocated based on priority levels. Lower priority jobs are executed only if there are sufficient spare worker threads free to allow for higher priority jobs that may arise.
CJobManager::CJobManager | ( | ) |
unsigned int CJobManager::AddJob | ( | CJob * | job, |
IJobCallback * | callback, | ||
CJob::PRIORITY | priority = CJob::PRIORITY_LOW ) |
Add a job to the threaded job manager. On completion or abort of the job or in case the job could not be added successfully, the CJob object will be destroyed.
job | a pointer to the job to add. The job should be subclassed from CJob |
callback | a pointer to an IJobCallback instance to receive job progress and completion notices. |
priority | the priority that this job should run at. |
void CJobManager::CancelJobs | ( | ) |
Cancel all remaining jobs, preparing for shutdown Should be called prior to destroying any objects that may be being used as callbacks.
|
protected |
Get a new job to process. Blocks until a new job is available, or a timeout has occurred.
bool CJobManager::IsProcessing | ( | const CJob::PRIORITY & | priority | ) | const |
Checks to see if any jobs with specific priority are currently processing.
priority | to search for |
int CJobManager::IsProcessing | ( | const std::string & | type | ) | const |
Checks to see if any jobs of a specific type are currently processing.
type | Job type to search for |
Callback from CJobWorker after a job has completed. Calls IJobCallback::OnJobComplete(), and then destroys job.
job | a pointer to the calling subclassed CJob instance. |
success | the result from the DoWork call |
|
protected |
Callback from CJob to report progress and check for cancellation. Checks for cancellation, and calls IJobCallback::OnJobProgress().
progress | amount of processing performed to date, out of total. |
total | total amount of processing. |
job | pointer to the calling subclassed CJob instance. |
void CJobManager::PauseJobs | ( | ) |
Suspends queueing of jobs with priority PRIORITY_LOW_PAUSABLE until unpaused Useful to (for ex) stop queuing thumb jobs during video start/playback. Does not affect currently processing jobs, use IsProcessing to see if any need to be waited on.
void CJobManager::Restart | ( | ) |
Re-start accepting jobs again Called after calling CancelJobs() to allow this manager to accept more jobs.
std::logic_error | if the manager was not previously cancelled |
|
inline |
Add a function f to this job manager for asynchronously execution.
|
inline |
Add a function f to this job manager for asynchronously execution.
void CJobManager::UnPauseJobs | ( | ) |
Resumes queueing of (previously paused) jobs with priority PRIORITY_LOW_PAUSABLE.
|
friend |
|
friend |
|
friend |