ModuleManager.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00020 #ifndef ModuleManager_h
00021 #define ModuleManager_h
00022 
00023 // STL includes
00024 #include <string>
00025 #include <vector>
00026 #include <map>
00027 
00028 // ACE includes
00029 #include <ace/DLL.h>
00030 
00031 // RTC includes
00032 #include <rtm/Manager.h>
00033 #include <rtm/Properties.h>
00034 
00035 
00036 #define CONFIG_EXT    "manager.modules.config_ext"
00037 #define CONFIG_PATH   "manager.modules.config_path"
00038 #define DETECT_MOD    "manager.modules.detect_loadable"
00039 #define MOD_LOADPTH   "manager.modules.load_path"
00040 #define INITFUNC_SFX  "manager.modules.init_func_suffix"
00041 #define INITFUNC_PFX  "manager.modules.init_func_prefix"
00042 #define ALLOW_ABSPATH "manager.modules.abs_path_allowed"
00043 #define ALLOW_URL     "manager.modules.download_allowed"
00044 #define MOD_DWNDIR    "manager.modules.download_dir"
00045 #define MOD_DELMOD    "manager.modules.download_cleanup"
00046 #define MOD_PRELOAD   "manager.modules.preload"
00047 
00048 namespace RTC
00049 {
00069   class ModuleManager
00070   {
00071   public:
00093     ModuleManager(Properties& prop);
00094     
00106     ~ModuleManager();
00107     
00115     struct Error
00116     {
00117       Error(const std::string& _reason)
00118         : reason(_reason) {}
00119       std::string reason;
00120     };
00121     
00130     struct NotFound
00131     {
00132       NotFound(const std::string& _name)
00133         : name(_name) {}
00134       std::string name;
00135     };
00136     
00145     struct FileNotFound
00146       : public NotFound
00147     {
00148       FileNotFound(const std::string& _name)
00149         : NotFound(_name) {}
00150     };
00151     
00160     struct ModuleNotFound
00161       : public NotFound
00162     {
00163       ModuleNotFound(const std::string& _name)
00164         : NotFound(_name) {}
00165     };
00166     
00175     struct SymbolNotFound
00176       : public NotFound
00177     {
00178       SymbolNotFound(const std::string& _name)
00179         : NotFound(_name) {}
00180     };
00181     
00190     struct NotAllowedOperation
00191       : public Error
00192     {
00193       NotAllowedOperation(const std::string& _reason)
00194         : Error(_reason) {}
00195     };
00196     
00205     struct InvalidArguments
00206       : public Error
00207     {
00208       InvalidArguments(const std::string& _reason)
00209         : Error(_reason) {}
00210     };
00211     
00220     struct InvalidOperation
00221       : public Error
00222     {
00223       InvalidOperation(const std::string& _reason)
00224         : Error(_reason) {}
00225     };
00226     typedef void (*ModuleInitFunc)(Manager*);
00227     
00273     std::string load(const std::string& file_name);
00274     
00302     std::string load(const std::string& file_name, const std::string& init_func);
00303     
00321     void unload(const std::string& file_name);
00322     
00336     void unloadAll();
00337     
00345     void* symbol(const std::string& file_name, const std::string& func_name)
00346       throw (ModuleNotFound, SymbolNotFound);
00347     
00365     void setLoadpath(const std::vector<std::string>& load_path);
00366     
00384     inline std::vector<std::string> getLoadPath()
00385     {
00386       return m_loadPath;
00387     }
00388     
00406     void addLoadpath(const std::vector<std::string>& load_path);
00407     
00425     std::vector<std::string> getLoadedModules();
00426     
00445     std::vector<std::string> getLoadableModules();
00446     
00460     inline void allowAbsolutePath()
00461     {
00462       m_absoluteAllowed = true;
00463     }
00464     
00478     inline void disallowAbsolutePath()
00479     {
00480       m_absoluteAllowed = false;
00481     }
00482     
00500     inline void allowModuleDownload()
00501     {
00502       m_downloadAllowed = true;
00503     }
00504     
00518     inline void disallowModuleDownload()
00519     {
00520       m_downloadAllowed = false;
00521     }
00522     
00546     std::string findFile(const std::string& fname,
00547                          const std::vector<std::string>& load_path);
00548     
00570     bool fileExist(const std::string& filename);
00571     
00593     std::string getInitFuncName(const std::string& file_path);
00594     
00595   protected:
00596     struct DLL
00597     {
00598       ACE_DLL dll;
00599     };
00600     
00601     typedef std::vector<std::string>     StringVector;
00602     typedef StringVector::iterator       StringVectorItr;
00603     typedef StringVector::const_iterator StringVectorConstItr;
00604     
00605     typedef std::map<std::string, DLL> DllMap;
00606     typedef DllMap::iterator           DllMapItr;
00607     typedef DllMap::const_iterator     DllMapConstItr;
00608     
00616     Properties& m_properties;
00617     
00625     DllMap m_modules;
00626     
00634     StringVector m_loadPath;
00642     StringVector m_configPath;
00650     bool m_downloadAllowed;
00658     bool m_absoluteAllowed;
00659     
00667     std::string m_initFuncSuffix;
00675     std::string m_initFuncPrefix;
00676     
00677   };   // class ModuleManager
00678 };     // namespace RTC  
00679 
00680 #endif // ModuleManager_h

Generated on Wed May 21 05:17:34 2008 for OpenRTM by  doxygen 1.5.3