22 #include <coil/File.h> 23 #include <coil/Process.h> 28 #include <coil/stringutil.h> 47 : rtclog(
"ModuleManager"), m_properties(prop)
80 RTC_TRACE((
"load(fname = %s)", file_name.c_str()));
87 RTC_ERROR((
"Downloading module is not allowed."));
97 std::string file_path;
102 RTC_ERROR((
"Absolute path is not allowed"));
107 file_path = file_name;
118 RTC_ERROR((
"Invalid file name: Empty file name."));
123 RTC_ERROR((
"Module file not found: %s", file_path.c_str()));
129 int retval = dll->dll.open(file_path.c_str());
132 RTC_ERROR((
"Module file %s load failed: %s",
133 file_path.c_str(), dll->dll.error()));
135 throw Error(
"DLL open failed.");
137 dll->properties[
"file_path"] = file_path;
141 RTC_ERROR((
"Module registration failed: %s", file_path.c_str()));
156 const std::string& init_func)
158 RTC_TRACE((
"load(fname = %s, init_func = %s)",
159 file_name.c_str(), init_func.c_str()));
161 name =
load(file_name);
193 m_modules.unregisterObject(file_name.c_str());
212 std::vector<DLLEntity*> dlls(
m_modules.getObjects());
214 for (
int i(0), len(dlls.size()); i < len; ++i)
216 std::string ident(dlls[i]->properties[
"file_path"]);
231 const std::string& func_name)
235 file_name.c_str(), func_name.c_str()))
240 RTC_ERROR((
"Module %s not found in module table.", file_name.c_str()));
244 RTC_DEBUG((
"Finding function symbol: %s in %s",
245 func_name.c_str(), file_name.c_str()));
247 func = dll->
dll.
symbol(func_name.c_str());
251 RTC_ERROR((
"Specified symbol %s not found.", func_name.c_str()));
304 std::vector< DLLEntity* > dlls(
m_modules.getObjects());
305 std::vector<coil::Properties> modules;
306 for (
int i(0), len(dlls.size()); i < len; ++i)
308 modules.push_back(dlls[i]->properties);
327 RTC_DEBUG((
"langs: %s", gprop[
"manager.supported_languages"].c_str()));
330 for (
size_t l(0); l < langs.size(); ++l)
340 RTC_DEBUG((
"Modile profile size: %d (newly founded modules)",
347 RTC_DEBUG((
"Modile profile size: %d (invalid mod-profiles deleted)",
360 const std::vector<std::string>& load_path)
362 RTC_TRACE((
"findFile(%s, %s)", fname.c_str(),
365 std::string file_name(fname);
367 it = load_path.begin();
368 it_end = load_path.end();
372 std::string f((*it) +
"/" + file_name);
380 return std::string(
"");
392 RTC_TRACE((
"fileExist(%s)", filename.c_str()));
393 std::ifstream infile;
394 infile.open(filename.c_str(), std::ios::in);
396 if (infile.fail() != 0)
419 RTC_TRACE((
"getInitFuncName(%s)", file_path.c_str()));
435 std::vector<coil::Properties>::iterator it(
m_modprofs.begin());
439 if (!
fileExist((*it)[
"module_file_path"]))
457 std::string l =
"manager.modules." + lang;
468 for (
size_t i(0); i < paths.size(); ++i)
470 if (paths[i].empty())
472 RTC_WARN((
"Given load path is empty"));
475 std::string&
path(paths[i]);
476 RTC_DEBUG((
"Module load path: %s", path.c_str()));
480 for (
size_t s(0); s < suffixes.size(); ++s)
482 std::string glob(
"*."); glob += suffixes[s];
484 RTC_DEBUG((
"File list (path:%s, ext:%s): %s", path.c_str(),
486 flist.insert(flist.end(), tmp.begin(), tmp.end());
490 for (
size_t j(0); j < flist.size(); ++j)
492 if (*(path.end() - 1) !=
'/') { path +=
"/"; }
493 std::string fpath(path + flist[j]);
512 if (
m_modprofs[k][
"module_file_path"] == fpath)
515 RTC_DEBUG((
"Module %s already exists in cache.",
522 RTC_DEBUG((
"New module: %s", fpath.c_str()));
523 modules.push_back(fpath);
538 std::string l =
"manager.modules." + lang;
540 std::vector<coil::Properties>
prop;
542 for (
size_t i(0), len(modules.size()); i < len; ++i)
544 std::string
cmd(lprop[
"profile_cmd"]);
545 cmd +=
" \"" + modules[i] +
"\"";
547 if ((fd =
popen(cmd.c_str(),
"r")) == NULL)
549 std::cerr <<
"popen faild" << std::endl;
557 std::string line(str);
559 line.erase(line.size() - 1);
560 std::string::size_type pos(line.find(
":"));
561 if (pos != std::string::npos)
563 std::string key(line.substr(0, pos));
565 p[key] = line.substr(pos + 1);
570 RTC_DEBUG((
"rtcprof cmd sub process done."));
571 if (p[
"implementation_id"].empty()) {
continue; }
573 p[
"module_file_path"] = modules[i].c_str();
574 modprops.push_back(p);
void * symbol(const std::string &file_name, const std::string &func_name)
Refer to the symbol of the module.
void(* ModuleInitFunc)(Manager *)
Structure for exception handling of unimplemented part and specified module missing.
std::vector< coil::Properties > vProperties
#define RTC_ERROR(fmt)
Error log output macro.
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.
Structure for exception handling when file open is failed.
void addLoadpath(const std::vector< std::string > &load_path)
Add the module load path.
~ModuleManager(void)
Destructor.
std::vector< coil::Properties > getLoadableModules()
Get the loadable module list.
void * symbol(const char *symbol_name)
Return an address of the memory where a symbol was loaded.
ObjectManager< const char *, DLLEntity, DllPred > m_modules
Module list that has already loaded.
void setLoadpath(const std::vector< std::string > &load_path)
Set the module load path.
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
void eraseHeadBlank(std::string &str)
Erase the head blank characters of string.
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
Split string by delimiter.
Structure for exception handling when specified symbol cannot be found.
std::string load(const std::string &file_name)
Load the module.
std::vector< coil::Properties > getLoadedModules()
Get the module list that has been loaded.
static Manager & instance()
Get instance of the manager.
void eraseBothEndsBlank(std::string &str)
Erase the head blank and the tail blank characters of string.
#define RTC_WARN(fmt)
Warning log output macro.
RTComponent manager class.
bool isAbsolutePath(const std::string &str)
Investigate whether the given string is absolute path or not.
bool m_downloadAllowed
Flag of URL when specify module for the load.
Structure for exception handling when specified operation is invalid.
std::vector< std::string > vstring
StringVector m_loadPath
Module load path list.
StringVector m_configPath
Configuration path list.
Structure for exception handling when specified argument is invalid.
#define RTC_DEBUG(fmt)
Debug level log output macro.
bool fileExist(const std::string &filename)
Check whether the file exists.
void addNewFile(const std::string &fpath, coil::vstring &modules)
Adding file path not existing cache.
std::string flatten(vstring sv)
Create CSV file from the given string list.
Structure for exception handling when specified module cannot be found.
bool isURL(const std::string &str)
Investigate whether the given string is URL or not.
Loadable modules manager class.
void removeInvalidModules()
Removing incalid module profiles.
FILE * popen(const char *cmd, const char *mode)
coil::vstring filelist(const char *path, const char *glob_str="")
Get file list.
prop
Organization::get_organization_property ();.
Class represents a set of properties.
void unloadAll()
Unload all modules.
bool toBool(std::string str, std::string yes, std::string no, bool default_value)
Convert given string into bool value.
Structure for exception handling when specified file cannot be found.
StringVector::const_iterator StringVectorConstItr
Structure for DLL management.
void unload(const std::string &file_name)
Unload the module.
virtual int close(void)
Unload of the Dynamic link library.
ModuleManager(coil::Properties &prop)
Constructor.
const char * basename(const char *path)
Get a file name part than a file pass.
void getModuleProfiles(const std::string &lang, const coil::vstring &modules, vProperties &modprops)
Getting module properties from given language and file list.
std::string findFile(const std::string &fname, const std::vector< std::string > &load_path)
Search the file from the LoadPath.
void getModuleList(const std::string &lang, coil::vstring &modules)
Getting loadable file list on the loadpath for given language.
std::string m_initFuncSuffix
Initial execution function suffix.
Structure for exception handling when specified operation cannot be allowed.
Functor for_each(CorbaSequence &seq, Functor f)
Apply the functor to all CORBA sequence elements.
std::string m_initFuncPrefix
Initial execution function prefix.