collision_plugin_cache.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2014 Fetch Robotics 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 Fetch Robotics 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 
37 #include <memory>
38 
39 static const std::string LOGNAME = "collision_detection";
40 
41 namespace collision_detection
42 {
44 {
45 public:
47  {
48  try
49  {
50  cache_ = std::make_shared<pluginlib::ClassLoader<CollisionPlugin>>("moveit_core",
51  "collision_detection::CollisionPlugin");
52  }
54  {
55  ROS_ERROR("Unable to construct collision plugin loader. Error: %s", e.what());
56  }
57  }
58 
59  CollisionPluginPtr load(const std::string& name)
60  {
61  CollisionPluginPtr plugin;
62  try
63  {
64  plugin = cache_->createUniqueInstance(name);
65  plugins_[name] = plugin;
66  }
68  {
69  ROS_ERROR_STREAM("Exception while loading " << name << ": " << ex.what());
70  }
71  return plugin;
72  }
73 
74  bool activate(const std::string& name, const planning_scene::PlanningScenePtr& scene, bool exclusive)
75  {
76  std::map<std::string, CollisionPluginPtr>::iterator it = plugins_.find(name);
77  if (it == plugins_.end())
78  {
79  CollisionPluginPtr plugin = load(name);
80  if (plugin)
81  {
82  return plugin->initialize(scene, exclusive);
83  }
84  return false;
85  }
86  if (it->second)
87  {
88  return it->second->initialize(scene, exclusive);
89  }
90  return false;
91  }
92 
93 private:
94  std::shared_ptr<pluginlib::ClassLoader<CollisionPlugin>> cache_;
95  std::map<std::string, CollisionPluginPtr> plugins_;
96 };
97 
99 {
100  cache_ = std::make_shared<CollisionPluginCacheImpl>();
101 }
102 
104 
105 bool CollisionPluginCache::activate(const std::string& name, const planning_scene::PlanningScenePtr& scene,
106  bool exclusive)
107 {
108  return cache_->activate(name, scene, exclusive);
109 }
110 
111 } // namespace collision_detection
collision_detection::CollisionPluginCache::CollisionPluginCacheImpl::CollisionPluginCacheImpl
CollisionPluginCacheImpl()
Definition: collision_plugin_cache.cpp:46
ROS_ERROR_STREAM
#define ROS_ERROR_STREAM(args)
collision_detection::CollisionPluginCache::CollisionPluginCacheImpl
Definition: collision_plugin_cache.cpp:43
collision_detection::CollisionPluginCache::CollisionPluginCacheImpl::plugins_
std::map< std::string, CollisionPluginPtr > plugins_
Definition: collision_plugin_cache.cpp:95
collision_detection::CollisionPluginCache::CollisionPluginCacheImpl::cache_
std::shared_ptr< pluginlib::ClassLoader< CollisionPlugin > > cache_
Definition: collision_plugin_cache.cpp:94
collision_detection::CollisionPluginCache::cache_
CollisionPluginCacheImplPtr cache_
Definition: collision_plugin_cache.h:124
pluginlib::PluginlibException
collision_detection::CollisionPluginCache::CollisionPluginCacheImpl::activate
bool activate(const std::string &name, const planning_scene::PlanningScenePtr &scene, bool exclusive)
Definition: collision_plugin_cache.cpp:74
name
std::string name
collision_detection::CollisionPluginCache::activate
bool activate(const std::string &name, const planning_scene::PlanningScenePtr &scene, bool exclusive)
Activate a specific collision plugin for the given planning scene instance.
Definition: collision_plugin_cache.cpp:105
collision_plugin_cache.h
ROS_ERROR
#define ROS_ERROR(...)
collision_detection::CollisionPluginCache::CollisionPluginCache
CollisionPluginCache()
Definition: collision_plugin_cache.cpp:98
class_loader.hpp
LOGNAME
static const std::string LOGNAME
Definition: collision_plugin_cache.cpp:39
collision_detection::CollisionPluginCache::~CollisionPluginCache
~CollisionPluginCache()
collision_detection::CollisionPluginCache::CollisionPluginCacheImpl::load
CollisionPluginPtr load(const std::string &name)
Definition: collision_plugin_cache.cpp:59
collision_detection
Definition: collision_detector_allocator_allvalid.h:42


moveit_core
Author(s): Ioan Sucan , Sachin Chitta , Acorn Pooley
autogenerated on Fri May 3 2024 02:28:40