diff --git a/build/windows/HGVersion/HGVersion.def b/build/windows/HGVersion/HGVersion.def index bc9bc63a..d7695080 100644 --- a/build/windows/HGVersion/HGVersion.def +++ b/build/windows/HGVersion/HGVersion.def @@ -27,4 +27,5 @@ HGVersion_HttpDownload HGVersion_ReleaseVersionList HGVersion_GetCurrVersion HGVersion_CompareVersion -HGVersion_BlackListCheck \ No newline at end of file +HGVersion_BlackListCheck +HGVersion_GetDriverVersionList \ No newline at end of file diff --git a/modules/version/HGVersion.cpp b/modules/version/HGVersion.cpp index c60ac6f3..19c359d4 100644 --- a/modules/version/HGVersion.cpp +++ b/modules/version/HGVersion.cpp @@ -316,4 +316,15 @@ HGResult HGAPI HGVersion_BlackListCheck(HGVersionMgr mgr, const HGChar* devSN, H HGVersionMgrImpl* versionMgrImpl = (HGVersionMgrImpl*)mgr; 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); } \ No newline at end of file diff --git a/modules/version/HGVersion.h b/modules/version/HGVersion.h index ee6a6920..a6c43d52 100644 --- a/modules/version/HGVersion.h +++ b/modules/version/HGVersion.h @@ -7,7 +7,6 @@ HG_DECLARE_HANDLE(HGVersionMgr); #define HGVERSION_APPNAME_SCANNER "Scanner" -#define HGVERSION_APPNAME_DRIVER "Driver" 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_GetDriverVersionList(HGVersionMgr mgr, const HGChar* devType, HGVersionInfo** info, HGUInt* count); + #endif /* __HGVERSION_H__ */ \ No newline at end of file diff --git a/modules/version/HGVersionImpl.cpp b/modules/version/HGVersionImpl.cpp index 254d56a2..75e811a0 100644 --- a/modules/version/HGVersionImpl.cpp +++ b/modules/version/HGVersionImpl.cpp @@ -1438,6 +1438,144 @@ HGResult HGVersionMgrImpl::BlackListCheck(const HGChar* devSN, HGBool* inList) return ret; } +static HGResult GetDriverVersionList(const std::string& devType, std::list& 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 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::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) { HGVersionMgrImpl* p = (HGVersionMgrImpl*)param; diff --git a/modules/version/HGVersionImpl.hpp b/modules/version/HGVersionImpl.hpp index 540ae620..3d17ddf7 100644 --- a/modules/version/HGVersionImpl.hpp +++ b/modules/version/HGVersionImpl.hpp @@ -45,6 +45,8 @@ public: static HGResult GetCurrVersion(const HGChar* appName, HGChar* version, HGUInt maxLen); HGResult BlackListCheck(const HGChar* devSN, HGBool* inList); + HGResult GetDriverVersionList(const HGChar* devType, HGVersionInfo** info, HGUInt* count); + private: static void ThreadFunc(HGThread thread, HGPointer param); static void MsgPumpFunc(HGMsgPump msgPump, const HGMsg* msg, HGPointer param);