#include "cumsgbuffer.h" cumsgbuffer::cumsgbuffer() { } void cumsgbuffer::addmsg(int id, qint64 ntime, std::string strVIN, std::string strqueryMD5, std::string strctrlMD5, std::vector *pxdata,bool bImportant,int nkeeptime,qint64 nculatency) { qDebug("ntime is %ld",ntime); mMutex.lock(); iv::cumsg * pmsg = 0; int nsize = mvectormsg.size(); int i; for(i=0;isize() > 0) { cmsg.xdata.resize(pxdata->size()); memcpy(cmsg.xdata.data(),pxdata->data(),pxdata->size()); } cmsg.mlastuptime = QDateTime::currentMSecsSinceEpoch(); cmsg.mbImportant = bImportant; cmsg.mkeeptime = nkeeptime; cmsg.mbhavequery = false; mvectormsg.push_back(cmsg); mMutex.unlock(); return; } if((pmsg->mbImportant != true)||(pmsg->mbhavequery)||((QDateTime::currentMSecsSinceEpoch() - pmsg->mlastuptime)>=pmsg->mkeeptime)) { pmsg->id = id; pmsg->ntime = ntime; pmsg->mbImportant = bImportant; pmsg->mbhavequery = false; pmsg->mlastuptime = QDateTime::currentMSecsSinceEpoch(); pmsg->mkeeptime = nkeeptime; pmsg->strqueryMD5 = strqueryMD5; pmsg->strctrlMD5 = strctrlMD5; pmsg->xdata.clear(); pmsg->mnlatency = nculatency; if(pxdata->size()>0) { pmsg->xdata.resize(pxdata->size()); memcpy(pmsg->xdata.data(),pxdata->data(),pxdata->size()); } } mMutex.unlock(); } int cumsgbuffer::getmsg(std::string strVIN,std::string strqueryMD5, qint64 nlasttime, int &id, qint64 &ntime, std::vector *pxdata,qint64 * pnculatency) { mMutex.lock(); iv::cumsg * pmsg = 0; int nsize = mvectormsg.size(); int i; std::vector * pvectormsg = &mvectormsg; for(i=0;istrqueryMD5) { std::cout<<" query error."<mbhavequery = true; if(nlasttime == pmsg->ntime) { mMutex.unlock(); return 0; } qint64 now = QDateTime::currentMSecsSinceEpoch(); if(abs(now - pmsg->mlastuptime)>60000) //Data is old not use. { mMutex.unlock(); return 0; } id = pmsg->id; ntime = pmsg->ntime; pxdata->clear(); *pnculatency = pmsg->mnlatency; int ndatasize = pmsg->xdata.size(); pxdata->resize(ndatasize); memcpy(pxdata->data(),pmsg->xdata.data(),ndatasize); mMutex.unlock(); return 1; }