callback_queue.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2009, 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, Inc. 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 #ifndef ROSCPP_CALLBACK_QUEUE_H
36 #define ROSCPP_CALLBACK_QUEUE_H
37 
39 #include "ros/time.h"
40 #include "common.h"
41 
42 #include <boost/shared_ptr.hpp>
43 #include <boost/thread/condition_variable.hpp>
44 #include <boost/thread/mutex.hpp>
45 #include <boost/thread/shared_mutex.hpp>
46 #include <boost/thread/tss.hpp>
47 
48 #include <list>
49 #include <deque>
50 
51 namespace ros
52 {
53 
57 class ROSCPP_DECL CallbackQueue : public CallbackQueueInterface
58 {
59 public:
60  CallbackQueue(bool enabled = true);
61  virtual ~CallbackQueue();
62 
63  virtual void addCallback(const CallbackInterfacePtr& callback, uint64_t removal_id = 0);
64  virtual void removeByID(uint64_t removal_id);
65 
67  {
72  };
73 
79  {
80  return callOne(ros::WallDuration());
81  }
82 
91  CallOneResult callOne(ros::WallDuration timeout);
92 
97  {
98  callAvailable(ros::WallDuration());
99  }
107  void callAvailable(ros::WallDuration timeout);
108 
112  bool empty() { return isEmpty(); }
116  bool isEmpty();
120  void clear();
121 
125  void enable();
129  void disable();
133  bool isEnabled();
134 
135 protected:
136  void setupTLS();
137 
138  struct TLS;
139  CallOneResult callOneCB(TLS* tls);
140 
141  struct IDInfo
142  {
143  uint64_t id;
144  boost::shared_mutex calling_rw_mutex;
145  };
147  typedef std::map<uint64_t, IDInfoPtr> M_IDInfo;
148 
149  IDInfoPtr getIDInfo(uint64_t id);
150 
152  {
154  : removal_id(0)
155  , marked_for_removal(false)
156  {}
158  uint64_t removal_id;
160  };
161  typedef std::list<CallbackInfo> L_CallbackInfo;
162  typedef std::deque<CallbackInfo> D_CallbackInfo;
164  size_t calling_;
165  boost::mutex mutex_;
166  boost::condition_variable condition_;
167 
168  boost::mutex id_info_mutex_;
170 
171  struct TLS
172  {
173  TLS()
174  : calling_in_this_thread(0xffffffffffffffffULL)
175  , cb_it(callbacks.end())
176  {}
179  D_CallbackInfo::iterator cb_it;
180  };
181  boost::thread_specific_ptr<TLS> tls_;
182 
183  bool enabled_;
184 };
186 
187 }
188 
189 #endif
ros::CallbackQueue::Disabled
@ Disabled
Definition: callback_queue.h:70
ros::CallbackQueue::TLS::cb_it
D_CallbackInfo::iterator cb_it
Definition: callback_queue.h:179
callback_queue_interface.h
ros::CallbackQueue::calling_
size_t calling_
Definition: callback_queue.h:164
ros::CallbackQueue::TLS
Definition: callback_queue.h:171
boost::shared_ptr< CallbackInterface >
ros::CallbackQueue::enabled_
bool enabled_
Definition: callback_queue.h:183
ros::CallbackQueue::CallbackInfo::removal_id
uint64_t removal_id
Definition: callback_queue.h:158
ros::CallbackQueue::TryAgain
@ TryAgain
Definition: callback_queue.h:69
ros::CallbackQueue::IDInfo
Definition: callback_queue.h:141
ros
time.h
ros::CallbackQueue::callbacks_
D_CallbackInfo callbacks_
Definition: callback_queue.h:163
ros::CallbackQueue::CallOneResult
CallOneResult
Definition: callback_queue.h:66
ros::CallbackQueue::CallbackInfo::callback
CallbackInterfacePtr callback
Definition: callback_queue.h:157
ros::CallbackQueue::CallbackInfo
Definition: callback_queue.h:151
ros::CallbackQueue::TLS::callbacks
D_CallbackInfo callbacks
Definition: callback_queue.h:178
ros::CallbackQueuePtr
boost::shared_ptr< CallbackQueue > CallbackQueuePtr
Definition: callback_queue.h:185
ros::CallbackQueue::IDInfo::id
uint64_t id
Definition: callback_queue.h:143
ros::CallbackQueue::condition_
boost::condition_variable condition_
Definition: callback_queue.h:166
ros::CallbackQueue::L_CallbackInfo
std::list< CallbackInfo > L_CallbackInfo
Definition: callback_queue.h:161
ros::CallbackQueue::empty
bool empty()
returns whether or not the queue is empty
Definition: callback_queue.h:112
ros::CallbackQueue
This is the default implementation of the ros::CallbackQueueInterface.
Definition: callback_queue.h:57
ros::CallbackQueue::id_info_
M_IDInfo id_info_
Definition: callback_queue.h:169
ros::CallbackQueue::IDInfo::calling_rw_mutex
boost::shared_mutex calling_rw_mutex
Definition: callback_queue.h:144
ros::CallbackQueue::D_CallbackInfo
std::deque< CallbackInfo > D_CallbackInfo
Definition: callback_queue.h:162
ros::CallbackQueue::id_info_mutex_
boost::mutex id_info_mutex_
Definition: callback_queue.h:168
ros::CallbackQueue::callOne
CallOneResult callOne()
Pop a single callback off the front of the queue and invoke it. If the callback was not ready to be c...
Definition: callback_queue.h:78
ros::WallDuration
ros::CallbackQueue::tls_
boost::thread_specific_ptr< TLS > tls_
Definition: callback_queue.h:181
ros::CallbackQueue::mutex_
boost::mutex mutex_
Definition: callback_queue.h:165
ros::CallbackQueue::M_IDInfo
std::map< uint64_t, IDInfoPtr > M_IDInfo
Definition: callback_queue.h:147
ros::CallbackQueue::Empty
@ Empty
Definition: callback_queue.h:71
ros::CallbackQueue::CallbackInfo::CallbackInfo
CallbackInfo()
Definition: callback_queue.h:153
ros::CallbackQueue::TLS::TLS
TLS()
Definition: callback_queue.h:173
ros::CallbackQueue::callAvailable
void callAvailable()
Invoke all callbacks currently in the queue. If a callback was not ready to be called,...
Definition: callback_queue.h:96
ros::CallbackQueue::Called
@ Called
Definition: callback_queue.h:68
ros::CallbackQueueInterface
Abstract interface for a queue used to handle all callbacks within roscpp.
Definition: callback_queue_interface.h:82
ros::CallbackQueue::TLS::calling_in_this_thread
uint64_t calling_in_this_thread
Definition: callback_queue.h:177
ros::CallbackQueue::CallbackInfo::marked_for_removal
bool marked_for_removal
Definition: callback_queue.h:159
ros::CallbackQueue::IDInfoPtr
boost::shared_ptr< IDInfo > IDInfoPtr
Definition: callback_queue.h:146


roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim, Dirk Thomas , Jacob Perron
autogenerated on Sat Sep 14 2024 02:59:35