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 "ros/console.h"
00033
00034 #include "pluginlib/class_desc.h"
00035
00036 #include "Poco/ClassLoader.h"
00037 #include "ros/package.h"
00038 #include "tinyxml.h"
00039 #include <vector>
00040 #include <map>
00041
00042
00043 #include "boost/algorithm/string.hpp"
00044 #include "pluginlib/boost_fs_wrapper.h"
00045
00046 namespace pluginlib
00047 {
00052 class PluginlibException: public std::runtime_error
00053 {
00054 public:
00055 PluginlibException(const std::string error_desc) : std::runtime_error(error_desc) {}
00056 };
00057
00062 class LibraryLoadException: public PluginlibException
00063 {
00064 public:
00065 LibraryLoadException(const std::string error_desc) : PluginlibException(error_desc) {}
00066 };
00067
00072 class CreateClassException: public PluginlibException
00073 {
00074 public:
00075 CreateClassException(const std::string error_desc) : PluginlibException(error_desc) {}
00076 };
00077
00082 template <class T>
00083 class ClassLoader
00084 {
00085 private:
00086 typedef std::map<std::string, unsigned int> LibraryCountMap;
00087
00088 public:
00089 typedef typename std::map<std::string, ClassDesc>::iterator ClassMapIterator;
00090
00091 public:
00098 ClassLoader(std::string package, std::string base_class, std::string attrib_name = std::string("plugin"));
00099
00103 ~ClassLoader();
00104
00109 std::vector<std::string> getDeclaredClasses();
00110
00116 std::string getName(const std::string& lookup_name);
00117
00123 bool isClassAvailable(const std::string& lookup_name);
00124
00130 std::string getClassType(const std::string& lookup_name);
00131
00137 std::string getClassDescription(const std::string& lookup_name);
00138
00143 std::string getBaseClassType() const;
00144
00150 std::string getClassPackage(const std::string& lookup_name);
00151
00160 T* createClassInstance(const std::string& lookup_name, bool auto_load = true);
00161
00167 bool isClassLoaded(const std::string& lookup_name);
00168
00174 void loadLibraryForClass(const std::string & lookup_name);
00175
00180 std::vector<std::string> getRegisteredLibraries();
00181
00182 private:
00188 std::string getClassLibraryPath(const std::string& lookup_name);
00189
00195 bool unloadClassLibrary(const std::string& library_path);
00196
00202 bool loadClassLibrary(const std::string& library_path);
00203
00209 std::vector<std::string> getClassesInLibrary(const std::string & library_path);
00210
00215 std::vector<std::string> getLoadedLibraries();
00216
00222 void loadClassLibraryInternal(const std::string& library_path, const std::string& list_name_arg = std::string(""));
00223
00224
00225 LibraryCountMap loaded_libraries_;
00226
00227
00228
00229 std::map<std::string, ClassDesc> classes_available_;
00230 std::string base_class_;
00231
00232 Poco::ClassLoader<T> poco_class_loader_;
00233 };
00234
00235 };
00236
00237 #include "class_loader_imp.h"
00238
00239 #endif //PLUGINLIB_CLASS_LOADER_H