Sfoglia il codice sorgente

Z991239-6443 #comment 健康实体 加载 guardianbase

80374374 4 mesi fa
parent
commit
95f339951e

+ 5 - 23
Module/mod_healthmanager/HealthManagerFSM.cpp

@@ -5,6 +5,8 @@
 #include <regex>
 #include "SpUtility.h"
 #include "iniutil.h"
+#include "fileutil.h"
+
 #if defined(RVC_OS_WIN)
 #include <TlHelp32.h>
 #include <iphlpapi.h>
@@ -27,15 +29,6 @@ using namespace std;
 const int MAX_AYSNC_TIMEOUT = 60000;
 const int MAX_IGNORE_TIMEOUT = 100;
 
-//TODO: CrossPlaform  [Gifur@2025730]
-unsigned long long GetLastErrorRVC() {
-#if defined(RVC_OS_WIN)
-	return GetLastError();
-#else
-	return errno;
-#endif //RVC_OS_WIN
-}
-
 enum EntityOP
 {
 	OP_STOP_ENTITY,
@@ -799,14 +792,8 @@ void CHealthManagerFSM::ToLogWarnTermAboutInfo()
 	char elapseTime[64] = {0};//使用机器启动时间秒数
 	ULONGLONG dwElapse = SP::Module::Comm::RVCGetTickCount();
 	DWORD elapseTimeTemp = dwElapse / 1000;
-	//TODO: CrossPlaform  [Gifur@2025729]
-#if defined(RVC_OS_WIN)
-	termInfo["OSTime"] = itoa(m_elapseTimeFromOSStart, xOSTime, 10);
-	termInfo["elapseTime"] = itoa(elapseTimeTemp, elapseTime, 10);
-#else
 	termInfo["OSTime"] = _itoa(m_elapseTimeFromOSStart, xOSTime, 10);
 	termInfo["elapseTime"] = _itoa(elapseTimeTemp, elapseTime, 10);
-#endif
 	
 	CSimpleStringA csRunPath("");
 	GetEntityBase()->GetFunction()->GetPath("Run", csRunPath);
@@ -846,12 +833,7 @@ bool CHealthManagerFSM::IfInUpgradeProcess()
 	ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("RunCfg", csRunCfgPath);
 	csFileName = csRunCfgPath + SPLIT_SLASH_STR + "starttime.dat";
 	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("csFileName:%s", csFileName.GetData());
-	//TODO: CrossPlaform  [Gifur@2025730]
-#if defined(RVC_OS_WIN)
-	if (_access((const char*)csFileName, 0) == 0) {
-#else
-	if (access((const char*)csFileName, F_OK) == 0) {
-#endif
+	if (ExistsFileA(csFileName)) {
 		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("升级切换中");
 		return true;
 	}
@@ -1143,7 +1125,7 @@ void CHealthManagerFSM::QueryAndSendCPUInfo()
 #else
 	ifstream cpuinfo("/proc/cpuinfo");
 	if (!cpuinfo.is_open()) {
-		DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("opening /proc/cpuinfo error:%s", strerror(GetLastErrorRVC()));
+		DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("opening /proc/cpuinfo error:%s", strerror(errno));
 		return;
 	}
 	std::map<std::string, std::string> map_cpuInfo;
@@ -1310,7 +1292,7 @@ void CHealthManagerFSM::CheckIfPinPadOK()
 			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("connect to pinpad failed.error code:%d", eErrCode);
 	}
 	else
-		DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("new PinPadService_ClientBase failed.GetLastError:%d", GetLastErrorRVC());
+		DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("new PinPadService_ClientBase failed.GetLastError:%d", GetLastError());
 	m_ullWaitForPinPad = ullWaitEnd - ullWaitStart;
 	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501A3").setCostTime(m_ullWaitForPinPad)("finish (or time out) check  PinPad");
 	return;

+ 32 - 61
Module/mod_healthmanager/mod_healthmanager.cpp

@@ -384,28 +384,15 @@ void CHealthManagerEntity::OnCheckTimeTimeout()
 				ErrorCodeEnum eErr = GetFunction()->GetPath("RunCfg", csRunCfgPath);
 				csStartTime = csRunCfgPath + SPLIT_SLASH_STR + "starttime.dat";
 				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("csStartTime:%s", csStartTime.GetData());
-
-				//TODO: CrossPlaform  [Gifur@2025728]
-#if defined(RVC_OS_WIN)
-				if (_access((const char*)csStartTime, 0) == 0) {
-					int ret = DeleteFileA(csStartTime);//oiltmp@20240423 why don't use remove ,what's the different?
-					if (ret != 0)//删除成功,清理前次记录的guardian版本记录
-					{
-						DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("delete start time file [%s] suc.", csStartTime.GetData());
-						spConfigRun->WriteConfigValue("Run", "VersionEx", "");
-					}
-					else
-						DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("delete time file [%s] error.[%d]", csStartTime.GetData(), GetLastError());
-				}
-#else
-				if (access((const char*)csStartTime, F_OK) == 0) {
-					int ret = remove(csStartTime);
-					if (ret == 0)//删除成功,清理前次记录的guardian版本记录
-						spConfigRun->WriteConfigValue("Run", "VersionEx", "");
-					else
-						DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("delete time file [%s] error.[%d]", csStartTime.GetData(), errno);
+				if (ExistsFileA(csStartTime)) {
+						if (RemoveFileA(csStartTime))//删除成功,清理前次记录的guardian版本记录
+						{
+							DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("delete start time file [%s] suc.", csStartTime.GetData());
+							spConfigRun->WriteConfigValue("Run", "VersionEx", "");
+						}
+						else
+							DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("delete time file [%s] error.[%d]", csStartTime.GetData(), GetLastError());
 				}
-#endif
 			}
 			if (iCheckGuardian > 0)
 			{
@@ -896,49 +883,33 @@ bool CHealthManagerEntity::DoRestart()
 		}
 		
 	}
-	//TODO: CrossPlaform  [Gifur@2025730]
-#if defined(RVC_OS_WIN)
 	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("guardian file path [%s]", deamonBasePath.GetData());
-	HMODULE hDll = LoadLibraryA(deamonBasePath);
-	if (hDll == NULL)
+	do 
 	{
-		DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("load guardianbase.dll failed(%d)", GetLastError());
-		return false;
-	}
+		if (!ExistsFileA(deamonBasePath)) {
+			DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("Load guardian %s failed: no exist", (const char*)deamonBasePath);
+			return false;
+		}
+		toolkit_lib_t guardianLib;
+		int res = toolkit_dlopen(deamonBasePath, &guardianLib);
+		if (res != 0) {
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("toolkit_dlopen[%s] failed with error %s.", deamonBasePath.GetData(), toolkit_dlerror(&guardianLib));
+			return false;
+		}
+		if ((res = toolkit_dlsym(&guardianLib, "ShakeHands", (void**)&m_pfShake)) != 0)
+		{
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Get 'ShakeHands' Func address failed with error: %s", toolkit_dlerror(&guardianLib));
+			toolkit_dlclose(&guardianLib);
+			return false;
+		}
+		if ((res = toolkit_dlsym(&guardianLib, "UpgradeRestart", (void**)&m_pfUpgradeRestart)) != 0)
+		{
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Get 'UpgradeRestart' Func address failed with error: %s", toolkit_dlerror(&guardianLib));
+			toolkit_dlclose(&guardianLib);
+			return false;
+		}
+	} while (false);
 
