nodelet_class.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include <nodelet/nodelet.h>
00031 #include <nodelet/detail/callback_queue.h>
00032 #include <nodelet/detail/callback_queue_manager.h>
00033 
00034 #include <ros/ros.h>
00035 #include <ros/callback_queue.h>
00036 
00037 namespace nodelet
00038 {
00039 
00040 Nodelet::Nodelet ()
00041 : inited_(false)
00042 , nodelet_name_("uninitialized")
00043 {
00044 }
00045 
00046 Nodelet::~Nodelet()
00047 {
00048 }
00049 
00050 ros::CallbackQueueInterface& Nodelet::getSTCallbackQueue () const
00051 {
00052   if (!inited_)
00053   {
00054     throw UninitializedException("getSTCallbackQueue");
00055   }
00056 
00057   return *nh_->getCallbackQueue();
00058 }
00059 
00060 ros::CallbackQueueInterface& Nodelet::getMTCallbackQueue () const
00061 {
00062   if (!inited_)
00063   {
00064     throw UninitializedException("getMTCallbackQueue");
00065   }
00066 
00067   return *mt_nh_->getCallbackQueue();
00068 }
00069 
00070 ros::NodeHandle& Nodelet::getNodeHandle() const
00071 {
00072   if (!inited_)
00073   {
00074     throw UninitializedException("getNodeHandle");
00075   }
00076 
00077   return *nh_;
00078 }
00079 ros::NodeHandle& Nodelet::getPrivateNodeHandle() const
00080 {
00081   if (!inited_)
00082   {
00083     throw UninitializedException("getPrivateNodeHandle");
00084   }
00085 
00086   return *private_nh_;
00087 }
00088 ros::NodeHandle& Nodelet::getMTNodeHandle() const
00089 {
00090   if (!inited_)
00091   {
00092     throw UninitializedException("getMTNodeHandle");
00093   }
00094 
00095   return *mt_nh_;
00096 }
00097 ros::NodeHandle& Nodelet::getMTPrivateNodeHandle() const
00098 {
00099   if (!inited_)
00100   {
00101     throw UninitializedException("getMTPrivateNodeHandle");
00102   }
00103 
00104   return *mt_private_nh_;
00105 }
00106 
00107 void Nodelet::init(const std::string& name, const M_string& remapping_args, const V_string& my_argv,
00108                    ros::CallbackQueueInterface* st_queue, ros::CallbackQueueInterface* mt_queue)
00109 {
00110   if (inited_)
00111   {
00112     throw MultipleInitializationException();
00113   }
00114 
00115   nodelet_name_ = name;
00116   remapping_args_ = remapping_args;
00117   my_argv_ = my_argv;
00118 
00119   // Set up NodeHandles with correct namespaces
00120   private_nh_.reset(new ros::NodeHandle(name, remapping_args));
00121   nh_.reset(new ros::NodeHandle(ros::names::parentNamespace(name), remapping_args));
00122   mt_private_nh_.reset(new ros::NodeHandle(name, remapping_args));
00123   mt_nh_.reset(new ros::NodeHandle(ros::names::parentNamespace(name), remapping_args));
00124 
00125   // Use the provided callback queues (or the global queue if they're NULL).
00126   // This allows Loader and CallbackQueueManager to spread nodelets over multiple threads.
00127   private_nh_->setCallbackQueue(st_queue);
00128   nh_->setCallbackQueue(st_queue);
00129   mt_private_nh_->setCallbackQueue(mt_queue);
00130   mt_nh_->setCallbackQueue(mt_queue);
00131 
00132   NODELET_DEBUG ("Nodelet initializing");
00133   inited_ = true;
00134   this->onInit ();
00135 }
00136 
00137 } // namespace nodelet


nodelet
Author(s): Tully Foote, Radu Bogdan Rusu
autogenerated on Sun Feb 17 2019 03:43:51