nodelet_class.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 
30 #include <nodelet/nodelet.h>
33 
34 #include <ros/ros.h>
35 #include <ros/callback_queue.h>
36 
37 namespace nodelet
38 {
39 
41 : inited_(false)
42 , nodelet_name_("uninitialized")
43 {
44 }
45 
47 {
48 }
49 
51 {
52  if (!inited_)
53  {
54  throw UninitializedException("getSTCallbackQueue");
55  }
56 
57  return *nh_->getCallbackQueue();
58 }
59 
61 {
62  if (!inited_)
63  {
64  throw UninitializedException("getMTCallbackQueue");
65  }
66 
67  return *mt_nh_->getCallbackQueue();
68 }
69 
71 {
72  if (!inited_)
73  {
74  throw UninitializedException("getNodeHandle");
75  }
76 
77  return *nh_;
78 }
80 {
81  if (!inited_)
82  {
83  throw UninitializedException("getPrivateNodeHandle");
84  }
85 
86  return *private_nh_;
87 }
89 {
90  if (!inited_)
91  {
92  throw UninitializedException("getMTNodeHandle");
93  }
94 
95  return *mt_nh_;
96 }
98 {
99  if (!inited_)
100  {
101  throw UninitializedException("getMTPrivateNodeHandle");
102  }
103 
104  return *mt_private_nh_;
105 }
106 
107 void Nodelet::init(const std::string& name, const M_string& remapping_args, const V_string& my_argv,
109 {
110  if (inited_)
111  {
113  }
114 
115  nodelet_name_ = name;
116  remapping_args_ = remapping_args;
117  my_argv_ = my_argv;
118 
119  // Set up NodeHandles with correct namespaces
120  private_nh_.reset(new ros::NodeHandle(name, remapping_args));
121  nh_.reset(new ros::NodeHandle(ros::names::parentNamespace(name), remapping_args));
122  mt_private_nh_.reset(new ros::NodeHandle(name, remapping_args));
123  mt_nh_.reset(new ros::NodeHandle(ros::names::parentNamespace(name), remapping_args));
124 
125  // Use the provided callback queues (or the global queue if they're NULL).
126  // This allows Loader and CallbackQueueManager to spread nodelets over multiple threads.
127  private_nh_->setCallbackQueue(st_queue);
128  nh_->setCallbackQueue(st_queue);
129  mt_private_nh_->setCallbackQueue(mt_queue);
130  mt_nh_->setCallbackQueue(mt_queue);
131 
132  NODELET_DEBUG ("Nodelet initializing");
133  inited_ = true;
134  this->onInit ();
135 }
136 
137 } // namespace nodelet
nodelet::V_string
std::vector< std::string > V_string
Definition: loader.h:57
nodelet::Nodelet::init
void init(const std::string &name, const M_string &remapping_args, const V_string &my_argv, ros::CallbackQueueInterface *st_queue=NULL, ros::CallbackQueueInterface *mt_queue=NULL)
Init function called at startup.
Definition: nodelet_class.cpp:107
nodelet.h
nodelet::Nodelet::getNodeHandle
ros::NodeHandle & getNodeHandle() const
Definition: nodelet_class.cpp:70
nodelet::M_string
std::map< std::string, std::string > M_string
Definition: loader.h:55
ros.h
nodelet::MultipleInitializationException
Definition: nodelet.h:178
nodelet::Nodelet::getMTPrivateNodeHandle
ros::NodeHandle & getMTPrivateNodeHandle() const
Definition: nodelet_class.cpp:97
nodelet::Nodelet::private_nh_
NodeHandlePtr private_nh_
Definition: nodelet.h:214
nodelet::Nodelet::mt_private_nh_
NodeHandlePtr mt_private_nh_
Definition: nodelet.h:216
nodelet::Nodelet::getPrivateNodeHandle
ros::NodeHandle & getPrivateNodeHandle() const
Definition: nodelet_class.cpp:79
ros::names::parentNamespace
ROSCPP_DECL std::string parentNamespace(const std::string &name)
nodelet::Nodelet::onInit
virtual void onInit()=0
nodelet::Nodelet::getMTCallbackQueue
ros::CallbackQueueInterface & getMTCallbackQueue() const
Definition: nodelet_class.cpp:60
nodelet::Nodelet::inited_
bool inited_
Definition: nodelet.h:209
callback_queue.h
nodelet::Nodelet::nh_
NodeHandlePtr nh_
Definition: nodelet.h:213
nodelet::Nodelet::~Nodelet
virtual ~Nodelet()
Definition: nodelet_class.cpp:46
nodelet
Definition: callback_queue.h:44
callback_queue.h
nodelet::Nodelet::mt_nh_
NodeHandlePtr mt_nh_
Definition: nodelet.h:215
nodelet::Nodelet::remapping_args_
M_string remapping_args_
Definition: nodelet.h:218
nodelet::UninitializedException
Definition: nodelet.h:170
callback_queue_manager.h
nodelet::Nodelet::my_argv_
V_string my_argv_
Definition: nodelet.h:217
nodelet::Nodelet::Nodelet
Nodelet()
Empty constructor required for dynamic loading.
Definition: nodelet_class.cpp:40
ros::CallbackQueueInterface
nodelet::Nodelet::getSTCallbackQueue
ros::CallbackQueueInterface & getSTCallbackQueue() const
Definition: nodelet_class.cpp:50
ros::NodeHandle
nodelet::Nodelet::nodelet_name_
std::string nodelet_name_
Definition: nodelet.h:211
nodelet::Nodelet::getMTNodeHandle
ros::NodeHandle & getMTNodeHandle() const
Definition: nodelet_class.cpp:88
NODELET_DEBUG
#define NODELET_DEBUG(...)
Definition: nodelet.h:49


nodelet
Author(s): Tully Foote, Radu Bogdan Rusu, Michael Carroll
autogenerated on Fri Jan 12 2024 03:40:39