Skip to content

Commit 4bff078

Browse files
committed
modify:more info report support
1 parent 7a6b18a commit 4bff078

File tree

8 files changed

+260
-38
lines changed

8 files changed

+260
-38
lines changed
-106 KB
Binary file not shown.

XEngine_Example/AIApi_APPExample/AIApi_APPExample.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ int main()
4242
XNETHANDLE xhToken = 0;
4343

4444
LPCXSTR lpszAPIUrl = _X("https://api.zhizengzeng.com/v1/chat/completions");
45-
LPCXSTR lpszAPIKey = _X("sk-1");
45+
LPCXSTR lpszAPIKey = _X("sk-zk2e0065dd7c8411828ce612337c2f9d1086841436f63c48");
4646
LPCXSTR lpszAPIModel = _X("gpt-4o");
4747

4848
//LPCXSTR lpszAPIUrl = _X("https://api.hunyuan.cloud.tencent.com/v1/chat/completions");
49-
//LPCXSTR lpszAPIKey = _X("sk-1");
49+
//LPCXSTR lpszAPIKey = _X("sk-dXVprOeQSWrodQcTYuHoGytHaifId7QlwaBebeWxfyPUipFk");
5050
//LPCXSTR lpszAPIModel = _X("hunyuan-turbos-latest");
5151

5252
if (!AIApi_Chat_Create(&xhToken, lpszAPIUrl, lpszAPIKey, XEngine_AIApi_CBRecv))

XEngine_Module/XEngine_InfoReport/InfoReport_APIMachine/InfoReport_APIMachine.cpp

Lines changed: 201 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,17 @@ bool CInfoReport_APIMachine::InfoReport_APIMachine_Send(LPCXSTR lpszAPIUrl, LPCX
7878
Json::StreamWriterBuilder st_JsonBuilder;
7979
Json::CharReaderBuilder st_JsonReader;
8080

81-
XCHAR tszMachineText[2048] = {};
82-
InfoReport_APIMachine_GetText(tszMachineText);
81+
XCHAR tszMachineSoftware[8192] = {};
82+
XCHAR tszMachineHardware[8192] = {};
83+
InfoReport_APIMachine_Hardware(tszMachineHardware);
84+
InfoReport_APIMachine_Software(tszMachineSoftware);
8385

8486
st_JsonRoot["tszServiceName"] = lpszServiceName;
8587
st_JsonRoot["tszMachineName"] = tszOSName;
8688
st_JsonRoot["tszMachineUser"] = tszUserName;
8789
st_JsonRoot["tszMachineSystem"] = tszComputerName;
88-
st_JsonRoot["tszMachineText"] = tszMachineText;
89-
90+
st_JsonRoot["tszMachineSoftware"] = tszMachineSoftware;
91+
st_JsonRoot["tszMachineHardware"] = tszMachineHardware;
9092
st_JsonBuilder["emitUTF8"] = true;
9193

9294
XCHAR* ptszMsgBuffer = NULL;
@@ -277,46 +279,212 @@ bool CInfoReport_APIMachine::InfoReport_APIMachine_Delete(LPCXSTR lpszAPIUrl, LP
277279
}
278280
return true;
279281
}
280-
//////////////////////////////////////////////////////////////////////////
281-
// 保护函数
282-
//////////////////////////////////////////////////////////////////////////
283-
bool CInfoReport_APIMachine::InfoReport_APIMachine_GetText(XCHAR* ptszMSGBuffer)
282+
/********************************************************************
283+
函数名称:InfoReport_APIMachine_Hardware
284+
函数功能:获取硬件信息
285+
参数.一:ptszHWInfo
286+
In/Out:Out
287+
类型:字符指针
288+
可空:N
289+
意思:导出获取到的数据,这个数据是JSON格式
290+
参数.二:pInt_Len
291+
In/Out:Out
292+
类型:整数型指针
293+
可空:Y
294+
意思:导出数据的长度
295+
返回值
296+
类型:逻辑型
297+
意思:是否成功
298+
备注:
299+
*********************************************************************/
300+
bool CInfoReport_APIMachine::InfoReport_APIMachine_Hardware(XCHAR* ptszSWInfo, int* pInt_Len /* = NULL */)
284301
{
285302
InfoReport_IsErrorOccur = false;
286303

287-
XCHAR tszOSName[128] = {};
288-
XCHAR tszOSVersion[128] = {};
289-
XCHAR tszOSBuild[128] = {};
290-
XLONG nOSArch = 0;
291-
int nProcessCount = 0;
304+
if ((NULL == ptszSWInfo))
305+
{
306+
InfoReport_IsErrorOccur = true;
307+
InfoReport_dwErrorCode = ERROR_XENGINE_THIRDPART_INFOREPORT_CODE;
308+
return false;
309+
}
310+
int nDiskNumber = 0;
311+
XCHAR** pptszRootName;
312+
SYSTEMAPI_DISK_INFOMATION st_DiskInfo = {};
292313
SYSTEMAPI_CPU_INFOMATION st_CPUInfo = {};
293314
SYSTEMAPI_MEMORY_INFOMATION st_MemoryInfo = {};
315+
SYSTEMAPI_SERIAL_INFOMATION st_SDKSerial = {};
316+
317+
if (!SystemApi_HardWare_GetDiskNumber(&pptszRootName, &nDiskNumber))
318+
{
319+
InfoReport_IsErrorOccur = true;
320+
InfoReport_dwErrorCode = SystemApi_GetLastError();
321+
return false;
322+
}
323+
BaseLib_Memory_Free((XPPPMEM)&pptszRootName, nDiskNumber);
324+
325+
XCHAR tszDriveStr[XPATH_MAX];
326+
memset(tszDriveStr, '\0', XPATH_MAX);
327+
#ifdef _MSC_BUILD
328+
GetLogicalDriveStringsA(XPATH_MAX, tszDriveStr);
329+
#else
330+
LPCXSTR lpszDir = _X("/");
331+
strcpy(tszDriveStr, lpszDir);
332+
#endif
333+
334+
if (!SystemApi_HardWare_GetDiskInfomation(tszDriveStr, &st_DiskInfo, XENGINE_SYSTEMSDK_API_SYSTEM_SIZE_MB))
335+
{
336+
InfoReport_IsErrorOccur = true;
337+
InfoReport_dwErrorCode = SystemApi_GetLastError();
338+
return false;
339+
}
340+
if (!SystemApi_HardWare_GetCpuInfomation(&st_CPUInfo))
341+
{
342+
InfoReport_IsErrorOccur = true;
343+
InfoReport_dwErrorCode = SystemApi_GetLastError();
344+
return false;
345+
}
346+
if (!SystemApi_System_GetMemoryUsage(&st_MemoryInfo, XENGINE_SYSTEMSDK_API_SYSTEM_SIZE_MB))
347+
{
348+
InfoReport_IsErrorOccur = true;
349+
InfoReport_dwErrorCode = SystemApi_GetLastError();
350+
return false;
351+
}
352+
if (!SystemApi_HardWare_GetSerial(&st_SDKSerial))
353+
{
354+
InfoReport_IsErrorOccur = true;
355+
InfoReport_dwErrorCode = SystemApi_GetLastError();
356+
return false;
357+
}
294358

295359
Json::Value st_JsonRoot;
296-
Json::Value st_JsonCPUObject;
297-
Json::Value st_JsonOSObject;
298-
Json::Value st_JsonMEMObject;
299-
Json::StreamWriterBuilder st_JsonBuilder;
360+
Json::Value st_JsonDisk;
361+
Json::Value st_JsonCpu;
362+
Json::Value st_JsonSerial;
363+
Json::Value st_JsonMemory;
364+
Json::Value st_JsonNetCard;
365+
366+
st_JsonDisk["DiskNumber"] = nDiskNumber;
367+
st_JsonDisk["DiskFree"] = (Json::UInt64)st_DiskInfo.dwDiskFree;
368+
st_JsonDisk["DiskTotal"] = (Json::UInt64)st_DiskInfo.dwDiskTotal;
369+
st_JsonDisk["DiskName"] = tszDriveStr;
370+
371+
st_JsonCpu["CpuNumber"] = st_CPUInfo.nCPUNumber;
372+
st_JsonCpu["CpuSpeed"] = st_CPUInfo.nCPUSpeed;
373+
st_JsonCpu["CpuName"] = st_CPUInfo.tszCPUName;
374+
375+
st_JsonMemory["MemoryFree"] = (Json::UInt64)st_MemoryInfo.dwMemory_Free;
376+
st_JsonMemory["MemoryTotal"] = (Json::UInt64)st_MemoryInfo.dwMemory_Total;
377+
378+
st_JsonSerial["DiskSerial"] = st_SDKSerial.tszDiskSerial;
379+
st_JsonSerial["CpuSerial"] = st_SDKSerial.tszCPUSerial;
380+
st_JsonSerial["BoardSerial"] = st_SDKSerial.tszBoardSerial;
381+
st_JsonSerial["SystemSerial"] = st_SDKSerial.tszSystemSerial;
382+
383+
int nListCount = 0;
384+
XSOCKET_CARDINFO** ppSt_ListIFInfo;
385+
XSocket_Api_GetCardInfo(&ppSt_ListIFInfo, &nListCount);
386+
for (int i = 0; i < nListCount; i++)
387+
{
388+
Json::Value st_JsonIPAddr;
389+
st_JsonIPAddr["tszIFName"] = ppSt_ListIFInfo[i]->tszIFName;
390+
st_JsonIPAddr["tszIPAddr"] = ppSt_ListIFInfo[i]->tszIPAddr;
391+
st_JsonIPAddr["tszBroadAddr"] = ppSt_ListIFInfo[i]->tszBroadAddr;
392+
st_JsonIPAddr["tszDnsAddr"] = ppSt_ListIFInfo[i]->tszDnsAddr;
393+
st_JsonIPAddr["tszMacAddr"] = ppSt_ListIFInfo[i]->tszMacAddr;
394+
st_JsonNetCard.append(st_JsonIPAddr);
395+
}
396+
BaseLib_Memory_Free((XPPPMEM)&ppSt_ListIFInfo, nListCount);
300397

301-
SystemApi_System_GetSystemVer(tszOSName, tszOSVersion, tszOSBuild, &nOSArch);
302-
SystemApi_HardWare_GetCpuInfomation(&st_CPUInfo);
303-
SystemApi_System_GetMemoryUsage(&st_MemoryInfo, XENGINE_SYSTEMSDK_API_SYSTEM_SIZE_MB);
304-
SystemApi_System_GetProcessCount(&nProcessCount);
398+
st_JsonRoot["Disk"] = st_JsonDisk;
399+
st_JsonRoot["Cpu"] = st_JsonCpu;
400+
st_JsonRoot["Memory"] = st_JsonMemory;
401+
st_JsonRoot["Serial"] = st_JsonSerial;
402+
st_JsonRoot["NetCard"] = st_JsonNetCard;
403+
404+
if (NULL != pInt_Len)
405+
{
406+
*pInt_Len = st_JsonRoot.toStyledString().length();
407+
}
408+
memcpy(ptszSWInfo, st_JsonRoot.toStyledString().c_str(), st_JsonRoot.toStyledString().length());
409+
410+
return true;
411+
}
412+
/********************************************************************
413+
函数名称:InfoReport_APIMachine_Software
414+
函数功能:获取软件系统信息
415+
参数.一:ptszSWInfo
416+
In/Out:Out
417+
类型:字符指针
418+
可空:N
419+
意思:导出系统信息JSON结构
420+
参数.二:pInt_Len
421+
In/Out:Out
422+
类型:整数型指针
423+
可空:Y
424+
意思:导出系统信息长度
425+
返回值
426+
类型:逻辑型
427+
意思:是否成功
428+
备注:
429+
*********************************************************************/
430+
bool CInfoReport_APIMachine::InfoReport_APIMachine_Software(XCHAR* ptszSWInfo, int* pInt_Len /* = NULL */)
431+
{
432+
InfoReport_IsErrorOccur = false;
433+
434+
if ((NULL == ptszSWInfo))
435+
{
436+
InfoReport_IsErrorOccur = true;
437+
InfoReport_dwErrorCode = ERROR_XENGINE_THIRDPART_INFOREPORT_PARAMENT;
438+
return false;
439+
}
440+
int nProcessCount = 0;
441+
XLONG nOSProcessor = 0;
442+
XCHAR tszOSBuild[256] = {};
443+
XCHAR tszOSVersion[256] = {};
444+
XCHAR tszOSInfo[256] = {};
445+
XCHAR tszUPTime[256] = {};
446+
XCHAR tszServicePacket[256] = {};
447+
XENGINE_LIBTIME st_LibTimer = {};
448+
SYSTEMAPI_CPU_INFOMATION st_CPUInfo = {};
305449

306-
st_JsonCPUObject["nCPUNumber"] = st_CPUInfo.nCPUNumber;
307-
st_JsonCPUObject["nCPUSpeed"] = st_CPUInfo.nCPUSpeed;
308-
st_JsonOSObject["OSArch"] = (Json::Value::Int)nOSArch;
309-
st_JsonOSObject["OSVersion"] = tszOSVersion;
310-
st_JsonOSObject["tszOSBuild"] = tszOSBuild;
450+
if (!SystemApi_System_GetSystemVer(tszOSInfo, tszOSVersion, tszOSBuild, &nOSProcessor))
451+
{
452+
InfoReport_IsErrorOccur = true;
453+
InfoReport_dwErrorCode = SystemApi_GetLastError();
454+
return false;
455+
}
456+
if (!SystemApi_System_GetProcessCount(&nProcessCount))
457+
{
458+
InfoReport_IsErrorOccur = true;
459+
InfoReport_dwErrorCode = SystemApi_GetLastError();
460+
return false;
461+
}
462+
if (!SystemApi_System_GetUpTime(&st_LibTimer))
463+
{
464+
InfoReport_IsErrorOccur = true;
465+
InfoReport_dwErrorCode = SystemApi_GetLastError();
466+
return false;
467+
}
311468

312-
st_JsonMEMObject["nTotal"] = (Json::Value::UInt64)st_MemoryInfo.dwMemory_Total;
313-
st_JsonMEMObject["nFree"] = (Json::Value::UInt64)st_MemoryInfo.dwMemory_Free;
469+
sprintf(tszUPTime, "%04d-%02d-%02d %02d:%02d:%02d", st_LibTimer.wYear, st_LibTimer.wMonth, st_LibTimer.wDay, st_LibTimer.wHour, st_LibTimer.wMinute, st_LibTimer.wSecond);
314470

315-
st_JsonRoot["nProcessCount"] = nProcessCount;
316-
st_JsonRoot["st_CPUObject"] = st_JsonCPUObject;
317-
st_JsonRoot["st_OSObject"] = st_JsonOSObject;
318-
st_JsonRoot["st_MEMObject"] = st_JsonMEMObject;
471+
Json::Value st_JsonRoot;
472+
Json::Value st_JsonSystem;
473+
474+
st_JsonSystem["OSUPTime"] = tszUPTime;
475+
st_JsonSystem["OSVersion"] = tszOSInfo;
476+
st_JsonSystem["OSVersion"] = tszOSVersion;
477+
st_JsonSystem["OSBuild"] = tszOSBuild;
478+
st_JsonSystem["OSArch"] = (Json::Value::Int)nOSProcessor;
479+
st_JsonSystem["OSProcessCount"] = nProcessCount;
480+
481+
st_JsonRoot["OSInfo"] = st_JsonSystem;
482+
483+
if (NULL != pInt_Len)
484+
{
485+
*pInt_Len = st_JsonRoot.toStyledString().length();
486+
}
487+
memcpy(ptszSWInfo, st_JsonRoot.toStyledString().c_str(), st_JsonRoot.toStyledString().length());
319488

320-
_tcsxcpy(ptszMSGBuffer, st_JsonRoot.toStyledString().c_str());
321489
return true;
322490
}

XEngine_Module/XEngine_InfoReport/InfoReport_APIMachine/InfoReport_APIMachine.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class CInfoReport_APIMachine
2020
bool InfoReport_APIMachine_Send(LPCXSTR lpszAPIUrl, LPCXSTR lpszServiceName, __int64x* pInt_TimeNumber = NULL);
2121
bool InfoReport_APIMachine_GetTime(LPCXSTR lpszAPIUrl, LPCXSTR lpszServiceName, __int64x* pInt_TimeNumber);
2222
bool InfoReport_APIMachine_Delete(LPCXSTR lpszAPIUrl, LPCXSTR lpszServiceName);
23+
public:
24+
bool InfoReport_APIMachine_Hardware(XCHAR* ptszSWInfo, int* pInt_Len = NULL);
25+
bool InfoReport_APIMachine_Software(XCHAR* ptszSWInfo, int* pInt_Len = NULL);
2326
protected:
24-
bool InfoReport_APIMachine_GetText(XCHAR *ptszMSGBuffer);
2527
};

XEngine_Module/XEngine_InfoReport/InfoReport_Define.h

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,42 @@ extern "C" bool InfoReport_APIMachine_GetTime(LPCXSTR lpszAPIUrl, LPCXSTR lpszSe
8383
意思:是否成功
8484
备注:lpszAPIUrl = _X("http://127.0.0.1:5501/api?function=machine");
8585
*********************************************************************/
86-
extern "C" bool InfoReport_APIMachine_Delete(LPCXSTR lpszAPIUrl, LPCXSTR lpszServiceName);
86+
extern "C" bool InfoReport_APIMachine_Delete(LPCXSTR lpszAPIUrl, LPCXSTR lpszServiceName);
87+
/********************************************************************
88+
函数名称:InfoReport_APIMachine_Hardware
89+
函数功能:获取硬件信息
90+
参数.一:ptszHWInfo
91+
In/Out:Out
92+
类型:字符指针
93+
可空:N
94+
意思:导出获取到的数据,这个数据是JSON格式
95+
参数.二:pInt_Len
96+
In/Out:Out
97+
类型:整数型指针
98+
可空:Y
99+
意思:导出数据的长度
100+
返回值
101+
类型:逻辑型
102+
意思:是否成功
103+
备注:
104+
*********************************************************************/
105+
extern "C" bool InfoReport_APIMachine_Hardware(XCHAR* ptszSWInfo, int* pInt_Len = NULL);
106+
/********************************************************************
107+
函数名称:InfoReport_APIMachine_Software
108+
函数功能:获取软件系统信息
109+
参数.一:ptszSWInfo
110+
In/Out:Out
111+
类型:字符指针
112+
可空:N
113+
意思:导出系统信息JSON结构
114+
参数.二:pInt_Len
115+
In/Out:Out
116+
类型:整数型指针
117+
可空:Y
118+
意思:导出系统信息长度
119+
返回值
120+
类型:逻辑型
121+
意思:是否成功
122+
备注:
123+
*********************************************************************/
124+
extern "C" bool InfoReport_APIMachine_Software(XCHAR* ptszSWInfo, int* pInt_Len = NULL);

XEngine_Module/XEngine_InfoReport/XEngine_InfoReport.def

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ EXPORTS
55

66
InfoReport_APIMachine_Send
77
InfoReport_APIMachine_GetTime
8-
InfoReport_APIMachine_Delete
8+
InfoReport_APIMachine_Delete
9+
10+
InfoReport_APIMachine_Hardware
11+
InfoReport_APIMachine_Software

XEngine_Module/XEngine_InfoReport/pch.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,12 @@ extern "C" bool InfoReport_APIMachine_GetTime(LPCXSTR lpszAPIUrl, LPCXSTR lpszSe
4040
extern "C" bool InfoReport_APIMachine_Delete(LPCXSTR lpszAPIUrl, LPCXSTR lpszServiceName)
4141
{
4242
return m_APIMachine.InfoReport_APIMachine_Delete(lpszAPIUrl, lpszServiceName);
43+
}
44+
extern "C" bool InfoReport_APIMachine_Hardware(XCHAR* ptszSWInfo, int* pInt_Len)
45+
{
46+
return m_APIMachine.InfoReport_APIMachine_Hardware(ptszSWInfo, pInt_Len);
47+
}
48+
extern "C" bool InfoReport_APIMachine_Software(XCHAR* ptszSWInfo, int* pInt_Len)
49+
{
50+
return m_APIMachine.InfoReport_APIMachine_Software(ptszSWInfo, pInt_Len);
4351
}

XEngine_Module/XEngine_InfoReport/pch.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#include <XEngine_Include/XEngine_SystemSdk/SystemApi_Error.h>
3434
#include <XEngine_Include/XEngine_Client/APIClient_Define.h>
3535
#include <XEngine_Include/XEngine_Client/APIClient_Error.h>
36+
#include <XEngine_Include/XEngine_NetHelp/XSocket_Define.h>
37+
#include <XEngine_Include/XEngine_NetHelp/XSocket_Error.h>
3638
#include "InfoReport_Define.h"
3739
#include "InfoReport_Error.h"
3840
/********************************************************************
@@ -53,6 +55,7 @@ extern XLONG InfoReport_dwErrorCode;
5355
#pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib")
5456
#pragma comment(lib,"XEngine_SystemSdk/XEngine_SystemApi")
5557
#pragma comment(lib,"XEngine_Client/XClient_APIHelp")
58+
#pragma comment(lib,"XEngine_NetHelp/NetHelp_XSocket")
5659
#ifdef _DEBUG
5760
#ifdef _M_X64
5861
#pragma comment(lib,"x64/Debug/jsoncpp")

0 commit comments

Comments
 (0)