Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "nodelet_plugin_provider.h"
00034
00035 #include "roscpp_plugin_provider.h"
00036
00037 #include <stdexcept>
00038 #include <boost/bind.hpp>
00039
00040 namespace rqt_gui_cpp {
00041
00042 NodeletPluginProvider::NodeletPluginProvider(const QString& export_tag, const QString& base_class_type)
00043 : qt_gui_cpp::RosPluginlibPluginProvider<rqt_gui_cpp::Plugin>(export_tag, base_class_type)
00044 , loader_(0)
00045 {}
00046
00047 NodeletPluginProvider::~NodeletPluginProvider()
00048 {
00049 if (loader_)
00050 {
00051 delete loader_;
00052 }
00053 }
00054
00055 void NodeletPluginProvider::unload(void* instance)
00056 {
00057 qDebug("NodeletPluginProvider::unload()");
00058 if (!instances_.contains(instance))
00059 {
00060 qCritical("NodeletPluginProvider::unload() instance not found");
00061 return;
00062 }
00063
00064 QString nodelet_name = instances_[instance];
00065 bool unloaded = loader_->unload(nodelet_name.toStdString());
00066 if (!unloaded)
00067 {
00068 qCritical("NodeletPluginProvider::unload() '%s' failed", nodelet_name.toStdString().c_str());
00069 }
00070
00071 qt_gui_cpp::RosPluginlibPluginProvider<rqt_gui_cpp::Plugin>::unload(instance);
00072 }
00073
00074 void NodeletPluginProvider::init_loader()
00075 {
00076
00077 if (loader_ == 0)
00078 {
00079 loader_ = new nodelet::Loader(boost::bind(&NodeletPluginProvider::create_instance, this, _1));
00080 }
00081 }
00082
00083 boost::shared_ptr<Plugin> NodeletPluginProvider::create_plugin(const std::string& lookup_name, qt_gui_cpp::PluginContext* plugin_context)
00084 {
00085 init_loader();
00086
00087 nodelet::M_string remappings;
00088 nodelet::V_string my_argv;
00089 std::string nodelet_name = lookup_name + "_" + QString::number(plugin_context->serialNumber()).toStdString();
00090 instance_.reset();
00091 qDebug("NodeletPluginProvider::create_plugin() load %s", lookup_name.c_str());
00092 bool loaded = loader_->load(nodelet_name, lookup_name, remappings, my_argv);
00093 if (loaded)
00094 {
00095 qDebug("NodeletPluginProvider::create_plugin() loaded");
00096 instances_[&*instance_] = nodelet_name.c_str();
00097 }
00098 boost::shared_ptr<rqt_gui_cpp::Plugin> instance = instance_;
00099 instance_.reset();
00100 return instance;
00101 }
00102
00103 boost::shared_ptr<nodelet::Nodelet> NodeletPluginProvider::create_instance(const std::string& lookup_name)
00104 {
00105 instance_ = qt_gui_cpp::RosPluginlibPluginProvider<rqt_gui_cpp::Plugin>::create_plugin(lookup_name);
00106 return instance_;
00107 }
00108
00109 void NodeletPluginProvider::init_plugin(const QString& plugin_id, qt_gui_cpp::PluginContext* plugin_context, qt_gui_cpp::Plugin* plugin)
00110 {
00111 qDebug("NodeletPluginProvider::init_plugin()");
00112
00113 rqt_gui_cpp::Plugin* nodelet = dynamic_cast<rqt_gui_cpp::Plugin*>(plugin);
00114 if (!nodelet)
00115 {
00116 throw std::runtime_error("plugin is not a nodelet");
00117 }
00118
00119 qt_gui_cpp::RosPluginlibPluginProvider<rqt_gui_cpp::Plugin>::init_plugin(plugin_id, plugin_context, plugin);
00120 }
00121
00122 }