-	m_pfShake = (pfShakeHands)GetProcAddress(hDll,"ShakeHands");
-	if (m_pfShake == NULL)
-	{
-		DbgWithLink(LOG_LEVEL_ERROR,LOG_TYPE_SYSTEM)("get ShakeHands function address failed(%d)",GetLastError());
-		return false;
-	}
-	m_pfUpgradeRestart = (pfUpgradeRestart)GetProcAddress(hDll,"UpgradeRestart");
-	if (m_pfUpgradeRestart == NULL)
-	{
-		DbgWithLink(LOG_LEVEL_ERROR,LOG_TYPE_SYSTEM)("get UpgradeRestart function address failed(%d)",GetLastError());
-		return false;
-	}
-#else
-	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("guardian file path [%s]", (LPCTSTR)deamonBasePath);
-	void* handle = dlopen(deamonBasePath, RTLD_LAZY);
-	if (handle == NULL)
-	{
-		DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("load libGuardianBase.so failed(%d)", errno);
-		return false;
-	}
-	m_pfShake = (pfShakeHands)dlsym(handle, "ShakeHands");
-	if (m_pfShake == NULL)
-	{
-		DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("get ShakeHands failed(%d)", GetLastError());
-		return false;
-	}
-	m_pfUpgradeRestart = (pfUpgradeRestart)dlsym(handle, "UpgradeRestart");
-	if (m_pfUpgradeRestart == NULL)
-	{
-		DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("get UpgradeRestart failed(%d)", GetLastError());
-		return false;
-	}
-#endif
 	DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("have load guardian base file (dll/so).");
 	if (CheckGuardianIsRun(true) > 0)
 	{