Kodi Documentation 22.0
Kodi is an open source media player and entertainment hub.
Loading...
Searching...
No Matches
CJobManager Class Referencefinal

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

CJobGetNextJob ()
 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
 

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 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.

See also
CJob and IJobCallback

Constructor & Destructor Documentation

◆ CJobManager()

CJobManager::CJobManager ( )

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. On completion or abort of the job or in case the job could not be added successfully, the CJob object will be destroyed.

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
On success, a unique identifier for this job, to be used with other interaction, 0 otherwise. In case of failure, the passed CJob object will be deleted before returning from this method.
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()

◆ GetNextJob()

CJob * CJobManager::GetNextJob ( )
protected

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

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 Symbol 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: