This class provides simple API for executing background jobs. A queue of jobs is created and the specified jobs are executed in order, one at a time. More...
#include <background_processing.h>
Public Types | |
typedef boost::function< void()> | JobCallback |
The signature for job callbacks. More... | |
enum | JobEvent { ADD, REMOVE, COMPLETE } |
Events for jobs. More... | |
typedef boost::function< void(JobEvent, const std::string &)> | JobUpdateCallback |
The signature for callback triggered when job events take place: the event that took place and the name of the job. More... | |
Public Member Functions | |
void | addJob (const JobCallback &job, const std::string &name) |
Add a job to the queue of jobs to execute. A name is also specifies for the job. More... | |
BackgroundProcessing () | |
Constructor. The background thread is activated automatically. More... | |
void | clear () |
Clear the queue of jobs. More... | |
void | clearJobUpdateEvent () |
Clear the callback to be triggered when events in JobEvent take place. More... | |
std::size_t | getJobCount () const |
Get the size of the queue of jobs (includes currently processed job). More... | |
void | setJobUpdateEvent (const JobUpdateCallback &event) |
Set the callback to be triggered when events in JobEvent take place. More... | |
~BackgroundProcessing () | |
Finishes currently executing job, clears the remaining queue. More... | |
Private Member Functions | |
void | processingThread () |
Private Attributes | |
boost::mutex | action_lock_ |
std::deque< std::string > | action_names_ |
std::deque< JobCallback > | actions_ |
boost::condition_variable | new_action_condition_ |
bool | processing_ |
std::unique_ptr< boost::thread > | processing_thread_ |
JobUpdateCallback | queue_change_event_ |
bool | run_processing_thread_ |
This class provides simple API for executing background jobs. A queue of jobs is created and the specified jobs are executed in order, one at a time.
Definition at line 120 of file background_processing.h.
typedef boost::function<void()> moveit::tools::BackgroundProcessing::JobCallback |
The signature for job callbacks.
Definition at line 171 of file background_processing.h.
typedef boost::function<void(JobEvent, const std::string&)> moveit::tools::BackgroundProcessing::JobUpdateCallback |
The signature for callback triggered when job events take place: the event that took place and the name of the job.
Definition at line 168 of file background_processing.h.
Events for jobs.
Enumerator | |
---|---|
ADD | Called when a job is added to the queue. |
REMOVE | Called when a job is removed from the queue without execution. |
COMPLETE | Called when a job is completed (and removed from the queue) |
Definition at line 156 of file background_processing.h.
moveit::tools::BackgroundProcessing::BackgroundProcessing | ( | ) |
Constructor. The background thread is activated automatically.
Definition at line 108 of file background_processing.cpp.
moveit::tools::BackgroundProcessing::~BackgroundProcessing | ( | ) |
Finishes currently executing job, clears the remaining queue.
Definition at line 116 of file background_processing.cpp.
void moveit::tools::BackgroundProcessing::addJob | ( | const JobCallback & | job, |
const std::string & | name | ||
) |
Add a job to the queue of jobs to execute. A name is also specifies for the job.
Definition at line 161 of file background_processing.cpp.
void moveit::tools::BackgroundProcessing::clear | ( | ) |
Clear the queue of jobs.
Definition at line 173 of file background_processing.cpp.
void moveit::tools::BackgroundProcessing::clearJobUpdateEvent | ( | ) |
Clear the callback to be triggered when events in JobEvent take place.
Definition at line 200 of file background_processing.cpp.
std::size_t moveit::tools::BackgroundProcessing::getJobCount | ( | ) | const |
Get the size of the queue of jobs (includes currently processed job).
Definition at line 188 of file background_processing.cpp.
|
private |
Definition at line 123 of file background_processing.cpp.
void moveit::tools::BackgroundProcessing::setJobUpdateEvent | ( | const JobUpdateCallback & | event | ) |
Set the callback to be triggered when events in JobEvent take place.
Definition at line 194 of file background_processing.cpp.
|
mutableprivate |
Definition at line 198 of file background_processing.h.
|
private |
Definition at line 201 of file background_processing.h.
|
private |
Definition at line 200 of file background_processing.h.
|
private |
Definition at line 199 of file background_processing.h.
|
private |
Definition at line 205 of file background_processing.h.
|
private |
Definition at line 195 of file background_processing.h.
|
private |
Definition at line 203 of file background_processing.h.
|
private |
Definition at line 196 of file background_processing.h.