OpenRTM-aist  1.2.2
ModuleManager.h
[詳解]
1 // -*- C++ -*-
20 #ifndef RTC_MODULEMANAGER_H
21 #define RTC_MODULEMANAGER_H
22 
23 // STL includes
24 #include <string>
25 #include <vector>
26 #include <map>
27 
28 // ACE includes
29 #include <coil/DynamicLib.h>
30 
31 // RTC includes
32 #include <rtm/Manager.h>
33 #include <coil/Properties.h>
34 #include <rtm/ObjectManager.h>
35 
36 
37 #define CONFIG_EXT "manager.modules.config_ext"
38 #define CONFIG_PATH "manager.modules.config_path"
39 #define DETECT_MOD "manager.modules.detect_loadable"
40 #define MOD_LOADPTH "manager.modules.load_path"
41 #define INITFUNC_SFX "manager.modules.init_func_suffix"
42 #define INITFUNC_PFX "manager.modules.init_func_prefix"
43 #define ALLOW_ABSPATH "manager.modules.abs_path_allowed"
44 #define ALLOW_URL "manager.modules.download_allowed"
45 #define MOD_DWNDIR "manager.modules.download_dir"
46 #define MOD_DELMOD "manager.modules.download_cleanup"
47 #define MOD_PRELOAD "manager.modules.preload"
48 
49 #ifdef WIN32
50 #pragma warning( disable : 4290 )
51 #endif
52 
53 namespace RTC
54 {
75  {
76  typedef std::vector<coil::Properties> vProperties;
77  public:
100 
112  ~ModuleManager(void);
113 
121  struct Error
122  {
123  Error(const std::string& _reason)
124  : reason(_reason) {}
125  std::string reason;
126  };
127 
136  struct NotFound
137  {
138  NotFound(const std::string& _name)
139  : name(_name) {}
140  std::string name;
141  };
142 
152  : public NotFound
153  {
154  FileNotFound(const std::string& _name)
155  : NotFound(_name) {}
156  };
157 
167  : public NotFound
168  {
169  ModuleNotFound(const std::string& _name)
170  : NotFound(_name) {}
171  };
172 
182  : public NotFound
183  {
184  SymbolNotFound(const std::string& _name)
185  : NotFound(_name) {}
186  };
187 
197  : public Error
198  {
199  NotAllowedOperation(const std::string& _reason)
200  : Error(_reason) {}
201  };
202 
212  : public Error
213  {
214  InvalidArguments(const std::string& _reason)
215  : Error(_reason) {}
216  };
217 
227  : public Error
228  {
229  InvalidOperation(const std::string& _reason)
230  : Error(_reason) {}
231  };
232  typedef void (*ModuleInitFunc)(Manager*);
233 
279  std::string load(const std::string& file_name);
280 
308  std::string load(const std::string& file_name,
309  const std::string& init_func);
310 
328  void unload(const std::string& file_name);
329 
343  void unloadAll();
344 
352  void* symbol(const std::string& file_name, const std::string& func_name)
354 
372  void setLoadpath(const std::vector<std::string>& load_path);
373 
391  inline std::vector<std::string> getLoadPath()
392  {
393  return m_loadPath;
394  }
395 
413  void addLoadpath(const std::vector<std::string>& load_path);
414 
432  std::vector<coil::Properties> getLoadedModules();
433 
452  std::vector<coil::Properties> getLoadableModules();
453 
467  inline void allowAbsolutePath()
468  {
469  m_absoluteAllowed = true;
470  }
471 
485  inline void disallowAbsolutePath()
486  {
487  m_absoluteAllowed = false;
488  }
489 
507  inline void allowModuleDownload()
508  {
509  m_downloadAllowed = true;
510  }
511 
526  {
527  m_downloadAllowed = false;
528  }
529 
553  std::string findFile(const std::string& fname,
554  const std::vector<std::string>& load_path);
555 
577  bool fileExist(const std::string& filename);
578 
600  std::string getInitFuncName(const std::string& file_path);
601 
602  protected:
610  void removeInvalidModules();
611 
619  void getModuleList(const std::string& lang, coil::vstring& modules);
620 
628  void addNewFile(const std::string& fpath, coil::vstring& modules, const std::string& lang);
629 
637  void getModuleProfiles(const std::string& lang,
638  const coil::vstring& modules, vProperties& modprops);
639 
648 
656  struct DLLEntity
657  {
660  };
661 
662  typedef std::vector<std::string> StringVector;
663  typedef StringVector::iterator StringVectorItr;
664  typedef StringVector::const_iterator StringVectorConstItr;
665 
666  typedef std::vector<DLLEntity> DllMap;
667  typedef DllMap::iterator DllMapItr;
668  typedef DllMap::const_iterator DllMapConstItr;
669 
670 
679 
687  class DllPred
688  {
689  std::string m_filepath;
690  public:
691  DllPred(const char* filepath) : m_filepath(filepath) {}
692  DllPred(const DLLEntity* dll) : m_filepath(dll->properties["file_path"]) {}
693  bool operator()(DLLEntity* dllentity)
694  {
695  return m_filepath == dllentity->properties.getProperty("file_path");
696  }
697  };
706 
739 
747  std::string m_initFuncSuffix;
748 
756  std::string m_initFuncPrefix;
757 
766  {
767  public:
770  {
771  dll->dll.close();
772  delete dll;
773  }
774  };
775 
776  vProperties m_modprofs;
777  std::map<std::string, coil::vstring> m_loadfailmods;
778 
779  }; // class ModuleManager
780 }; // namespace RTC
781 
782 #ifdef WIN32
783 #pragma warning( default : 4290 )
784 #endif
785 
786 #endif // RTC_MODULEMANAGER_H
RTC::ModuleManager::StringVectorConstItr
StringVector::const_iterator StringVectorConstItr
Definition: ModuleManager.h:664
RTC::ModuleManager::DllMap
std::vector< DLLEntity > DllMap
Definition: ModuleManager.h:666
RTC::ModuleManager::getInitFuncName
std::string getInitFuncName(const std::string &file_path)
初期化関数シンボルを生成する
RTC::ModuleManager::DllMapItr
DllMap::iterator DllMapItr
Definition: ModuleManager.h:667
RTC::ModuleManager::m_initFuncPrefix
std::string m_initFuncPrefix
初期実行関数プリフィックス
Definition: ModuleManager.h:756
RTC::ModuleManager::UnloadPred
モジュールアンロードファンクタ
Definition: ModuleManager.h:765
RTC::ModuleManager::UnloadPred::UnloadPred
UnloadPred()
Definition: ModuleManager.h:768
DynamicLib.h
RTC::ModuleManager::ModuleNotFound::ModuleNotFound
ModuleNotFound(const std::string &_name)
Definition: ModuleManager.h:169
RTC::ModuleManager::Error::Error
Error(const std::string &_reason)
Definition: ModuleManager.h:123
RTC::ModuleManager::m_initFuncSuffix
std::string m_initFuncSuffix
初期実行関数サフィックス
Definition: ModuleManager.h:747
Properties.h
Property list class (derived from Java Properties)
RTC::ModuleManager::m_loadfailmods
std::map< std::string, coil::vstring > m_loadfailmods
Definition: ModuleManager.h:777
RTC::ModuleManager::InvalidArguments::InvalidArguments
InvalidArguments(const std::string &_reason)
Definition: ModuleManager.h:214
RTC::ModuleManager::NotAllowedOperation::NotAllowedOperation
NotAllowedOperation(const std::string &_reason)
Definition: ModuleManager.h:199
Manager.h
-*- C++ -*-
RTC::ModuleManager::DllMapConstItr
DllMap::const_iterator DllMapConstItr
Definition: ModuleManager.h:668
RTC::ModuleManager::InvalidOperation::InvalidOperation
InvalidOperation(const std::string &_reason)
Definition: ModuleManager.h:229
coil::DynamicLib::close
virtual int close(void)
動的リンクライブラリのアンロード
RTC::ModuleManager::allowAbsolutePath
void allowAbsolutePath()
モジュールの絶対パス指定許可
Definition: ModuleManager.h:467
RTC::ModuleManager::DLLEntity
DLL管理用構造体
Definition: ModuleManager.h:656
RTC::ModuleManager::m_modules
ObjectManager< const char *, DLLEntity, DllPred > m_modules
ロード済みモジュールリスト
Definition: ModuleManager.h:705
RTC::ModuleManager::removeInvalidModules
void removeInvalidModules()
無効なモジュールプロファイルを削除する
RTC::ModuleManager::m_properties
coil::Properties & m_properties
Module Manager プロパティ
Definition: ModuleManager.h:678
ObjectManager.h
Object management class
RTC::ModuleManager::StringVectorItr
StringVector::iterator StringVectorItr
Definition: ModuleManager.h:663
ObjectManager
オブジェクト管理用クラス
Definition: ObjectManager.h:51
RTC::ModuleManager::setLoadpath
void setLoadpath(const std::vector< std::string > &load_path)
モジュールロードパスを指定する
RTC::ModuleManager::addNewFile
void addNewFile(const std::string &fpath, coil::vstring &modules, const std::string &lang)
キャッシュに無いパスだけmodulesに追加する
RTC::ModuleManager::FileNotFound
指定ファイル不明例外処理用構造体
Definition: ModuleManager.h:151
RTC::ModuleManager::FileNotFound::FileNotFound
FileNotFound(const std::string &_name)
Definition: ModuleManager.h:154
RTC::ModuleManager::m_configPath
StringVector m_configPath
コンフィギュレーション・パス・リスト
Definition: ModuleManager.h:722
RTC::ModuleManager::Error
ファイル・オープン失敗例外処理用構造体
Definition: ModuleManager.h:121
RTC::ModuleManager::ModuleNotFound
指定モジュール不明例外処理用構造体
Definition: ModuleManager.h:166
RTC::ModuleManager::SymbolNotFound
指定シンボル不明例外処理用構造体
Definition: ModuleManager.h:181
RTC::ModuleManager::DLLEntity::properties
coil::Properties properties
Definition: ModuleManager.h:658
RTC::ModuleManager::symbol
void * symbol(const std::string &file_name, const std::string &func_name)
モジュールのシンボルの参照
RTC::ModuleManager::m_downloadAllowed
bool m_downloadAllowed
モジュールURL指定許可フラグ
Definition: ModuleManager.h:730
RTC::ModuleManager::SymbolNotFound::SymbolNotFound
SymbolNotFound(const std::string &_name)
Definition: ModuleManager.h:184
RTC::Logger
Logger クラス
Definition: SystemLogger.h:99
coil::vstring
std::vector< std::string > vstring
Definition: stringutil.h:45
RTC::ModuleManager::NotFound::NotFound
NotFound(const std::string &_name)
Definition: ModuleManager.h:138
RTC::ModuleManager::ModuleInitFunc
void(* ModuleInitFunc)(Manager *)
Definition: ModuleManager.h:232
RTC::ModuleManager::allowModuleDownload
void allowModuleDownload()
モジュールのURL指定許可
Definition: ModuleManager.h:507
RTC::ModuleManager::InvalidArguments
指定引数不正時例外処理用構造体
Definition: ModuleManager.h:211
RTC::ModuleManager::DllPred::DllPred
DllPred(const char *filepath)
Definition: ModuleManager.h:691
RTC::ModuleManager::disallowAbsolutePath
void disallowAbsolutePath()
モジュールの絶対パス指定禁止
Definition: ModuleManager.h:485
RTC::ModuleManager::getLoadPath
std::vector< std::string > getLoadPath()
モジュールロードパスを取得する
Definition: ModuleManager.h:391
RTC::ModuleManager::addLoadpath
void addLoadpath(const std::vector< std::string > &load_path)
モジュールロードパスを追加する
coil::Properties
プロパティセットを表現するクラス
Definition: Properties.h:101
RTC::ModuleManager::Error::reason
std::string reason
Definition: ModuleManager.h:125
RTC::ModuleManager::findFile
std::string findFile(const std::string &fname, const std::vector< std::string > &load_path)
LoadPath からのファイルの検索
RTC::ModuleManager::rtclog
Logger rtclog
ロガーストリーム
Definition: ModuleManager.h:647
RTC::ModuleManager::NotAllowedOperation
指定操作禁止時例外処理用構造体
Definition: ModuleManager.h:196
RTC::ModuleManager::getLoadedModules
std::vector< coil::Properties > getLoadedModules()
ロード済みのモジュールリストを取得する
RTC::ModuleManager
モジュールマネージャクラス
Definition: ModuleManager.h:74
RTC::ModuleManager::load
std::string load(const std::string &file_name)
モジュールのロード
RTC::ModuleManager::NotFound::name
std::string name
Definition: ModuleManager.h:140
RTC::ModuleManager::DllPred
ロード済みモジュールリスト
Definition: ModuleManager.h:687
RTC::ModuleManager::DllPred::operator()
bool operator()(DLLEntity *dllentity)
Definition: ModuleManager.h:693
RTC::ModuleManager::getModuleProfiles
void getModuleProfiles(const std::string &lang, const coil::vstring &modules, vProperties &modprops)
指定言語、ファイルリストからモジュールのプロパティを返す
RTC::ModuleManager::DllPred::DllPred
DllPred(const DLLEntity *dll)
Definition: ModuleManager.h:692
RTC::ModuleManager::unload
void unload(const std::string &file_name)
モジュールのアンロード
RTC::Manager
Manager クラス
Definition: Manager.h:81
RTC::ModuleManager::fileExist
bool fileExist(const std::string &filename)
ファイルが存在するかどうかのチェック
RTC::ModuleManager::StringVector
std::vector< std::string > StringVector
Definition: ModuleManager.h:662
coil::Properties::getProperty
const std::string & getProperty(const std::string &key) const
指定されたキーを持つプロパティを、プロパティリストから探す
RTC::ModuleManager::disallowModuleDownload
void disallowModuleDownload()
モジュールのURL指定禁止
Definition: ModuleManager.h:525
RTC
RTコンポーネント
RTC::ModuleManager::m_absoluteAllowed
bool m_absoluteAllowed
モジュール絶対パス指定許可フラグ
Definition: ModuleManager.h:738
RTC::ModuleManager::NotFound
未実装部,指定モジュール不明例外処理用構造体
Definition: ModuleManager.h:136
RTC::ModuleManager::m_loadPath
StringVector m_loadPath
モジュール・ロード・パス・リスト
Definition: ModuleManager.h:714
RTC::ModuleManager::~ModuleManager
~ModuleManager(void)
デストラクタ
RTC::ModuleManager::ModuleManager
ModuleManager(coil::Properties &prop)
コンストラクタ
RTC::ModuleManager::UnloadPred::operator()
void operator()(DLLEntity *dll)
Definition: ModuleManager.h:769
coil::DynamicLib
DynamicLib クラス
Definition: DynamicLib.h:48
RTC::ModuleManager::unloadAll
void unloadAll()
全モジュールのアンロード
RTC::ModuleManager::DLLEntity::dll
coil::DynamicLib dll
Definition: ModuleManager.h:659
RTC::ModuleManager::m_modprofs
vProperties m_modprofs
Definition: ModuleManager.h:776
RTC::ModuleManager::InvalidOperation
指定操作不正時例外処理用構造体
Definition: ModuleManager.h:226
RTC::ModuleManager::getModuleList
void getModuleList(const std::string &lang, coil::vstring &modules)
指定言語におけるロードパス上のローダブルなファイルリストを返す
RTC::ModuleManager::getLoadableModules
std::vector< coil::Properties > getLoadableModules()
ロード可能モジュールリストを取得する