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;
140 for (std::vector<std::string>::iterator it = classes.begin(); it != classes.end(); it++)
142 std::string lookup_name = *it;
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();
158 attributes[
"plugin_path"] = plugin_path.c_str();
163 attributes[
"not_available"] =
"";
166 QString label = 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)
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());
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