plugin.cpp
Go to the documentation of this file.
00001 #include <vigir_pluginlib/plugin.h>
00002 
00003 
00004 
00005 namespace vigir_pluginlib
00006 {
00007 #ifdef __GNUG__
00008 #include <cstdlib>
00009 #include <memory>
00010 #include <cxxabi.h>
00011 
00012 // enable c++11 by passing the flag -std=c++11 to g++
00013 std::string demangle(const char* name)
00014 {
00015   int status = 0;
00016 
00017   std::unique_ptr<char, void(*)(void*)> res
00018   {
00019     abi::__cxa_demangle(name, NULL, NULL, &status),
00020     std::free
00021   };
00022 
00023   return (status==0) ? res.get() : name ;
00024 }
00025 
00026 #else
00027 
00028 // does nothing if not g++
00029 std::string demangle(const char* name)
00030 {
00031   return name;
00032 }
00033 
00034 #endif
00035 
00036 Plugin::Plugin(const std::string& name, const std::string& type_class_package, const std::string& base_class_package, const std::string& base_class)
00037 {
00038   msgs::PluginDescription description;
00039   description.name.data = name;
00040   description.type_class_package.data = type_class_package;
00041   description.base_class_package.data = base_class_package;
00042   description.base_class.data = base_class;
00043 }
00044 
00045 Plugin::~Plugin()
00046 {
00047 }
00048 
00049 bool Plugin::setup(ros::NodeHandle& nh, const vigir_generic_params::ParameterSet& /*global_params*/)
00050 {
00051   setNodehandle(nh);
00052 
00053   // reinitialize plugin's local parameter set
00054   std::string public_ns = description_.public_param_ns.data + "/params";
00055   std::string private_ns = description_.private_param_ns.data + "/params";
00056 
00057   // get parameters from rosparam server
00058   vigir_generic_params::ParameterSet params;
00059   if (nh.hasParam(public_ns))
00060     params.updateFromXmlRpcValue(nh.param(public_ns, XmlRpc::XmlRpcValue()));
00061   if (nh.hasParam(private_ns))
00062     params.updateFromXmlRpcValue(nh.param(private_ns, XmlRpc::XmlRpcValue()));
00063 
00064   setParams(params);
00065 
00066   return true;
00067 }
00068 
00069 const msgs::PluginDescription& Plugin::getDescription() const
00070 {
00071   if (description_.type_class.data.empty())
00072   {
00073     (const_cast<Plugin*>(this))->description_.type_class.data = _typeClass(this);
00074     (const_cast<Plugin*>(this))->updateDescription(description_);
00075   }
00076   return description_;
00077 }
00078 
00079 const std::string& Plugin::getName() const
00080 {
00081   return description_.name.data;
00082 }
00083 
00084 const std::string& Plugin::getTypeClassPackage() const
00085 {
00086   return description_.type_class_package.data;
00087 }
00088 
00089 const std::string& Plugin::getTypeClass() const
00090 {
00091   if (description_.type_class.data.empty())
00092   {
00093     (const_cast<Plugin*>(this))->description_.type_class.data = _typeClass(this);
00094     (const_cast<Plugin*>(this))->updateDescription(description_);
00095   }
00096   return description_.type_class.data;
00097 }
00098 
00099 const std::string& Plugin::getBaseClassPackage() const
00100 {
00101   return description_.base_class_package.data;
00102 }
00103 
00104 const std::string& Plugin::getBaseClass() const
00105 {
00106   return description_.base_class.data;
00107 }
00108 
00109 void Plugin::updateDescription(const msgs::PluginDescription& description)
00110 {
00111   description_ = description;
00112 }
00113 
00114 void Plugin::setNodehandle(const ros::NodeHandle& nh)
00115 {
00116   nh_ = nh;
00117 }
00118 
00119 void Plugin::setParams(const vigir_generic_params::ParameterSet& params)
00120 {
00121   params_ = params;
00122 }
00123 } // namespace


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