|
@@ -0,0 +1,190 @@
|
|
|
|
+#include <QCoreApplication>
|
|
|
|
+#include <QDateTime>
|
|
|
|
+#include <iostream>
|
|
|
|
+#include <vector>
|
|
|
|
+
|
|
|
|
+#include "cumsgbuffer.h"
|
|
|
|
+#include "pcmsgbuffer.h"
|
|
|
|
+
|
|
|
|
+#include <iostream>
|
|
|
|
+#include <memory>
|
|
|
|
+#include <string>
|
|
|
|
+
|
|
|
|
+#include <grpcpp/grpcpp.h>
|
|
|
|
+#include <grpcpp/health_check_service_interface.h>
|
|
|
|
+#include <grpcpp/ext/proto_server_reflection_plugin.h>
|
|
|
|
+
|
|
|
|
+#include "uploadthreadmsg.grpc.pb.h"
|
|
|
|
+
|
|
|
|
+using grpc::Server;
|
|
|
|
+using grpc::ServerBuilder;
|
|
|
|
+using grpc::ServerContext;
|
|
|
|
+using grpc::Status;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+#include <QDateTime>
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+static cumsgbuffer gcumsgbuf;
|
|
|
|
+static pcmsgbuffer gpcmsgbuf;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+// Logic and data behind the server's behavior.
|
|
|
|
+class UploadServiceImpl final : public iv::UploadThread::Service {
|
|
|
|
+ Status uploaddata(ServerContext* context, const iv::UploadRequestThread* request,
|
|
|
|
+ iv::UploadReplyThread* reply) override {
|
|
|
|
+
|
|
|
|
+ std::vector<char> 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<char > 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 queryctrl(ServerContext* context, const iv::queryReqThread* request,
|
|
|
|
+ iv::queryReplyThread* reply) override {
|
|
|
|
+
|
|
|
|
+ int id;
|
|
|
|
+ qint64 ntime;
|
|
|
|
+ std::vector<char > xvectorquerydata;
|
|
|
|
+
|
|
|
|
+ std::vector<char> xvectordata;
|
|
|
|
+ if(request->xdata().size()>0)
|
|
|
|
+ {
|
|
|
|
+ xvectordata.resize(request->xdata().size());
|
|
|
|
+ memcpy(xvectordata.data(),request->xdata().data(),request->xdata().size());
|
|
|
|
+ gpcmsgbuf.addmsg(request->id(),request->ntime(),request->strvin(),request->strctrlmd5(),&xvectordata,
|
|
|
|
+ request->bimportant(),request->kepptime());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ int nres = gcumsgbuf.getmsg(request->strvin(),request->strquerymd5(),request->nlasttime(),id,ntime,&xvectorquerydata);
|
|
|
|
+
|
|
|
|
+ reply->set_nres(nres);
|
|
|
|
+ if(nres > 0)
|
|
|
|
+ {
|
|
|
|
+ reply->set_xdata(xvectorquerydata.data(),xvectorquerydata.size());
|
|
|
|
+ reply->set_id(id);
|
|
|
|
+ reply->set_ntime(ntime);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return Status::OK;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Status uploadpic(ServerContext* context, const iv::PicUpRequestThread* request,
|
|
|
|
+ iv::PicUpReplyThread* reply) override {
|
|
|
|
+ gcumsgbuf.addPicData(request->strvin(),request->xdata().data(),
|
|
|
|
+ request->xdata().size(),request->npictime(),request->ncampos());
|
|
|
|
+ reply->set_nres(0);
|
|
|
|
+
|
|
|
|
+ return Status::OK;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+// Status ctrl(ServerContext* context, const iv::ctrlreq* request,
|
|
|
|
+// iv::ctrlReply * reply) override {
|
|
|
|
+
|
|
|
|
+// std::vector<char> 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> 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();
|
|
|
|
+}
|