OpenRTM-aist 2.0.2
Loading...
Searching...
No Matches
ModuleManager.h
Go to the documentation of this file.
1// -*- C++ -*-
20#ifndef RTC_MODULEMANAGER_H
21#define RTC_MODULEMANAGER_H
22
23
24// ACE includes
25#include <coil/DynamicLib.h>
26
27// RTC includes
28#include <rtm/Manager.h>
29#include <coil/Properties.h>
30#include <rtm/ObjectManager.h>
31
32// STL includes
33#include <string>
34#include <utility>
35#include <vector>
36#include <map>
37
38#define CONFIG_EXT "manager.modules.config_ext"
39#define CONFIG_PATH "manager.modules.config_path"
40#define DETECT_MOD "manager.modules.detect_loadable"
41#define MOD_LOADPTH "manager.modules.load_path"
42#define INITFUNC_SFX "manager.modules.init_func_suffix"
43#define INITFUNC_PFX "manager.modules.init_func_prefix"
44#define ALLOW_ABSPATH "manager.modules.abs_path_allowed"
45#define ALLOW_URL "manager.modules.download_allowed"
46#define MOD_DWNDIR "manager.modules.download_dir"
47#define MOD_DELMOD "manager.modules.download_cleanup"
48#define MOD_PRELOAD "manager.modules.preload"
49
50namespace RTC
51{
72 {
73 using vProperties = std::vector<coil::Properties>;
74 public:
96 explicit ModuleManager(coil::Properties& prop);
97
110
118 struct Error
119 {
120 explicit Error(std::string _reason)
121 : reason(std::move(_reason)) {}
122 std::string reason;
123 };
124
133 struct NotFound
134 {
135 explicit NotFound(std::string _name)
136 : name(std::move(_name)) {}
137 std::string name;
138 };
139
149 : public NotFound
150 {
151 explicit FileNotFound(const std::string& _name)
152 : NotFound(_name) {}
153 };
154
164 : public NotFound
165 {
166 explicit ModuleNotFound(const std::string& _name)
167 : NotFound(_name) {}
168 };
169
179 : public NotFound
180 {
181 explicit SymbolNotFound(const std::string& _name)
182 : NotFound(_name) {}
183 };
184
194 : public Error
195 {
196 explicit NotAllowedOperation(const std::string& _reason)
197 : Error(_reason) {}
198 };
199
209 : public Error
210 {
211 explicit InvalidArguments(const std::string& _reason)
212 : Error(_reason) {}
213 };
214
224 : public Error
225 {
226 explicit InvalidOperation(const std::string& _reason)
227 : Error(_reason) {}
228 };
229 using ModuleInitFunc = void (*)(Manager*);
230
276 std::string load(const std::string& file_name);
277
305 std::string load(const std::string& file_name,
306 const std::string& init_func);
307
325 void unload(const std::string& file_name);
326
340 void unloadAll();
341
349 void* symbol(const std::string& file_name, const std::string& func_name);
350
368 void setLoadpath(const std::vector<std::string>& load_path);
369
387 inline std::vector<std::string> getLoadPath()
388 {
389 return m_loadPath;
390 }
391
409 void addLoadpath(const std::vector<std::string>& load_path);
410
428 std::vector<coil::Properties> getLoadedModules();
429
448 std::vector<coil::Properties> getLoadableModules();
449
463 inline void allowAbsolutePath()
464 {
465 m_absoluteAllowed = true;
466 }
467
482 {
483 m_absoluteAllowed = false;
484 }
485
504 {
505 m_downloadAllowed = true;
506 }
507
522 {
523 m_downloadAllowed = false;
524 }
525
549 std::string findFile(const std::string& fname,
550 const std::vector<std::string>& load_path);
551
573 bool fileExist(const std::string& filename);
574
596 std::string getInitFuncName(const std::string& file_path);
597
598 protected:
607
615 void getModuleList(const std::string& lang, coil::vstring& modules);
616
624 void addNewFile(const std::string& fpath, coil::vstring& modules, const std::string& lang);
625
633 void getModuleProfiles(const std::string& lang,
634 const coil::vstring& modules, vProperties& modprops);
635
644
653 {
654 coil::Properties properties;
655 coil::DynamicLib dll;
656 };
657
658 using StringVector = std::vector<std::string>;
659 using StringVectorItr = StringVector::iterator;
660 using StringVectorConstItr = StringVector::const_iterator;
661
662 using DllMap = std::vector<DLLEntity>;
663 using DllMapItr = DllMap::iterator;
664 using DllMapConstItr = DllMap::const_iterator;
665
666
674 coil::Properties& m_properties;
675
684 {
685 std::string m_filepath;
686 public:
687 explicit DllPred(const char* filepath) : m_filepath(filepath) {}
688 explicit DllPred(const DLLEntity* dll)
689 : m_filepath(dll->properties["file_path"]) {}
690 bool operator()(DLLEntity* dllentity)
691 {
692 return m_filepath == dllentity->properties.getProperty("file_path");
693 }
694 };
703
736
744 std::string m_initFuncSuffix;
745
753 std::string m_initFuncPrefix;
754
763
772 {
773 public:
774 UnloadPred() = default;
776 {
777 dll->dll.close();
778 delete dll;
779 }
780 };
781
782 vProperties m_modprofs;
783 std::map<std::string, coil::vstring> m_loadfailmods;
784
785 }; // class ModuleManager
786} // namespace RTC
787
788#endif // RTC_MODULEMANAGER_H
-*- C++ -*-
Object management class.
Class for managing objects.
Definition ObjectManager.h:52
Logger class.
Definition SystemLogger.h:101
Manager class.
Definition Manager.h:91
Module list that has already loaded .
Definition ModuleManager.h:684
DllPred(const char *filepath)
Definition ModuleManager.h:687
DllPred(const DLLEntity *dll)
Definition ModuleManager.h:688
bool operator()(DLLEntity *dllentity)
Definition ModuleManager.h:690
Module unloading functor .
Definition ModuleManager.h:772
void operator()(DLLEntity *dll)
Definition ModuleManager.h:775
ModuleManager class.
Definition ModuleManager.h:72
void(*)(Manager *) ModuleInitFunc
Definition ModuleManager.h:229
StringVector m_loadPath
Module load path list .
Definition ModuleManager.h:711
std::string m_initFuncPrefix
Initial execution function prefix .
Definition ModuleManager.h:753
void addLoadpath(const std::vector< std::string > &load_path)
Add the module load path.
std::string load(const std::string &file_name)
Load the module.
StringVector::iterator StringVectorItr
Definition ModuleManager.h:659
void disallowAbsolutePath()
Disallow absolute path when specify module path.
Definition ModuleManager.h:481
void unload(const std::string &file_name)
Unload the module.
void * symbol(const std::string &file_name, const std::string &func_name)
Refer to the symbol of the module .
std::map< std::string, coil::vstring > m_loadfailmods
Definition ModuleManager.h:783
ObjectManager< const char *, DLLEntity, DllPred > m_modules
Module list that has already loaded .
Definition ModuleManager.h:702
ModuleManager(coil::Properties &prop)
Constructor.
std::vector< std::string > getLoadPath()
Get the module load path.
Definition ModuleManager.h:387
void allowAbsolutePath()
Allow absolute path when specify module path.
Definition ModuleManager.h:463
std::vector< coil::Properties > getLoadedModules()
Get the module list that has been loaded.
coil::vstring m_supported_languages
Definition ModuleManager.h:762
std::string load(const std::string &file_name, const std::string &init_func)
Load and intialize the module.
void getModuleProfiles(const std::string &lang, const coil::vstring &modules, vProperties &modprops)
Getting module properties from given language and file list .
std::vector< DLLEntity > DllMap
Definition ModuleManager.h:662
DllMap::iterator DllMapItr
Definition ModuleManager.h:663
void disallowModuleDownload()
Disallow URL when specify module path.
Definition ModuleManager.h:521
std::string findFile(const std::string &fname, const std::vector< std::string > &load_path)
Search the file from the LoadPath.
void removeInvalidModules()
Removing incalid module profiles .
std::string getInitFuncName(const std::string &file_path)
Create initialization function symbol.
bool m_absoluteAllowed
Flag of absolute path when specify module for the load. .
Definition ModuleManager.h:735
void addNewFile(const std::string &fpath, coil::vstring &modules, const std::string &lang)
Adding file path not existing cache .
void allowModuleDownload()
Allow URL when specify module path.
Definition ModuleManager.h:503
void unloadAll()
Unload all modules.
DllMap::const_iterator DllMapConstItr
Definition ModuleManager.h:664
std::vector< coil::Properties > getLoadableModules()
Get the loadable module list.
void setLoadpath(const std::vector< std::string > &load_path)
Set the module load path.
coil::Properties & m_properties
Module Manager properties .
Definition ModuleManager.h:674
void getModuleList(const std::string &lang, coil::vstring &modules)
Getting loadable file list on the loadpath for given language .
bool m_downloadAllowed
Flag of URL when specify module for the load. .
Definition ModuleManager.h:727
bool fileExist(const std::string &filename)
Check whether the file exists.
StringVector::const_iterator StringVectorConstItr
Definition ModuleManager.h:660
std::string m_initFuncSuffix
Initial execution function suffix .
Definition ModuleManager.h:744
StringVector m_configPath
Configuration path list .
Definition ModuleManager.h:719
~ModuleManager()
Destructor.
vProperties m_modprofs
Definition ModuleManager.h:782
std::vector< std::string > StringVector
Definition ModuleManager.h:658
Logger rtclog
Logger stream .
Definition ModuleManager.h:643
RT-Component.
Structure for DLL management .
Definition ModuleManager.h:653
coil::Properties properties
Definition ModuleManager.h:654
coil::DynamicLib dll
Definition ModuleManager.h:655
Structure for exception handling when file open is failed .
Definition ModuleManager.h:119
std::string reason
Definition ModuleManager.h:122
Error(std::string _reason)
Definition ModuleManager.h:120
Structure for exception handling when specified file cannot be found .
Definition ModuleManager.h:150
FileNotFound(const std::string &_name)
Definition ModuleManager.h:151
Structure for exception handling when specified argument is invalid. .
Definition ModuleManager.h:210
InvalidArguments(const std::string &_reason)
Definition ModuleManager.h:211
Structure for exception handling when specified operation is invalid. .
Definition ModuleManager.h:225
InvalidOperation(const std::string &_reason)
Definition ModuleManager.h:226
Structure for exception handling when specified module cannot be found .
Definition ModuleManager.h:165
ModuleNotFound(const std::string &_name)
Definition ModuleManager.h:166
Structure for exception handling when specified operation cannot be allowed. .
Definition ModuleManager.h:195
NotAllowedOperation(const std::string &_reason)
Definition ModuleManager.h:196
Structure for exception handling of unimplemented part and specified module missing .
Definition ModuleManager.h:134
std::string name
Definition ModuleManager.h:137
NotFound(std::string _name)
Definition ModuleManager.h:135
Structure for exception handling when specified symbol cannot be found .
Definition ModuleManager.h:180
SymbolNotFound(const std::string &_name)
Definition ModuleManager.h:181