#include "groupmsgbuf.h" #include groupmsgbuf::groupmsgbuf() { std::string strgroupdbpath = "/home/yuchuli/groupdb.db"; mpgroupdb = new groupdb(strgroupdbpath.data()); } int groupmsgbuf::ProcGroupMsg(const iv::group::groupRequest * preq,iv::group::groupReply* reply) { iv::group::vehicleinfo xvinfo; if(!xvinfo.ParseFromArray(preq->xdata().data(),preq->xdata().size())) { std::cout<<"Parse Vehicle info fail"<set_nres(0); return 0; } iv::groupmsgunit * p = NULL; unsigned int i; mMutexGroup.lock(); for(i=0;imnLastUpdateTime = QDateTime::currentMSecsSinceEpoch(); p->minfo.CopyFrom(xvinfo); break; } } if(p == NULL) { iv::groupmsgunit xmsgunit; xmsgunit.strvehid = xvinfo.vehicleid(); xmsgunit.mnLastUpdateTime = QDateTime::currentMSecsSinceEpoch(); xmsgunit.minfo.CopyFrom(xvinfo); mvectorgroupmsg.push_back(xmsgunit); p = &mvectorgroupmsg[mvectorgroupmsg.size()-1]; } mMutexGroup.unlock(); if(preq->ngroup() == 0) { reply->set_nres(0); return 0; } qint64 nNow = QDateTime::currentMSecsSinceEpoch(); iv::group::groupinfo xgroupinfo; mMutexGroup.lock(); for(i=0;ingroup()) { iv::group::vehicleinfo * pvinfo = xgroupinfo.add_mvehinfo(); pvinfo->CopyFrom(mvectorgroupmsg[i].minfo); } } } mMutexGroup.unlock(); reply->set_nres(1); reply->set_ngroup(preq->ngroup()); int ndatasize = xgroupinfo.ByteSize(); std::shared_ptr pstr_buf = std::shared_ptr(new char[ndatasize]); if(xgroupinfo.SerializeToArray(pstr_buf.get(),ndatasize)) { reply->set_xdata(pstr_buf.get(),ndatasize); } else { std::cout<<" xgroupinfo serialize fail."<CopyFrom(mvectorgroupmsg[i].minfo); } } mMutexGroup.unlock(); reply->set_nres(1); reply->set_ngroup(preq->ngroup()); int ndatasize = xgroupinfo.ByteSize(); std::shared_ptr pstr_buf = std::shared_ptr(new char[ndatasize]); if(xgroupinfo.SerializeToArray(pstr_buf.get(),ndatasize)) { reply->set_xdata(pstr_buf.get(),ndatasize); } else { std::cout<<" xgroupinfo serialize fail."<