#include #include #include #include #include "cumsgbuffer.h" #include "pcmsgbuffer.h" #include #include #include #include #include #include #include "uploadmsg.grpc.pb.h" using grpc::Server; using grpc::ServerBuilder; using grpc::ServerContext; using grpc::Status; #include static cumsgbuffer gcumsgbuf; static pcmsgbuffer gpcmsgbuf; // Logic and data behind the server's behavior. class UploadServiceImpl final : public iv::Upload::Service { Status upload(ServerContext* context, const iv::UploadRequest* request, iv::UploadReply* reply) override { std::vector xvectordata; qDebug("size is %d",request->xdata().size()); if(request->xdata().size()>0) { xvectordata.resize(request->xdata().size()); memcpy(xvectordata.data(),request->xdata().data(),request->xdata().size()); } gcumsgbuf.addmsg(request->id(),request->ntime(),request->strvin(),request->strquerymd5(),request->strctrlmd5(), &xvectordata,request->bimportant(),request->kepptime()); // std::string strVIN,strctrlMD5; int id; qint64 ntime; std::vector xvectorctrldata; int nres = gpcmsgbuf.getmsg(request->strvin(),request->strctrlmd5(),id,ntime,&xvectorctrldata); reply->set_nres(nres); if(nres == 1) { reply->set_xdata(xvectorctrldata.data(),xvectorctrldata.size()); } // char * strdata = new char[10000000]; // qint64 time = QDateTime::currentMSecsSinceEpoch(); // memcpy(strdata,&time,8); // reply->set_data(strdata,10000000); // delete strdata; return Status::OK; } Status query(ServerContext* context, const iv::queryreq* request, iv::queryReply* reply) override { int id; qint64 ntime; std::vector xvectorquerydata; int nres = gcumsgbuf.getmsg(request->strvin(),request->strquerymd5(),request->nlasttime(),id,ntime,&xvectorquerydata); reply->set_nres(nres); if(nres > 0) { reply->set_data(xvectorquerydata.data(),xvectorquerydata.size()); reply->set_id(id); reply->set_ntime(ntime); } return Status::OK; } Status ctrl(ServerContext* context, const iv::ctrlreq* request, iv::ctrlReply * reply) override { std::vector xvectordata; if(request->data().size()>0) { xvectordata.resize(request->data().size()); memcpy(xvectordata.data(),request->data().data(),request->data().size()); } int nid = gpcmsgbuf.addmsg(request->id(),request->ntime(),request->strvin(),request->strctrlmd5(),&xvectordata, request->bimportant(),request->kepptime()); reply->set_nsendid(nid); return Status::OK; } }; void RunServer() { std::string server_address("0.0.0.0:50051"); UploadServiceImpl service; grpc::EnableDefaultHealthCheckService(true); // grpc::reflection::InitProtoReflectionServerBuilderPlugin(); ServerBuilder builder; // Listen on the given address without any authentication mechanism. builder.AddListeningPort(server_address, grpc::InsecureServerCredentials()); builder.SetMaxReceiveMessageSize(300000000); // builder.SetMaxMessageSize(100000000); // builder.SetMaxSendMessageSize(100000000); // Register "service" as the instance through which we'll communicate with // clients. In this case it corresponds to an *synchronous* service. builder.RegisterService(&service); // Finally assemble the server. std::unique_ptr server(builder.BuildAndStart()); std::cout << "Server listening on " << server_address << std::endl; // Wait for the server to shutdown. Note that some other thread must be // responsible for shutting down the server for this call to ever return. server->Wait(); } int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); gpcmsgbuf.start(); RunServer(); return a.exec(); }