extended "-i" parameter of find command to accept further ID parts
This commit is contained in:
+35
-27
@@ -70,10 +70,11 @@ Message::Message(const string circuit, const string name,
|
||||
m_key = key;
|
||||
}
|
||||
|
||||
Message::Message(const bool isWrite, const bool isPassive,
|
||||
Message::Message(const string circuit, const string name,
|
||||
const bool isWrite, const bool isPassive,
|
||||
const unsigned char pb, const unsigned char sb,
|
||||
DataField* data, const bool deleteData)
|
||||
: m_circuit(), m_name(), m_isWrite(isWrite),
|
||||
: m_circuit(circuit), m_name(name), m_isWrite(isWrite),
|
||||
m_isPassive(isPassive), m_comment(),
|
||||
m_srcAddress(SYN), m_dstAddress(SYN),
|
||||
m_data(data), m_deleteData(true),
|
||||
@@ -108,6 +109,31 @@ string getDefault(const string value, vector<string>* defaults, size_t pos)
|
||||
return defaults->at(pos);
|
||||
}
|
||||
|
||||
result_t Message::parseId(string input, vector<unsigned char>& id)
|
||||
{
|
||||
istringstream in(input);
|
||||
while (!in.eof()) {
|
||||
while (in.peek() == ' ')
|
||||
in.get();
|
||||
if (in.eof()) // no more digits
|
||||
break;
|
||||
input.clear();
|
||||
input.push_back((char)in.get());
|
||||
if (in.eof()) {
|
||||
return RESULT_ERR_INVALID_ARG; // too short hex
|
||||
}
|
||||
input.push_back((char)in.get());
|
||||
|
||||
result_t result;
|
||||
unsigned char value = (unsigned char)parseInt(input.c_str(), 16, 0, 0xff, result);
|
||||
if (result != RESULT_OK) {
|
||||
return result; // invalid hex value
|
||||
}
|
||||
id.push_back(value);
|
||||
}
|
||||
return RESULT_OK;
|
||||
}
|
||||
|
||||
result_t Message::create(vector<string>::iterator& it, const vector<string>::iterator end,
|
||||
vector< vector<string> >* defaultsRows, Condition* condition, const string& filename,
|
||||
DataFieldTemplates* templates, vector<Message*>& messages)
|
||||
@@ -226,25 +252,9 @@ result_t Message::create(vector<string>::iterator& it, const vector<string>::ite
|
||||
else
|
||||
token = getDefault("", defaults, defaultPos).append(token);
|
||||
}
|
||||
istringstream input(token);
|
||||
while (!input.eof()) {
|
||||
while (input.peek() == ' ')
|
||||
input.get();
|
||||
if (input.eof()) // no more digits
|
||||
break;
|
||||
token.clear();
|
||||
token.push_back((char)input.get());
|
||||
if (input.eof()) {
|
||||
return RESULT_ERR_INVALID_ARG; // to short hex
|
||||
}
|
||||
token.push_back((char)input.get());
|
||||
|
||||
unsigned char value = (unsigned char)parseInt(token.c_str(), 16, 0, 0xff, result);
|
||||
if (result != RESULT_OK) {
|
||||
return result; // invalid hex value
|
||||
}
|
||||
id.push_back(value);
|
||||
}
|
||||
result = parseId(token, id);
|
||||
if (result!=RESULT_OK)
|
||||
return result;
|
||||
if (pos == 0 && id.size() != 2)
|
||||
return RESULT_ERR_INVALID_ARG; // missing/to short/to long PBSB
|
||||
|
||||
@@ -1064,7 +1074,7 @@ Message* MessageMap::find(const string& circuit, const string& name, const bool
|
||||
return NULL;
|
||||
}
|
||||
|
||||
deque<Message*> MessageMap::findAll(const string& circuit, const string& name, const short pb, const bool completeMatch,
|
||||
deque<Message*> MessageMap::findAll(const string& circuit, const string& name, const bool completeMatch,
|
||||
const bool withRead, const bool withWrite, const bool withPassive)
|
||||
{
|
||||
deque<Message*> ret;
|
||||
@@ -1074,7 +1084,6 @@ deque<Message*> MessageMap::findAll(const string& circuit, const string& name, c
|
||||
FileReader::tolower(lname);
|
||||
bool checkCircuit = lcircuit.length() > 0;
|
||||
bool checkName = name.length() > 0;
|
||||
bool checkPb = pb >= 0;
|
||||
for (map<string, vector<Message*> >::iterator it = m_messagesByName.begin(); it != m_messagesByName.end(); it++) {
|
||||
if (it->first[0] == '-') // avoid duplicates: instances stored multiple times have a key starting with "-"
|
||||
continue;
|
||||
@@ -1093,8 +1102,6 @@ deque<Message*> MessageMap::findAll(const string& circuit, const string& name, c
|
||||
if (completeMatch ? (check != lname) : (check.find(lname) == check.npos))
|
||||
continue;
|
||||
}
|
||||
if (checkPb && message->getId()[0] != pb)
|
||||
continue;
|
||||
if (message->isPassive()) {
|
||||
if (!withPassive)
|
||||
continue;
|
||||
@@ -1184,7 +1191,7 @@ void MessageMap::invalidateCache(Message* message)
|
||||
if (pos!=string::npos)
|
||||
circuit.resize(pos);
|
||||
string name = message->getName();
|
||||
deque<Message*> messages = findAll(circuit, name, -1, false, true, true, true);
|
||||
deque<Message*> messages = findAll(circuit, name, false, true, true, true);
|
||||
for (deque<Message*>::iterator it = messages.begin(); it != messages.end(); it++) {
|
||||
if (*it==message)
|
||||
continue;
|
||||
@@ -1244,7 +1251,8 @@ void MessageMap::clear()
|
||||
for (map<unsigned long long, vector<Message*> >::iterator it = m_messagesByKey.begin(); it != m_messagesByKey.end(); it++) {
|
||||
vector<Message*> keyMessages = it->second;
|
||||
for (vector<Message*>::iterator kit = keyMessages.begin(); kit != keyMessages.end(); kit++) {
|
||||
delete *kit;
|
||||
Message* message = *kit;
|
||||
delete message;
|
||||
}
|
||||
keyMessages.clear();
|
||||
}
|
||||
|
||||
+15
-5
@@ -94,7 +94,9 @@ public:
|
||||
Condition* condition=NULL);
|
||||
|
||||
/**
|
||||
* Construct a new temporary instance.
|
||||
* Construct a new simple instance (e.g. for scanning).
|
||||
* @param circuit the circuit name, or empty for not storing by name.
|
||||
* @param name the message name (unique within the same circuit and type), or empty for not storing by name.
|
||||
* @param isWrite whether this is a write message.
|
||||
* @param isPassive true if message can only be initiated by a participant other than us,
|
||||
* false if message can be initiated by any participant.
|
||||
@@ -103,7 +105,8 @@ public:
|
||||
* @param data the @a DataField for encoding/decoding the message.
|
||||
* @param deleteData whether to delete the @a DataField during destruction.
|
||||
*/
|
||||
Message(const bool isWrite, const bool isPassive,
|
||||
Message(const string circuit, const string name,
|
||||
const bool isWrite, const bool isPassive,
|
||||
const unsigned char pb, const unsigned char sb,
|
||||
DataField* data, const bool deleteData);
|
||||
|
||||
@@ -112,6 +115,14 @@ public:
|
||||
*/
|
||||
virtual ~Message() { if (m_deleteData) delete m_data; }
|
||||
|
||||
/**
|
||||
* Parse an ID part from the input @a string.
|
||||
* @param input the input @a string, hex digits optionally separated by space.
|
||||
* @param id the vector to which to add the parsed values.
|
||||
* @return @a RESULT_OK on success, or an error code.
|
||||
*/
|
||||
static result_t parseId(string input, vector<unsigned char>& id);
|
||||
|
||||
/**
|
||||
* Factory method for creating new instances.
|
||||
* @param it the iterator to traverse for the definition parts.
|
||||
@@ -644,7 +655,7 @@ public:
|
||||
MessageMap(const bool addAll=false) : FileReader::FileReader(true),
|
||||
m_addAll(addAll), m_maxIdLength(0), m_messageCount(0), m_conditionalMessageCount(0), m_passiveMessageCount(0)
|
||||
{
|
||||
m_scanMessage = new Message(false, false, 0x07, 0x04, DataFieldSet::getIdentFields(), true);
|
||||
m_scanMessage = new Message("scan", "ident", false, false, 0x07, 0x04, DataFieldSet::getIdentFields(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -720,7 +731,6 @@ public:
|
||||
* Find all active get @a Message instances for the specified circuit and name.
|
||||
* @param circuit the circuit name, or empty for any.
|
||||
* @param name the message name, or empty for any.
|
||||
* @param pb the primary ID byte, or -1 for any (default any).
|
||||
* @param completeMatch false to also include messages where the circuit and name matches only a part of the given circuit and name (default true).
|
||||
* @param withRead true to include read messages (default true).
|
||||
* @param withWrite true to include write messages (default false).
|
||||
@@ -728,7 +738,7 @@ public:
|
||||
* @return the found @a Message instances.
|
||||
* Note: the caller may not free the returned instances.
|
||||
*/
|
||||
deque<Message*> findAll(const string& circuit, const string& name, const short pb=-1, const bool completeMatch=true,
|
||||
deque<Message*> findAll(const string& circuit, const string& name, const bool completeMatch=true,
|
||||
const bool withRead=true, const bool withWrite=false, const bool withPassive=false);
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user