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
+12 -2
View File
@@ -1724,7 +1724,8 @@ deque<Message*> MessageMap::findAll(const string& circuit, const string& name, c
return ret; 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) if (master.size() < 5)
return NULL; return NULL;
@@ -1749,7 +1750,9 @@ Message* MessageMap::find(SymbolString& master, bool anyDestination)
exp = 3; exp = 3;
} }
map<unsigned long long , vector<Message*> >::iterator it = m_messagesByKey.find(key); map<unsigned long long , vector<Message*> >::iterator it;
if (withPassive) {
it = m_messagesByKey.find(key);
if (it != m_messagesByKey.end()) { if (it != m_messagesByKey.end()) {
Message* message = getFirstAvailable(it->second, idLength, &master); Message* message = getFirstAvailable(it->second, idLength, &master);
if (message) if (message)
@@ -1764,18 +1767,25 @@ Message* MessageMap::find(SymbolString& master, bool anyDestination)
return message; return message;
} }
} }
} else {
key &= ~ID_SOURCE_MASK;
}
if (withRead) {
it = m_messagesByKey.find(key | ID_SOURCE_ACTIVE_READ); // try again with special value for active read it = m_messagesByKey.find(key | ID_SOURCE_ACTIVE_READ); // try again with special value for active read
if (it != m_messagesByKey.end()) { if (it != m_messagesByKey.end()) {
Message* message = getFirstAvailable(it->second, idLength, &master); Message* message = getFirstAvailable(it->second, idLength, &master);
if (message) if (message)
return message; return message;
} }
}
if (withWrite) {
it = m_messagesByKey.find(key | ID_SOURCE_ACTIVE_WRITE); // try again with special value for active write it = m_messagesByKey.find(key | ID_SOURCE_ACTIVE_WRITE); // try again with special value for active write
if (it != m_messagesByKey.end()) { if (it != m_messagesByKey.end()) {
Message* message = getFirstAvailable(it->second, idLength, &master); Message* message = getFirstAvailable(it->second, idLength, &master);
if (message) if (message)
return message; return message;
} }
}
if (idLength == 0) if (idLength == 0)
break; break;
} }
+5 -1
View File
@@ -1173,10 +1173,14 @@ public:
* Find the @a Message instance for the specified master data. * Find the @a Message instance for the specified master data.
* @param master the master @a SymbolString for identifying the @a Message. * @param master the master @a SymbolString for identifying the @a Message.
* @param anyDestination true to only return messages without a particular destination. * @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. * @return the @a Message instance, or NULL.
* Note: the caller may not free the returned instance. * 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. * Invalidate cached data of the @a Message and all other instances with a matching name key.