diff --git a/src/lib/ebus/message.cpp b/src/lib/ebus/message.cpp index 04517452..4a02c41a 100644 --- a/src/lib/ebus/message.cpp +++ b/src/lib/ebus/message.cpp @@ -1724,7 +1724,8 @@ deque 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 >::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 >::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; diff --git a/src/lib/ebus/message.h b/src/lib/ebus/message.h index 75d51f42..de92db11 100644 --- a/src/lib/ebus/message.h +++ b/src/lib/ebus/message.h @@ -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.