增加获取服务器驱动列表的功能
This commit is contained in:
parent
110641b7e7
commit
740f49fdab
|
@ -28,3 +28,4 @@ HGVersion_ReleaseVersionList
|
||||||
HGVersion_GetCurrVersion
|
HGVersion_GetCurrVersion
|
||||||
HGVersion_CompareVersion
|
HGVersion_CompareVersion
|
||||||
HGVersion_BlackListCheck
|
HGVersion_BlackListCheck
|
||||||
|
HGVersion_GetDriverVersionList
|
|
@ -317,3 +317,14 @@ HGResult HGAPI HGVersion_BlackListCheck(HGVersionMgr mgr, const HGChar* devSN, H
|
||||||
HGVersionMgrImpl* versionMgrImpl = (HGVersionMgrImpl*)mgr;
|
HGVersionMgrImpl* versionMgrImpl = (HGVersionMgrImpl*)mgr;
|
||||||
return versionMgrImpl->BlackListCheck(devSN, inList);
|
return versionMgrImpl->BlackListCheck(devSN, inList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HGResult HGAPI HGVersion_GetDriverVersionList(HGVersionMgr mgr, const HGChar* devType, HGVersionInfo** info, HGUInt* count)
|
||||||
|
{
|
||||||
|
if (NULL == mgr)
|
||||||
|
{
|
||||||
|
return HGBASE_ERR_INVALIDARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
HGVersionMgrImpl* versionMgrImpl = (HGVersionMgrImpl*)mgr;
|
||||||
|
return versionMgrImpl->GetDriverVersionList(devType, info, count);
|
||||||
|
}
|
|
@ -7,7 +7,6 @@
|
||||||
HG_DECLARE_HANDLE(HGVersionMgr);
|
HG_DECLARE_HANDLE(HGVersionMgr);
|
||||||
|
|
||||||
#define HGVERSION_APPNAME_SCANNER "Scanner"
|
#define HGVERSION_APPNAME_SCANNER "Scanner"
|
||||||
#define HGVERSION_APPNAME_DRIVER "Driver"
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
@ -78,4 +77,7 @@ HGEXPORT HGResult HGAPI HGVersion_CompareVersion(const HGChar* version1, const H
|
||||||
|
|
||||||
HGEXPORT HGResult HGAPI HGVersion_BlackListCheck(HGVersionMgr mgr, const HGChar* devSN, HGBool *inList);
|
HGEXPORT HGResult HGAPI HGVersion_BlackListCheck(HGVersionMgr mgr, const HGChar* devSN, HGBool *inList);
|
||||||
|
|
||||||
|
// 驱动
|
||||||
|
HGEXPORT HGResult HGAPI HGVersion_GetDriverVersionList(HGVersionMgr mgr, const HGChar* devType, HGVersionInfo** info, HGUInt* count);
|
||||||
|
|
||||||
#endif /* __HGVERSION_H__ */
|
#endif /* __HGVERSION_H__ */
|
|
@ -1438,6 +1438,144 @@ HGResult HGVersionMgrImpl::BlackListCheck(const HGChar* devSN, HGBool* inList)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static HGResult GetDriverVersionList(const std::string& devType, std::list<VersionInfoImpl>& versionList)
|
||||||
|
{
|
||||||
|
versionList.clear();
|
||||||
|
|
||||||
|
HGResult ret = HGBASE_ERR_FAIL;
|
||||||
|
CURL* curl = curl_easy_init();
|
||||||
|
if (NULL != curl)
|
||||||
|
{
|
||||||
|
std::stringstream out;
|
||||||
|
|
||||||
|
std::string url = "http://cd.holdtecs.net:50080/api/ver?app=Driver&dev_type=" + devType;
|
||||||
|
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 2);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||||
|
|
||||||
|
struct curl_slist* headers = NULL;
|
||||||
|
headers = curl_slist_append(headers, "Accept-Encoding:gzip, deflate, sdch");
|
||||||
|
headers = curl_slist_append(headers, "Accept-Language:zh-CN,zh;q=0.8");
|
||||||
|
headers = curl_slist_append(headers, "Connection:keep-alive");
|
||||||
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
|
||||||
|
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &out);
|
||||||
|
|
||||||
|
/* Perform the request, res will get the return code */
|
||||||
|
CURLcode res = curl_easy_perform(curl);
|
||||||
|
/* Check for errors */
|
||||||
|
if (res != CURLE_OK)
|
||||||
|
fprintf(stderr, "curl_easy_perform() failed: %s", curl_easy_strerror(res));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::string str_json = out.str(); // 返回值
|
||||||
|
HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "str_json=%s", str_json.c_str());
|
||||||
|
|
||||||
|
cJSON* json = cJSON_Parse(str_json.c_str());
|
||||||
|
if (NULL != json)
|
||||||
|
{
|
||||||
|
cJSON* p = json->child;
|
||||||
|
while (NULL != p)
|
||||||
|
{
|
||||||
|
if (0 == strcmp(p->string, "code") && p->type == cJSON_Number)
|
||||||
|
{
|
||||||
|
if (1 == p->valueint)
|
||||||
|
ret = HGBASE_ERR_OK;
|
||||||
|
}
|
||||||
|
else if (0 == strcmp(p->string, "data") && p->type == cJSON_Array)
|
||||||
|
{
|
||||||
|
cJSON* p2 = p->child;
|
||||||
|
while (NULL != p2)
|
||||||
|
{
|
||||||
|
VersionInfoImpl version;
|
||||||
|
|
||||||
|
cJSON* p3 = p2->child;
|
||||||
|
while (NULL != p3)
|
||||||
|
{
|
||||||
|
if (0 == strcmp(p3->string, "full") && p3->type == cJSON_String)
|
||||||
|
version.url = p3->valuestring;
|
||||||
|
else if (0 == strcmp(p3->string, "size") && p3->type == cJSON_String)
|
||||||
|
version.size = atoll(p3->valuestring);
|
||||||
|
else if (0 == strcmp(p3->string, "desc") && p3->type == cJSON_String)
|
||||||
|
version.desc = p3->valuestring;
|
||||||
|
else if (0 == strcmp(p3->string, "bug") && p3->type == cJSON_String)
|
||||||
|
version.bugInfo = p3->valuestring;
|
||||||
|
else if (0 == strcmp(p3->string, "md5") && p3->type == cJSON_String)
|
||||||
|
version.md5 = p3->valuestring;
|
||||||
|
else if (0 == strcmp(p3->string, "v") && p3->type == cJSON_String)
|
||||||
|
version.version = p3->valuestring;
|
||||||
|
|
||||||
|
p3 = p3->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
versionList.push_back(version);
|
||||||
|
p2 = p2->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
p = p->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON_Delete(json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
curl_slist_free_all(headers);
|
||||||
|
/* always cleanup */
|
||||||
|
curl_easy_cleanup(curl);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
HGResult HGVersionMgrImpl::GetDriverVersionList(const HGChar* devType, HGVersionInfo** info, HGUInt* count)
|
||||||
|
{
|
||||||
|
if (NULL == info || NULL == count)
|
||||||
|
{
|
||||||
|
return HGBASE_ERR_INVALIDARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::list<VersionInfoImpl> versionList;
|
||||||
|
HGResult ret = ::GetDriverVersionList(devType, versionList);
|
||||||
|
if (HGBASE_ERR_OK != ret)
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (versionList.empty())
|
||||||
|
{
|
||||||
|
return HGBASE_ERR_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
HGUInt count2 = (HGUInt)versionList.size();
|
||||||
|
HGVersionInfo* info2 = new HGVersionInfo[count2];
|
||||||
|
|
||||||
|
HGUInt index = 0;
|
||||||
|
std::list<VersionInfoImpl>::const_iterator iter;
|
||||||
|
for (iter = versionList.begin(); iter != versionList.end(); ++iter)
|
||||||
|
{
|
||||||
|
const VersionInfoImpl& ver = *iter;
|
||||||
|
info2[index].version = new HGChar[ver.version.size() + 1];
|
||||||
|
strcpy(info2[index].version, ver.version.c_str());
|
||||||
|
info2[index].desc = new HGChar[ver.desc.size() + 1];
|
||||||
|
strcpy(info2[index].desc, ver.desc.c_str());
|
||||||
|
info2[index].bugInfo = new HGChar[ver.bugInfo.size() + 1];
|
||||||
|
strcpy(info2[index].bugInfo, ver.bugInfo.c_str());
|
||||||
|
info2[index].url = new HGChar[ver.url.size() + 1];
|
||||||
|
strcpy(info2[index].url, ver.url.c_str());
|
||||||
|
info2[index].size = ver.size;
|
||||||
|
info2[index].md5 = new HGChar[ver.md5.size() + 1];
|
||||||
|
strcpy(info2[index].md5, ver.md5.c_str());
|
||||||
|
|
||||||
|
++index;
|
||||||
|
}
|
||||||
|
|
||||||
|
*info = info2;
|
||||||
|
*count = count2;
|
||||||
|
return HGBASE_ERR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
void HGVersionMgrImpl::ThreadFunc(HGThread thread, HGPointer param)
|
void HGVersionMgrImpl::ThreadFunc(HGThread thread, HGPointer param)
|
||||||
{
|
{
|
||||||
HGVersionMgrImpl* p = (HGVersionMgrImpl*)param;
|
HGVersionMgrImpl* p = (HGVersionMgrImpl*)param;
|
||||||
|
|
|
@ -45,6 +45,8 @@ public:
|
||||||
static HGResult GetCurrVersion(const HGChar* appName, HGChar* version, HGUInt maxLen);
|
static HGResult GetCurrVersion(const HGChar* appName, HGChar* version, HGUInt maxLen);
|
||||||
HGResult BlackListCheck(const HGChar* devSN, HGBool* inList);
|
HGResult BlackListCheck(const HGChar* devSN, HGBool* inList);
|
||||||
|
|
||||||
|
HGResult GetDriverVersionList(const HGChar* devType, HGVersionInfo** info, HGUInt* count);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void ThreadFunc(HGThread thread, HGPointer param);
|
static void ThreadFunc(HGThread thread, HGPointer param);
|
||||||
static void MsgPumpFunc(HGMsgPump msgPump, const HGMsg* msg, HGPointer param);
|
static void MsgPumpFunc(HGMsgPump msgPump, const HGMsg* msg, HGPointer param);
|
||||||
|
|
Loading…
Reference in New Issue