optimized handling scan result and remove typeinfo dependency
This commit is contained in:
+12
-10
@@ -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<unsigned>(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<unsigned>(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;
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <pthread.h>
|
||||
#include <typeinfo>
|
||||
|
||||
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<unsigned char, string>* 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<unsigned char, string>* m_scanResults;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user