Skip to content

Commit 543353d

Browse files
authored
Merge pull request #1156 from Nobu19800/bugs/loadmodule
create_component関数でRTCが起動できない場合がある問題の修正
2 parents 4053802 + 9a3b5f4 commit 543353d

File tree

4 files changed

+324
-110
lines changed

4 files changed

+324
-110
lines changed

src/lib/rtm/Manager.cpp

Lines changed: 85 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -403,53 +403,72 @@ namespace RTC
403403
RTC_TRACE(("Manager::load(fname = %s, initfunc = %s)",
404404
fname.c_str(), initfunc.c_str()));
405405

406-
std::string file_name(fname);
406+
coil::Properties prop;
407+
prop["module_file_name"] = fname;
408+
409+
return load(prop, initfunc);
410+
}
411+
412+
/*!
413+
* @if jp
414+
* @brief モジュールのロード
415+
* @else
416+
* @brief Load module
417+
* @endif
418+
*/
419+
ReturnCode_t Manager::load(coil::Properties &prop,
420+
const std::string &initfunc)
421+
{
422+
RTC_TRACE(("Manager::load(filename = %s, filepath = %s, language = %s, initfunc = %s)",
423+
prop["module_file_name"].c_str(), prop["module_file_path"].c_str(), prop["language"].c_str(), initfunc.c_str()));
424+
425+
std::string file_name(prop["module_file_name"]);
407426
std::string init_func(initfunc);
408427
m_listeners.module_.preLoad(file_name, init_func);
409428
try
429+
{
430+
if (init_func.empty())
410431
{
411-
if (init_func.empty())
412-
{
413-
if (coil::isAbsolutePath(file_name))
414-
{
415-
coil::vstring mod(coil::split(file_name, "/"));
416-
mod = coil::split(mod.back(), "\\");
417-
mod = coil::split(mod.back(), ".");
418-
init_func = mod[0] + "Init";
419-
}
420-
else
421-
{
422-
coil::vstring mod(coil::split(file_name, "."));
423-
init_func = mod[0] + "Init";
424-
}
425-
}
426-
std::string path(m_module->load(file_name, init_func));
427-
RTC_DEBUG(("module path: %s", path.c_str()));
428-
m_listeners.module_.postLoad(path, init_func);
429-
}
430-
catch(RTC::ModuleManager::NotAllowedOperation& e)
431-
{
432-
RTC_ERROR(("Operation not allowed: %s",
433-
e.reason.c_str()));
434-
return RTC::PRECONDITION_NOT_MET;
435-
}
436-
catch(RTC::ModuleManager::NotFound& e)
437-
{
438-
RTC_ERROR(("Not found: %s",
439-
e.name.c_str()));
440-
return RTC::RTC_ERROR;
441-
}
442-
catch(RTC::ModuleManager::InvalidArguments& e)
443-
{
444-
RTC_ERROR(("Invalid argument: %s",
445-
e.reason.c_str()));
446-
return RTC::BAD_PARAMETER;
447-
}
448-
catch(RTC::ModuleManager::Error& e)
449-
{
450-
RTC_ERROR(("Error: %s", e.reason.c_str()));
451-
return RTC::RTC_ERROR;
432+
if (coil::isAbsolutePath(file_name))
433+
{
434+
coil::vstring mod(coil::split(file_name, "/"));
435+
mod = coil::split(mod.back(), "\\");
436+
mod = coil::split(mod.back(), ".");
437+
init_func = mod[0] + "Init";
438+
}
439+
else
440+
{
441+
coil::vstring mod(coil::split(file_name, "."));
442+
init_func = mod[0] + "Init";
443+
}
452444
}
445+
std::string path(m_module->load(prop, init_func));
446+
RTC_DEBUG(("module path: %s", path.c_str()));
447+
m_listeners.module_.postLoad(path, init_func);
448+
}
449+
catch (RTC::ModuleManager::NotAllowedOperation &e)
450+
{
451+
RTC_ERROR(("Operation not allowed: %s",
452+
e.reason.c_str()));
453+
return RTC::PRECONDITION_NOT_MET;
454+
}
455+
catch (RTC::ModuleManager::NotFound &e)
456+
{
457+
RTC_ERROR(("Not found: %s",
458+
e.name.c_str()));
459+
return RTC::RTC_ERROR;
460+
}
461+
catch (RTC::ModuleManager::InvalidArguments &e)
462+
{
463+
RTC_ERROR(("Invalid argument: %s",
464+
e.reason.c_str()));
465+
return RTC::BAD_PARAMETER;
466+
}
467+
catch (RTC::ModuleManager::Error &e)
468+
{
469+
RTC_ERROR(("Error: %s", e.reason.c_str()));
470+
return RTC::RTC_ERROR;
471+
}
453472
catch (...)
454473
{
455474
RTC_ERROR(("Unknown error."));
@@ -687,30 +706,31 @@ std::vector<coil::Properties> Manager::getLoadableModules()
687706
std::vector<coil::Properties> mp(m_module->getLoadableModules());
688707
RTC_INFO(("%d loadable modules found", mp.size()));
689708

690-
std::vector<coil::Properties>::iterator it;
691-
it = std::find_if(mp.begin(), mp.end(), ModulePredicate(comp_id));
692-
if (it == mp.end())
693-
{
694-
RTC_ERROR(("No module for %s in loadable modules list",
695-
comp_id["implementation_id"].c_str()));
696-
return nullptr;
697-
}
698-
if (it->findNode("module_file_path") == nullptr)
699-
{
700-
RTC_ERROR(("Hmm...module_file_path key not found."));
701-
return nullptr;
702-
}
703-
// module loading
704-
RTC_INFO(("Loading module: %s", (*it)["module_file_path"].c_str()));
705-
load((*it)["module_file_path"], "");
706-
factory = m_factory.find(comp_id);
707-
if (factory == nullptr)
708-
{
709-
RTC_ERROR(("Factory not found for loaded module: %s",
710-
comp_id["implementation_id"].c_str()));
711-
return nullptr;
712-
}
709+
std::vector<coil::Properties>::iterator it;
710+
it = std::find_if(mp.begin(), mp.end(), ModulePredicate(comp_id));
711+
if (it == mp.end())
712+
{
713+
RTC_ERROR(("No module for %s in loadable modules list",
714+
comp_id["implementation_id"].c_str()));
715+
return nullptr;
713716
}
717+
if (it->findNode("module_file_path") == nullptr)
718+
{
719+
RTC_ERROR(("Hmm...module_file_path key not found."));
720+
return nullptr;
721+
}
722+
// module loading
723+
RTC_INFO(("Loading module: %s", (*it)["module_file_path"].c_str()));
724+
load((*it), "");
725+
factory = m_factory.find(comp_id);
726+
if (factory == nullptr)
727+
{
728+
RTC_ERROR(("Factory not found for loaded module: %s",
729+
comp_id["implementation_id"].c_str()));
730+
return nullptr;
731+
}
732+
733+
}
714734

715735
coil::Properties prop;
716736
prop = factory->profile();

src/lib/rtm/Manager.h

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ namespace RTC
467467
* @return 終了コード
468468
* RTC::RTC_OK 正常終了
469469
* RTC::RTC_ERROR ロード失敗・不明なエラー
470-
* RTC::PRECONDITION_NOT_MET 設定にり許可されない操作
470+
* RTC::PRECONDITION_NOT_MET 設定により許可されない操作
471471
* RTC::BAD_PARAMETER 不正なパラメータ
472472
*
473473
* @else
@@ -489,6 +489,44 @@ namespace RTC
489489
*/
490490
ReturnCode_t load(const std::string& fname, const std::string& initfunc);
491491

492+
/*!
493+
* @if jp
494+
* @brief [CORBA interface] モジュールのロード
495+
*
496+
* 指定したコンポーネントのモジュールをロードするとともに、
497+
* 指定した初期化関数を実行する。
498+
*
499+
* @param prop module_file_name: モジュールファイル名
500+
* module_file_path: モジュールファイルのパス
501+
* language: プログラミング言語
502+
* @param initfunc 初期化関数名
503+
* @return 終了コード
504+
* RTC::RTC_OK 正常終了
505+
* RTC::RTC_ERROR ロード失敗・不明なエラー
506+
* RTC::PRECONDITION_NOT_MET 設定により許可されない操作
507+
* RTC::BAD_PARAMETER 不正なパラメータ
508+
*
509+
* @else
510+
*
511+
* @brief [CORBA interface] Load module
512+
*
513+
* Load specified module (shared library, DLL etc..),
514+
* and invoke initialize function.
515+
*
516+
* @param prop module_file_name: module file name
517+
* module_file_path: module file path
518+
* language: programming language
519+
* @param initfunc The initialize function name
520+
* @return Return code
521+
* RTC::RTC_OK Normal return
522+
* RTC::RTC_ERROR Load failed, or unknown error
523+
* RTC::PRECONDITION_NOT_MET Not allowed operation by conf
524+
* RTC::BAD_PARAMETER Invalid parameter
525+
*
526+
* @endif
527+
*/
528+
ReturnCode_t load(coil::Properties &prop, const std::string& initfunc);
529+
492530
/*!
493531
* @if jp
494532
*
@@ -1394,6 +1432,27 @@ namespace RTC
13941432
*/
13951433
std::string createORBOptions();
13961434

1435+
/*!
1436+
* @if jp
1437+
* @brief giopからはじまるORBエンドポイントでの指定した場合にtrue、
1438+
* それ以外(例えばホスト名:ポート番号の指定)の場合はfalseを返す。
1439+
*
1440+
*
1441+
* @param endpoint エンドポイント
1442+
*
1443+
* @return エンドポイントの指定方法
1444+
*
1445+
* @else
1446+
* @brief
1447+
*
1448+
* @param endpoint
1449+
*
1450+
* @return
1451+
*
1452+
* @endif
1453+
*/
1454+
static bool isORBEndPoint(const std::string& endpoint);
1455+
13971456
/*!
13981457
* @if jp
13991458
* @brief エンドポイントの生成

0 commit comments

Comments
 (0)