|
@@ -11,6 +11,63 @@
|
|
|
#include "GpioClass.h"
|
|
|
#include "UpsClass.h"
|
|
|
|
|
|
+ErrorCodeEnum CAdapterLoadChecker::EditLDLibraryPathForVendor(LPCTSTR filePath, BOOL fAdd)
|
|
|
+{
|
|
|
+ if (filePath == NULL || strlen(filePath) == 0) {
|
|
|
+ return Error_Param;
|
|
|
+ }
|
|
|
+ const char* name = "LD_LIBRARY_PATH";
|
|
|
+ char szOldValue[1025] = { '\0' };
|
|
|
+ size_t size = 1024;
|
|
|
+ int result = toolkit_getenv(name, szOldValue, &size);
|
|
|
+ if (result != 0) {
|
|
|
+ Dbg("getenv %s failed: %s", name, toolkit_strerror(result));
|
|
|
+ if (!fAdd) {
|
|
|
+ return Error_Succeed;
|
|
|
+ }
|
|
|
+ if (result == TOOLKIT_ENOENT) {
|
|
|
+ return Error_NotExist;
|
|
|
+ } else {
|
|
|
+ return Error_Unexpect;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Dbg("env(%s)=%s", name, szOldValue);
|
|
|
+
|
|
|
+ CSimpleStringA strTmp(szOldValue);
|
|
|
+ CSimpleStringA strNewPath(filePath);
|
|
|
+
|
|
|
+ if (strTmp.IsStartWith(strNewPath)) {
|
|
|
+ Dbg("already exist at front!!!!");
|
|
|
+ if (fAdd) {
|
|
|
+ return Error_AlreadyExist;
|
|
|
+ } else {
|
|
|
+ strNewPath = strTmp.SubString(strNewPath.GetLength() + 1, strTmp.GetLength() - 1);
|
|
|
+ }
|
|
|
+ } else if (strTmp.IndexOf(strNewPath) != -1) {
|
|
|
+ Dbg("already exist at inner!");
|
|
|
+ return Error_InvalidState;
|
|
|
+ } else if (fAdd) {
|
|
|
+ strNewPath += ":";
|
|
|
+ strNewPath += strTmp;
|
|
|
+ } else {
|
|
|
+ return Error_Succeed;
|
|
|
+ }
|
|
|
+
|
|
|
+FINALLY:
|
|
|
+
|
|
|
+ result = toolkit_setenv(name, strNewPath);
|
|
|
+ if (result != 0) {
|
|
|
+ Dbg("setenv failed: %s", toolkit_strerror(result));
|
|
|
+ return Error_Unexpect;
|
|
|
+ }
|
|
|
+
|
|
|
+ size = 1024;
|
|
|
+ memset(szOldValue, '\0', sizeof(szOldValue));
|
|
|
+ toolkit_getenv(name, szOldValue, &size);
|
|
|
+ Dbg("finally:{%s}", szOldValue);
|
|
|
+ return Error_Succeed;
|
|
|
+}
|
|
|
+
|
|
|
ErrorCodeEnum CAdapterLoadChecker::CheckDeviceAndAdapterAvailable(const VendorLibInfoEx& libInfo, CSimpleStringA& strErrMsg)
|
|
|
{
|
|
|
ErrorCodeEnum result(Error_Succeed);
|
|
@@ -32,6 +89,20 @@ ErrorCodeEnum CAdapterLoadChecker::CheckDeviceAndAdapterAvailable(const VendorLi
|
|
|
return Error_NotExist;
|
|
|
}
|
|
|
|
|
|
+ bool toClearEnv(false);
|
|
|
+ CSimpleStringA strDepFullPath(libInfo.optCfg.strDepDirWithSlashOrFileName + libInfo.strVendor);
|
|
|
+ if (ExistsDirA(strDepFullPath)) {
|
|
|
+ ErrorCodeEnum ec = EditLDLibraryPathForVendor(strDepFullPath, TRUE);
|
|
|
+ if (ec == Error_Succeed || ec == Error_AlreadyExist) {
|
|
|
+ toClearEnv = true;
|
|
|
+ } else {
|
|
|
+ strErrMsg = CSimpleStringA::Format("设置适配器库加载路径失败:%s", SpStrError(ec));
|
|
|
+ return ec;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Dbg("{%s} dir not exists!", strDepFullPath.GetData());
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
switch (select) {
|
|
|
case 0: //PinPad
|
|
@@ -49,10 +120,10 @@ ErrorCodeEnum CAdapterLoadChecker::CheckDeviceAndAdapterAvailable(const VendorLi
|
|
|
devImpl->GetLastErr(devErrInfo);
|
|
|
strErrMsg = CSimpleStringA::Format("打开设备失败:[%s] %s", SpStrError(result), devErrInfo.szErrMsg);
|
|
|
}
|
|
|
+ devImpl.TearDown();
|
|
|
} else {
|
|
|
strErrMsg = CSimpleStringA::Format("文件加载或获取对象失败:%s", SpStrError(result));
|
|
|
}
|
|
|
- devImpl.TearDown();
|
|
|
}
|
|
|
break;
|
|
|
case 1: //CardIssuer
|
|
@@ -71,10 +142,11 @@ ErrorCodeEnum CAdapterLoadChecker::CheckDeviceAndAdapterAvailable(const VendorLi
|
|
|
devImpl->GetLastErr(devErrInfo);
|
|
|
strErrMsg = CSimpleStringA::Format("打开设备失败:[%s] %s", SpStrError(result), devErrInfo.szErrMsg);
|
|
|
}
|
|
|
+ devImpl.TearDown();
|
|
|
} else {
|
|
|
strErrMsg = CSimpleStringA::Format("文件加载或获取对象失败:%s", SpStrError(result));
|
|
|
}
|
|
|
- devImpl.TearDown();
|
|
|
+
|
|
|
}
|
|
|
break;
|
|
|
case 2: //IDCertificate
|
|
@@ -92,10 +164,10 @@ ErrorCodeEnum CAdapterLoadChecker::CheckDeviceAndAdapterAvailable(const VendorLi
|
|
|
devImpl->GetLastErr(devErrInfo);
|
|
|
strErrMsg = CSimpleStringA::Format("打开设备失败:[%s] %s", SpStrError(result), devErrInfo.szErrMsg);
|
|
|
}
|
|
|
+ devImpl.TearDown();
|
|
|
} else {
|
|
|
strErrMsg = CSimpleStringA::Format("文件加载或获取对象失败:%s", SpStrError(result));
|
|
|
}
|
|
|
- devImpl.TearDown();
|
|
|
}
|
|
|
break;
|
|
|
case 3: //ContactlessCard
|
|
@@ -113,10 +185,10 @@ ErrorCodeEnum CAdapterLoadChecker::CheckDeviceAndAdapterAvailable(const VendorLi
|
|
|
devImpl->GetLastErr(devErrInfo);
|
|
|
strErrMsg = CSimpleStringA::Format("打开设备失败:[%s] %s", SpStrError(result), devErrInfo.szErrMsg);
|
|
|
}
|
|
|
+ devImpl.TearDown();
|
|
|
} else {
|
|
|
strErrMsg = CSimpleStringA::Format("文件加载或获取对象失败:%s", SpStrError(result));
|
|
|
}
|
|
|
- devImpl.TearDown();
|
|
|
}
|
|
|
break;
|
|
|
case 4: //HSPScanner
|
|
@@ -134,10 +206,10 @@ ErrorCodeEnum CAdapterLoadChecker::CheckDeviceAndAdapterAvailable(const VendorLi
|
|
|
devImpl->GetLastErr(devErrInfo);
|
|
|
strErrMsg = CSimpleStringA::Format("打开设备失败:[%s] %s", SpStrError(result), devErrInfo.szErrMsg);
|
|
|
}
|
|
|
+ devImpl.TearDown();
|
|
|
} else {
|
|
|
strErrMsg = CSimpleStringA::Format("文件加载或获取对象失败:%s", SpStrError(result));
|
|
|
}
|
|
|
- devImpl.TearDown();
|
|
|
}
|
|
|
break;
|
|
|
case 5: //FingerPrint
|
|
@@ -155,10 +227,10 @@ ErrorCodeEnum CAdapterLoadChecker::CheckDeviceAndAdapterAvailable(const VendorLi
|
|
|
devImpl->GetLastErr(devErrInfo);
|
|
|
strErrMsg = CSimpleStringA::Format("打开设备失败:[%s] %s", SpStrError(result), devErrInfo.szErrMsg);
|
|
|
}
|
|
|
+ devImpl.TearDown();
|
|
|
} else {
|
|
|
strErrMsg = CSimpleStringA::Format("文件加载或获取对象失败:%s", SpStrError(result));
|
|
|
}
|
|
|
- devImpl.TearDown();
|
|
|
}
|
|
|
break;
|
|
|
case 6: //WatchDog
|
|
@@ -176,10 +248,10 @@ ErrorCodeEnum CAdapterLoadChecker::CheckDeviceAndAdapterAvailable(const VendorLi
|
|
|
devImpl->GetLastErr(devErrInfo);
|
|
|
strErrMsg = CSimpleStringA::Format("打开设备失败:[%s] %s", SpStrError(result), devErrInfo.szErrMsg);
|
|
|
}
|
|
|
+ devImpl.TearDown();
|
|
|
} else {
|
|
|
strErrMsg = CSimpleStringA::Format("文件加载或获取对象失败:%s", SpStrError(result));
|
|
|
}
|
|
|
- devImpl.TearDown();
|
|
|
}
|
|
|
break;
|
|
|
case 7: //Gpio
|
|
@@ -199,10 +271,10 @@ ErrorCodeEnum CAdapterLoadChecker::CheckDeviceAndAdapterAvailable(const VendorLi
|
|
|
devImpl->GetLastErr(devErrInfo);
|
|
|
strErrMsg = CSimpleStringA::Format("打开设备失败:[%s] %s", SpStrError(result), devErrInfo.szErrMsg);
|
|
|
}
|
|
|
+ devImpl.TearDown();
|
|
|
} else {
|
|
|
strErrMsg = CSimpleStringA::Format("文件加载或获取对象失败:%s", SpStrError(result));
|
|
|
}
|
|
|
- devImpl.TearDown();
|
|
|
}
|
|
|
break;
|
|
|
case 8: //Ups
|
|
@@ -220,10 +292,10 @@ ErrorCodeEnum CAdapterLoadChecker::CheckDeviceAndAdapterAvailable(const VendorLi
|
|
|
devImpl->GetLastErr(devErrInfo);
|
|
|
strErrMsg = CSimpleStringA::Format("打开设备失败:[%s] %s", SpStrError(result), devErrInfo.szErrMsg);
|
|
|
}
|
|
|
+ devImpl.TearDown();
|
|
|
} else {
|
|
|
strErrMsg = CSimpleStringA::Format("文件加载或获取对象失败:%s", SpStrError(result));
|
|
|
}
|
|
|
- devImpl.TearDown();
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
@@ -232,5 +304,10 @@ ErrorCodeEnum CAdapterLoadChecker::CheckDeviceAndAdapterAvailable(const VendorLi
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
+ if (toClearEnv) {
|
|
|
+ ErrorCodeEnum ec = EditLDLibraryPathForVendor(strDepFullPath, FALSE);
|
|
|
+ Dbg("Clear Env Path returned: %s", SpStrError(ec));
|
|
|
+ }
|
|
|
+
|
|
|
return result;
|
|
|
}
|