plugin_aggregator.h
Go to the documentation of this file.
00001 //=================================================================================================
00002 // Copyright (c) 2016, Alexander Stumpf, TU Darmstadt
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 //     * Redistributions of source code must retain the above copyright
00008 //       notice, this list of conditions and the following disclaimer.
00009 //     * Redistributions in binary form must reproduce the above copyright
00010 //       notice, this list of conditions and the following disclaimer in the
00011 //       documentation and/or other materials provided with the distribution.
00012 //     * Neither the name of the Simulation, Systems Optimization and Robotics
00013 //       group, TU Darmstadt nor the names of its contributors may be used to
00014 //       endorse or promote products derived from this software without
00015 //       specific prior written permission.
00016 
00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00018 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00019 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00020 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
00021 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00026 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 //=================================================================================================
00028 
00029 #ifndef VIGIR_PLUGINLIB_PLUGIN_AGGREGATOR_H__
00030 #define VIGIR_PLUGINLIB_PLUGIN_AGGREGATOR_H__
00031 
00032 #include <ros/ros.h>
00033 
00034 #include <vigir_generic_params/parameter_manager.h>
00035 
00036 #include <vigir_pluginlib/plugin_manager.h>
00037 
00038 
00039 
00040 namespace vigir_pluginlib
00041 {
00042 template<class PluginClass>
00043 class PluginAggregator
00044 {
00045 public:
00046   // typedefs
00047   typedef boost::shared_ptr<PluginAggregator<PluginClass>> Ptr;
00048   typedef boost::shared_ptr<const PluginAggregator<PluginClass>> ConstPtr;
00049   typedef boost::weak_ptr<PluginAggregator<PluginClass>> WeakPtr;
00050   typedef boost::weak_ptr<const PluginAggregator<PluginClass>> ConstWeakPtr;
00051 
00052   PluginAggregator(const std::string& name = std::string("PluginAggregator"))
00053     : name_(name) {}
00054 
00058   virtual void loadPlugins()
00059   {
00060     // get step cost estimator plugins
00061     PluginManager::getPluginsByType(plugins_);
00062 
00063     if (plugins_.empty())
00064       ROS_WARN("[%s] loadPlugins: Couldn't find any plugin of type '%s'.", name_.c_str(), vigir_pluginlib::Plugin::getTypeClass<PluginClass>().c_str());
00065     else
00066     {
00067       ROS_INFO("[%s] Plugins loaded:", name_.c_str());
00068       for (const boost::shared_ptr<PluginClass> plugin : plugins_)
00069       {
00070         if (plugin)
00071           ROS_INFO("    %s", plugin->getName().c_str());
00072       }
00073     }
00074   }
00075 
00080   virtual std::vector<boost::shared_ptr<PluginClass>> getPlugins() const
00081   {
00082     return plugins_;
00083   }
00084 
00089   virtual size_t size() const
00090   {
00091     return plugins_.size();
00092   }
00093 
00099   virtual bool loadParams(const vigir_generic_params::ParameterSet& params)
00100   {
00101     bool result = true;
00102 
00103     for (const boost::shared_ptr<PluginClass> plugin : plugins_)
00104     {
00105       if (plugin)
00106         result &= plugin->loadParams(params);
00107     }
00108 
00109     return result;
00110   }
00111 
00112 protected:
00113   std::string name_;
00114   std::vector<boost::shared_ptr<PluginClass>> plugins_;
00115 };
00116 }
00117 
00118 #endif


vigir_pluginlib
Author(s): Alexander Stumpf
autogenerated on Tue Sep 13 2016 03:47:30