background_processing.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2012, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Ioan Sucan */
36 
37 #ifndef MOVEIT_BACKGROUND_PROCESSING_
38 #define MOVEIT_BACKGROUND_PROCESSING_
39 
40 #include <deque>
41 #include <string>
42 #include <boost/thread.hpp>
43 #include <boost/function.hpp>
44 #include <boost/noncopyable.hpp>
45 #include <memory>
46 
47 namespace moveit
48 {
52 namespace tools
53 {
57 class BackgroundProcessing : private boost::noncopyable
58 {
59 public:
61  enum JobEvent
62  {
64  ADD,
69  };
70 
73  typedef boost::function<void(JobEvent, const std::string&)> JobUpdateCallback;
74 
76  typedef boost::function<void()> JobCallback;
77 
80 
83 
85  void addJob(const JobCallback& job, const std::string& name);
86 
88  std::size_t getJobCount() const;
89 
91  void clear();
92 
94  void setJobUpdateEvent(const JobUpdateCallback& event);
95 
97  void clearJobUpdateEvent();
98 
99 private:
100  std::unique_ptr<boost::thread> processing_thread_;
102 
103  mutable boost::mutex action_lock_;
104  boost::condition_variable new_action_condition_;
105  std::deque<JobCallback> actions_;
106  std::deque<std::string> action_names_;
107 
108  JobUpdateCallback queue_change_event_;
109 
111 
112  void processingThread();
113 };
114 }
115 }
116 
117 #endif
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.
Called when a job is removed from the queue without execution.
Called when a job is completed (and removed from the queue)
~BackgroundProcessing()
Finishes currently executing job, clears the remaining queue.
std::unique_ptr< boost::thread > processing_thread_
std::size_t getJobCount() const
Get the size of the queue of jobs (includes currently processed job).
void clear()
Clear the queue of jobs.
This class provides simple API for executing background jobs. A queue of jobs is created and the spec...
boost::function< void()> JobCallback
The signature for job callbacks.
void clearJobUpdateEvent()
Clear the callback to be triggered when events in JobEvent take place.
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 na...
Called when a job is added to the queue.
Main namespace for MoveIt!
boost::condition_variable new_action_condition_
void setJobUpdateEvent(const JobUpdateCallback &event)
Set the callback to be triggered when events in JobEvent take place.


moveit_core
Author(s): Ioan Sucan , Sachin Chitta , Acorn Pooley
autogenerated on Sun Oct 18 2020 13:16:33