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> 38 virtual const char*
what() const noexcept
39 {
return m_msg.c_str(); }
41 template<
typename... Args>
64 {
return m_filename; }
67 { m_filename = filename; }
75 m_currentLine = e->Row();
84 bool parseBool(
const std::string& value,
int line);
91 inline const std::map<std::string, std::string>&
arguments()
const 94 void setArg(
const std::string& name,
const std::string& value,
bool override);
96 void setEnvironment(
const std::string& name,
const std::string& value);
98 inline const std::map<std::string, std::string>
environment()
const 99 {
return m_environment; }
101 bool shouldSkip(TiXmlElement* e);
106 void setRemap(
const std::string& from,
const std::string& to);
108 {
return m_remappings; }
110 template<
typename... Args>
113 std::string msg = fmt::format(fmt, args...);
115 if(m_currentLine >= 0)
118 m_filename, m_currentLine, msg
127 template<
typename... Args>
128 void warning(
const char* fmt,
const Args& ... args)
const 130 std::string msg = fmt::format(fmt, args...);
132 if(m_currentLine >= 0)
134 fmt::print(stderr,
"{}:{}: Warning: {}\n", m_filename, m_currentLine, msg);
138 fmt::print(stderr,
"{}: Warning: {}\n", m_filename, msg);
146 int m_currentLine = -1;
147 std::map<std::string, std::string>
m_args;
155 typedef std::shared_ptr<LaunchConfig>
Ptr;
156 typedef std::shared_ptr<const LaunchConfig>
ConstPtr;
158 constexpr
static float DEFAULT_CPU_LIMIT = 0.9f;
159 constexpr
static uint64_t DEFAULT_MEMORY_LIMIT = 500*1024*1024;
160 constexpr
static float DEFAULT_STOP_TIMEOUT = 5.0f;
164 void setArgument(
const std::string& name,
const std::string& value);
166 void setDefaultStopTimeout(
double timeout);
167 void setDefaultCPULimit(
double CPULimit);
168 void setDefaultMemoryLimit(uint64_t memoryLimit);
170 void parse(
const std::string& filename,
bool onlyArguments =
false);
171 void parseString(
const std::string& input,
bool onlyArguments =
false);
175 inline const std::map<std::string, XmlRpc::XmlRpcValue>&
parameters()
const 178 inline const std::vector<Node::Ptr>&
nodes()
const 181 inline const std::map<std::string, std::string>&
arguments()
const 182 {
return m_rootContext.arguments(); }
184 std::string anonName(
const std::string& base);
187 {
return m_rosmonNodeName; }
190 {
return m_windowTitle; }
198 void parseTopLevelAttributes(TiXmlElement* element);
200 void parse(TiXmlElement* element,
ParseContext* ctx,
bool onlyArguments =
false);
201 void parseNode(TiXmlElement* element,
ParseContext ctx);
203 void parseROSParam(TiXmlElement* element,
ParseContext ctx);
204 void parseInclude(TiXmlElement* element,
ParseContext ctx);
205 void parseArgument(TiXmlElement* element,
ParseContext& ctx);
206 void parseEnv(TiXmlElement* element,
ParseContext& ctx);
207 void parseRemap(TiXmlElement* element,
ParseContext& ctx);
209 void loadYAMLParams(
const ParseContext& ctx,
const YAML::Node& n,
const std::string& prefix);
237 double m_defaultStopTimeout{DEFAULT_STOP_TIMEOUT};
238 uint64_t m_defaultMemoryLimit{DEFAULT_MEMORY_LIMIT};
239 double m_defaultCPULimit{DEFAULT_CPU_LIMIT};
config evaluateParameters()
virtual const char * what() const noexcept
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
const std::string & prefix() const
ParseException format(const char *format, const Args &...args)
std::vector< std::future< YAMLResult > > m_yamlParamJobs
const char * UNSET_MARKER
std::map< std::string, std::string > m_anonNames
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
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
void warning(const char *fmt, const Args &...args) const
ParseException error(const char *fmt, const Args &...args) const
std::vector< Node::Ptr > m_nodes
std::string windowTitle() const
ParseContext m_rootContext
std::string m_windowTitle
std::string m_rosmonNodeName
const std::map< std::string, std::string > & arguments() const
std::map< std::string, std::string > m_remappings
const std::map< std::string, std::string > & remappings()
std::map< std::string, XmlRpc::XmlRpcValue > ParameterList