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 
90 void Node::setRequired(bool required)
91 {
93 }
94 
95 void Node::setRespawn(bool respawn)
96 {
98 }
99 
100 void Node::setRespawnDelay(const ros::WallDuration& respawnDelay)
101 {
103 }
104 
105 void Node::setNumRespawnsAllowed(int numRespawnsAllowed)
106 {
108 }
109 
110 void Node::setSpawnDelay(const ros::WallDuration& spawnDelay)
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 
160 void Node::setMemoryLimit(uint64_t memoryLimitByte)
161 {
163 }
164 
165 void Node::setCPULimit(double cpuLimit)
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 }
rosmon::launch::Node::setRemappings
void setRemappings(const std::map< std::string, std::string > &remappings)
Definition: node.cpp:50
rosmon::launch::Node::m_remappings
std::map< std::string, std::string > m_remappings
Definition: node.h:130
rosmon::launch::Node::setNumRespawnsAllowed
void setNumRespawnsAllowed(int numRespawnsAllowed)
Definition: node.cpp:105
rosmon
Definition: diagnostics_publisher.cpp:34
rosmon::launch::Node::setSpawnDelay
void setSpawnDelay(const ros::WallDuration &spawnDelay)
Definition: node.cpp:110
rosmon::launch::Node::setStopTimeout
void setStopTimeout(double timeout)
Definition: node.cpp:155
rosmon::launch::Node::respawnDelay
ros::WallDuration respawnDelay() const
Definition: node.h:81
rosmon::launch::Node::setMuted
void setMuted(bool muted)
Definition: node.cpp:170
rosmon::launch::Node::setNamespace
void setNamespace(const std::string &ns)
Definition: node.cpp:80
clean
ROSCPP_DECL std::string clean(const std::string &name)
rosmon::launch::Node::setClearParams
void setClearParams(bool on)
Definition: node.cpp:150
rosmon::launch::Node::m_coredumpsEnabled
bool m_coredumpsEnabled
Definition: node.h:144
rosmon::launch::Node::m_extraEnvironment
std::map< std::string, std::string > m_extraEnvironment
Definition: node.h:133
rosmon::launch::Node::m_stopTimeout
double m_stopTimeout
Definition: node.h:150
rosmon::launch::Node::m_respawnDelay
ros::WallDuration m_respawnDelay
Definition: node.h:136
rosmon::launch::Node::respawn
bool respawn() const
Definition: node.h:78
rosmon::launch::Node::setRespawnDelay
void setRespawnDelay(const ros::WallDuration &respawnDelay)
Definition: node.cpp:100
rosmon::launch::Node::setExtraEnvironment
void setExtraEnvironment(const std::map< std::string, std::string > &env)
Definition: node.cpp:85
rosmon::launch::Node::m_numRespawnsAllowed
int m_numRespawnsAllowed
Definition: node.h:137
rosmon::launch::Node::spawnDelay
ros::WallDuration spawnDelay() const
Definition: node.h:87
package
string package
error
std::runtime_error error(const char *format, const Args &... args)
Definition: node.cpp:16
rosmon::launch::Node::m_type
std::string m_type
Definition: node.h:124
rosmon::launch::Node::m_memoryLimitByte
uint64_t m_memoryLimitByte
Definition: node.h:152
rosmon::launch::Node::cpuLimit
double cpuLimit() const
Definition: node.h:113
rosmon::launch::Node::memoryLimitByte
uint64_t memoryLimitByte() const
Definition: node.h:110
node.h
rosmon::launch::Node::setCPULimit
void setCPULimit(double cpuLimit)
Definition: node.cpp:165
rosmon::launch::Node::m_launchPrefix
std::vector< std::string > m_launchPrefix
Definition: node.h:142
rosmon::launch::Node::addExtraArguments
void addExtraArguments(const std::string &argString)
Definition: node.cpp:55
rosmon::launch::Node::setRespawn
void setRespawn(bool respawn)
Definition: node.cpp:95
rosmon::launch::Node::m_workingDirectory
std::string m_workingDirectory
Definition: node.h:146
rosmon::launch::Node::m_executable
std::string m_executable
Definition: node.h:126
rosmon::launch::Node::m_spawnDelay
ros::WallDuration m_spawnDelay
Definition: node.h:138
rosmon::launch::Node::setLaunchPrefix
void setLaunchPrefix(const std::string &launchPrefix)
Definition: node.cpp:115
rosmon::launch::Node::launchPrefix
std::vector< std::string > launchPrefix() const
Definition: node.h:95
rosmon::launch::Node::m_clearParams
bool m_clearParams
Definition: node.h:148
rosmon::launch::substitutions::env
std::string env(const std::string &name)
Definition: substitution.cpp:67
rosmon::launch::Node::numRespawnsAllowed
int numRespawnsAllowed() const
Definition: node.h:84
rosmon::launch::Node::m_stdoutDisplayed
bool m_stdoutDisplayed
Definition: node.h:156
rosmon::launch::Node::m_muted
bool m_muted
Definition: node.h:155
std
rosmon::launch::Node::setWorkingDirectory
void setWorkingDirectory(const std::string &workingDirectory)
Definition: node.cpp:145
rosmon::launch::Node::m_namespace
std::string m_namespace
Definition: node.h:128
rosmon::launch::Node::m_required
bool m_required
Definition: node.h:140
rosmon::launch::Node::m_extraArgs
std::vector< std::string > m_extraArgs
Definition: node.h:131
rosmon::PackageRegistry::getExecutable
static std::string getExecutable(const std::string &package, const std::string &name)
Definition: package_registry.cpp:122
ros::WallDuration
rosmon::launch::Node::m_cpuLimit
double m_cpuLimit
Definition: node.h:153
rosmon::launch::Node::m_package
std::string m_package
Definition: node.h:123
rosmon::launch::Node::Node
Node(std::string name, std::string package, std::string type)
Definition: node.cpp:28
rosmon::launch::Node::required
bool required() const
Definition: node.h:92
rosmon::launch::Node::m_respawn
bool m_respawn
Definition: node.h:135
rosmon::launch::Node::setRequired
void setRequired(bool required)
Definition: node.cpp:90
rosmon::launch::Node::setStdoutDisplayed
void setStdoutDisplayed(bool showStdout)
Definition: node.cpp:175
rosmon::launch::Node::remappings
std::map< std::string, std::string > remappings() const
Definition: node.h:69
rosmon::launch::Node::setCoredumpsEnabled
void setCoredumpsEnabled(bool on)
Definition: node.cpp:140
rosmon::launch::Node::setMemoryLimit
void setMemoryLimit(uint64_t memoryLimitByte)
Definition: node.cpp:160


rosmon_core
Author(s): Max Schwarz
autogenerated on Wed Feb 21 2024 04:01:14