callback_queue.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
32 
33 #include <ros/callback_queue.h>
34 
35 namespace nodelet
36 {
37 namespace detail
38 {
39 
41  const ros::VoidConstPtr& tracked_object)
42 : parent_(parent)
43 , tracked_object_(tracked_object)
44 , has_tracked_object_(tracked_object)
45 {
46 }
47 
49 {
50 }
51 
52 void CallbackQueue::addCallback(const ros::CallbackInterfacePtr& cb, uint64_t owner_id)
53 {
54  if (queue_.isEnabled())
55  {
56  queue_.addCallback(cb, owner_id);
57  parent_->callbackAdded(shared_from_this());
58  }
59 }
60 
61 void CallbackQueue::removeByID(uint64_t owner_id)
62 {
63  queue_.removeByID(owner_id);
64 }
65 
67 {
68  // Don't try to call the callback after its nodelet has been destroyed!
69  ros::VoidConstPtr tracker;
71  {
72  tracker = tracked_object_.lock();
73 
74  if (!tracker)
76  }
77 
78  return queue_.callOne();
79 }
80 
82 {
83  queue_.enable();
84 }
85 
87 {
88  queue_.disable();
89 }
90 
91 
92 } // namespace detail
93 } // namespace nodelet
void enable()
Enable the queue (queue is enabled by default)
virtual void addCallback(const CallbackInterfacePtr &callback, uint64_t removal_id=0)
void disable()
Disable the queue, meaning any calls to addCallback() will have no effect.
CallOneResult callOne()
CallbackQueueManager * parent_
ros::VoidConstWPtr tracked_object_
virtual void removeByID(uint64_t owner_id)
void callbackAdded(const CallbackQueuePtr &queue)
virtual void addCallback(const ros::CallbackInterfacePtr &callback, uint64_t owner_id=0)
virtual void removeByID(uint64_t removal_id)
CallbackQueue(CallbackQueueManager *parent, const ros::VoidConstPtr &tracked_object=ros::VoidConstPtr())


nodelet
Author(s): Tully Foote, Radu Bogdan Rusu
autogenerated on Mon Feb 28 2022 22:57:12