#include "grpcclientthread.h" grpcclientthread * ggrpcclient; #ifdef Android #include "adcintelligentshow.h" extern ADCIntelligentShow * gAShow; #endif void ListenData(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname) { ggrpcclient->UpdateData(strdata,nSize,strmemname); // std::cout<<"name is "< vecmodulename; if(config["server"]) { mstrserverip = config["server"].as(); } if(config["port"]) { mstrserverport = config["port"].as(); } if(config["uploadinterval"]) { mstrqueryinterval = config["uploadinterval"].as(); } std::string strmsgname; if(config["querymessage"]) { for(YAML::const_iterator it= config["querymessage"].begin(); it != config["querymessage"].end();++it) { std::string strtitle = it->first.as(); std::cout<(); strncpy(xmu.mstrmsgname,strmsgname.data(),255); xmu.mnBufferSize = config["querymessage"][strtitle]["buffersize"].as(); xmu.mnBufferCount = config["querymessage"][strtitle]["buffercount"].as(); mvectorquerymsgunit.push_back(xmu); } } } else { } if(config["ctrlmessage"]) { std::string strnodename = "ctrlmessage"; for(YAML::const_iterator it= config[strnodename].begin(); it != config[strnodename].end();++it) { std::string strtitle = it->first.as(); std::cout<(); strncpy(xmu.mstrmsgname,strmsgname.data(),255); xmu.mnBufferSize = config[strnodename][strtitle]["buffersize"].as(); xmu.mnBufferCount = config[strnodename][strtitle]["buffercount"].as(); mvectorctrlmsgunit.push_back(xmu); } } } else { } return; } void grpcclientthread::addquerymsgunit(std::string strquerymsg, int nbuffsize, int nbuffcount) { int i; for(i=0;i channel = grpc::CreateCustomChannel( target_str, grpc::InsecureChannelCredentials(),cargs); std::unique_ptr stub_ = iv::ivgrpc::NewStub(channel); int nid = 0; // Container for the data we expect from the server. gpr_timespec timespec; timespec.tv_sec = 3;//设置阻塞时间为2秒 timespec.tv_nsec = 0; timespec.clock_type = GPR_TIMESPAN; int ndataindex = 0; // ClientContext context; int nctrlindex = 0; int nctrlnid = 0; while(!QThread::isInterruptionRequested()) { iv::queryreq request; iv::queryReply reply; std::this_thread::sleep_for(std::chrono::milliseconds(1)); if((xTime.elapsed()-nlastsend)query(&context, request, &reply); if (status.ok()) { // std::cout<CopyFrom(xctrl); } } mMutexMsg.unlock(); if(ctrlrequest.msg_size()>0) { ctrlrequest.set_nid(nctrlnid); nctrlnid++; ctrlrequest.set_strdevicename(mstrdevname); ClientContext contextctrl ; contextctrl.set_deadline(timespec); Status status2 = stub_->ctrl(&contextctrl, ctrlrequest, &ctrlreply); if (status2.ok()) { // std::cout<msgname()<msgname().data(),mvectorquerymsgunit[i].mstrmsgname,256) == 0) { // std::cout<<"msg is "<msgname()<<" size is: "<xdata().size()<msgname().data(),"tracemap",256) == 0) { std::cout<<"trace map size is "<xdata().size()<xdata().data(),pxmsg->xdata().size()); #else gAShow->AndroidSetMsg(pxmsg->msgname().data(),pxmsg->xdata().data(),pxmsg->xdata().size()); #endif break; } } } void grpcclientthread::setdevname(std::string strdevname) { mstrdevname = strdevname; } void grpcclientthread::setserverip(std::string strip) { mstrserverip = strip; } void grpcclientthread::setserverport(std::string strport) { mstrserverport = strport; } void grpcclientthread::setqueryinterval(std::string strinterval) { mstrqueryinterval = strinterval; }