22 #include <coil/File.h> 23 #include <coil/Process.h> 28 #include <coil/stringutil.h> 41 : rtclog(
"ModuleManager"), m_properties(prop)
74 RTC_TRACE((
"load(fname = %s)", file_name.c_str()));
90 std::string file_path;
99 file_path = file_name;
113 int retval = dll->dll.open(file_path.c_str());
117 throw Error(
"DLL open failed.");
119 dll->properties[
"file_path"] = file_path;
136 const std::string& init_func)
138 RTC_TRACE((
"load(fname = %s, init_func = %s)",
139 file_name.c_str(), init_func.c_str()));
141 name =
load(file_name);
173 m_modules.unregisterObject(file_name.c_str());
191 std::vector<DLLEntity*> dlls(
m_modules.getObjects());
193 for (
int i(0), len(dlls.size()); i < len; ++i)
195 std::string ident(dlls[i]->properties[
"file_path"]);
210 const std::string& func_name)
221 func = dll->
dll.
symbol(func_name.c_str());
274 std::vector< DLLEntity* > dlls(
m_modules.getObjects());
275 std::vector<coil::Properties> modules;
276 for (
int i(0), len(dlls.size()); i < len; ++i)
278 modules.push_back(dlls[i]->properties);
297 RTC_DEBUG((
"langs: %s", gprop[
"manager.supported_languages"].c_str()));
300 for (
size_t l(0); l < langs.size(); ++l)
310 RTC_DEBUG((
"Modile profile size: %d (newly founded modules)",
317 RTC_DEBUG((
"Modile profile size: %d (invalid mod-profiles deleted)",
330 const std::vector<std::string>& load_path)
333 std::string file_name(fname);
335 it = load_path.begin();
336 it_end = load_path.end();
340 std::string f((*it) +
"/" + file_name);
348 return std::string(
"");
360 std::ifstream infile;
361 infile.open(filename.c_str(), std::ios::in);
363 if (infile.fail() != 0)
401 std::vector<coil::Properties>::iterator it(
m_modprofs.begin());
405 if (!
fileExist((*it)[
"module_file_path"]))
423 std::string l =
"manager.modules." + lang;
434 for (
size_t i(0); i < paths.size(); ++i)
436 if (paths[i].empty())
438 RTC_WARN((
"Given load path is empty"));
441 std::string&
path(paths[i]);
442 RTC_DEBUG((
"Module load path: %s", path.c_str()));
446 for (
size_t s(0); s < suffixes.size(); ++s)
448 std::string glob(
"*."); glob += suffixes[s];
450 RTC_DEBUG((
"File list (path:%s, ext:%s): %s", path.c_str(),
452 flist.insert(flist.end(), tmp.begin(), tmp.end());
456 for (
size_t j(0);
j < flist.size(); ++
j)
458 if (*(path.end() - 1) !=
'/') { path +=
"/"; }
459 std::string fpath(path + flist[
j]);
478 if (
m_modprofs[k][
"module_file_path"] == fpath)
481 RTC_DEBUG((
"Module %s already exists in cache.",
488 RTC_DEBUG((
"New module: %s", fpath.c_str()));
489 modules.push_back(fpath);
504 std::string l =
"manager.modules." + lang;
506 std::vector<coil::Properties>
prop;
508 for (
size_t i(0), len(modules.size()); i < len; ++i)
510 std::string
cmd(lprop[
"profile_cmd"]);
511 cmd +=
" \"" + modules[i] +
"\"";
513 if ((fd =
popen(cmd.c_str(),
"r")) == NULL)
515 std::cerr <<
"popen faild" << std::endl;
523 std::string line(str);
524 line.erase(line.size() - 1);
525 std::string::size_type pos(line.find(
":"));
526 if (pos != std::string::npos)
528 std::string key(line.substr(0, pos));
530 p[key] = line.substr(pos + 1);
535 RTC_DEBUG((
"rtcprof cmd sub process done."));
536 if (p[
"implementation_id"].empty()) {
continue; }
538 p[
"module_file_path"] = modules[i].c_str();
539 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
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.
def j(str, encoding="cp932")
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.