4 #ifndef ROSMON_LAUNCH_LAUNCH_CONFIG_H 5 #define ROSMON_LAUNCH_LAUNCH_CONFIG_H 17 #include <yaml-cpp/yaml.h> 19 #include <fmt/format.h> 42 virtual const char*
what() const noexcept
43 {
return m_msg.c_str(); }
45 template<
typename... Args>
68 {
return m_filename; }
71 { m_filename = filename; }
79 m_currentLine = e->Row();
85 void parseScopeAttributes(TiXmlElement* e,
ParseContext& attr_ctx);
89 bool parseBool(
const std::string& value,
int line);
96 inline const std::map<std::string, std::string>&
arguments()
const 99 void setArg(
const std::string& name,
const std::string& value,
bool override);
101 void setEnvironment(
const std::string& name,
const std::string& value);
103 inline const std::map<std::string, std::string>
environment()
const 104 {
return m_environment; }
106 bool shouldSkip(TiXmlElement* e);
111 void setRemap(
const std::string& from,
const std::string& to);
113 {
return m_remappings; }
115 std::string anonName(
const std::string& base);
117 template<
typename... Args>
120 std::string msg = fmt::format(fmt, args...);
122 if(m_currentLine >= 0)
125 m_filename, m_currentLine, msg
134 template<
typename... Args>
135 void warning(
const char* fmt,
const Args& ... args)
const;
139 {
return m_cpuLimit; }
141 { m_cpuLimit = limit; }
144 {
return m_memoryLimit; }
146 { m_memoryLimit = limit; }
149 {
return m_stopTimeout; }
151 { m_stopTimeout = timeout; }
154 {
return m_coredumpsEnabled; }
156 { m_coredumpsEnabled = enabled; }
163 int m_currentLine = -1;
164 std::map<std::string, std::string>
m_args;
172 bool m_coredumpsEnabled =
true;
178 typedef std::shared_ptr<LaunchConfig>
Ptr;
179 typedef std::shared_ptr<const LaunchConfig>
ConstPtr;
189 void setWarningOutput(std::ostream* warningStream);
191 {
return *m_warningOutput; }
193 void setArgument(
const std::string& name,
const std::string& value);
195 void setDefaultStopTimeout(
double timeout);
196 void setDefaultCPULimit(
double CPULimit);
197 void setDefaultMemoryLimit(uint64_t memoryLimit);
201 void parse(
const std::string& filename,
bool onlyArguments =
false);
202 void parseString(
const std::string& input,
bool onlyArguments =
false);
206 inline const std::map<std::string, XmlRpc::XmlRpcValue>&
parameters()
const 209 inline const std::vector<Node::Ptr>&
nodes()
const 212 inline const std::map<std::string, std::string>&
arguments()
const 213 {
return m_rootContext.arguments(); }
215 std::string anonName(
const std::string& base);
218 {
return m_rosmonNodeName; }
221 {
return m_windowTitle; }
223 std::string generateAnonHash();
226 {
return m_disableUI; }
234 void parseTopLevelAttributes(TiXmlElement* element);
236 void parse(TiXmlElement* element,
ParseContext* ctx,
bool onlyArguments =
false);
237 void parseNode(TiXmlElement* element,
ParseContext& ctx);
239 void parseROSParam(TiXmlElement* element,
ParseContext& ctx);
240 void parseInclude(TiXmlElement* element,
ParseContext ctx);
241 void parseArgument(TiXmlElement* element,
ParseContext& ctx);
242 void parseEnv(TiXmlElement* element,
ParseContext& ctx);
243 void parseRemap(TiXmlElement* element,
ParseContext& ctx);
245 void loadYAMLParams(
const ParseContext& ctx,
const YAML::Node& n,
const std::string& prefix);
274 bool m_disableUI =
false;
276 std::ostream* m_warningOutput = &std::cerr;
279 template<
typename... Args>
282 std::string msg = fmt::format(fmt, args...);
284 if(m_currentLine >= 0)
286 m_config->warningOutput() << fmt::format(
287 "{}:{}: Warning: {}\n", m_filename, m_currentLine, msg
292 m_config->warningOutput() << fmt::format(
293 "{}: Warning: {}\n", m_filename, msg
config evaluateParameters()
virtual const char * what() const noexcept
std::map< std::string, std::string > m_anonNames
void setCoredumpsEnabled(bool enabled)
const std::vector< Node::Ptr > & nodes() const
std::mt19937_64 m_anonGen
std::string simplifyWhitespace(const std::string &input)
Compress any sequence of whitespace to single spaces.
std::future< XmlRpc::XmlRpcValue > ParameterFuture
void setFilename(const std::string &filename)
ParseException(const std::string &msg)
const std::map< std::string, std::string > environment() const
ParseContext(LaunchConfig *config)
const std::map< std::string, XmlRpc::XmlRpcValue > & parameters() const
std::map< std::string, ParameterFuture > m_paramJobs
virtual ~ParseException()
std::shared_ptr< LaunchConfig > Ptr
std::string rosmonNodeName() const
bool coredumpsEnabled() const
const std::string & prefix() const
ParseException format(const char *format, const Args &...args)
std::vector< std::future< YAMLResult > > m_yamlParamJobs
std::ostream & warningOutput()
const char * UNSET_MARKER
constexpr double DEFAULT_STOP_TIMEOUT
std::map< std::string, std::string > m_args
const std::map< std::string, std::string > & arguments() const
std::map< std::string, std::string > m_environment
const std::string & filename() const
void setCPULimit(double limit)
constexpr uint64_t DEFAULT_MEMORY_LIMIT
config parseString(R"EOF(
<launch>
<group ns="/">
<param name="param1" value="hello" />
</group>
<node name="test_node" pkg="rosmon_core" type="abort" ns="/racecar">
<param name="private_param" value="hello again" />
</node>
</launch>
)EOF")
void setCurrentElement(TiXmlElement *e)
std::shared_ptr< const LaunchConfig > ConstPtr
uint64_t memoryLimit() const
void warning(const char *fmt, const Args &...args) const
ParseException error(const char *fmt, const Args &...args) const
std::vector< Node::Ptr > m_nodes
constexpr double DEFAULT_CPU_LIMIT
std::string windowTitle() const
ParseContext m_rootContext
std::string m_windowTitle
void setMemoryLimit(uint64_t limit)
std::string m_rosmonNodeName
void setStopTimeout(double timeout)
const std::map< std::string, std::string > & arguments() const
double stopTimeout() const
std::map< std::string, std::string > m_remappings
const std::map< std::string, std::string > & remappings()
std::map< std::string, XmlRpc::XmlRpcValue > ParameterList