From f34265b818138fffeb5c6759599b9f602556ae86 Mon Sep 17 00:00:00 2001 From: john30 Date: Sat, 19 Sep 2015 09:50:54 +0200 Subject: [PATCH] added findAll(SymbolString) and invalidateCache() --- src/lib/ebus/message.cpp | 57 ++++++++++++++++++++++++++++++++-------- src/lib/ebus/message.h | 14 ++++++++++ 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/src/lib/ebus/message.cpp b/src/lib/ebus/message.cpp index 8c18f3c4..8a1124b8 100644 --- a/src/lib/ebus/message.cpp +++ b/src/lib/ebus/message.cpp @@ -649,17 +649,26 @@ deque MessageMap::findAll(const string& circuit, const string& name, c Message* MessageMap::find(SymbolString& master) { + deque ret = findAll(master); + + return ret.size()>0 ? ret.front() : NULL; +} + +deque MessageMap::findAll(SymbolString& master) +{ + deque ret; + if (master.size() < 5) - return NULL; + return ret; unsigned char maxIdLength = master[4]; if (maxIdLength < m_minIdLength) - return NULL; + return ret; if (maxIdLength > m_maxIdLength) maxIdLength = m_maxIdLength; if (master.size() < 5+maxIdLength) - return NULL; + return ret; - for (int idLength = maxIdLength; idLength >= m_minIdLength; idLength--) { + for (int idLength = maxIdLength; ret.size()==0 && idLength >= m_minIdLength; idLength--) { int exp = 7; unsigned long long key = (unsigned long long)idLength << (8 * exp + 5); key |= (unsigned long long)getMasterNumber(master[0]) << (8 * exp--); @@ -670,21 +679,47 @@ Message* MessageMap::find(SymbolString& master) key |= (unsigned long long)master[5 + i] << (8 * exp--); map::iterator it = m_messagesByKey.find(key); - if (it != m_messagesByKey.end()) - return it->second; - + if (it != m_messagesByKey.end()) { + ret.push_back(it->second); + } if ((key & ID_SOURCE_MASK) != 0) { it = m_messagesByKey.find(key & ~ID_SOURCE_MASK); // try again without specific source master if (it != m_messagesByKey.end()) - return it->second; + ret.push_back(it->second); } - it = m_messagesByKey.find(key | ID_SOURCE_MASK); // try again with special value for active if (it != m_messagesByKey.end()) - return it->second; + ret.push_back(it->second); } - return NULL; + return ret; +} + +void MessageMap::invalidateCache(Message* message) +{ + message->m_lastUpdateTime = 0; + string circuit = message->getCircuit(); + size_t pos = circuit.find('#'); + if (pos!=string::npos) + circuit.resize(pos); + string name = message->getName(); + deque messages = findAll(circuit, name, -1, false, true, true, true); + for (deque::iterator it = messages.begin(); it != messages.end(); it++) { + if (*it==message) + continue; + message = *it; + if (name!=message->getName()) + continue; // check exact name + string check = message->getCircuit(); + if (check!=circuit) { + size_t pos = check.find('#'); + if (pos!=string::npos) + check.resize(pos); + if (check!=circuit) + continue; + } + message->m_lastUpdateTime = 0; + } } void MessageMap::addPollMessage(Message* message) diff --git a/src/lib/ebus/message.h b/src/lib/ebus/message.h index 4d46c856..47e46758 100644 --- a/src/lib/ebus/message.h +++ b/src/lib/ebus/message.h @@ -397,6 +397,20 @@ public: */ Message* find(SymbolString& master); + /** + * Find all @a Message instances for the specified master data. + * @param master the master @a SymbolString for identifying the @a Message. + * @return the @a Message instance, or NULL. + * Note: the caller may not free the returned instances. + */ + deque findAll(SymbolString& master); + + /** + * Invalidate cached data of the @a Message and all other instances with a matching name key. + * @param message the @a Message to invalidate. + */ + void invalidateCache(Message* message); + /** * Add a @a Message to the list of instances to poll. * @param message the @a Message to poll.