Skip to content

Commit

Permalink
Merge pull request #1124 from OpenRTM/manager_arg
Browse files Browse the repository at this point in the history
getParameterByModulename()'s bug fixed
  • Loading branch information
Nobu19800 authored Oct 29, 2023
2 parents 7090007 + 5f49f72 commit 2e78884
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 55 deletions.
82 changes: 27 additions & 55 deletions src/lib/rtm/ManagerServant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,65 +323,37 @@ namespace RTM

std::string ManagerServant::getParameterByModulename(const std::string& param_name, std::string &module_name)
{
size_t pos0 = module_name.find("&" + param_name + "=");
size_t pos1 = module_name.find("?" + param_name + "=");

if (pos0 == std::string::npos && pos1 == std::string::npos)
{
return "";
}

size_t pos = 0;
if (pos0 == std::string::npos)
{
pos = pos1;
}
else
{
pos = pos0;
}

std::string paramstr;
size_t endpos = module_name.find('&', pos + 1);


if (endpos == std::string::npos)
{
endpos = module_name.find('?', pos + 1);

if (endpos == std::string::npos)
{
paramstr = module_name.substr((pos + 1));

}
else
{
paramstr = module_name.substr((pos + 1), endpos);
}
}
else
{
paramstr = module_name.substr((pos + 1), endpos);
}
RTC_VERBOSE(("%s arg: %s", param_name.c_str(), paramstr.c_str()));

size_t eqpos = paramstr.find('=');

paramstr = paramstr.substr(eqpos + 1);
size_t param_start = module_name.find(param_name + "=");

if (param_start == std::string::npos)
{ // no specified param
return "";
}

RTC_DEBUG(("%s is %s", param_name.c_str(), paramstr.c_str()));
size_t param_end = module_name.find("&", param_start);

if (endpos == std::string::npos)
{
module_name = module_name.substr(0, pos);
}
else
{
module_name = module_name.substr(0, pos) + module_name.substr(endpos);
}
if (param_end == std::string::npos)
{ // param is end of param list
param_end = module_name.length();
}

return paramstr;
// extract param's value
// module_name?....param_name=param_value
// substr( ^ arg1 ^ arg2 ^ )
std::string param_value =
module_name.substr(param_start + param_name.length() + 1,
param_end - param_start - param_name.length() - 1);
RTC_DEBUG(("%s is %s", param_name.c_str(), param_value.c_str()));
// remove specified param
if (module_name[param_start - 1] == '?')
{ // module_name?{param_name=param_value}: remove {}
module_name.erase(param_start, param_end - param_start + 1);
}
if (module_name[param_start - 1] == '&')
{ // module_name?other_param...{&param_name=param_value}: remove {}
module_name.erase(param_start - 1, param_end - param_start + 1);
}
return param_value;
}

/*!
Expand Down
26 changes: 26 additions & 0 deletions src/lib/rtm/ManagerServant.h
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,32 @@ namespace RTM
* @endif
*/
void updateMasterManager();
/*
* @if jp
* @brief create引数から指定されたキーの値を返す
*
* create引数から指定されたキーを値を返すとともに、そのキーと値を削除した引
* 数を返す。
* module_name: module_name?param1=value1&param2=value2&param3...
* param_name: param2
* の場合
* 返り値: value2
* module_name: module_name?param1=value1&param3...
* となる。
*
* @else @brief returns value of specified param_name from create arg
*
* This function returns the value of specified param_name from
* create argument, and delete param_name=value from the create
* arg string. If the arguments are
* module_name: module_name?param1=value1&param2=value2&param3...
* param_name: param2
* this function returns
* ret value: value2
* module_name: module_name?param1=value1&param3...
*
* @endif
*/
std::string getParameterByModulename(const std::string& param_name, std::string &module_name);
static bool isProcessIDManager(const std::string& mgrname);

Expand Down

0 comments on commit 2e78884

Please sign in to comment.