#include "VersionDll.h" #include "base/HGDef.h" #include "base/HGInc.h" VersionDll::VersionDll() { m_dll = NULL; m_funcCreateMgr = NULL; m_funcDestroyMgr = NULL; m_funcGetServerConfig = NULL; m_funcGetVersionList = NULL; m_funcPostCrashInfo = NULL; m_funcPostUserFeedback = NULL; m_funcHttpDownload = NULL; m_funcReleaseVersionList = NULL; m_funcGetCurrVersion = NULL; m_funcCompareVersion = NULL; m_mgr = NULL; Load(); } VersionDll::~VersionDll() { Free(); } HGResult VersionDll::Load() { if (NULL != m_dll) { return HGBASE_ERR_FAIL; } #if defined(HG_CMP_MSC) #if defined(OEM_HANWANG) HGBase_CreateDll("HwVersion.dll", &m_dll); #elif defined(OEM_LISICHENG) HGBase_CreateDll("LscVersion.dll", &m_dll); #else HGBase_CreateDll("HGVersion.dll", &m_dll); #endif #else #if defined(OEM_HANWANG) HGBase_CreateDll("libHwVersion.so", &m_dll); #elif defined(OEM_LISICHENG) HGBase_CreateDll("libLscVersion.so", &m_dll); #else HGBase_CreateDll("libHGVersion.so", &m_dll); #endif #endif if (NULL == m_dll) { return HGBASE_ERR_FAIL; } bool ok = true; do { HGBase_GetDllProcAddress(m_dll, "HGVersion_CreateMgr", (HGPointer *)&m_funcCreateMgr); if (NULL == m_funcCreateMgr) { ok = false; break; } HGBase_GetDllProcAddress(m_dll, "HGVersion_DestroyMgr", (HGPointer *)&m_funcDestroyMgr); if (NULL == m_funcDestroyMgr) { ok = false; break; } HGBase_GetDllProcAddress(m_dll, "HGVersion_GetServerConfig", (HGPointer *)&m_funcGetServerConfig); if (NULL == m_funcGetServerConfig) { ok = false; break; } HGBase_GetDllProcAddress(m_dll, "HGVersion_PostCrashInfo", (HGPointer *)&m_funcPostCrashInfo); if (NULL == m_funcPostCrashInfo) { ok = false; break; } HGBase_GetDllProcAddress(m_dll, "HGVersion_PostUserFeedback", (HGPointer *)&m_funcPostUserFeedback); if (NULL == m_funcPostUserFeedback) { ok = false; break; } HGBase_GetDllProcAddress(m_dll, "HGVersion_GetVersionList", (HGPointer *)&m_funcGetVersionList); if (NULL == m_funcGetVersionList) { ok = false; break; } HGBase_GetDllProcAddress(m_dll, "HGVersion_HttpDownload", (HGPointer *)&m_funcHttpDownload); if (NULL == m_funcHttpDownload) { ok = false; break; } HGBase_GetDllProcAddress(m_dll, "HGVersion_ReleaseVersionList", (HGPointer *)&m_funcReleaseVersionList); if (NULL == m_funcReleaseVersionList) { ok = false; break; } HGBase_GetDllProcAddress(m_dll, "HGVersion_GetCurrVersion", (HGPointer *)&m_funcGetCurrVersion); if (NULL == m_funcGetCurrVersion) { ok = false; break; } HGBase_GetDllProcAddress(m_dll, "HGVersion_CompareVersion", (HGPointer *)&m_funcCompareVersion); if (NULL == m_funcCompareVersion) { ok = false; break; } m_funcCreateMgr(&m_mgr); if (NULL == m_mgr) { ok = false; break; } }while (0); if (!ok) { m_funcCreateMgr = NULL; m_funcDestroyMgr = NULL; m_funcGetServerConfig = NULL; m_funcGetVersionList = NULL; m_funcPostCrashInfo = NULL; m_funcPostUserFeedback = NULL; m_funcHttpDownload = NULL; m_funcReleaseVersionList = NULL; m_funcGetCurrVersion = NULL; m_funcCompareVersion = NULL; HGBase_DestroyDll(m_dll); m_dll = NULL; return HGBASE_ERR_FAIL; } return HGBASE_ERR_OK; } HGResult VersionDll::Free() { if (NULL == m_dll) { return HGBASE_ERR_FAIL; } m_funcDestroyMgr(m_mgr); m_mgr = NULL; HGBase_DestroyDll(m_dll); m_dll = NULL; } HGBool VersionDll::IsValid() { return (NULL != m_dll); } HGResult VersionDll::GetServerConfig(HGServerConfig *config) { if (NULL == m_funcGetServerConfig) { return HGBASE_ERR_FAIL; } return m_funcGetServerConfig(m_mgr, config); } HGResult VersionDll::GetVersionList(const HGChar* appName, HGVersionInfo **info, HGUInt *count) { if (NULL == m_funcGetVersionList) { return HGBASE_ERR_FAIL; } return m_funcGetVersionList(m_mgr, appName, info, count); } HGResult VersionDll::HttpDownload(const HGChar *url, const HGChar *saveFilePath, HGHttpDownloadFunc func, HGPointer param) { if (NULL == m_funcHttpDownload) { return HGBASE_ERR_FAIL; } return m_funcHttpDownload(m_mgr, url, saveFilePath, func, param); } HGResult VersionDll::ReleaseVersionList(HGVersionInfo* info, HGUInt count) { if (NULL == m_funcReleaseVersionList) { return HGBASE_ERR_FAIL; } return m_funcReleaseVersionList(info, count); } HGResult VersionDll::GetCurrVersion(const HGChar* appName, HGChar* version, HGUInt maxLen) { if (NULL == m_funcGetCurrVersion) { return HGBASE_ERR_FAIL; } return m_funcGetCurrVersion(appName, version, maxLen); } HGResult VersionDll::CompareVersion(const HGChar* version1, const HGChar* version2, HGInt* result) { if (NULL == m_funcCompareVersion) { return HGBASE_ERR_FAIL; } return m_funcCompareVersion(version1, version2, result); } HGResult VersionDll::PostCrashInfo(const HGChar* appName, const HGChar* desc, const HGChar* crashFilePath, const HGChar* exceptionAddr) { if (NULL == m_funcPostCrashInfo) { return HGBASE_ERR_FAIL; } return m_funcPostCrashInfo(m_mgr, appName, desc, crashFilePath, exceptionAddr); } HGResult VersionDll::PostUserFeedback(const HGChar* appName, const HGChar* desc, const HGChar* feedback, const HGChar* contact) { if (NULL == m_funcPostUserFeedback) { return HGBASE_ERR_FAIL; } return m_funcPostUserFeedback(m_mgr, appName, desc, feedback, contact); }