1 #include "ErrorHandler/MessageAnalyzer/ma_richmsg.h"
2 #include "ErrorHandler/MessageAnalyzer/ma_rule.h"
4 using namespace novadaq::errorhandler;
8 bool parse_msg_ref(std::string
const& s,
ma_rule const* rule, std::vector<cond_arg_t>& symbols)
10 size_t pos = s.find(
'.');
12 if (pos == std::string::npos)
return false;
14 cond_idx_t cond_idx = rule->get_cond_idx(s.substr(0, pos));
18 if (pos == s.size() || s[pos] !=
'$')
return false;
22 if (pos == s.size() || std::string(
"stmg").find(s[pos]) == std::string::npos)
return false;
27 if (pos == s.size() - 1)
29 symbols.push_back(cond_arg_t(cond_idx, SOURCE));
35 if (pos == s.size() - 1)
37 symbols.push_back(cond_arg_t(cond_idx, TARGET));
43 if (pos == s.size() - 1)
45 symbols.push_back(cond_arg_t(cond_idx, MESSAGE));
51 if (pos == s.size() - 2 && s[pos + 1] >=
'1' && s[pos + 1] <=
'9')
53 symbols.push_back(cond_arg_t(cond_idx, (arg_t)(GROUP1 + s[pos + 1] -
'1')));
63 bool parse_msg(std::string
const& s,
ma_rule const* rule, std::string& stripped_msg, std::vector<size_t>& insert_pos, std::vector<cond_arg_t>& symbols)
66 size_t pos = s.find(
"${");
69 while (pos != std::string::npos)
72 insert_pos.push_back(ins);
73 stripped_msg.append(s, old, pos - old);
75 size_t close = s.find(
'}', pos);
77 if (close == std::string::npos)
80 if (!parse_msg_ref(s.substr(pos + 2, close - pos - 2), rule, symbols))
84 pos = s.find(
"${", old);
88 stripped_msg.append(s.substr(old));
95 ma_richmsg::ma_richmsg()
104 ma_richmsg::ma_richmsg(std::string
const& s,
ma_rule const* parent)
114 void ma_richmsg::init(
ma_rule const* parent, std::string
const& s)
119 if (!parse_msg(plain_msg, rule, stripped_msg, insert_pos, symbols))
120 throw std::runtime_error(
"Error parsing rule messages!");
123 const std::string& ma_richmsg::plain_message()
const
128 std::string ma_richmsg::message()
const
130 std::string result = stripped_msg;
131 ma_domain
const& alarm = rule->get_alarm();
133 for (
int i = symbols.size() - 1; i >= 0; --i)
136 size_t cond_idx = symbols[i].first.second;
137 arg_t cond_arg = symbols[i].second;
139 result.insert(insert_pos[i], cond_ptr->get_arg(alarm[cond_idx], cond_arg));