ModuleManager.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00020 #ifndef RTC_MODULEMANAGER_H
00021 #define RTC_MODULEMANAGER_H
00022 
00023 // STL includes
00024 #include <string>
00025 #include <vector>
00026 #include <map>
00027 
00028 // ACE includes
00029 #include <coil/DynamicLib.h>
00030 
00031 // RTC includes
00032 #include <rtm/Manager.h>
00033 #include <coil/Properties.h>
00034 #include <rtm/ObjectManager.h>
00035 
00036 
00037 #define CONFIG_EXT    "manager.modules.config_ext"
00038 #define CONFIG_PATH   "manager.modules.config_path"
00039 #define DETECT_MOD    "manager.modules.detect_loadable"
00040 #define MOD_LOADPTH   "manager.modules.load_path"
00041 #define INITFUNC_SFX  "manager.modules.init_func_suffix"
00042 #define INITFUNC_PFX  "manager.modules.init_func_prefix"
00043 #define ALLOW_ABSPATH "manager.modules.abs_path_allowed"
00044 #define ALLOW_URL     "manager.modules.download_allowed"
00045 #define MOD_DWNDIR    "manager.modules.download_dir"
00046 #define MOD_DELMOD    "manager.modules.download_cleanup"
00047 #define MOD_PRELOAD   "manager.modules.preload"
00048 
00049 #ifdef WIN32
00050 #pragma warning( disable : 4290 )
00051 #endif
00052 
00053 namespace RTC
00054 {
00074   class ModuleManager
00075   {
00076     typedef std::vector<coil::Properties> vProperties;
00077   public:
00099     ModuleManager(coil::Properties& prop);
00100     
00112     ~ModuleManager(void);
00113     
00121     struct Error
00122     {
00123       Error(const std::string& _reason)
00124         : reason(_reason) {}
00125       std::string reason;
00126     };
00127     
00136     struct NotFound
00137     {
00138       NotFound(const std::string& _name)
00139         : name(_name) {}
00140       std::string name;
00141     };
00142     
00151     struct FileNotFound
00152       : public NotFound
00153     {
00154       FileNotFound(const std::string& _name)
00155         : NotFound(_name) {}
00156     };
00157     
00166     struct ModuleNotFound
00167       : public NotFound
00168     {
00169       ModuleNotFound(const std::string& _name)
00170         : NotFound(_name) {}
00171     };
00172     
00181     struct SymbolNotFound
00182       : public NotFound
00183     {
00184       SymbolNotFound(const std::string& _name)
00185         : NotFound(_name) {}
00186     };
00187     
00196     struct NotAllowedOperation
00197       : public Error
00198     {
00199       NotAllowedOperation(const std::string& _reason)
00200         : Error(_reason) {}
00201     };
00202     
00211     struct InvalidArguments
00212       : public Error
00213     {
00214       InvalidArguments(const std::string& _reason)
00215         : Error(_reason) {}
00216     };
00217     
00226     struct InvalidOperation
00227       : public Error
00228     {
00229       InvalidOperation(const std::string& _reason)
00230         : Error(_reason) {}
00231     };
00232     typedef void (*ModuleInitFunc)(Manager*);
00233     
00279     std::string load(const std::string& file_name);
00280     
00308     std::string load(const std::string& file_name,
00309                      const std::string& init_func);
00310     
00328     void unload(const std::string& file_name);
00329     
00343     void unloadAll();
00344     
00352     void* symbol(const std::string& file_name, const std::string& func_name)
00353       throw (ModuleNotFound, SymbolNotFound);
00354     
00372     void setLoadpath(const std::vector<std::string>& load_path);
00373     
00391     inline std::vector<std::string> getLoadPath()
00392     {
00393       return m_loadPath;
00394     }
00395     
00413     void addLoadpath(const std::vector<std::string>& load_path);
00414     
00432     std::vector<coil::Properties> getLoadedModules();
00433     
00452     std::vector<coil::Properties> getLoadableModules();
00453 
00467     inline void allowAbsolutePath()
00468     {
00469       m_absoluteAllowed = true;
00470     }
00471     
00485     inline void disallowAbsolutePath()
00486     {
00487       m_absoluteAllowed = false;
00488     }
00489     
00507     inline void allowModuleDownload()
00508     {
00509       m_downloadAllowed = true;
00510     }
00511     
00525     inline void disallowModuleDownload()
00526     {
00527       m_downloadAllowed = false;
00528     }
00529     
00553     std::string findFile(const std::string& fname,
00554                          const std::vector<std::string>& load_path);
00555     
00577   bool fileExist(const std::string& filename);
00578     
00600     std::string getInitFuncName(const std::string& file_path);
00601     
00602   protected:
00610     void removeInvalidModules();
00611     
00619     void getModuleList(const std::string& lang, coil::vstring& modules);
00620 
00628     void addNewFile(const std::string& fpath, coil::vstring& modules);
00629 
00637     void getModuleProfiles(const std::string& lang,
00638                            const coil::vstring& modules, vProperties& modprops);
00639 
00647     Logger rtclog;
00648 
00656     struct DLLEntity
00657     {
00658       coil::Properties properties;
00659       coil::DynamicLib dll;
00660     };
00661     
00662     typedef std::vector<std::string>     StringVector;
00663     typedef StringVector::iterator       StringVectorItr;
00664     typedef StringVector::const_iterator StringVectorConstItr;
00665     
00666     typedef std::vector<DLLEntity>    DllMap;
00667     typedef DllMap::iterator           DllMapItr;
00668     typedef DllMap::const_iterator     DllMapConstItr;
00669 
00670     
00678     coil::Properties& m_properties;
00679     
00687     class DllPred
00688     {
00689       std::string m_filepath;
00690     public:
00691       DllPred(const char* filepath) : m_filepath(filepath) {}
00692       DllPred(const DLLEntity* dll) : m_filepath(dll->properties["file_path"]) {}
00693       bool operator()(DLLEntity* dllentity)
00694       {
00695         return m_filepath == dllentity->properties.getProperty("file_path");
00696       }
00697     };
00705     ObjectManager<const char*, DLLEntity, DllPred> m_modules;
00706     
00714     StringVector m_loadPath;
00722     StringVector m_configPath;
00730     bool m_downloadAllowed;
00738     bool m_absoluteAllowed;
00739     
00747     std::string m_initFuncSuffix;
00748 
00756     std::string m_initFuncPrefix;
00757 
00765     class UnloadPred
00766     {
00767     public:
00768       UnloadPred(){}
00769       void operator()(DLLEntity* dll)
00770       {
00771         dll->dll.close();
00772         delete dll;
00773       }
00774     };
00775 
00776     vProperties m_modprofs;
00777 
00778   };   // class ModuleManager
00779 };     // namespace RTC  
00780 
00781 #ifdef WIN32
00782 #pragma warning( default : 4290 )
00783 #endif
00784 
00785 #endif // RTC_MODULEMANAGER_H


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sat Jun 8 2019 18:49:05