added message direction selectors to MessageMap::find(SymbolString)

This commit is contained in:
john30
2016-04-24 11:12:00 +02:00
parent 186afca37d
commit d1e4a838b9
2 changed files with 35 additions and 21 deletions
+30 -20
View File
@@ -1724,7 +1724,8 @@ deque<Message*> MessageMap::findAll(const string& circuit, const string& name, c
return ret;
}
Message* MessageMap::find(SymbolString& master, bool anyDestination)
Message* MessageMap::find(SymbolString& master, bool anyDestination,
const bool withRead, const bool withWrite, const bool withPassive)
{
if (master.size() < 5)
return NULL;
@@ -1749,32 +1750,41 @@ Message* MessageMap::find(SymbolString& master, bool anyDestination)
exp = 3;
}
map<unsigned long long , vector<Message*> >::iterator it = m_messagesByKey.find(key);
if (it != m_messagesByKey.end()) {
Message* message = getFirstAvailable(it->second, idLength, &master);
if (message)
return message;
}
if ((key & ID_SOURCE_MASK) != 0) {
map<unsigned long long , vector<Message*> >::iterator it;
if (withPassive) {
it = m_messagesByKey.find(key);
if (it != m_messagesByKey.end()) {
Message* message = getFirstAvailable(it->second, idLength, &master);
if (message)
return message;
}
if ((key & ID_SOURCE_MASK) != 0) {
key &= ~ID_SOURCE_MASK;
it = m_messagesByKey.find(key & ~ID_SOURCE_MASK); // try again without specific source master
if (it != m_messagesByKey.end()) {
Message* message = getFirstAvailable(it->second, idLength, &master);
if (message)
return message;
}
}
} else {
key &= ~ID_SOURCE_MASK;
it = m_messagesByKey.find(key & ~ID_SOURCE_MASK); // try again without specific source master
}
if (withRead) {
it = m_messagesByKey.find(key | ID_SOURCE_ACTIVE_READ); // try again with special value for active read
if (it != m_messagesByKey.end()) {
Message* message = getFirstAvailable(it->second, idLength, &master);
if (message)
return message;
}
}
it = m_messagesByKey.find(key | ID_SOURCE_ACTIVE_READ); // try again with special value for active read
if (it != m_messagesByKey.end()) {
Message* message = getFirstAvailable(it->second, idLength, &master);
if (message)
return message;
}
it = m_messagesByKey.find(key | ID_SOURCE_ACTIVE_WRITE); // try again with special value for active write
if (it != m_messagesByKey.end()) {
Message* message = getFirstAvailable(it->second, idLength, &master);
if (message)
return message;
if (withWrite) {
it = m_messagesByKey.find(key | ID_SOURCE_ACTIVE_WRITE); // try again with special value for active write
if (it != m_messagesByKey.end()) {
Message* message = getFirstAvailable(it->second, idLength, &master);
if (message)
return message;
}
}
if (idLength == 0)
break;
+5 -1
View File
@@ -1173,10 +1173,14 @@ public:
* Find the @a Message instance for the specified master data.
* @param master the master @a SymbolString for identifying the @a Message.
* @param anyDestination true to only return messages without a particular destination.
* @param withRead true to include read messages (default true).
* @param withWrite true to include write messages (default true).
* @param withPassive true to include passive messages (default true).
* @return the @a Message instance, or NULL.
* Note: the caller may not free the returned instance.
*/
Message* find(SymbolString& master, bool anyDestination=false);
Message* find(SymbolString& master, bool anyDestination=false,
const bool withRead=true, const bool withWrite=true, const bool withPassive=true);
/**
* Invalidate cached data of the @a Message and all other instances with a matching name key.