node.cpp
Go to the documentation of this file.
1 // Launch configuration for a single Node
2 // Author: Max Schwarz <max.schwarz@uni-bonn.de>
3 
4 #include "node.h"
5 
6 #include "../package_registry.h"
7 
8 #include <wordexp.h>
9 #include <glob.h>
10 
11 #include <cstdarg>
12 
13 #include <fmt/format.h>
14 
15 template<typename... Args>
16 std::runtime_error error(const char* format, const Args& ... args)
17 {
18  std::string msg = fmt::format(format, args...);
19  return std::runtime_error(msg);
20 }
21 
22 namespace rosmon
23 {
24 
25 namespace launch
26 {
27 
28 Node::Node(std::string name, std::string package, std::string type)
29  : m_name(std::move(name))
30  , m_package(std::move(package))
31  , m_type(std::move(type))
32 
33  // NOTE: roslaunch documentation seems to suggest that this is true by default,
34  // however, the source tells a different story...
35  , m_respawn(false)
36  , m_respawnDelay(1.0)
37 
38  , m_required(false)
39  , m_coredumpsEnabled(true)
40  , m_clearParams(false)
41  , m_stopTimeout(5.0)
42  , m_memoryLimitByte(15e6)
43  , m_cpuLimit(0.05)
44 {
46 }
47 
48 void Node::setRemappings(const std::map<std::string, std::string>& remappings)
49 {
51 }
52 
53 void Node::addExtraArguments(const std::string& argString)
54 {
55  wordexp_t tokens;
56 
57  // Get rid of newlines since this confuses wordexp
58  std::string clean = argString;
59  for(auto& c : clean)
60  {
61  if(c == '\n' || c == '\r')
62  c = ' ';
63  }
64 
65  // NOTE: This also does full shell expansion (things like $PATH)
66  // But since we trust the user here (and modifying PATH etc dooms us in
67  // any case), I think we can use wordexp here.
68  int ret = wordexp(clean.c_str(), &tokens, WRDE_NOCMD);
69  if(ret != 0)
70  throw error("You're supplying something strange in 'args': '{}' (wordexp ret {})", clean, ret);
71 
72  for(unsigned int i = 0; i < tokens.we_wordc; ++i)
73  m_extraArgs.emplace_back(tokens.we_wordv[i]);
74 
75  wordfree(&tokens);
76 }
77 
78 void Node::setNamespace(const std::string& ns)
79 {
80  m_namespace = ns;
81 }
82 
83 void Node::setExtraEnvironment(const std::map<std::string, std::string>& env)
84 {
86 }
87 
89 {
91 }
92 
94 {
96 }
97 
99 {
101 }
102 
103 void Node::setLaunchPrefix(const std::string& launchPrefix)
104 {
105  wordexp_t tokens;
106 
107  // Get rid of newlines since this confuses wordexp
108  std::string clean = launchPrefix;
109  for(auto& c : clean)
110  {
111  if(c == '\n' || c == '\r')
112  c = ' ';
113  }
114 
115  // NOTE: This also does full shell expansion (things like $PATH)
116  // But since we trust the user here (and modifying PATH etc dooms us in
117  // any case), I think we can use wordexp here.
118  int ret = wordexp(clean.c_str(), &tokens, WRDE_NOCMD);
119  if(ret != 0)
120  throw error("You're supplying something strange in 'launch-prefix': '{}' (wordexp ret {})", clean, ret);
121 
122  for(unsigned int i = 0; i < tokens.we_wordc; ++i)
123  m_launchPrefix.emplace_back(tokens.we_wordv[i]);
124 
125  wordfree(&tokens);
126 }
127 
129 {
130  m_coredumpsEnabled = on;
131 }
132 
133 void Node::setWorkingDirectory(const std::string& cwd)
134 {
135  m_workingDirectory = cwd;
136 }
137 
138 void Node::setClearParams(bool on)
139 {
140  m_clearParams = on;
141 }
142 
143 void Node::setStopTimeout(double timeout)
144 {
145  m_stopTimeout = timeout;
146 }
147 
149 {
151 }
152 
154 {
156 }
157 
158 }
159 
160 }
Node(std::string name, std::string package, std::string type)
Definition: node.cpp:28
float m_cpuLimit
Definition: node.h:134
bool respawn() const
Definition: node.h:73
std::string m_type
Definition: node.h:107
void setCoredumpsEnabled(bool on)
Definition: node.cpp:128
std::string m_namespace
Definition: node.h:111
float cpuLimit() const
Definition: node.h:102
std::map< std::string, std::string > m_remappings
Definition: node.h:113
ros::WallDuration respawnDelay() const
Definition: node.h:76
uint64_t memoryLimitByte() const
Definition: node.h:99
std::string m_executable
Definition: node.h:109
void setStopTimeout(double timeout)
Definition: node.cpp:143
ROSCPP_DECL std::string clean(const std::string &name)
std::map< std::string, std::string > m_extraEnvironment
Definition: node.h:116
void setMemoryLimit(uint64_t memoryLimitByte)
Definition: node.cpp:148
std::string m_workingDirectory
Definition: node.h:127
ros::WallDuration m_respawnDelay
Definition: node.h:119
void setLaunchPrefix(const std::string &launchPrefix)
Definition: node.cpp:103
bool m_clearParams
Definition: node.h:129
void setRemappings(const std::map< std::string, std::string > &remappings)
Definition: node.cpp:48
void setRequired(bool required)
Definition: node.cpp:88
std::runtime_error error(const char *format, const Args &...args)
Definition: node.cpp:16
bool m_coredumpsEnabled
Definition: node.h:125
std::string env(const std::string &name)
void setClearParams(bool on)
Definition: node.cpp:138
bool required() const
Definition: node.h:81
std::vector< std::string > m_extraArgs
Definition: node.h:114
void addExtraArguments(const std::string &argString)
Definition: node.cpp:53
std::string m_package
Definition: node.h:106
std::map< std::string, std::string > remappings() const
Definition: node.h:64
void setCPULimit(float cpuLimit)
Definition: node.cpp:153
uint64_t m_memoryLimitByte
Definition: node.h:133
void setExtraEnvironment(const std::map< std::string, std::string > &env)
Definition: node.cpp:83
void setWorkingDirectory(const std::string &workingDirectory)
Definition: node.cpp:133
void setNamespace(const std::string &ns)
Definition: node.cpp:78
void setRespawn(bool respawn)
Definition: node.cpp:93
std::vector< std::string > launchPrefix() const
Definition: node.h:84
std::vector< std::string > m_launchPrefix
Definition: node.h:123
double m_stopTimeout
Definition: node.h:131
static std::string getExecutable(const std::string &package, const std::string &name)
void setRespawnDelay(const ros::WallDuration &respawnDelay)
Definition: node.cpp:98


rosmon_core
Author(s): Max Schwarz
autogenerated on Wed Jul 10 2019 03:10:12