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>

Classes

class  CJobWorker
 
struct  JobFinder
 

Public Member Functions

 CJobManager ()
 
bool IsRunning () const
 
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 asynchronous 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 asynchronous 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.
 
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().
 
CJobGetNextJob ()
 Get a new job to process. Blocks until a new job is available, or a timeout has occurred.
 
 CJobManager ()=default
 
bool IsRunning () const
 Returns whether the job manager is currently running.
 
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 asynchronous 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 asynchronous 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.
 
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().
 
CJobGetNextJob ()
 Get a new job to process. Blocks until a new job is available, or a timeout has occurred.
 

Friends

class CJobWorker
 

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() [1/2]

CJobManager::CJobManager ( )

◆ CJobManager() [2/2]

CJobManager::CJobManager ( )
default

Member Function Documentation

◆ AddJob() [1/2]

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

◆ AddJob() [2/2]

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() [1/2]

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

◆ CancelJob() [2/2]

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() [1/2]

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

◆ CancelJobs() [2/2]

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() [1/2]

CJob * CJobManager::GetNextJob ( )

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

See also
CJob

◆ GetNextJob() [2/2]

CJob * CJobManager::GetNextJob ( )

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

See also
CJob

◆ IsProcessing() [1/4]

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/4]

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() [3/4]

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

◆ IsProcessing() [4/4]

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

◆ IsRunning() [1/2]

bool CJobManager::IsRunning ( ) const
inline
Todo
doxy

◆ IsRunning() [2/2]

bool CJobManager::IsRunning ( ) const

Returns whether the job manager is currently running.

Returns
True if the job manager is running and able to process jobs, false if it has been stopped or not started. The method will return false after the job manager has been shut down or before it has been started.
See also
CJob

◆ OnJobComplete() [1/2]

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

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

◆ OnJobComplete() [2/2]

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

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() [1/2]

bool CJobManager::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().

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

◆ OnJobProgress() [2/2]

bool CJobManager::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().

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() [1/2]

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

◆ PauseJobs() [2/2]

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() [1/2]

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

◆ Restart() [2/2]

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/4]

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

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

Parameters
fthe function to add.
prioritythe priority that this job should run at.
See also
CJob, AddJob()

◆ Submit() [2/4]

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

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

Parameters
fthe function to add.
prioritythe priority that this job should run at.
See also
CJob, AddJob()

◆ Submit() [3/4]

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

Parameters
fthe function to add.
callbacka pointer to an IJobCallback instance to receive job progress and completion notices.
prioritythe priority that this job should run at.
See also
CJob, IJobCallback, AddJob()

◆ Submit() [4/4]

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

Parameters
fthe function to add.
callbacka pointer to an IJobCallback instance to receive job progress and completion notices.
prioritythe priority that this job should run at.
See also
CJob, IJobCallback, AddJob()

◆ UnPauseJobs() [1/2]

void CJobManager::UnPauseJobs ( )

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

See also
PauseJobs()

◆ UnPauseJobs() [2/2]

void CJobManager::UnPauseJobs ( )

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

See also
PauseJobs()

Friends And Related Symbol Documentation

◆ CJobWorker

friend class CJobWorker
friend

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