diff --git a/src/lib/ebus/message.cpp b/src/lib/ebus/message.cpp index 4a02c41a..d477f2fa 100644 --- a/src/lib/ebus/message.cpp +++ b/src/lib/ebus/message.cpp @@ -1305,7 +1305,7 @@ string Instruction::getDestination() } -result_t LoadInstruction::execute(MessageMap* messages, ostringstream& log) { +result_t LoadInstruction::execute(MessageMap* messages, ostringstream& log, void (*loadInfoFunc)(MessageMap* messages, const unsigned char address, string filename)) { result_t result = messages->readFromFile(m_filename, false, m_defaultDest, m_defaultCircuit, m_defaultSuffix); if (log.tellp()>0) log << ", "; @@ -1314,6 +1314,20 @@ result_t LoadInstruction::execute(MessageMap* messages, ostringstream& log) { return result; } log << (isSingleton() ? "loaded " : "included ") << m_filename << " for \"" << getDestination() << "\""; + if (isSingleton() && loadInfoFunc!=NULL && !m_defaultDest.empty()) { + result_t temp; + unsigned char address = (unsigned char)parseInt(m_defaultDest.c_str(), 16, 0, 0xff, temp); + if (temp==RESULT_OK) { + size_t pos = m_filename.find_last_of('/'); + string filename; + if (pos==string::npos) { + filename = m_filename; + } else { + filename = m_filename.substr(pos+1); + } + (*loadInfoFunc)(messages, address, filename); + } + } return result; } @@ -1585,7 +1599,7 @@ result_t MessageMap::resolveCondition(Condition* condition) { return result; } -result_t MessageMap::executeInstructions(bool verbose, ostringstream& log) { +result_t MessageMap::executeInstructions(ostringstream& log, void (*loadInfoFunc)(MessageMap* messages, const unsigned char address, string filename)) { m_lastError = ""; result_t overallResult = RESULT_OK; vector remove; @@ -1613,7 +1627,7 @@ result_t MessageMap::executeInstructions(bool verbose, ostringstream& log) { if (instruction->isSingleton()) { removeSingletons = true; } - result_t result = instruction->execute(this, log); + result_t result = instruction->execute(this, log, loadInfoFunc); if (result!=RESULT_OK) { overallResult = result; } @@ -1646,6 +1660,22 @@ result_t MessageMap::executeInstructions(bool verbose, ostringstream& log) { return overallResult; } +void MessageMap::addLoadedFile(unsigned char address, string file) +{ + if (file.empty()) return; + if (m_loadedFiles.find(address)==m_loadedFiles.end()) + m_loadedFiles[address] = "\""+file+"\""; + else + m_loadedFiles[address] += ", \""+file+"\""; +} + +string MessageMap::getLoadedFiles(unsigned char address) +{ + if (m_loadedFiles.find(address)==m_loadedFiles.end()) + return ""; + return m_loadedFiles[address]; +} + vector* MessageMap::getByKey(const unsigned long long key) { map >::iterator it = m_messagesByKey.find(key); if (it != m_messagesByKey.end()) @@ -1831,6 +1861,7 @@ void MessageMap::addPollMessage(Message* message, bool toFront) void MessageMap::clear() { + m_loadedFiles.clear(); // clear poll messages while (!m_pollMessages.empty()) { m_pollMessages.top(); diff --git a/src/lib/ebus/message.h b/src/lib/ebus/message.h index de92db11..1886b46c 100644 --- a/src/lib/ebus/message.h +++ b/src/lib/ebus/message.h @@ -993,9 +993,10 @@ public: * Execute the instruction. * @param messages the @a MessageMap. * @param log the @a ostringstream to log success messages to (if necessary). + * @param loadInfoFunc the function to call for successful loading of a file for a certain address, or NULL. * @return @a RESULT_OK on success, or an error code. */ - virtual result_t execute(MessageMap* messages, ostringstream& log) = 0; + virtual result_t execute(MessageMap* messages, ostringstream& log, void (*loadInfoFunc)(MessageMap* messages, const unsigned char address, string filename)=NULL) = 0; private: @@ -1044,7 +1045,7 @@ public: virtual ~LoadInstruction() { } // @copydoc - virtual result_t execute(MessageMap* messages, ostringstream& log); + virtual result_t execute(MessageMap* messages, ostringstream& log, void (*loadInfoFunc)(MessageMap* messages, const unsigned char address, string filename)=NULL); private: @@ -1130,11 +1131,25 @@ public: /** * Run all executable @a Instruction instances. - * @param verbose whether to verbosely add all problems to the error message. * @param log the @a ostringstream to log success messages to (if necessary). + * @param loadInfoFunc the function to call for successful loading of a file for a participant, or NULL. * @return @a RESULT_OK on success, or an error code. */ - result_t executeInstructions(bool verbose, ostringstream& log); + result_t executeInstructions(ostringstream& log, void (*loadInfoFunc)(MessageMap* messages, const unsigned char address, string file)=NULL); + + /** + * Add a loaded file to a participant. + * @param address the slave address. + * @param file the name of the file from which a configuration part was loaded for the participant. + */ + void addLoadedFile(unsigned char address, string file); + + /** + * Get the loaded files for a participant. + * @param address the slave address. + * @return the name of the file(s) loaded for the participant (separated by comma and enclosed in double quotes), or empty. + */ + string getLoadedFiles(unsigned char address); /** * Get the stored @a Message instances for the key. @@ -1258,6 +1273,9 @@ private: /** the @a Message instance used for scanning. */ Message* m_scanMessage; + /** the loaded configuration files by slave address. */ + map m_loadedFiles; + /** the maximum ID length used by any of the known @a Message instances. */ unsigned char m_maxIdLength;