diff --git a/src/lib/ebus/message.cpp b/src/lib/ebus/message.cpp index 1ccc07d9..df25d79f 100644 --- a/src/lib/ebus/message.cpp +++ b/src/lib/ebus/message.cpp @@ -1206,7 +1206,7 @@ result_t Condition::create(const string condName, vector::iterator& it, } string valueList = it==end ? "" : *(it++); if (valueList.length()==0) { - returnValue = new SimpleCondition(condName, circuit, name, dstAddress, field); + returnValue = new SimpleCondition(condName, condName, circuit, name, dstAddress, field); return RESULT_OK; } if (valueList[0]=='\'') { @@ -1216,7 +1216,7 @@ result_t Condition::create(const string condName, vector::iterator& it, if (result!=RESULT_OK) { return result; } - returnValue = new SimpleStringCondition(condName, circuit, name, dstAddress, field, values); + returnValue = new SimpleStringCondition(condName, condName, circuit, name, dstAddress, field, values); return RESULT_OK; } // numbers @@ -1225,7 +1225,7 @@ result_t Condition::create(const string condName, vector::iterator& it, if (result!=RESULT_OK) { return result; } - returnValue = new SimpleNumericCondition(condName, circuit, name, dstAddress, field, valueRanges); + returnValue = new SimpleNumericCondition(condName, condName, circuit, name, dstAddress, field, valueRanges); return RESULT_OK; } @@ -1246,7 +1246,7 @@ SimpleCondition* SimpleCondition::derive(string valueList) if (result!=RESULT_OK) { return NULL; } - return new SimpleStringCondition(name, m_circuit, m_name, m_dstAddress, m_field, values); + return new SimpleStringCondition(name, m_refName, m_circuit, m_name, m_dstAddress, m_field, values); } // numbers if (!isNumeric()) { @@ -1257,13 +1257,23 @@ SimpleCondition* SimpleCondition::derive(string valueList) if (result!=RESULT_OK) { return NULL; } - return new SimpleNumericCondition(name, m_circuit, m_name, m_dstAddress, m_field, valueRanges); + return new SimpleNumericCondition(name, m_refName, m_circuit, m_name, m_dstAddress, m_field, valueRanges); } -void SimpleCondition::dump(ostream& output) +void SimpleCondition::dump(ostream& output, bool matched) { - output << "[" << m_condName << "]"; - //output << "{name="<(m_dstAddress)<<",valuessize="<(m_valueRanges.size())<<"}"; + if (matched) { + if (!m_isTrue) { + return; + } + output << "[" << m_refName; + if (m_hasValues) { + output << "=" << m_matchedValue; + } + output << "]"; + } else { + output << "[" << m_condName << "]"; + } } CombinedCondition* SimpleCondition::combineAnd(Condition* other) @@ -1356,6 +1366,7 @@ bool SimpleNumericCondition::checkValue(Message* message, string field) { if (result==RESULT_OK) { for (size_t i=0; i+1(value); return true; } } @@ -1371,6 +1382,7 @@ bool SimpleStringCondition::checkValue(Message* message, string field) { string value = output.str(); for (size_t i=0; i::iterator it = m_conditions.begin(); it!=m_conditions.end(); it++) { Condition* condition = *it; - condition->dump(output); + condition->dump(output, matched); } } @@ -1478,7 +1490,7 @@ result_t LoadInstruction::execute(MessageMap* messages, ostringstream& log, Cond string comment; if (condition) { ostringstream out; - condition->dump(out); + condition->dump(out, true); comment = out.str(); log << " ("+comment+")"; } @@ -1560,6 +1572,10 @@ result_t MessageMap::addDefaultFromFile(vector< vector >& defaults, vect if (type.length()>0 && type[0]=='[' && type[type.length()-1]==']') { // condition type = type.substr(1, type.length()-2); + if (type.find('[')!=string::npos || type.find(']')!=string::npos) { + m_lastError = "invalid condition name "+type; + return RESULT_ERR_INVALID_ARG; + } string key = filename+":"+type; map::iterator it = m_conditions.find(key); if (it != m_conditions.end()) { diff --git a/src/lib/ebus/message.h b/src/lib/ebus/message.h index 90737abd..3f4c26eb 100644 --- a/src/lib/ebus/message.h +++ b/src/lib/ebus/message.h @@ -477,8 +477,6 @@ public: */ void dump(ostream& output, vector* columns=NULL, bool withConditions=false); -protected: - /** * Write the specified column to the @a ostream. * @param output the @a ostream to append the formatted value to. @@ -487,6 +485,8 @@ protected: */ virtual void dumpColumn(ostream& output, size_t column, bool withConditions); +protected: + /** the optional circuit name. */ const string m_circuit; @@ -743,10 +743,11 @@ public: virtual SimpleCondition* derive(string valueList) { return NULL; }; /** - * Write the condition definition to the @a ostream. + * Write the condition definition or resolved expression to the @a ostream. * @param output the @a ostream to append to. + * @param matched true for dumping the matched value if the condition is true, false for dumping the definition. */ - virtual void dump(ostream& output) = 0; + virtual void dump(ostream& output, bool matched=false) = 0; /** * Combine this condition with another instance using a logical and. @@ -791,15 +792,16 @@ public: /** * Construct a new instance. * @param condName the name of the condition. + * @param refName the reference name for dumping. * @param circuit the circuit name. * @param name the message name, or empty for scan message. * @param dstAddress the override destination address, or @a SYN (only for @a Message without specific destination as well as scan message). * @param field the field name. * @param hasValues whether a value has to be checked against. */ - SimpleCondition(const string condName, const string circuit, const string name, const unsigned char dstAddress, const string field, const bool hasValues=false) + SimpleCondition(const string condName, const string refName, const string circuit, const string name, const unsigned char dstAddress, const string field, const bool hasValues=false) : Condition(), - m_condName(condName), m_circuit(circuit), m_name(name), m_dstAddress(dstAddress), m_field(field), m_hasValues(hasValues), m_message(NULL) { } + m_condName(condName), m_refName(refName), m_circuit(circuit), m_name(name), m_dstAddress(dstAddress), m_field(field), m_hasValues(hasValues), m_message(NULL) { } /** * Destructor. @@ -810,7 +812,7 @@ public: virtual SimpleCondition* derive(string valueList); // @copydoc - virtual void dump(ostream& output); + virtual void dump(ostream& output, bool matched=false); // @copydoc virtual CombinedCondition* combineAnd(Condition* other); @@ -837,11 +839,17 @@ protected: */ virtual bool checkValue(Message* message, const string field) { return true; } + /** the value that matched in @a checkValue. */ + string m_matchedValue; + private: /** the condition name. */ const string m_condName; + /** the reference name for dumping. */ + const string m_refName; + /** the circuit name. */ const string m_circuit; @@ -873,14 +881,15 @@ public: /** * Construct a new instance. * @param condName the name of the condition. + * @param refName the reference name for dumping. * @param circuit the circuit name. * @param name the message name, or empty for scan message. * @param dstAddress the override destination address, or @a SYN (only for @a Message without specific destination as well as scan message). * @param field the field name. * @param valueRanges the valid value ranges (pairs of from/to inclusive), empty for @a m_message seen check. */ - SimpleNumericCondition(const string condName, const string circuit, const string name, const unsigned char dstAddress, const string field, const vector valueRanges) - : SimpleCondition(condName, circuit, name, dstAddress, field, true), + SimpleNumericCondition(const string condName, const string refName, const string circuit, const string name, const unsigned char dstAddress, const string field, const vector valueRanges) + : SimpleCondition(condName, refName, circuit, name, dstAddress, field, true), m_valueRanges(valueRanges) { } /** @@ -911,14 +920,15 @@ public: /** * Construct a new instance. * @param condName the name of the condition. + * @param refName the reference name for dumping. * @param circuit the circuit name. * @param name the message name, or empty for scan message. * @param dstAddress the override destination address, or @a SYN (only for @a Message without specific destination as well as scan message). * @param field the field name. * @param values the valid values. */ - SimpleStringCondition(const string condName, const string circuit, const string name, const unsigned char dstAddress, const string field, const vector values) - : SimpleCondition(condName, circuit, name, dstAddress, field, true), + SimpleStringCondition(const string condName, const string refName, const string circuit, const string name, const unsigned char dstAddress, const string field, const vector values) + : SimpleCondition(condName, refName, circuit, name, dstAddress, field, true), m_values(values) { } /** @@ -961,7 +971,7 @@ public: virtual ~CombinedCondition() {} // @copydoc - virtual void dump(ostream& output); + virtual void dump(ostream& output, bool matched=false); // @copydoc virtual CombinedCondition* combineAnd(Condition* other) { m_conditions.push_back(other); return this; }