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 #ifndef PLUGINLIB_CLASS_LOADER_H
00030 #define PLUGINLIB_CLASS_LOADER_H
00031
00032 #include "boost/algorithm/string.hpp"
00033 #include "class_loader/multi_library_class_loader.h"
00034 #include <map>
00035 #include "pluginlib/class_desc.h"
00036 #include "pluginlib/class_loader_base.h"
00037 #include "pluginlib/pluginlib_exceptions.h"
00038 #include "ros/console.h"
00039 #include "ros/package.h"
00040 #include "tinyxml.h"
00041
00042
00043
00044
00045
00046 namespace pluginlib
00047 {
00052 template <class T>
00053 class ClassLoader: public ClassLoaderBase
00054 {
00055 public:
00056 typedef typename std::map<std::string, ClassDesc>::iterator ClassMapIterator;
00057
00058 public:
00067 ClassLoader(std::string package, std::string base_class, std::string attrib_name = std::string("plugin"), std::vector<std::string> plugin_xml_paths = std::vector<std::string>());
00068
00072 ~ClassLoader();
00073
00083 __attribute__((deprecated)) T* createClassInstance(const std::string& lookup_name, bool auto_load = true);
00084
00092 boost::shared_ptr<T> createInstance(const std::string& lookup_name);
00093
00102 T* createUnmanagedInstance(const std::string& lookup_name);
00103
00108 std::vector<std::string> getPluginXmlPaths();
00109
00114 std::vector<std::string> getDeclaredClasses();
00115
00121 virtual std::string getName(const std::string& lookup_name);
00122
00127 virtual std::string getBaseClassType() const;
00128
00134 virtual std::string getClassType(const std::string& lookup_name);
00135
00141 virtual std::string getClassDescription(const std::string& lookup_name);
00142
00148 virtual std::string getClassLibraryPath(const std::string& lookup_name);
00149
00155 virtual std::string getClassPackage(const std::string& lookup_name);
00156
00162 virtual std::string getPluginManifestPath(const std::string& lookup_name);
00163
00168 virtual std::vector<std::string> getRegisteredLibraries();
00169
00175 bool isClassLoaded(const std::string& lookup_name);
00176
00182 virtual bool isClassAvailable(const std::string& lookup_name);
00183
00189 virtual void loadLibraryForClass(const std::string & lookup_name);
00190
00195 virtual void refreshDeclaredClasses();
00196
00203 virtual int unloadLibraryForClass(const std::string& lookup_name);
00204
00205 private:
00209 std::string callCommandLine(const char* cmd);
00210
00216 std::vector<std::string> getPluginXmlPaths(const std::string& package, const std::string& attrib_name);
00217
00224 std::map<std::string, ClassDesc> determineAvailableClasses(const std::vector<std::string>& plugin_xml_paths);
00225
00229 std::string extractPackageNameFromPackageXML(const std::string& package_xml_path);
00230
00234 std::vector<std::string> getAllLibraryPathsToTry(const std::string& library_name, const std::string& exporting_package_name);
00235
00239 std::vector<std::string> getCatkinLibraryPaths();
00240
00246 std::string getErrorStringForUnknownClass(const std::string& lookup_name);
00247
00251 std::string getPathSeparator();
00252
00256 std::string getROSBuildLibraryPath(const std::string& exporting_package_name);
00257
00261 std::string getPackageFromPluginXMLFilePath(const std::string & path);
00262
00266 std::string joinPaths(const std::string& path1, const std::string& path2);
00267
00271 std::vector<std::string> parseToStringVector(std::string newline_delimited_str);
00272
00276 void processSingleXMLPluginFile(const std::string& xml_file, std::map<std::string, ClassDesc>& class_available);
00277
00281 std::string stripAllButFileFromPath(const std::string& path);
00282
00283
00289 int unloadClassLibraryInternal(const std::string& library_path);
00290
00291 private:
00292 std::vector<std::string> plugin_xml_paths_;
00293 std::map<std::string, ClassDesc> classes_available_;
00294 std::string package_;
00295 std::string base_class_;
00296 std::string attrib_name_;
00297 class_loader::MultiLibraryClassLoader lowlevel_class_loader_;
00298 };
00299 };
00300
00301 #include "class_loader_imp.h" //Note: The implementation of the methods is in a separate file for clarity
00302
00303 #endif //PLUGINLIB_CLASS_LOADER_H
00304