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 #pragma once
38 
39 #include <deque>
40 #include <string>
41 #include <boost/thread.hpp>
42 #include <boost/function.hpp>
43 #include <boost/noncopyable.hpp>
44 #include <memory>
45 
46 namespace moveit
47 {
51 namespace tools
52 {
56 class BackgroundProcessing : private boost::noncopyable
57 {
58 public:
60  enum JobEvent
61  {
63  ADD,
65  REMOVE,
67  COMPLETE
68  };
69 
72  typedef boost::function<void(JobEvent, const std::string&)> JobUpdateCallback;
73 
75  typedef boost::function<void()> JobCallback;
76 
79 
82 
84  void addJob(const JobCallback& job, const std::string& name);
85 
87  std::size_t getJobCount() const;
88 
90  void clear();
91 
93  void setJobUpdateEvent(const JobUpdateCallback& event);
94 
96  void clearJobUpdateEvent();
97 
98 private:
99  std::unique_ptr<boost::thread> processing_thread_;
101 
102  mutable boost::mutex action_lock_;
103  boost::condition_variable new_action_condition_;
104  std::deque<JobCallback> actions_;
105  std::deque<std::string> action_names_;
106 
108 
109  bool processing_;
110 
111  void processingThread();
112 };
113 } // namespace tools
114 } // namespace moveit
moveit::tools::BackgroundProcessing::new_action_condition_
boost::condition_variable new_action_condition_
Definition: background_processing.h:199
moveit::tools::BackgroundProcessing::COMPLETE
@ COMPLETE
Called when a job is completed (and removed from the queue)
Definition: background_processing.h:195
moveit::tools::BackgroundProcessing::setJobUpdateEvent
void setJobUpdateEvent(const JobUpdateCallback &event)
Set the callback to be triggered when events in JobEvent take place.
Definition: background_processing.cpp:194
moveit::tools::BackgroundProcessing::processingThread
void processingThread()
Definition: background_processing.cpp:123
moveit::tools::BackgroundProcessing::queue_change_event_
JobUpdateCallback queue_change_event_
Definition: background_processing.h:203
moveit::tools::BackgroundProcessing::clear
void clear()
Clear the queue of jobs.
Definition: background_processing.cpp:173
moveit::tools::BackgroundProcessing::~BackgroundProcessing
~BackgroundProcessing()
Finishes currently executing job, clears the remaining queue.
Definition: background_processing.cpp:116
moveit::tools::BackgroundProcessing::action_lock_
boost::mutex action_lock_
Definition: background_processing.h:198
moveit::tools::BackgroundProcessing::JobEvent
JobEvent
Events for jobs.
Definition: background_processing.h:156
moveit::tools::BackgroundProcessing::BackgroundProcessing
BackgroundProcessing()
Constructor. The background thread is activated automatically.
Definition: background_processing.cpp:108
name
std::string name
moveit::tools::BackgroundProcessing::JobUpdateCallback
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...
Definition: background_processing.h:168
moveit::tools::BackgroundProcessing::processing_
bool processing_
Definition: background_processing.h:205
moveit::tools::BackgroundProcessing::action_names_
std::deque< std::string > action_names_
Definition: background_processing.h:201
moveit::tools::BackgroundProcessing::processing_thread_
std::unique_ptr< boost::thread > processing_thread_
Definition: background_processing.h:195
moveit::tools::BackgroundProcessing::REMOVE
@ REMOVE
Called when a job is removed from the queue without execution.
Definition: background_processing.h:193
moveit::tools::BackgroundProcessing::run_processing_thread_
bool run_processing_thread_
Definition: background_processing.h:196
moveit
Main namespace for MoveIt.
Definition: background_processing.h:46
moveit::tools::BackgroundProcessing::actions_
std::deque< JobCallback > actions_
Definition: background_processing.h:200
moveit::tools::BackgroundProcessing::addJob
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.
Definition: background_processing.cpp:161
moveit::tools::BackgroundProcessing::clearJobUpdateEvent
void clearJobUpdateEvent()
Clear the callback to be triggered when events in JobEvent take place.
Definition: background_processing.cpp:200
moveit::tools::BackgroundProcessing::JobCallback
boost::function< void()> JobCallback
The signature for job callbacks.
Definition: background_processing.h:171
moveit::tools::BackgroundProcessing::ADD
@ ADD
Called when a job is added to the queue.
Definition: background_processing.h:191
moveit::tools::BackgroundProcessing::getJobCount
std::size_t getJobCount() const
Get the size of the queue of jobs (includes currently processed job).
Definition: background_processing.cpp:188


moveit_core
Author(s): Ioan Sucan , Sachin Chitta , Acorn Pooley
autogenerated on Thu Nov 21 2024 03:23:41