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
10 , std::vector<cond_arg_t> & symbols )
12 size_t pos = s.find(
'.');
14 if( pos==std::string::npos )
return false;
16 cond_idx_t cond_idx = rule->get_cond_idx( s.substr(0, pos) );
20 if( pos==s.size() || s[pos]!=
'$')
return false;
24 if( pos==s.size() || std::string(
"stmg").find(s[pos])==std::string::npos)
return false;
31 symbols.push_back( cond_arg_t(cond_idx, SOURCE) );
39 symbols.push_back( cond_arg_t(cond_idx, TARGET) );
47 symbols.push_back( cond_arg_t(cond_idx, MESSAGE) );
53 if( pos==s.size()-2 && s[pos+1]>=
'1' && s[pos+1]<=
'9' )
55 symbols.push_back( cond_arg_t( cond_idx, (arg_t)(GROUP1+s[pos+1]-
'1') ) );
66 bool parse_msg( std::string
const & s
68 , std::string & stripped_msg
69 , std::vector<size_t> & insert_pos
70 , std::vector<cond_arg_t> & symbols )
73 size_t pos = s.find(
"${");
76 while( pos!=std::string::npos )
79 insert_pos.push_back(ins);
80 stripped_msg.append(s, old, pos-old);
82 size_t close = s.find(
'}', pos);
84 if( close == std::string::npos )
87 if ( !parse_msg_ref( s.substr(pos+2, close-pos-2), rule, symbols ) )
91 pos = s.find(
"${", old);
95 stripped_msg.append(s.substr(old));
102 ma_richmsg::ma_richmsg( )
112 ma_richmsg::ma_richmsg( std::string
const & s,
ma_rule const * parent )
122 void ma_richmsg::init(
ma_rule const * parent, std::string
const & s )
127 if( !parse_msg(plain_msg, rule, stripped_msg, insert_pos, symbols) )
128 throw std::runtime_error(
"Error parsing rule messages!");
131 const std::string & ma_richmsg::plain_message()
const
136 std::string ma_richmsg::message()
const
138 std::string result = stripped_msg;
139 ma_domain
const & alarm = rule->get_alarm();
141 for(
int i=symbols.size()-1; i>=0; --i)
144 size_t cond_idx = symbols[i].first.second;
145 arg_t cond_arg = symbols[i].second;
147 result.insert( insert_pos[i]
148 , cond_ptr->get_arg(alarm[cond_idx], cond_arg));