39 #include <nodelet/NodeletLoad.h>
40 #include <nodelet/NodeletList.h>
41 #include <nodelet/NodeletUnload.h>
43 #include <boost/ptr_container/ptr_map.hpp>
44 #include <boost/utility.hpp>
90 nodelet::NodeletLoad::Response &res)
92 boost::mutex::scoped_lock lock(
lock_);
96 if (req.remap_source_args.size() != req.remap_target_args.size())
98 ROS_ERROR(
"Bad remapppings provided, target and source of different length");
102 for (
size_t i = 0; i < req.remap_source_args.size(); ++i)
109 res.success =
parent_->
load(req.name, req.type, remappings, req.my_argv);
112 if (res.success && !req.bond_id.empty())
124 nodelet::NodeletUnload::Response &res)
126 res.success =
unload(req.name);
132 boost::mutex::scoped_lock lock(
lock_);
137 ROS_ERROR(
"Failed to find nodelet with name '%s' to unload.", name.c_str());
142 M_stringToBond::iterator it =
bond_map_.find(name);
145 it->second->setBrokenCallback(boost::function<
void(
void)>());
154 nodelet::NodeletList::Response &res)
206 boost::function<boost::shared_ptr<Nodelet> (
const std::string& lookup_name)>
create_instance_;
219 create_instance_ = boost::bind(&Loader::createInstance, loader, boost::placeholders::_1);
230 int num_threads_param;
231 server_nh.
param(
"num_worker_threads", num_threads_param, 0);
252 impl_->advertiseRosApi(
this, server_nh);
256 : impl_(new
Impl(create_instance))
266 const std::vector<std::string> & my_argv)
268 boost::mutex::scoped_lock lock(
lock_);
269 if (
impl_->nodelets_.count(name) > 0)
271 ROS_ERROR(
"Cannot load nodelet %s for one exists with that name already", name.c_str());
278 p =
impl_->create_instance_(type);
280 catch (std::runtime_error& e)
283 if(!
impl_->refresh_classes_)
285 ROS_ERROR(
"Failed to load nodelet [%s] of type [%s]: %s", name.c_str(), type.c_str(), e.what());
292 impl_->refresh_classes_();
293 p =
impl_->create_instance_(type);
295 catch (std::runtime_error& e2)
300 ROS_ERROR(
"Failed to load nodelet [%s] of type [%s] even after refreshing the cache: %s", name.c_str(), type.c_str(), e2.what());
301 ROS_ERROR(
"The error before refreshing the cache was: %s", e.what());
310 ROS_DEBUG(
"Done loading nodelet %s", name.c_str());
313 impl_->nodelets_.insert(
const_cast<std::string&
>(name), mn);
318 ROS_DEBUG(
"Done initing nodelet %s", name.c_str());
320 Impl::M_stringToNodelet::iterator it =
impl_->nodelets_.find(name);
321 if (it !=
impl_->nodelets_.end())
323 impl_->nodelets_.erase(it);
324 ROS_DEBUG (
"Failed to initialize nodelet %s", name.c_str ());
333 boost::mutex::scoped_lock lock (
lock_);
334 Impl::M_stringToNodelet::iterator it =
impl_->nodelets_.find(name);
335 if (it !=
impl_->nodelets_.end())
337 impl_->nodelets_.erase(it);
338 ROS_DEBUG (
"Done unloading nodelet %s", name.c_str ());
347 boost::mutex::scoped_lock lock(
lock_);
348 impl_->nodelets_.clear();
354 boost::mutex::scoped_lock lock (
lock_);
355 std::vector<std::string> output;
356 Impl::M_stringToNodelet::iterator it =
impl_->nodelets_.begin();
357 for (; it !=
impl_->nodelets_.end(); ++it)
359 output.push_back(it->first);