From cdc9ab4241c6c2dd402d3e9adfa7f9ae0c7e1f79 Mon Sep 17 00:00:00 2001 From: gscalamera <graziano.scalamera@elettra.eu> Date: Fri, 7 Apr 2017 17:19:36 +0200 Subject: [PATCH] Fixed key=value;.. syntax for formula parsing and configuration --- src/Alarm.cpp | 10 +++++----- src/alarm_grammar.h | 40 ++++++++++++++++++++++++---------------- src/alarm_table.cpp | 40 ++++++++++++++++++++-------------------- 3 files changed, 49 insertions(+), 41 deletions(-) diff --git a/src/Alarm.cpp b/src/Alarm.cpp index 6a8294f..8df09c1 100644 --- a/src/Alarm.cpp +++ b/src/Alarm.cpp @@ -1910,9 +1910,9 @@ Tango::DevVarStringArray *Alarm::search_alarm(Tango::DevString argin) { ostringstream os; os.clear(); - os << ai->second.ts.tv_sec << "\t" << ai->second.name << "\t" /*TODO<< KEY(FORMULA_KEY)*/ << ai->second.formula << "\t" << KEY(ONDELAY_KEY) << ai->second.on_delay << "\t" << KEY(OFFDELAY_KEY) << ai->second.off_delay << - "\t" << KEY(LEVEL_KEY) << ai->second.lev << "\t" << KEY(SILENT_TIME_KEY) << ai->second.silent_time << "\t" << KEY(GROUP_KEY) << ai->second.grp2str() << "\t" << KEY(MESSAGE_KEY) << ai->second.msg << "\t" << - KEY(ON_COMMAND_KEY) << ai->second.cmd_name_a << "\t" << KEY(OFF_COMMAND_KEY) << ai->second.cmd_name_n << "\t" << KEY(ENABLED_KEY) << (ai->second.enabled ? "1" : "0") << ends; + os << ai->second.ts.tv_sec << SEP << KEY(NAME_KEY) << ai->second.name << SEP << KEY(FORMULA_KEY) << ai->second.formula << SEP << KEY(ONDELAY_KEY) << ai->second.on_delay << SEP << KEY(OFFDELAY_KEY) << ai->second.off_delay << + SEP << KEY(LEVEL_KEY) << ai->second.lev << SEP << KEY(SILENT_TIME_KEY) << ai->second.silent_time << SEP << KEY(GROUP_KEY) << ai->second.grp2str() << SEP << KEY(MESSAGE_KEY) << ai->second.msg << + SEP << KEY(ON_COMMAND_KEY) << ai->second.cmd_name_a << SEP << KEY(OFF_COMMAND_KEY) << ai->second.cmd_name_n << SEP << KEY(ENABLED_KEY) << (ai->second.enabled ? "1" : "0") << ends; alarm_filtered.push_back(os.str()); } } /* for */ @@ -4506,9 +4506,9 @@ void Alarm::find_event_formula(tree_parse_info_t tree, vector<string> & ev) void Alarm::eval_node_event(iter_t const& i, vector<string> & ev) { - DEBUG_STREAM << "In eval_node_event. i->value = " << + DEBUG_STREAM << "In eval_node_event. i->value = '" << string(i->value.begin(), i->value.end()) << - " i->children.size() = " << i->children.size() << " NODE=" << rule_names[i->value.id()] << endl; + "' i->children.size() = " << i->children.size() << " NODE=" << rule_names[i->value.id()] << endl; ostringstream err; err << "Looking for event in formula tree: "; /*if (i->value.id() == formula_grammar::event_ID) diff --git a/src/alarm_grammar.h b/src/alarm_grammar.h index 220888a..fb2f743 100644 --- a/src/alarm_grammar.h +++ b/src/alarm_grammar.h @@ -80,6 +80,8 @@ #define ENABLED_KEY "enabled" #define KEY(S_VAL) S_VAL "=" +#define SEP ";" + //////////////////////////////////////////////////////////////////////////// using namespace std; #if BOOST_VERSION < 103600 @@ -177,7 +179,8 @@ struct alarm_parse : public grammar<alarm_parse> //std::pair<string, vector<string> > temp; expression - = discard_node_d + = no_node_d[str_p(KEY(NAME_KEY))] >> + no_node_d [ name_alm [ @@ -185,6 +188,9 @@ struct alarm_parse : public grammar<alarm_parse> ] ] //discard_node_d >> + no_node_d[separator] + >> + no_node_d[str_p(KEY(FORMULA_KEY))] >> root_node_d [ formula @@ -192,19 +198,19 @@ struct alarm_parse : public grammar<alarm_parse> assign_a(self.m_alarm.formula) //save formula in alarm_t ] ] //root_node_d - >> *(discard_node_d[option]) + >> *(no_node_d[option]) ; option - = discard_node_d[on_delay] | - discard_node_d[off_delay] | - discard_node_d[level] | - discard_node_d[silent_time] | - discard_node_d[group] | - discard_node_d[msg] | - discard_node_d[on_command] | - discard_node_d[off_command] | - discard_node_d[enabled] + = no_node_d[separator] >> no_node_d[on_delay] | + no_node_d[separator] >> no_node_d[off_delay] | + no_node_d[separator] >> no_node_d[level] | + no_node_d[separator] >> no_node_d[silent_time] | + no_node_d[separator] >> no_node_d[group] | + no_node_d[separator] >> no_node_d[msg] | + no_node_d[separator] >> no_node_d[on_command] | + no_node_d[separator] >> no_node_d[off_command] | + no_node_d[separator] >> no_node_d[enabled] ; //------------------------------ALARM NAME-------------------------------------- @@ -248,13 +254,13 @@ struct alarm_parse : public grammar<alarm_parse> ; //------------------------------MESSAGE-------------------------------------- msg - = discard_node_d[str_p(KEY(MESSAGE_KEY))] >> - ch_p('"') - >> (+(anychar_p - '\"')) //one ore more char except '"' + = discard_node_d[str_p(KEY(MESSAGE_KEY))] + //>> ch_p('"') + >> (+(anychar_p - ';')) //one ore more char except ';' [ assign_a(self.m_alarm.msg) ] - >> '"' + //>> '"' ; //---------------------------ON DELAY---------------------------------------- on_delay @@ -318,13 +324,15 @@ struct alarm_parse : public grammar<alarm_parse> assign_a(self.m_alarm.enabled) //save enabled in alarm_t ] ; + //------------------------------SEPARATOR-------------------------------------- + separator = ch_p(SEP); } typedef rule<ScannerT> rule_t; rule_t expression, event, option; rule<typename lexeme_scanner<ScannerT>::type> symbol; //needed to use lexeme_d in rule name rule<typename lexeme_scanner<ScannerT>::type> symbol_attr_name; //needed to use lexeme_d in rule name - rule_t name, name_alm, val, token, oper, msg, group, level, on_delay, off_delay, silent_time, on_command, off_command, enabled; + rule_t name, name_alm, val, token, oper, msg, group, level, on_delay, off_delay, silent_time, on_command, off_command, enabled, separator; formula_grammar formula; rule_t const& diff --git a/src/alarm_table.cpp b/src/alarm_table.cpp index 0f2aad1..ad3ddc6 100644 --- a/src/alarm_table.cpp +++ b/src/alarm_table.cpp @@ -180,16 +180,16 @@ void alarm_t::confstr(string &s) { ostringstream conf; conf << - name << "\t" << - /*TODO: KEY(FORMULA_KEY)<<*/formula << "\t" << - KEY(ONDELAY_KEY)<<on_delay << "\t" << - KEY(OFFDELAY_KEY)<<off_delay << "\t" << - KEY(LEVEL_KEY)<< lev << "\t" << - KEY(SILENT_TIME_KEY)<<silent_time << "\t" << - KEY(GROUP_KEY)<< grp2str() << "\t" << - KEY(MESSAGE_KEY)<< "\"" << msg << "\"\t" << - KEY(ON_COMMAND_KEY)<< cmd_name_a << "\t" << - KEY(OFF_COMMAND_KEY)<< cmd_name_n << "\t" << + KEY(NAME_KEY)<<name << SEP << + KEY(FORMULA_KEY)<<formula << SEP << + KEY(ONDELAY_KEY)<<on_delay << SEP << + KEY(OFFDELAY_KEY)<<off_delay << SEP << + KEY(LEVEL_KEY)<< lev << SEP << + KEY(SILENT_TIME_KEY)<<silent_time << SEP << + KEY(GROUP_KEY)<< grp2str() << SEP << + KEY(MESSAGE_KEY)<< msg << SEP << + KEY(ON_COMMAND_KEY)<< cmd_name_a << SEP << + KEY(OFF_COMMAND_KEY)<< cmd_name_n << SEP << KEY(ENABLED_KEY)<< (enabled ? "1" : "0"); s = conf.str(); } @@ -963,16 +963,16 @@ void alarm_table::get_alarm_list_db(vector<string> &al_list, map<string, string> i++; } stringstream alm; - alm << alm_name << "\t" << - /*TODO: KEY(FORMULA_KEY)<<*/alm_formula << "\t" << - KEY(ONDELAY_KEY)<<alm_on_delay << "\t" << - KEY(OFFDELAY_KEY)<<alm_off_delay << "\t" << - KEY(LEVEL_KEY)<< alm_level << "\t" << - KEY(SILENT_TIME_KEY)<<alm_silence_time << "\t" << - KEY(GROUP_KEY)<< alm_group << "\t" << - KEY(MESSAGE_KEY)<< "\"" << alm_message << "\"\t" << - KEY(ON_COMMAND_KEY)<< alm_on_command << "\t" << - KEY(OFF_COMMAND_KEY)<< alm_off_command << "\t" << + alm << KEY(NAME_KEY)<<alm_name << SEP << + KEY(FORMULA_KEY)<<alm_formula << SEP << + KEY(ONDELAY_KEY)<<alm_on_delay << SEP << + KEY(OFFDELAY_KEY)<<alm_off_delay << SEP << + KEY(LEVEL_KEY)<< alm_level << SEP << + KEY(SILENT_TIME_KEY)<<alm_silence_time << SEP << + KEY(GROUP_KEY)<< alm_group << SEP << + KEY(MESSAGE_KEY)<< alm_message << SEP << + KEY(ON_COMMAND_KEY)<< alm_on_command << SEP << + KEY(OFF_COMMAND_KEY)<< alm_off_command << SEP << KEY(ENABLED_KEY)<< alm_enabled; if(alm_name.empty() || alm_formula.empty() || alm_level.empty() || alm_group.empty() || alm_message.empty()) //TODO: decide if all mandatory { -- GitLab