|
@@ -0,0 +1,67 @@
|
|
|
+
|
|
|
+# ivservice使用说明
|
|
|
+
|
|
|
+## 1.功能介绍
|
|
|
+ivservice用于便于编写服务接口
|
|
|
+
|
|
|
+## 2.服务端使用说明
|
|
|
+服务端需要编写回调函数,如下所示
|
|
|
+```
|
|
|
+void ProcVINReq(std::shared_ptr<char> pstr_req,const int nreqsize,std::shared_ptr<char> & pstr_res,int & nressize)
|
|
|
+{
|
|
|
+ (void)pstr_req;
|
|
|
+ (void)nreqsize;
|
|
|
+ nressize = gstrVIN.size() +1;
|
|
|
+ pstr_res = std::shared_ptr<char>(new char[nressize]);
|
|
|
+ *(pstr_res.get() + nressize) = 0;
|
|
|
+ memcpy(pstr_res.get(),gstrVIN.data(),gstrVIN.size());
|
|
|
+}
|
|
|
+```
|
|
|
+然后实例化一个服务即可:
|
|
|
+```
|
|
|
+iv::service::Server serviceVersion("Version",ProcVersionReq);
|
|
|
+```
|
|
|
+
|
|
|
+## 3.客户端使用说明
|
|
|
+请求服务的方法由两种。
|
|
|
+同步请求,同步请求的默认等待时间为100ms,如下:
|
|
|
+```
|
|
|
+ iv::service::Client xclientVersion("Version");
|
|
|
+ std::shared_ptr<char> pstrvt_ptr;
|
|
|
+ int ndatasize;
|
|
|
+ if(xclientVersion.SendRequest(pstr_ptr,100,pstrvt_ptr,ndatasize) == iv::service::Client::HAVE_RES)
|
|
|
+ {
|
|
|
+ std::cout<<" Version: "<< pstrvt_ptr.get()<<std::endl;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::cout<<" Can't Get Version"<<std::endl;
|
|
|
+ }
|
|
|
+```
|
|
|
+异步请求,异步请求需要回调函数,如下:
|
|
|
+```
|
|
|
+void ProcAsyncVin(std::shared_ptr<char> & pstr_res,int & ndatasize,int nres)
|
|
|
+{
|
|
|
+ if(nres == 0)
|
|
|
+ {
|
|
|
+ std::cout<<"not get Service VIN"<<std::endl;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(nres == 1)
|
|
|
+ {
|
|
|
+ (void)ndatasize;
|
|
|
+ std::string strVIN;
|
|
|
+ strVIN.append(pstr_res.get());
|
|
|
+ std::cout<<"VIN:"<<pstr_res.get()<<std::endl;
|
|
|
+ }
|
|
|
+}
|
|
|
+```
|
|
|
+异步请求的默认等待时间时30s,调用方法如下:
|
|
|
+```
|
|
|
+ iv::service::Client xclientVIN("VIN");
|
|
|
+ std::shared_ptr<char> pstr_ptr = std::shared_ptr<char>(new char[100]);
|
|
|
+ xclientVIN.AsyncSendRequest(pstr_ptr,100,ProcAsyncVin);
|
|
|
+```
|
|
|
+
|
|
|
+
|
|
|
+
|