فهرست منبع

Z991239-6443 #comment LoadCMBPrint 卡库

80374374 1 ماه پیش
والد
کامیت
9f65c07336
1فایلهای تغییر یافته به همراه38 افزوده شده و 72 حذف شده
  1. 38 72
      Module/mod_cardissuerstore/CardIssuerStoreFSM.cpp

+ 38 - 72
Module/mod_cardissuerstore/CardIssuerStoreFSM.cpp

@@ -18,6 +18,9 @@
 #include "stdafx.h"
 #if defined(RVC_OS_LINUX)
 #include <dlfcn.h>
+#define CMBPRINT_LIBRARY_NAME "libCMBPrint.so"
+#else
+#define CMBPRINT_LIBRARY_NAME "CMBPrint.dll"
 #endif //RVC_OS_LINUX
 
 using namespace SP::Module::Comm;
@@ -1403,24 +1406,21 @@ ErrorCodeEnum CCardIssuerFSM::OnInit()
 			CSimpleStringA runinfodbFile = runinfoPath + "\\runcfg\\CardLibDB_CMB.db3";
 			CSimpleStringA depdbFile = depPath + "\\CardLibDB_CMB.db3";
 
-			//TODO: CrossPlaform 建议直接使用ExistsFileA等接口判断文件是否存在 [Gifur@2025728]
-			WIN32_FIND_DATA findData;
-			if (FindFirstFileA((LPCTSTR)runinfodbFile, &findData) == INVALID_HANDLE_VALUE
-				&& FindFirstFileA((LPCTSTR)depdbFile, &findData) != INVALID_HANDLE_VALUE)	
+			if (ExistsFileA(depdbFile) && !ExistsFileA(runinfodbFile))
 			{
 				//如果运行时不存在该文件,则拷贝
 				LogWarn(Severity_Low, Error_Unexpect, CardIssuerStore_UserErrorCode_EastCom_Not_Exist_DataFile, "runinfo has no CardLibDB_CMB.db3 file.");
 				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start copy file CardLibDB_CMB.db3 to runinfo.");
-				CopyFile(depdbFile.GetData(), runinfodbFile.GetData(), FALSE);
+				CopyFileA(depdbFile.GetData(), runinfodbFile.GetData(), FALSE);
 				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("end copy file CardLibDB_CMB.db3 to runinfo.");
 			}
-			else if(FindFirstFileA((LPCTSTR)runinfodbFile, &findData) != INVALID_HANDLE_VALUE){
-				//LogWarn(Severity_Low, Error_Unexpect, CardIssuerStore_UserErrorCode_EastCom_Exist_DataFile, "runinfo has CardLibDB_CMB.db3 file.");
+			else if(ExistsFileA(runinfodbFile)){
+
 				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("has exist CardLibDB_CMB.db3 in runinfo");
-			}else if(FindFirstFileA((LPCTSTR)depdbFile, &findData) == INVALID_HANDLE_VALUE){
+
+			}else if(!ExistsFileA(depdbFile)){
+
 				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("no CardLibDB_CMB.db3 in dep");
-			}else{
-				
 			}
 		}
 	}
