track running scans

This commit is contained in:
john30
2016-03-13 10:21:05 +01:00
parent 9f1d7ee331
commit 84cd4a7a55
2 changed files with 24 additions and 5 deletions
+15 -4
View File
@@ -144,6 +144,7 @@ bool ScanRequest::notify(result_t result, SymbolString& slave)
if (m_slaves.empty()) { if (m_slaves.empty()) {
logNotice(lf_bus, "scan finished"); logNotice(lf_bus, "scan finished");
m_busHandler->setScanFinished();
return false; return false;
} }
if (m_messages.empty()) { if (m_messages.empty()) {
@@ -155,6 +156,7 @@ bool ScanRequest::notify(result_t result, SymbolString& slave)
m_message = m_messages.front(); m_message = m_messages.front();
m_messages.pop_front(); m_messages.pop_front();
if (prepare(m_master[0]) < RESULT_OK) { if (prepare(m_master[0]) < RESULT_OK) {
m_busHandler->setScanFinished();
return false; // give up return false; // give up
} }
return true; return true;
@@ -690,12 +692,11 @@ result_t BusHandler::setState(BusState state, result_t result, bool firstRepetit
if (restart) { if (restart) {
m_currentRequest->m_busLostRetries = 0; m_currentRequest->m_busLostRetries = 0;
m_nextRequests.push(m_currentRequest); m_nextRequests.push(m_currentRequest);
} } else if (m_currentRequest->m_deleteOnFinish) {
else if (m_currentRequest->m_deleteOnFinish)
delete m_currentRequest; delete m_currentRequest;
else } else {
m_finishedRequests.push(m_currentRequest); m_finishedRequests.push(m_currentRequest);
}
m_currentRequest = NULL; m_currentRequest = NULL;
} }
} }
@@ -860,6 +861,7 @@ result_t BusHandler::startScan(bool full)
delete request; delete request;
return result==RESULT_ERR_EOF ? RESULT_EMPTY : result; return result==RESULT_ERR_EOF ? RESULT_EMPTY : result;
} }
m_runningScans++;
m_nextRequests.push(request); m_nextRequests.push(request);
return RESULT_OK; return RESULT_OK;
} }
@@ -874,8 +876,17 @@ void BusHandler::setScanResult(unsigned char dstAddress, string str)
} }
} }
void BusHandler::setScanFinished()
{
if (m_runningScans>0)
m_runningScans--;
}
void BusHandler::formatScanResult(ostringstream& output) void BusHandler::formatScanResult(ostringstream& output)
{ {
if (m_runningScans>0) {
output << static_cast<unsigned>(m_runningScans) << " scan(s) still running" << endl;
}
bool first = true; bool first = true;
for (unsigned char slave = 1; slave != 0; slave++) { // 0 is known to be a master for (unsigned char slave = 1; slave != 0; slave++) { // 0 is known to be a master
map<unsigned char, string>::iterator it = m_scanResults.find(slave); map<unsigned char, string>::iterator it = m_scanResults.find(slave);
+9 -1
View File
@@ -322,7 +322,7 @@ public:
m_masterCount(1), m_autoLockCount(lockCount==0), m_lockCount(lockCount<=3 ? 3 : lockCount), m_remainLockCount(m_autoLockCount), m_masterCount(1), m_autoLockCount(lockCount==0), m_lockCount(lockCount<=3 ? 3 : lockCount), m_remainLockCount(m_autoLockCount),
m_generateSynInterval(generateSyn ? SYN_TIMEOUT*getMasterNumber(ownAddress)+SYMBOL_DURATION : 0), m_generateSynInterval(generateSyn ? SYN_TIMEOUT*getMasterNumber(ownAddress)+SYMBOL_DURATION : 0),
m_pollInterval(pollInterval), m_lastReceive(0), m_lastPoll(0), m_pollInterval(pollInterval), m_lastReceive(0), m_lastPoll(0),
m_currentRequest(NULL), m_nextSendPos(0), m_currentRequest(NULL), m_runningScans(0), m_nextSendPos(0),
m_symPerSec(0), m_maxSymPerSec(0), m_symPerSec(0), m_maxSymPerSec(0),
m_state(bs_noSignal), m_repeat(false), m_state(bs_noSignal), m_repeat(false),
m_command(false), m_commandCrcValid(false), m_response(false), m_responseCrcValid(false), m_command(false), m_commandCrcValid(false), m_response(false), m_responseCrcValid(false),
@@ -369,6 +369,11 @@ public:
*/ */
void setScanResult(unsigned char dstAddress, string str); void setScanResult(unsigned char dstAddress, string str);
/**
* Called from @a ScanRequest upon completion.
*/
void setScanFinished();
/** /**
* Format the scan result to the @a ostringstream. * Format the scan result to the @a ostringstream.
* @param output the @a ostringstream to format the scan result to. * @param output the @a ostringstream to format the scan result to.
@@ -530,6 +535,9 @@ private:
/** the queue of @a BusRequests that are already finished. */ /** the queue of @a BusRequests that are already finished. */
Queue<BusRequest*> m_finishedRequests; Queue<BusRequest*> m_finishedRequests;
/** the number of scan request currently running. */
unsigned int m_runningScans;
/** the offset of the next symbol that needs to be sent from the command or response, /** the offset of the next symbol that needs to be sent from the command or response,
* (only relevant if m_request is set and state is @a bs_command or @a bs_response). */ * (only relevant if m_request is set and state is @a bs_command or @a bs_response). */
unsigned char m_nextSendPos; unsigned char m_nextSendPos;