Kodi Documentation 18.0
Kodi is an open source media player and entertainment hub.
CJobManager Class Referencefinal

Job Manager class for scheduling asynchronous jobs. More...

#include <JobManager.h>

Public Member Functions

unsigned int AddJob (CJob *job, IJobCallback *callback, CJob::PRIORITY priority=CJob::PRIORITY_LOW)
 Add a job to the threaded job manager. More...
 
template<typename F >
void Submit (F &&f, CJob::PRIORITY priority=CJob::PRIORITY_LOW)
 Add a function f to this job manager for asynchronously execution. More...
 
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. More...
 
void CancelJob (unsigned int jobID)
 Cancel a job with the given id. More...
 
void CancelJobs ()
 Cancel all remaining jobs, preparing for shutdown Should be called prior to destroying any objects that may be being used as callbacks. More...
 
void Restart ()
 Re-start accepting jobs again Called after calling CancelJobs() to allow this manager to accept more jobs. More...
 
int IsProcessing (const std::string &type) const
 Checks to see if any jobs of a specific type are currently processing. More...
 
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. More...
 
void UnPauseJobs ()
 Resumes queueing of (previously paused) jobs with priority PRIORITY_LOW_PAUSABLE. More...
 
bool IsProcessing (const CJob::PRIORITY &priority) const
 Checks to see if any jobs with specific priority are currently processing. More...
 

Static Public Member Functions

static CJobManagerGetInstance ()
 The only way through which the global instance of the CJobManager should be accessed. More...
 

Protected Member Functions

CJobGetNextJob (const CJobWorker *worker)
 Get a new job to process. Blocks until a new job is available, or a timeout has occurred. More...
 
void OnJobComplete (bool success, CJob *job)
 Callback from CJobWorker after a job has completed. Calls IJobCallback::OnJobComplete(), and then destroys job. More...
 
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(). More...
 

Friends

class CJobWorker
 
class CJob
 
class CJobQueue
 

Detailed Description

Job Manager class for scheduling asynchronous jobs.

Controls asynchronous job execution, by allowing clients to add and cancel jobs. Should be accessed via CJobManager::GetInstance(). 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.

See also
CJob and IJobCallback

Member Function Documentation

◆ AddJob()

unsigned int CJobManager::AddJob ( CJob job,
IJobCallback callback,
CJob::PRIORITY  priority = CJob::PRIORITY_LOW 
)

Add a job to the threaded job manager.

Parameters
joba pointer to the job to add. The job should be subclassed from CJob
callbacka pointer to an IJobCallback instance to receive job progress and completion notices.
prioritythe priority that this job should run at.
Returns
a unique identifier for this job, to be used with other interaction
See also
CJob, IJobCallback, CancelJob()

◆ CancelJob()

void CJobManager::CancelJob ( unsigned int  jobID)

Cancel a job with the given id.

Parameters
jobIDthe id of the job to cancel, retrieved previously from AddJob()
See also
AddJob()

◆ CancelJobs()

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.

See also
CancelJob(), AddJob()

◆ GetInstance()

CJobManager & CJobManager::GetInstance ( )
static

The only way through which the global instance of the CJobManager should be accessed.

Returns
the global instance.

◆ GetNextJob()

CJob * CJobManager::GetNextJob ( const CJobWorker worker)
protected

Get a new job to process. Blocks until a new job is available, or a timeout has occurred.

Parameters
workera pointer to the current CJobWorker instance requesting a job.
See also
CJob

◆ IsProcessing() [1/2]

bool CJobManager::IsProcessing ( const CJob::PRIORITY priority) const

Checks to see if any jobs with specific priority are currently processing.

Parameters
priorityto search for
Returns
true if processing jobs, else returns false

◆ IsProcessing() [2/2]

int CJobManager::IsProcessing ( const std::string &  type) const

Checks to see if any jobs of a specific type are currently processing.

Parameters
typeJob type to search for
Returns
Number of matching jobs

◆ OnJobComplete()

void CJobManager::OnJobComplete ( bool  success,
CJob job 
)
protected

Callback from CJobWorker after a job has completed. Calls IJobCallback::OnJobComplete(), and then destroys job.

Parameters
joba pointer to the calling subclassed CJob instance.
successthe result from the DoWork call
See also
IJobCallback, CJob

◆ OnJobProgress()

bool CJobManager::OnJobProgress ( unsigned int  progress,
unsigned int  total,
const CJob job 
) const
protected

Callback from CJob to report progress and check for cancellation. Checks for cancellation, and calls IJobCallback::OnJobProgress().

Parameters
progressamount of processing performed to date, out of total.
totaltotal amount of processing.
jobpointer to the calling subclassed CJob instance.
Returns
true if the job has been cancelled, else returns false.
See also
IJobCallback, CJob

◆ PauseJobs()

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.

See also
UnPauseJobs()

◆ Restart()

void CJobManager::Restart ( )

Re-start accepting jobs again Called after calling CancelJobs() to allow this manager to accept more jobs.

Exceptions
std::logic_errorif the manager was not previously cancelled
See also
CancelJobs()

◆ Submit() [1/2]

template<typename F >
void CJobManager::Submit ( F &&  f,
CJob::PRIORITY  priority = CJob::PRIORITY_LOW 
)
inline

Add a function f to this job manager for asynchronously execution.

◆ Submit() [2/2]

template<typename F >
void CJobManager::Submit ( F &&  f,
IJobCallback callback,
CJob::PRIORITY  priority = CJob::PRIORITY_LOW 
)
inline

Add a function f to this job manager for asynchronously execution.

◆ UnPauseJobs()

void CJobManager::UnPauseJobs ( )

Resumes queueing of (previously paused) jobs with priority PRIORITY_LOW_PAUSABLE.

See also
PauseJobs()

Friends And Related Function Documentation

◆ CJob

friend class CJob
friend

◆ CJobQueue

friend class CJobQueue
friend

◆ CJobWorker

friend class CJobWorker
friend

The documentation for this class was generated from the following files: