Skip to content

Commit d557cc1

Browse files
committed
added:get time number for info report
modify:the complete request address is no longer required
1 parent d83de9e commit d557cc1

File tree

6 files changed

+118
-5
lines changed

6 files changed

+118
-5
lines changed

XEngine_Source/StorageModule_InfoReport/InfoReport_APIMachine/InfoReport_APIMachine.cpp

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ CInfoReport_APIMachine::~CInfoReport_APIMachine()
3333
返回值
3434
类型:逻辑型
3535
意思:是否成功
36-
备注:lpszAPIUrl = _X("http://127.0.0.1:5501/api?function=machine&params1=0");
36+
备注:lpszAPIUrl = _X("http://127.0.0.1:5501/api?function=machine");
3737
*********************************************************************/
3838
bool CInfoReport_APIMachine::InfoReport_APIMachine_Send(LPCXSTR lpszAPIUrl)
3939
{
@@ -48,6 +48,7 @@ bool CInfoReport_APIMachine::InfoReport_APIMachine_Send(LPCXSTR lpszAPIUrl)
4848
int nLen = 0;
4949
int nCode = 0;
5050

51+
XCHAR tszAPIUrl[MAX_PATH] = {};
5152
XCHAR tszOSName[128] = {};
5253
XCHAR tszOSVersion[128] = {};
5354
XCHAR tszOSBuild[128] = {};
@@ -57,6 +58,8 @@ bool CInfoReport_APIMachine::InfoReport_APIMachine_Send(LPCXSTR lpszAPIUrl)
5758
XCLIENT_APIHTTP st_HTTPParam = {};
5859
SYSTEMAPI_SERIAL_INFOMATION st_SDKSerial = {};
5960

61+
_xstprintf(tszAPIUrl, _X("%s&params1=0"), lpszAPIUrl);
62+
6063
SystemApi_System_GetSystemVer(tszOSName, tszOSVersion, tszOSBuild, &nOSArch);
6164
SystemApi_System_GetSysName(NULL, tszComputerName);
6265
SystemApi_HardWare_GetSerial(&st_SDKSerial);
@@ -76,7 +79,7 @@ bool CInfoReport_APIMachine::InfoReport_APIMachine_Send(LPCXSTR lpszAPIUrl)
7679

7780
XCHAR* ptszMsgBuffer = NULL;
7881
st_HTTPParam.nTimeConnect = 2;
79-
if (!APIClient_Http_Request(_X("POST"), lpszAPIUrl, Json::writeString(st_JsonBuilder, st_JsonRoot).c_str(), &nCode, &ptszMsgBuffer, &nLen, NULL, NULL, &st_HTTPParam))
82+
if (!APIClient_Http_Request(_X("POST"), tszAPIUrl, Json::writeString(st_JsonBuilder, st_JsonRoot).c_str(), &nCode, &ptszMsgBuffer, &nLen, NULL, NULL, &st_HTTPParam))
8083
{
8184
InfoReport_IsErrorOccur = true;
8285
InfoReport_dwErrorCode = APIClient_GetLastError();
@@ -86,6 +89,88 @@ bool CInfoReport_APIMachine::InfoReport_APIMachine_Send(LPCXSTR lpszAPIUrl)
8689

8790
return true;
8891
}
92+
/********************************************************************
93+
函数名称:InfoReport_APIMachine_GetTime
94+
函数功能:获取报告次数
95+
参数.一:lpszAPIUrl
96+
In/Out:In
97+
类型:常量字符指针
98+
可空:N
99+
意思:输入请求地址
100+
参数.二:pInt_TimeNumber
101+
In/Out:Out
102+
类型:整数型指针
103+
可空:N
104+
意思:输出报告次数
105+
返回值
106+
类型:逻辑型
107+
意思:是否成功
108+
备注:
109+
*********************************************************************/
110+
bool CInfoReport_APIMachine::InfoReport_APIMachine_GetTime(LPCXSTR lpszAPIUrl, __int64x* pInt_TimeNumber)
111+
{
112+
InfoReport_IsErrorOccur = false;
113+
114+
if (NULL == lpszAPIUrl)
115+
{
116+
InfoReport_IsErrorOccur = true;
117+
InfoReport_dwErrorCode = ERROR_XENGINE_STORAGE_INFOREPORT_PARAMENT;
118+
return false;
119+
}
120+
int nLen = 0;
121+
int nCode = 0;
122+
XCHAR tszAPIUrl[MAX_PATH] = {};
123+
XCLIENT_APIHTTP st_HTTPParam = {};
124+
SYSTEMAPI_SERIAL_INFOMATION st_SDKSerial = {};
125+
126+
_xstprintf(tszAPIUrl, _X("%s&params1=2"), lpszAPIUrl);
127+
128+
SystemApi_HardWare_GetSerial(&st_SDKSerial);
129+
130+
Json::Value st_JsonRoot;
131+
JSONCPP_STRING st_JsonError;
132+
Json::StreamWriterBuilder st_JsonBuilder;
133+
Json::CharReaderBuilder st_JsonReader;
134+
135+
st_JsonRoot["tszMachineCode"] = st_SDKSerial.tszSystemSerial;
136+
st_JsonBuilder["emitUTF8"] = true;
137+
138+
XCHAR* ptszMsgBuffer = NULL;
139+
st_HTTPParam.nTimeConnect = 2;
140+
if (!APIClient_Http_Request(_X("POST"), tszAPIUrl, Json::writeString(st_JsonBuilder, st_JsonRoot).c_str(), &nCode, &ptszMsgBuffer, &nLen, NULL, NULL, &st_HTTPParam))
141+
{
142+
InfoReport_IsErrorOccur = true;
143+
InfoReport_dwErrorCode = APIClient_GetLastError();
144+
return false;
145+
}
146+
st_JsonRoot.clear();
147+
//开始解析配置文件
148+
std::unique_ptr<Json::CharReader> const pSt_JsonReader(st_JsonReader.newCharReader());
149+
if (!pSt_JsonReader->parse(ptszMsgBuffer, ptszMsgBuffer + nLen, &st_JsonRoot, &st_JsonError))
150+
{
151+
InfoReport_IsErrorOccur = true;
152+
InfoReport_dwErrorCode = ERROR_XENGINE_STORAGE_INFOREPORT_PARSE;
153+
return false;
154+
}
155+
BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer);
156+
157+
if (0 != st_JsonRoot["code"].asInt())
158+
{
159+
InfoReport_IsErrorOccur = true;
160+
InfoReport_dwErrorCode = ERROR_XENGINE_STORAGE_INFOREPORT_CODE;
161+
return false;
162+
}
163+
Json::Value st_JsonObject = st_JsonRoot["data"];
164+
//老版本
165+
if (st_JsonObject.isArray())
166+
{
167+
InfoReport_IsErrorOccur = true;
168+
InfoReport_dwErrorCode = ERROR_XENGINE_STORAGE_INFOREPORT_VERSION;
169+
return false;
170+
}
171+
*pInt_TimeNumber = st_JsonObject["nTimeNumber"].asInt64();
172+
return true;
173+
}
89174
//////////////////////////////////////////////////////////////////////////
90175
// 保护函数
91176
//////////////////////////////////////////////////////////////////////////

