added Condition::dump(), simplified Message::dump() and added prefixed condition dump, report invalid condition if field was defined but no values
This commit is contained in:
+28
-43
@@ -539,54 +539,23 @@ bool Message::isLessPollWeight(const Message* other)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Message::dump(ostream& output)
|
void Message::dump(ostream& output, vector<size_t>* columns)
|
||||||
{
|
{
|
||||||
if (m_isPassive) {
|
bool first = true, all = columns==NULL;
|
||||||
output << "u";
|
size_t end = all ? 9 : columns->size();
|
||||||
if (m_isWrite)
|
|
||||||
output << "w";
|
|
||||||
} else if (m_isWrite)
|
|
||||||
output << "w";
|
|
||||||
else {
|
|
||||||
output << "r";
|
|
||||||
if (m_pollPriority>0)
|
|
||||||
output << static_cast<unsigned>(m_pollPriority);
|
|
||||||
}
|
|
||||||
DataField::dumpString(output, m_circuit);
|
|
||||||
DataField::dumpString(output, m_name);
|
|
||||||
DataField::dumpString(output, m_comment);
|
|
||||||
output << FIELD_SEPARATOR;
|
|
||||||
if (m_srcAddress != SYN)
|
|
||||||
output << hex << setw(2) << setfill('0') << static_cast<unsigned>(m_srcAddress);
|
|
||||||
output << FIELD_SEPARATOR;
|
|
||||||
if (m_dstAddress != SYN)
|
|
||||||
output << hex << setw(2) << setfill('0') << static_cast<unsigned>(m_dstAddress);
|
|
||||||
output << FIELD_SEPARATOR;
|
|
||||||
unsigned int cnt = 0;
|
unsigned int cnt = 0;
|
||||||
for (vector<unsigned char>::const_iterator it = m_id.begin(); it < m_id.end(); it++) {
|
for (size_t i=0; i<end; i++) {
|
||||||
if (cnt++ == 2)
|
|
||||||
output << FIELD_SEPARATOR;
|
|
||||||
output << hex << setw(2) << setfill('0') << static_cast<unsigned>(*it);
|
|
||||||
}
|
|
||||||
if (cnt <= 2)
|
|
||||||
output << FIELD_SEPARATOR; // no further ID bytes besides PBSB
|
|
||||||
output << FIELD_SEPARATOR;
|
|
||||||
m_data->dump(output);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Message::dump(ostream& output, vector<size_t>& columns)
|
|
||||||
{
|
|
||||||
bool first = true;
|
|
||||||
unsigned int cnt = 0;
|
|
||||||
for (vector<size_t>::const_iterator it = columns.begin(); it < columns.end(); it++) {
|
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
output << FIELD_SEPARATOR;
|
output << FIELD_SEPARATOR;
|
||||||
}
|
}
|
||||||
size_t column = *it;
|
size_t column = all ? i : (*columns)[i];
|
||||||
switch (column) {
|
switch (column) {
|
||||||
case 0: // type
|
case 0: // type
|
||||||
|
if (m_condition!=NULL) {
|
||||||
|
m_condition->dump(output);
|
||||||
|
}
|
||||||
if (m_isPassive) {
|
if (m_isPassive) {
|
||||||
output << "u";
|
output << "u";
|
||||||
if (m_isWrite)
|
if (m_isWrite)
|
||||||
@@ -618,6 +587,7 @@ void Message::dump(ostream& output, vector<size_t>& columns)
|
|||||||
break;
|
break;
|
||||||
case 6: // PBSB
|
case 6: // PBSB
|
||||||
case 7: // ID
|
case 7: // ID
|
||||||
|
cnt = 0;
|
||||||
for (vector<unsigned char>::const_iterator it = m_id.begin(); it < m_id.end(); it++) {
|
for (vector<unsigned char>::const_iterator it = m_id.begin(); it < m_id.end(); it++) {
|
||||||
cnt++;
|
cnt++;
|
||||||
if (column == 6) {
|
if (column == 6) {
|
||||||
@@ -651,7 +621,7 @@ Message* getFirstAvailable(vector<Message*> &messages) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
result_t Condition::create(vector<string>::iterator& it, const vector<string>::iterator end, string defaultDest, string defaultCircuit, SimpleCondition*& returnValue)
|
result_t Condition::create(const string condName, vector<string>::iterator& it, const vector<string>::iterator end, string defaultDest, string defaultCircuit, SimpleCondition*& returnValue)
|
||||||
{
|
{
|
||||||
// name,circuit,messagename,[comment],[fieldname],[ZZ],values (name already skipped by caller)
|
// name,circuit,messagename,[comment],[fieldname],[ZZ],values (name already skipped by caller)
|
||||||
string circuit = it==end ? "" : *(it++); // circuit
|
string circuit = it==end ? "" : *(it++); // circuit
|
||||||
@@ -716,12 +686,19 @@ result_t Condition::create(vector<string>::iterator& it, const vector<string>::i
|
|||||||
valueRanges.push_back(val); // single value
|
valueRanges.push_back(val); // single value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (field.length()>0 && valueRanges.empty())
|
||||||
returnValue = new SimpleCondition(circuit, name, dstAddress, field, valueRanges);
|
return RESULT_ERR_INVALID_NUM;
|
||||||
|
returnValue = new SimpleCondition(condName, circuit, name, dstAddress, field, valueRanges);
|
||||||
return RESULT_OK;
|
return RESULT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SimpleCondition::dump(ostream& output)
|
||||||
|
{
|
||||||
|
output << "[" << m_condName << "]";
|
||||||
|
//output << "{name="<<m_name<<",field="<<m_field<<",dst="<<static_cast<unsigned>(m_dstAddress)<<",valuessize="<<static_cast<unsigned>(m_valueRanges.size())<<"}";
|
||||||
|
}
|
||||||
|
|
||||||
CombinedCondition* SimpleCondition::combineAnd(Condition* other)
|
CombinedCondition* SimpleCondition::combineAnd(Condition* other)
|
||||||
{
|
{
|
||||||
CombinedCondition* ret = new CombinedCondition();
|
CombinedCondition* ret = new CombinedCondition();
|
||||||
@@ -808,6 +785,14 @@ bool SimpleCondition::isTrue()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CombinedCondition::dump(ostream& output)
|
||||||
|
{
|
||||||
|
for (vector<Condition*>::iterator it = m_conditions.begin(); it!=m_conditions.end(); it++) {
|
||||||
|
Condition* condition = *it;
|
||||||
|
condition->dump(output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
result_t CombinedCondition::resolve(MessageMap* messages, ostringstream& errorMessage)
|
result_t CombinedCondition::resolve(MessageMap* messages, ostringstream& errorMessage)
|
||||||
{
|
{
|
||||||
for (vector<Condition*>::iterator it = m_conditions.begin(); it!=m_conditions.end(); it++) {
|
for (vector<Condition*>::iterator it = m_conditions.begin(); it!=m_conditions.end(); it++) {
|
||||||
@@ -906,7 +891,7 @@ result_t MessageMap::addDefaultFromFile(vector< vector<string> >& defaults, vect
|
|||||||
return RESULT_ERR_DUPLICATE_NAME;
|
return RESULT_ERR_DUPLICATE_NAME;
|
||||||
}
|
}
|
||||||
SimpleCondition* condition = NULL;
|
SimpleCondition* condition = NULL;
|
||||||
result_t result = Condition::create(++begin, row.end(), defaultDest, defaultCircuit, condition);
|
result_t result = Condition::create(type, ++begin, row.end(), defaultDest, defaultCircuit, condition);
|
||||||
if (condition==NULL || result!=RESULT_OK) {
|
if (condition==NULL || result!=RESULT_OK) {
|
||||||
m_lastError = "invalid condition";
|
m_lastError = "invalid condition";
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
+23
-12
@@ -317,17 +317,11 @@ public:
|
|||||||
bool isLessPollWeight(const Message* other);
|
bool isLessPollWeight(const Message* other);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write the message definition to the @a ostream.
|
* Write the message definition or parts of it to the @a ostream.
|
||||||
* @param output the @a ostream to append the formatted value to.
|
* @param output the @a ostream to append the formatted value to.
|
||||||
|
* @param columns the list of column indexes to write, or NULL for all.
|
||||||
*/
|
*/
|
||||||
void dump(ostream& output);
|
void dump(ostream& output, vector<size_t>* columns=NULL);
|
||||||
|
|
||||||
/**
|
|
||||||
* Write parts of the message definition to the @a ostream.
|
|
||||||
* @param output the @a ostream to append the formatted value to.
|
|
||||||
* @param columns the list of column indexes to write.
|
|
||||||
*/
|
|
||||||
void dump(ostream& output, vector<size_t>& columns);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@@ -453,6 +447,7 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory method for creating a new instance.
|
* Factory method for creating a new instance.
|
||||||
|
* @param condName the name of the condition.
|
||||||
* @param it the iterator to traverse for the definition parts.
|
* @param it the iterator to traverse for the definition parts.
|
||||||
* @param end the iterator pointing to the end of the definition parts.
|
* @param end the iterator pointing to the end of the definition parts.
|
||||||
* @param defaultDest the valid destination address extracted from the file name (from ZZ part), or empty.
|
* @param defaultDest the valid destination address extracted from the file name (from ZZ part), or empty.
|
||||||
@@ -460,7 +455,13 @@ public:
|
|||||||
* @param returnValue the variable in which to store the created instance.
|
* @param returnValue the variable in which to store the created instance.
|
||||||
* @return @a RESULT_OK on success, or an error code.
|
* @return @a RESULT_OK on success, or an error code.
|
||||||
*/
|
*/
|
||||||
static result_t create(vector<string>::iterator& it, const vector<string>::iterator end, string defaultDest, string defaultCircuit, SimpleCondition*& returnValue);
|
static result_t create(const string condName, vector<string>::iterator& it, const vector<string>::iterator end, string defaultDest, string defaultCircuit, SimpleCondition*& returnValue);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write the condition definition to the @a ostream.
|
||||||
|
* @param output the @a ostream to append to.
|
||||||
|
*/
|
||||||
|
virtual void dump(ostream& output) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Combine this condition with another instance using a logical and.
|
* Combine this condition with another instance using a logical and.
|
||||||
@@ -503,15 +504,16 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new instance.
|
* Construct a new instance.
|
||||||
|
* @param condName the name of the condition.
|
||||||
* @param circuit the circuit name.
|
* @param circuit the circuit name.
|
||||||
* @param name the message name, or empty for scan message.
|
* @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 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 field the field name.
|
||||||
* @param valueRanges the valid value ranges (pairs of from/to inclusive), empty for @a m_message seen check.
|
* @param valueRanges the valid value ranges (pairs of from/to inclusive), empty for @a m_message seen check.
|
||||||
*/
|
*/
|
||||||
SimpleCondition(const string circuit, const string name, const unsigned char dstAddress, const string field, const vector<unsigned int> valueRanges)
|
SimpleCondition(const string condName, const string circuit, const string name, const unsigned char dstAddress, const string field, const vector<unsigned int> valueRanges)
|
||||||
: Condition(),
|
: Condition(),
|
||||||
m_circuit(circuit), m_name(name), m_dstAddress(dstAddress), m_field(field),
|
m_condName(condName), m_circuit(circuit), m_name(name), m_dstAddress(dstAddress), m_field(field),
|
||||||
m_valueRanges(valueRanges), m_message(NULL) { }
|
m_valueRanges(valueRanges), m_message(NULL) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -519,6 +521,9 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual ~SimpleCondition() {}
|
virtual ~SimpleCondition() {}
|
||||||
|
|
||||||
|
// @copydoc
|
||||||
|
virtual void dump(ostream& output);
|
||||||
|
|
||||||
// @copydoc
|
// @copydoc
|
||||||
virtual CombinedCondition* combineAnd(Condition* other);
|
virtual CombinedCondition* combineAnd(Condition* other);
|
||||||
|
|
||||||
@@ -538,6 +543,9 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
/** the condition name. */
|
||||||
|
const string m_condName;
|
||||||
|
|
||||||
/** the circuit name. */
|
/** the circuit name. */
|
||||||
const string m_circuit;
|
const string m_circuit;
|
||||||
|
|
||||||
@@ -577,6 +585,9 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual ~CombinedCondition() {}
|
virtual ~CombinedCondition() {}
|
||||||
|
|
||||||
|
// @copydoc
|
||||||
|
virtual void dump(ostream& output);
|
||||||
|
|
||||||
// @copydoc
|
// @copydoc
|
||||||
virtual CombinedCondition* combineAnd(Condition* other) { m_conditions.push_back(other); return this; }
|
virtual CombinedCondition* combineAnd(Condition* other) { m_conditions.push_back(other); return this; }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user