@@ -1576,60 +1576,43 @@ int CCardIssuerFSM::Reset()
 
 bool CCardIssuerFSM::LoadCMBPrint(CSimpleStringA csBinPath)
 {
-	if (cmdDecodeEx == NULL) {
-		CSimpleStringA csCMBPrint("");
+	if (cmdDecodeEx != NULL) return true;
 
-		//TODO: CrossPlaform  [Gifur@2025730]
-#ifdef RVC_OS_LINUX
-		csCMBPrint = "libCMBPrint.so";
-		csCMBPrint = csBinPath + "/" + csCMBPrint;
-		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("cmbpath %s", (const char*)csCMBPrint);
-		void* hr = NULL;
-		hr = dlopen(csCMBPrint, RTLD_LAZY);
-		if (hr == NULL)
-		{
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA2WF5")("Load CMBPrint failed(%s).", dlerror());
-			return false;
-		}
-		//pfunc_unpack = (PF_unpack)dlsym(hLib, "_Z6unpackPcS_i");
-		if ((cmdDecodeMag2 = (lpCMBdecodeMag2)dlsym(hr, "CMBdecodeMag2")) == NULL)
-		{
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA2WF5")("Get Mag2 address failed.");
-			return false;
-		}
-		if ((cmdDecodeEx = (lpCMBdecodeEx)dlsym(hr, "CMBdecodeEx")) == NULL)
-		{
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA2WF5")("Get Mag23Ex address failed.");
-			cmdDecodeMag2 = NULL;
-			return false;
+	bool result(false);
+	CSimpleStringA csCMBPrint(CMBPRINT_LIBRARY_NAME);
+	csCMBPrint = csBinPath + SPLIT_SLASH_STR + csCMBPrint;
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("cmbpath %s", (const char*)csCMBPrint);
+	do 
+	{
+		if (!ExistsFileA(csCMBPrint)) {
+			DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setResultCode("RTA2WF5")("Load CMBPrint %s failed: no exist", (const char*)csCMBPrint);
+			break;
 		}
-#else
-		csCMBPrint = "CMBPrint.dll";
-		csCMBPrint = csBinPath + SPLIT_SLASH_STR + csCMBPrint;
-		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("cmbpath %s", (const char*)csCMBPrint);
-		HMODULE hr = LoadLibraryA(csCMBPrint);
-		if (hr == NULL)
-		{
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA2WF5")("Load CMBPrint failed(%d).", hr);
-			return false;
+		toolkit_lib_t cmbPrintLib;
+		int res = toolkit_dlopen(csCMBPrint, &cmbPrintLib);
+		if (res != 0) {
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA2WF5")("toolkit_dlopen[%s] failed with error %s.", csCMBPrint.GetData(), toolkit_dlerror(&cmbPrintLib));
+			break;
 		}
-		if ((cmdDecodeMag2 = (lpCMBdecodeMag2)GetProcAddress(hr, "CMBdecodeMag2")) == NULL)
+		if ((res = toolkit_dlsym(&cmbPrintLib, "CMBdecodeMag2", (void**)&cmdDecodeMag2)) != 0)
 		{
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA2WF5")("Get Mag2 address failed.");
-			return false;
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA2WF5")("Get 'CMBdecodeMag2' Func address failed with error: %s", toolkit_dlerror(&cmbPrintLib));
+			break;
 		}
-		if ((cmdDecodeEx = (lpCMBdecodeEx)GetProcAddress(hr, "CMBdecodeEx")) == NULL)
+		if ((res = toolkit_dlsym(&cmbPrintLib, "CMBdecodeEx", (void**)&cmdDecodeEx)) != 0)
 		{
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA2WF5")("Get Mag23Ex address failed.");
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA2WF5")("Get 'CMBdecodeEx' Func address failed with error: %s", toolkit_dlerror(&cmbPrintLib));
 			cmdDecodeMag2 = NULL;
-			return false;
+			break;
 		}
-#endif
 		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Load %s suc.", (const char*)csCMBPrint);
-	}
+		result = true;
 
-	return true;
+	} while (false);
+
+	return result;
 }
+
 ErrorCodeEnum CCardIssuerFSM::OpenDevice(BYTE btOpenType, const char* pDevSN)
 {
 	LOG_FUNCTION();
@@ -5124,16 +5107,10 @@ bool CCardIssuerFSM::SyncMaterialCount(IHttpFunc* client,SyncMaterialCountInfo s
 	qTempReq.m_headers.emplace(std::make_pair("Content-Type", "application/json"));
 	SyncMaterialCountReq1& req1 = qTempReq.reqInfo;
 
-	//TODO: CrossPlaform  [Gifur@2025730]
-#ifdef RVC_OS_WIN
-	strncpy_s(req1.TerminalNo, sizeof(req1.TerminalNo), info.strTerminalID, _TRUNCATE);
-	strncpy_s(req1.DeviceNo, sizeof(req1.DeviceNo), syncInfo.strDeviceNo, _TRUNCATE);
-	strncpy_s(req1.Material, sizeof(req1.Material), "DebitCard", _TRUNCATE);
-#else
 	strncpy(req1.TerminalNo, info.strTerminalID, sizeof(req1.TerminalNo));
 	strncpy(req1.DeviceNo, syncInfo.strDeviceNo, sizeof(req1.DeviceNo));
 	strncpy(req1.Material, "DebitCard", sizeof(req1.Material));
-#endif //RVC_OS_WIN
+
 	req1.CardBoxNum = syncInfo.dwCardBoxNum;
 	for (int i = 0; i <= syncInfo.dwCardBoxNum; i++)
 	{
@@ -5142,24 +5119,13 @@ bool CCardIssuerFSM::SyncMaterialCount(IHttpFunc* client,SyncMaterialCountInfo s
 		pReq2.bMaintain = syncInfo.arrMaintainFlag[i];
 		if (syncInfo.arrMaintainFlag[i])
 		{
-			//TODO: CrossPlaform  [Gifur@2025730]
-#ifdef RVC_OS_WIN
-			strncpy_s(pReq2.Maintainer, sizeof(pReq2.Maintainer), syncInfo.arrMaintainer[i], _TRUNCATE);
-#else
 			strncpy(pReq2.Maintainer, syncInfo.arrMaintainer[i], sizeof(pReq2.Maintainer));
-#endif //RVC_OS_WIN
 			pReq2.MaintainTime = syncInfo.arrMaintainTime[i];
 		}
-		//TODO: CrossPlaform  [Gifur@2025730]
-#ifdef RVC_OS_WIN
-		strncpy_s(pReq2.CardBoxNo, sizeof(pReq2.CardBoxNo), syncInfo.arrCardBoxNo[i], _TRUNCATE);
-		strncpy_s(pReq2.PsbCode, sizeof(pReq2.PsbCode), syncInfo.arrPsbCode[i], _TRUNCATE);
-		strncpy_s(pReq2.PsbName, sizeof(pReq2.PsbName), syncInfo.arrPsbName[i], _TRUNCATE);
-#else
 		strncpy(pReq2.CardBoxNo, syncInfo.arrCardBoxNo[i], sizeof(pReq2.CardBoxNo));
 		strncpy(pReq2.PsbCode, syncInfo.arrPsbCode[i], sizeof(pReq2.PsbCode));
 		strncpy(pReq2.PsbName, syncInfo.arrPsbName[i], sizeof(pReq2.PsbName));
-#endif //RVC_OS_WIN
+
 		pReq2.CardInit = syncInfo.arrCardInit[i];
 		pReq2.CardRemains = syncInfo.arrCardRemains[i];
 		pReq2.CardIssued = syncInfo.arrCardIssued[i];