| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- #include <QCoreApplication>
- #include <QDateTime>
- #include <iostream>
- #include <vector>
- #include "rpc_server.h"
- #include "cumsgbuffer.h"
- #include "pcmsgbuffer.h"
- struct uploadresponsemsg {
- int nres; //0 no message 1 have message
- int id;
- qint64 ntime;
- std::string strVIN;
- std::string strctrlMD5;
- std::vector<char> xdata;
- MSGPACK_DEFINE(nres,id, ntime,strVIN, strctrlMD5,xdata);
- };
- struct queryrespmsg {
- int nres;
- int id;
- qint64 ntime;
- std::vector<char> xdata;
- MSGPACK_DEFINE(nres,id, ntime,xdata);
- };
- struct ctrlrespmsg {
- int nsendid; // 0 write to buffer
- MSGPACK_DEFINE(nsendid);
- };
- struct queryctrlstate {
- int nstate; // 0 write to buffer
- MSGPACK_DEFINE(nstate);
- };
- static cumsgbuffer gcumsgbuf;
- static pcmsgbuffer gpcmsgbuf;
- using namespace rest_rpc;
- using namespace rpc_service;
- uploadresponsemsg get_clientresp(rpc_conn conn,int id,qint64 ntime,std::string strVIN,std::string strqueryMD5,std::string strctrlMD5,std::vector<char> xdata) {
- std::cout<<id<<" "<<strVIN<<" data size is "<<xdata.size()<<std::endl;
- uploadresponsemsg x;
- gcumsgbuf.addmsg(id,ntime,strVIN,strqueryMD5,strctrlMD5,&xdata);
- x.xdata.clear();
- int nres = gpcmsgbuf.getmsg(strVIN,strctrlMD5,x.id,x.ntime,&x.xdata);
- if(nres == 1)
- {
- x.nres = 1;
- }
- else x.nres = 0;
- // qDebug("res is %d",x.nres);
- // x.id = 1;
- // x.name = "hello";
- // char * strdata = new char[1000000];
- // x.strdata.append(strdata,1000);
- // delete strdata;
- // x.nlen = 1000;
- // x.dt = QDateTime::currentMSecsSinceEpoch();
- // x.xdata.push_back(1);
- // x.xdata.push_back(2);
- // x.xdata.push_back(3);
- return x;
- // return { 1, "tom", 20 };
- }
- queryrespmsg query_clientmsg(rpc_conn conn,std::string strVIN,std::string strqueryMD5,qint64 nlasttime)
- {
- queryrespmsg x;
- x.nres = gcumsgbuf.getmsg(strVIN,strqueryMD5,nlasttime,x.id,x.ntime,&x.xdata);
- return x;
- }
- ctrlrespmsg ctrl_client(rpc_conn conn,int id,qint64 ntime,std::string strVIN,std::string strctrlMD5,std::vector<char> xdata)
- {
- ctrlrespmsg x;
- x.nsendid = gpcmsgbuf.addmsg(id,ntime,strVIN,strctrlMD5,&xdata);
- // x.nres = ;
- return x;
- }
- queryctrlstate query_ctrlstate(rpc_conn conn,int nsendid)
- {
- queryctrlstate x;
- x.nstate = gpcmsgbuf.querysendstate(nsendid);
- return x;
- }
- int main(int argc, char *argv[])
- {
- QCoreApplication a(argc, argv);
- gpcmsgbuf.start();
- rpc_server server(9000, std::thread::hardware_concurrency());
- server.register_handler("get_clientresp", get_clientresp);
- server.register_handler("query_clientmsg", query_clientmsg);
- server.register_handler("ctrl_client", ctrl_client);
- server.register_handler("query_ctrlstate", query_ctrlstate);
- server.run();
- return a.exec();
- }
|