Skip to content

Commit

Permalink
Merge pull request #8 from rapyuta-robotics/feature/lw-respawn-all
Browse files Browse the repository at this point in the history
Respawn all option
  • Loading branch information
lindawang-6 authored Mar 11, 2020
2 parents 8f0bab5 + 4202493 commit 8faf10a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
18 changes: 15 additions & 3 deletions rosmon_core/src/launch/launch_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ void LaunchConfig::setDefaultMemoryLimit(uint64_t memoryLimit)
m_defaultMemoryLimit = memoryLimit;
}

void LaunchConfig::setRespawnBehaviour(bool respawnAll, bool respawnObey)
{
m_respawnAll = respawnAll;
m_respawnObey = respawnObey;
}

void LaunchConfig::parse(const std::string& filename, bool onlyArguments)
{
m_rootContext.setFilename(filename);
Expand Down Expand Up @@ -381,10 +387,16 @@ void LaunchConfig::parseNode(TiXmlElement* element, ParseContext ctx)
if(!fullNamespace.empty())
node->setNamespace(fullNamespace);

if(respawn)
if ((m_respawnObey && respawn) || !m_respawnObey)
{
node->setRespawn(ctx.parseBool(respawn, element->Row()));

if (!m_respawnObey)
{
node->setRespawn(m_respawnAll);
}
else
{
node->setRespawn(ctx.parseBool(respawn, element->Row()));
}
if(respawnDelay)
{
double seconds;
Expand Down
8 changes: 6 additions & 2 deletions rosmon_core/src/launch/launch_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ class LaunchConfig
void setArgument(const std::string& name, const std::string& value);

void setDefaultStopTimeout(double timeout);
void setDefaultCPULimit(double CPULimit);
void setDefaultMemoryLimit(uint64_t memoryLimit);
void setDefaultCPULimit(double CPULimit);
void setDefaultMemoryLimit(uint64_t memoryLimit);
void setRespawnBehaviour(bool respawnAll, bool respawnObey);

void parse(const std::string& filename, bool onlyArguments = false);
void parseString(const std::string& input, bool onlyArguments = false);
Expand Down Expand Up @@ -237,6 +238,9 @@ class LaunchConfig
double m_defaultStopTimeout{DEFAULT_STOP_TIMEOUT};
uint64_t m_defaultMemoryLimit{DEFAULT_MEMORY_LIMIT};
double m_defaultCPULimit{DEFAULT_CPU_LIMIT};

bool m_respawnAll;
bool m_respawnObey;
};

}
Expand Down
19 changes: 19 additions & 0 deletions rosmon_core/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ void usage()
" Use GROUP as name of the launch group. By default, empty\n"
" --launch-config=CONFIG\n"
" Use CONFIG as name of the launch config. By default, empty\n"
" --respawn-attr=obey|force_true|force_false\n"
" Force all nodes in launch group to respawn or not respawn,\n"
" or obey launch file. By default, nodes will obey.\n"
" --no-start Don't automatically start the nodes in the beginning\n"
" --stop-timeout=SECONDS\n"
" Kill a process if it is still running this long\n"
Expand Down Expand Up @@ -133,6 +136,7 @@ static const struct option OPTIONS[] = {
{"robot", required_argument, nullptr, 'r'},
{"launch-group", required_argument, nullptr, 'g'},
{"launch-config", required_argument, nullptr, 'z'},
{"respawn-attr", required_argument, nullptr, 'R'},
{"no-start", no_argument, nullptr, 'S'},
{"stop-timeout", required_argument, nullptr, 's'},
{"disable-diagnostics", no_argument, nullptr, 'D'},
Expand All @@ -158,6 +162,8 @@ int main(int argc, char** argv)
Action action = ACTION_LAUNCH;
bool enableUI = true;
bool flushLog = false;
bool respawnAll = false;
bool respawnObey = true;
bool startNodes = true;
double stopTimeout = rosmon::launch::LaunchConfig::DEFAULT_STOP_TIMEOUT;
uint64_t memoryLimit = rosmon::launch::LaunchConfig::DEFAULT_MEMORY_LIMIT;
Expand Down Expand Up @@ -264,6 +270,18 @@ int main(int argc, char** argv)
fmt::print(stderr, "Prefix : {}", optarg);
diagnosticsPrefix = std::string(optarg);
break;
case 'R':
if (optarg && (strcmp(optarg,"force_true")==0 || strcmp(optarg,"force_false")==0))
{
respawnAll = strcmp(optarg,"force_true")==0;
respawnObey = false;
}
else if (optarg && !((strcmp(optarg,"obey")==0)))
{
fmt::print(stderr, "Bad value for --respawn-attr argument: '{}'\n", optarg);
return 1;
}
break;
}
}

Expand Down Expand Up @@ -352,6 +370,7 @@ int main(int argc, char** argv)
config->setDefaultStopTimeout(stopTimeout);
config->setDefaultCPULimit(cpuLimit);
config->setDefaultMemoryLimit(memoryLimit);
config->setRespawnBehaviour(respawnAll, respawnObey);

// Parse launch file arguments from command line
for(int i = firstArg; i < argc; ++i)
Expand Down
1 change: 1 addition & 0 deletions rosmon_core/test/xml/test_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ TEST_CASE("node args", "[node]")
TEST_CASE("node respawn", "[node]")
{
LaunchConfig config;
config.setRespawnBehaviour(false, true);
config.parseString(R"EOF(
<launch>
<node name="test_node" pkg="rosmon_core" type="abort" respawn="true" respawn_delay="10" />
Expand Down

0 comments on commit 8faf10a

Please sign in to comment.