33 #ifndef qt_gui_cpp__RosPluginlibPluginProvider_H 34 #define qt_gui_cpp__RosPluginlibPluginProvider_H 48 #include <QCoreApplication> 93 virtual QMap<QString, QString>
discover(QObject* discovery_data)
105 Settings discovery_settings(discovery_data);
107 bool is_cached = discovery_settings.
contains(key);
109 std::vector<std::string> plugin_xml_paths;
113 QStringList paths = discovery_settings.
value(key).toStringList();
114 for (QStringList::const_iterator it = paths.begin(); it != paths.end(); it++)
116 plugin_xml_paths.push_back(it->toStdString());
121 qDebug(
"RosPluginlibPluginProvider::discover_descriptors() crawling for plugins of type '%s' and base class '%s'",
export_tag_.toStdString().c_str(), base_class_type_.toStdString().c_str());
130 for (std::vector<std::string>::const_iterator it = paths.begin(); it != paths.end(); it++)
132 qpaths.push_back(it->c_str());
134 discovery_settings.
setValue(key, qpaths);
137 QList<PluginDescriptor*> descriptors;
139 std::vector<std::string> classes = class_loader_->getDeclaredClasses();
140 for (std::vector<std::string>::iterator it = classes.begin(); it != classes.end(); it++)
142 std::string lookup_name = *it;
144 std::string name = class_loader_->getName(lookup_name);
145 std::string plugin_xml = class_loader_->getPluginManifestPath(lookup_name);
146 boost::filesystem::path p(plugin_xml);
147 #if BOOST_FILESYSTEM_VERSION >= 3 148 std::string plugin_path = p.parent_path().string();
150 std::string plugin_path = p.parent_path();
153 QMap<QString, QString> attributes;
154 attributes[
"class_name"] = name.c_str();
155 attributes[
"class_type"] = class_loader_->getClassType(lookup_name).c_str();
156 attributes[
"class_base_class_type"] = class_loader_->getBaseClassType().c_str();
157 attributes[
"package_name"] = class_loader_->getClassPackage(lookup_name).c_str();
158 attributes[
"plugin_path"] = plugin_path.c_str();
163 attributes[
"not_available"] =
"";
166 QString label = name.c_str();
167 QString statustip = class_loader_->getClassDescription(lookup_name).c_str();
170 parseManifest(lookup_name, plugin_path, label, statustip, icon, icontype, plugin_descriptor);
174 descriptors.append(plugin_descriptor);
195 qWarning(
"RosPluginlibPluginProvider::load_plugin() called on non-plugin plugin provider");
203 std::string lookup_name = plugin_id.toStdString();
207 qWarning(
"RosPluginlibPluginProvider::load_explicit_type(%s) class not available", lookup_name.c_str());
218 qWarning(
"RosPluginlibPluginProvider::load_explicit_type(%s) could not load library (%s)", lookup_name.c_str(), e.what());
223 qWarning(
"RosPluginlibPluginProvider::load_explicit_type(%s) failed creating instance (%s)", lookup_name.c_str(), e.what());
229 qWarning(
"RosPluginlibPluginProvider::load_explicit_type(%s) failed creating instance", lookup_name.c_str());
241 catch (std::exception& e)
244 qWarning(
"RosPluginlibPluginProvider::load_explicit_type(%s) failed initializing plugin (%s)", lookup_name.c_str(), e.what());
259 qCritical(
"RosPluginlibPluginProvider::unload() instance not found");
276 return QObject::event(e);
293 bool parseManifest(
const std::string& lookup_name,
const std::string& plugin_path, QString& label, QString& statustip, QString& icon, QString& icontype,
PluginDescriptor* plugin_descriptor)
297 std::string manifest_path =
class_loader_->getPluginManifestPath(lookup_name);
300 bool loaded = doc.LoadFile(manifest_path);
303 if (doc.ErrorRow() > 0)
305 qWarning(
"RosPluginlibPluginProvider::parseManifest() could not load manifest \"%s\" (%s [line %d, column %d])", manifest_path.c_str(), doc.ErrorDesc(), doc.ErrorRow(), doc.ErrorCol());
309 qWarning(
"RosPluginlibPluginProvider::parseManifest() could not load manifest \"%s\" (%s)", manifest_path.c_str(), doc.ErrorDesc());
315 std::string class_type =
class_loader_->getClassType(lookup_name);
316 TiXmlElement* library_element = doc.FirstChildElement(
"library");
317 while (library_element)
320 TiXmlElement* class_element = library_element->FirstChildElement(
"class");
321 while (class_element)
323 if (class_type.compare(class_element->Attribute(
"type")) == 0 &&
base_class_type_.compare(class_element->Attribute(
"base_class_type")) == 0)
325 TiXmlElement* qtgui_element = class_element->FirstChildElement(
"qtgui");
332 TiXmlElement* group_element = qtgui_element->FirstChildElement(
"group");
333 while (group_element)
336 QString group_statustip;
338 QString group_icontype;
339 parseActionAttributes(group_element, plugin_path, group_label, group_statustip, group_icon, group_icontype);
340 plugin_descriptor->
addGroupAttributes(group_label, group_statustip, group_icon, group_icontype);
342 group_element = group_element->NextSiblingElement(
"group");
347 class_element = class_element->NextSiblingElement(
"class");
351 library_element = library_element->NextSiblingElement(
"library");
354 qWarning(
"RosPluginlibPluginProvider::parseManifest() could not handle manifest \"%s\"", manifest_path.c_str());
358 void parseActionAttributes(TiXmlElement* element,
const std::string& plugin_path, QString& label, QString& statustip, QString& icon, QString& icontype)
360 TiXmlElement* child_element;
361 if ((child_element = element->FirstChildElement(
"label")) != 0)
363 label = child_element->GetText();
365 if ((child_element = element->FirstChildElement(
"icon")) != 0)
367 icontype = child_element->Attribute(
"type");
368 if (icontype ==
"file")
371 icon = plugin_path.c_str();
373 icon += child_element->GetText();
377 icon = child_element->GetText();
380 if ((child_element = element->FirstChildElement(
"statustip")) != 0)
382 statustip = child_element->GetText();
406 #endif // qt_gui_cpp__RosPluginlibPluginProvider_H virtual void initPlugin(PluginContext &)
virtual void * load(const QString &plugin_id, PluginContext *plugin_context)
void unload_pending_libraries()
virtual T * load_explicit_type(const QString &plugin_id, PluginContext *plugin_context)
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
virtual QMap< QString, QString > discover(QObject *discovery_data)
virtual boost::shared_ptr< T > create_plugin(const std::string &lookup_name, PluginContext *=0)
virtual Plugin * load_plugin(const QString &plugin_id, PluginContext *plugin_context)
virtual void init_plugin(const QString &, PluginContext *plugin_context, Plugin *plugin)
static RosPluginlibPluginProvider< T > * create_instance(const QString &export_tag, const QString &base_class_type)
virtual ~RosPluginlibPluginProvider()
bool contains(const QString &key) const
int unload_libraries_event_
QList< boost::shared_ptr< T > > libraries_to_unload_
bool parseManifest(const std::string &lookup_name, const std::string &plugin_path, QString &label, QString &statustip, QString &icon, QString &icontype, PluginDescriptor *plugin_descriptor)
void setValue(const QString &key, const QVariant &value)
virtual QMap< QString, QString > discover(QObject *discovery_data)
void parseActionAttributes(TiXmlElement *element, const std::string &plugin_path, QString &label, QString &statustip, QString &icon, QString &icontype)
QMap< void *, boost::shared_ptr< T > > instances_
std::vector< std::string > getPluginXmlPaths()
virtual QList< PluginDescriptor * > discover_descriptors(QObject *discovery_data)
void addGroupAttributes(const QString &label, const QString &statustip=QString(), const QString &icon=QString(), const QString &icontype=QString())
virtual void unload(void *instance)
RosPluginlibPluginProvider(const QString &export_tag, const QString &base_class_type)
pluginlib::ClassLoader< T > * class_loader_
void setActionAttributes(const QString &label, const QString &statustip=QString(), const QString &icon=QString(), const QString &icontype=QString())