diff --git a/ksgrd/SensorAgent.h b/ksgrd/SensorAgent.h --- a/ksgrd/SensorAgent.h +++ b/ksgrd/SensorAgent.h @@ -27,7 +27,7 @@ #include #include #include - +#include class QString; @@ -107,6 +107,7 @@ bool mDaemonOnLine; QString mHostName; + QSet mUnderwayRequests; }; /** @@ -127,6 +128,14 @@ void setId( int ); int id(); + friend uint qHash(const SensorRequest& sr, uint seed=0) { + return qHash(qMakePair(sr.mRequest, qMakePair(sr.mClient, sr.mId)), seed); + } + friend bool operator==(const SensorRequest& a, const SensorRequest& b) { + return a.mRequest == b.mRequest && + a.mClient == b.mClient && + a.mId == b.mId; + } private: QString mRequest; SensorClient *mClient = nullptr; diff --git a/ksgrd/SensorAgent.cpp b/ksgrd/SensorAgent.cpp --- a/ksgrd/SensorAgent.cpp +++ b/ksgrd/SensorAgent.cpp @@ -56,18 +56,10 @@ void SensorAgent::sendRequest( const QString &req, SensorClient *client, int id ) { SensorRequest *sensorreq = nullptr; - for(int i =0, total = mInputFIFO.size(); i < total; ++i) { - sensorreq = mInputFIFO.at(i); - if(id == sensorreq->id() && client == sensorreq->client() && req == sensorreq->request()) { - executeCommand(); - return; //don't bother to resend the same request if we already have it in our queue to send - } - } - for(int i =0, total = mProcessingFIFO.size(); i < total; ++i) { - sensorreq = mProcessingFIFO.at(i); - if(id == sensorreq->id() && client == sensorreq->client() && req == sensorreq->request()) - return; //don't bother to resend the same request if we have already sent the request to client and just waiting for an answer - } + SensorRequest nRequest { req, client, id }; + if (mUnderwayRequests.contains(nRequest)) + return; + mUnderwayRequests.insert(nRequest); /* The request is registered with the FIFO so that the answer can be * routed back to the requesting client. */ @@ -168,6 +160,7 @@ } SensorRequest *req = mProcessingFIFO.dequeue(); + mUnderwayRequests.remove(*req); // we are now responsible for the memory of req - we must delete it! if ( !req->client() ) { /* The client has disappeared before receiving the answer