XEngine_Source/StorageModule_InfoReport/InfoReport_APIMachine/InfoReport_APIMachine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class CInfoReport_APIMachine
1818
~CInfoReport_APIMachine();
1919
public:
2020
bool InfoReport_APIMachine_Send(LPCXSTR lpszAPIUrl);
21+
bool InfoReport_APIMachine_GetTime(LPCXSTR lpszAPIUrl, __int64x* pInt_TimeNumber);
2122
protected:
2223
bool InfoReport_APIMachine_GetText(XCHAR *ptszMSGBuffer);
2324
};

XEngine_Source/StorageModule_InfoReport/InfoReport_Define.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,23 @@ extern "C" XLONG InfoReport_GetLastError(int *pInt_ErrorCode = NULL);
3030
意思:是否成功
3131
备注:lpszAPIUrl = _X("http://127.0.0.1:5501/api?function=machine&params1=0");
3232
*********************************************************************/
33-
extern "C" bool InfoReport_APIMachine_Send(LPCXSTR lpszAPIUrl);
33+
extern "C" bool InfoReport_APIMachine_Send(LPCXSTR lpszAPIUrl);
34+
/********************************************************************
35+
函数名称:InfoReport_APIMachine_GetTime
36+
函数功能:获取报告次数
37+
参数.一:lpszAPIUrl
38+
In/Out:In
39+
类型:常量字符指针
40+
可空:N
41+
意思:输入请求地址
42+
参数.二:pInt_TimeNumber
43+
In/Out:Out
44+
类型:整数型指针
45+
可空:N
46+
意思:输出报告次数
47+
返回值
48+
类型:逻辑型
49+
意思:是否成功
50+
备注:
51+
*********************************************************************/
52+
extern "C" bool InfoReport_APIMachine_GetTime(LPCXSTR lpszAPIUrl, __int64x* pInt_TimeNumber);

XEngine_Source/StorageModule_InfoReport/InfoReport_Error.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@
1010
// Purpose: 信息报告错误码
1111
// History:
1212
*********************************************************************/
13-
#define ERROR_XENGINE_STORAGE_INFOREPORT_PARAMENT 0x01A0001
13+
#define ERROR_XENGINE_STORAGE_INFOREPORT_PARAMENT 0x01A0001
14+
#define ERROR_XENGINE_STORAGE_INFOREPORT_PARSE 0x01A0002
15+
#define ERROR_XENGINE_STORAGE_INFOREPORT_CODE 0x01A0003
16+
#define ERROR_XENGINE_STORAGE_INFOREPORT_VERSION 0x01A0004

XEngine_Source/StorageModule_InfoReport/StorageModule_InfoReport.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ LIBRARY
33
EXPORTS
44
InfoReport_GetLastError
55

6-
InfoReport_APIMachine_Send
6+
InfoReport_APIMachine_Send
7+
InfoReport_APIMachine_GetTime

XEngine_Source/StorageModule_InfoReport/pch.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,8 @@ extern "C" XLONG InfoReport_GetLastError(int* pInt_ErrorCode)
3232
extern "C" bool InfoReport_APIMachine_Send(LPCXSTR lpszAPIUrl)
3333
{
3434
return m_APIMachine.InfoReport_APIMachine_Send(lpszAPIUrl);
35+
}
36+
extern "C" bool InfoReport_APIMachine_GetTime(LPCXSTR lpszAPIUrl, __int64x * pInt_TimeNumber)
37+
{
38+
return m_APIMachine.InfoReport_APIMachine_GetTime(lpszAPIUrl, pInt_TimeNumber);
3539
}

0 commit comments

Comments
 (0)