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. | |
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. | |
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. | |
BackgroundProcessing () | |
Constructor. The background thread is activated automatically. | |
void | clear () |
Clear the queue of jobs. | |
void | clearJobUpdateEvent () |
Clear the callback to be triggered when events in JobEvent take place. | |
std::size_t | getJobCount () const |
Get the size of the queue of jobs (includes currently processed job). | |
void | setJobUpdateEvent (const JobUpdateCallback &event) |
Set the callback to be triggered when events in JobEvent take place. | |
~BackgroundProcessing () | |
Finishes currently executing job, clears the remaining queue. | |
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_ |
boost::scoped_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 59 of file background_processing.h.
typedef boost::function<void()> moveit::tools::BackgroundProcessing::JobCallback |
The signature for job callbacks.
Definition at line 78 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 75 of file background_processing.h.
Events for jobs.
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 64 of file background_processing.h.
Constructor. The background thread is activated automatically.
Definition at line 40 of file background_processing.cpp.
Finishes currently executing job, clears the remaining queue.
Definition at line 48 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 96 of file background_processing.cpp.
Clear the queue of jobs.
Definition at line 108 of file background_processing.cpp.
Clear the callback to be triggered when events in JobEvent take place.
Definition at line 135 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 123 of file background_processing.cpp.
void moveit::tools::BackgroundProcessing::processingThread | ( | ) | [private] |
Definition at line 55 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 129 of file background_processing.cpp.
boost::mutex moveit::tools::BackgroundProcessing::action_lock_ [mutable, private] |
Definition at line 106 of file background_processing.h.
std::deque<std::string> moveit::tools::BackgroundProcessing::action_names_ [private] |
Definition at line 109 of file background_processing.h.
std::deque<JobCallback> moveit::tools::BackgroundProcessing::actions_ [private] |
Definition at line 108 of file background_processing.h.
boost::condition_variable moveit::tools::BackgroundProcessing::new_action_condition_ [private] |
Definition at line 107 of file background_processing.h.
bool moveit::tools::BackgroundProcessing::processing_ [private] |
Definition at line 113 of file background_processing.h.
boost::scoped_ptr<boost::thread> moveit::tools::BackgroundProcessing::processing_thread_ [private] |
Definition at line 103 of file background_processing.h.
Definition at line 111 of file background_processing.h.
bool moveit::tools::BackgroundProcessing::run_processing_thread_ [private] |
Definition at line 104 of file background_processing.h.