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 
105 void Node::setLaunchPrefix(const std::string& launchPrefix)
106 {
107  wordexp_t tokens;
108 
109  // Get rid of newlines since this confuses wordexp
110  std::string clean = launchPrefix;
111  for(auto& c : clean)
112  {
113  if(c == '\n' || c == '\r')
114  c = ' ';
115  }
116 
117  // NOTE: This also does full shell expansion (things like $PATH)
118  // But since we trust the user here (and modifying PATH etc dooms us in
119  // any case), I think we can use wordexp here.
120  int ret = wordexp(clean.c_str(), &tokens, WRDE_NOCMD);
121  if(ret != 0)
122  throw error("You're supplying something strange in 'launch-prefix': '{}' (wordexp ret {})", clean, ret);
123 
124  for(unsigned int i = 0; i < tokens.we_wordc; ++i)
125  m_launchPrefix.emplace_back(tokens.we_wordv[i]);
126 
127  wordfree(&tokens);
128 }
129 
131 {
132  m_coredumpsEnabled = on;
133 }
134 
135 void Node::setWorkingDirectory(const std::string& cwd)
136 {
137  m_workingDirectory = cwd;
138 }
139 
140 void Node::setClearParams(bool on)
141 {
142  m_clearParams = on;
143 }
144 
145 void Node::setStopTimeout(double timeout)
146 {
147  m_stopTimeout = timeout;
148 }
149 
151 {
153 }
154 
156 {
158 }
159 
160 void Node::setMuted(bool muted)
161 {
162  m_muted = muted;
163 }
164 
165 void Node::setStdoutDisplayed(bool displayed)
166 {
167  m_stdoutDisplayed = displayed;
168 }
169 
170 }
171 
172 }
Node(std::string name, std::string package, std::string type)
Definition: node.cpp:28
void setCPULimit(double cpuLimit)
Definition: node.cpp:155
bool respawn() const
Definition: node.h:76
std::string m_type
Definition: node.h:116
void setCoredumpsEnabled(bool on)
Definition: node.cpp:130
std::string m_namespace
Definition: node.h:120
std::map< std::string, std::string > m_remappings
Definition: node.h:122
ros::WallDuration respawnDelay() const
Definition: node.h:79
uint64_t memoryLimitByte() const
Definition: node.h:102
std::string m_executable
Definition: node.h:118
void setStopTimeout(double timeout)
Definition: node.cpp:145
ROSCPP_DECL std::string clean(const std::string &name)
std::map< std::string, std::string > m_extraEnvironment
Definition: node.h:125
void setMemoryLimit(uint64_t memoryLimitByte)
Definition: node.cpp:150
std::string m_workingDirectory
Definition: node.h:136
ros::WallDuration m_respawnDelay
Definition: node.h:128
void setLaunchPrefix(const std::string &launchPrefix)
Definition: node.cpp:105
void setMuted(bool muted)
Definition: node.cpp:160
bool m_clearParams
Definition: node.h:138
void setRemappings(const std::map< std::string, std::string > &remappings)
Definition: node.cpp:50
void setRequired(bool required)
Definition: node.cpp:90
bool m_stdoutDisplayed
Definition: node.h:146
void setStdoutDisplayed(bool showStdout)
Definition: node.cpp:165
std::runtime_error error(const char *format, const Args &...args)
Definition: node.cpp:16
bool m_coredumpsEnabled
Definition: node.h:134
double cpuLimit() const
Definition: node.h:105
std::string env(const std::string &name)
void setClearParams(bool on)
Definition: node.cpp:140
bool required() const
Definition: node.h:84
std::vector< std::string > m_extraArgs
Definition: node.h:123
void addExtraArguments(const std::string &argString)
Definition: node.cpp:55
std::string m_package
Definition: node.h:115
double m_cpuLimit
Definition: node.h:143
std::map< std::string, std::string > remappings() const
Definition: node.h:67
uint64_t m_memoryLimitByte
Definition: node.h:142
void setExtraEnvironment(const std::map< std::string, std::string > &env)
Definition: node.cpp:85
void setWorkingDirectory(const std::string &workingDirectory)
Definition: node.cpp:135
void setNamespace(const std::string &ns)
Definition: node.cpp:80
void setRespawn(bool respawn)
Definition: node.cpp:95
std::vector< std::string > launchPrefix() const
Definition: node.h:87
std::vector< std::string > m_launchPrefix
Definition: node.h:132
double m_stopTimeout
Definition: node.h:140
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 Sat Jan 9 2021 03:35:43