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  , m_muted(false)
45  , m_stdoutDisplayed(true)
46 {
48 }
49 
50 void Node::setRemappings(const std::map<std::string, std::string>& remappings)
51 {
53 }
54 
55 void Node::addExtraArguments(const std::string& argString)
56 {
57  wordexp_t tokens;
58 
59  // Get rid of newlines since this confuses wordexp
60  std::string clean = argString;
61  for(auto& c : clean)
62  {
63  if(c == '\n' || c == '\r')
64  c = ' ';
65  }
66 
67  // NOTE: This also does full shell expansion (things like $PATH)
68  // But since we trust the user here (and modifying PATH etc dooms us in
69  // any case), I think we can use wordexp here.
70  int ret = wordexp(clean.c_str(), &tokens, WRDE_NOCMD);
71  if(ret != 0)
72  throw error("You're supplying something strange in 'args': '{}' (wordexp ret {})", clean, ret);
73 
74  for(unsigned int i = 0; i < tokens.we_wordc; ++i)
75  m_extraArgs.emplace_back(tokens.we_wordv[i]);
76 
77  wordfree(&tokens);
78 }
79 
80 void Node::setNamespace(const std::string& ns)
81 {
82  m_namespace = ns;
83 }
84 
85 void Node::setExtraEnvironment(const std::map<std::string, std::string>& env)
86 {
88 }
89 
91 {
93 }
94 
96 {
98 }
99 
101 {
103 }
104 
106 {
108 }
109 
111 {
113 }
114 
115 void Node::setLaunchPrefix(const std::string& launchPrefix)
116 {
117  wordexp_t tokens;
118 
119  // Get rid of newlines since this confuses wordexp
120  std::string clean = launchPrefix;
121  for(auto& c : clean)
122  {
123  if(c == '\n' || c == '\r')
124  c = ' ';
125  }
126 
127  // NOTE: This also does full shell expansion (things like $PATH)
128  // But since we trust the user here (and modifying PATH etc dooms us in
129  // any case), I think we can use wordexp here.
130  int ret = wordexp(clean.c_str(), &tokens, WRDE_NOCMD);
131  if(ret != 0)
132  throw error("You're supplying something strange in 'launch-prefix': '{}' (wordexp ret {})", clean, ret);
133 
134  for(unsigned int i = 0; i < tokens.we_wordc; ++i)
135  m_launchPrefix.emplace_back(tokens.we_wordv[i]);
136 
137  wordfree(&tokens);
138 }
139 
141 {
142  m_coredumpsEnabled = on;
143 }
144 
145 void Node::setWorkingDirectory(const std::string& cwd)
146 {
147  m_workingDirectory = cwd;
148 }
149 
150 void Node::setClearParams(bool on)
151 {
152  m_clearParams = on;
153 }
154 
155 void Node::setStopTimeout(double timeout)
156 {
157  m_stopTimeout = timeout;
158 }
159 
161 {
163 }
164 
166 {
168 }
169 
170 void Node::setMuted(bool muted)
171 {
172  m_muted = muted;
173 }
174 
175 void Node::setStdoutDisplayed(bool displayed)
176 {
177  m_stdoutDisplayed = displayed;
178 }
179 
180 }
181 
182 }
Node(std::string name, std::string package, std::string type)
Definition: node.cpp:28
void setCPULimit(double cpuLimit)
Definition: node.cpp:165
std::string m_type
Definition: node.h:124
void setCoredumpsEnabled(bool on)
Definition: node.cpp:140
int numRespawnsAllowed() const
Definition: node.h:84
std::string m_namespace
Definition: node.h:128
std::map< std::string, std::string > m_remappings
Definition: node.h:130
std::runtime_error error(const char *format, const Args &... args)
Definition: node.cpp:16
void setNumRespawnsAllowed(int numRespawnsAllowed)
Definition: node.cpp:105
std::string m_executable
Definition: node.h:126
void setStopTimeout(double timeout)
Definition: node.cpp:155
ROSCPP_DECL std::string clean(const std::string &name)
std::map< std::string, std::string > m_extraEnvironment
Definition: node.h:133
int m_numRespawnsAllowed
Definition: node.h:137
void setMemoryLimit(uint64_t memoryLimitByte)
Definition: node.cpp:160
std::string m_workingDirectory
Definition: node.h:146
bool respawn() const
Definition: node.h:78
bool required() const
Definition: node.h:92
ros::WallDuration m_respawnDelay
Definition: node.h:136
void setLaunchPrefix(const std::string &launchPrefix)
Definition: node.cpp:115
void setMuted(bool muted)
Definition: node.cpp:170
bool m_clearParams
Definition: node.h:148
void setRemappings(const std::map< std::string, std::string > &remappings)
Definition: node.cpp:50
void setRequired(bool required)
Definition: node.cpp:90
std::map< std::string, std::string > remappings() const
Definition: node.h:69
bool m_stdoutDisplayed
Definition: node.h:156
void setStdoutDisplayed(bool showStdout)
Definition: node.cpp:175
bool m_coredumpsEnabled
Definition: node.h:144
std::string env(const std::string &name)
void setClearParams(bool on)
Definition: node.cpp:150
ros::WallDuration spawnDelay() const
Definition: node.h:87
double cpuLimit() const
Definition: node.h:113
std::vector< std::string > m_extraArgs
Definition: node.h:131
void addExtraArguments(const std::string &argString)
Definition: node.cpp:55
std::string m_package
Definition: node.h:123
ros::WallDuration m_spawnDelay
Definition: node.h:138
double m_cpuLimit
Definition: node.h:153
std::vector< std::string > launchPrefix() const
Definition: node.h:95
ros::WallDuration respawnDelay() const
Definition: node.h:81
uint64_t m_memoryLimitByte
Definition: node.h:152
uint64_t memoryLimitByte() const
Definition: node.h:110
void setExtraEnvironment(const std::map< std::string, std::string > &env)
Definition: node.cpp:85
void setWorkingDirectory(const std::string &workingDirectory)
Definition: node.cpp:145
void setSpawnDelay(const ros::WallDuration &spawnDelay)
Definition: node.cpp:110
void setNamespace(const std::string &ns)
Definition: node.cpp:80
void setRespawn(bool respawn)
Definition: node.cpp:95
std::vector< std::string > m_launchPrefix
Definition: node.h:142
double m_stopTimeout
Definition: node.h:150
static std::string getExecutable(const std::string &package, const std::string &name)
void setRespawnDelay(const ros::WallDuration &respawnDelay)
Definition: node.cpp:100


rosmon_core
Author(s): Max Schwarz
autogenerated on Fri Jun 16 2023 02:15:06