From e507901d8fbdb0160329b6e41c5052adce449a5b Mon Sep 17 00:00:00 2001 From: john30 Date: Sun, 14 Dec 2014 12:15:40 +0100 Subject: [PATCH] optimized handling scan result and remove typeinfo dependency --- src/ebusd/bushandler.cpp | 22 ++++++++++++---------- src/ebusd/bushandler.h | 12 +++++++----- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/ebusd/bushandler.cpp b/src/ebusd/bushandler.cpp index 29f249ad..14e738b0 100644 --- a/src/ebusd/bushandler.cpp +++ b/src/ebusd/bushandler.cpp @@ -92,14 +92,20 @@ result_t ScanRequest::prepare(unsigned char ownMasterAddress, unsigned char dstA void ScanRequest::notify(result_t result) { + unsigned char dstAddress = m_master[1]; + ostringstream scanResult; if (result == RESULT_OK) { - m_scanResult << hex << setw(2) << setfill('0') << static_cast(m_master[1]) << UI_FIELD_SEPARATOR; - result = m_message->decode(pt_slaveData, m_slave, m_scanResult); // decode data + scanResult << hex << setw(2) << setfill('0') << static_cast(dstAddress) << UI_FIELD_SEPARATOR; + result = m_message->decode(pt_slaveData, m_slave, scanResult); // decode data } if (result != RESULT_OK) - L.log(bus, error, "scan %2.2x failed: %s", m_master[1], getResultCode(result)); - else - L.log(bus, event, "scan: %s", m_scanResult.str().c_str()); + L.log(bus, error, "scan %2.2x failed: %s", dstAddress, getResultCode(result)); + else { + string str = scanResult.str(); + L.log(bus, event, "scan: %s", str.c_str()); + if (m_scanResults != NULL) + (*m_scanResults)[dstAddress] = str; + } } @@ -574,10 +580,6 @@ result_t BusHandler::setState(BusState state, result_t result, bool firstRepetit m_seenAddresses[dstAddress] = true; m_request->notify(result); if (m_request->m_deleteOnFinish == true) { - if (result == RESULT_OK && typeid(*m_request) == typeid(ScanRequest)) { - string res = ((ScanRequest*)m_request)->m_scanResult.str(); - m_scanResults[dstAddress] = res; - } delete m_request; } m_request = NULL; @@ -662,7 +664,7 @@ result_t BusHandler::startScan(bool full) continue; } - ScanRequest* request = new ScanRequest(m_response, scanMessage); + ScanRequest* request = new ScanRequest(m_response, scanMessage, &m_scanResults); result_t result = request->prepare(m_ownMasterAddress, slave); if (result != RESULT_OK) { delete request; diff --git a/src/ebusd/bushandler.h b/src/ebusd/bushandler.h index 2f835986..a1e5c1f6 100644 --- a/src/ebusd/bushandler.h +++ b/src/ebusd/bushandler.h @@ -31,7 +31,6 @@ #include #include #include -#include using namespace std; @@ -161,9 +160,12 @@ public: * @brief Constructor. * @param slave the slave data @a SymbolString received. * @param message the associated @a Message. + * @param scanResults the map in which to store the formatted scan result by slave address. */ - ScanRequest(SymbolString& slave, Message* message) - : BusRequest(m_master, slave, true), m_message(message) {} + ScanRequest(SymbolString& slave, Message* message, + map* scanResults) + : BusRequest(m_master, slave, true), m_message(message), + m_scanResults(scanResults) {} /** * @brief Destructor. @@ -189,8 +191,8 @@ private: /** the associated @a Message. */ Message* m_message; - /** the formatted scan result. */ - ostringstream m_scanResult; + /** the map in which to store the formatted scan result by slave address. */ + map* m_scanResults; };