Sfoglia il codice sorgente

#IQRV #comment [DeviceControl] 适配器添加环境变量的设置

gifur 4 anni fa
parent
commit
5d59598fc8

+ 2 - 0
Module/mod_DeviceControl/DeviceAdaptChecker.cpp

@@ -142,6 +142,8 @@ CAutoArray<AdapterRootConfigInfo> CAdapterLoadChecker::GetConfigedAdapterInfo(LP
     return result;
 }
 
+
+
 bool VendorLibInfoEx::Load(CSimpleStringA& adapterFilename)
 {
     bool result(false);

+ 1 - 1
Module/mod_DeviceControl/DeviceAdaptChecker.h

@@ -95,7 +95,7 @@ public:
 
 
     static ErrorCodeEnum CheckDeviceAndAdapterAvailable(const VendorLibInfoEx& vendorLibInfo, CSimpleStringA& strErrMsg);
-
+    static ErrorCodeEnum EditLDLibraryPathForVendor(LPCTSTR filePath, BOOL fAdd);
 private:
     CAutoArray<CAdapterLoader*> mAdapterConfigList;
 };

+ 86 - 9
Module/mod_DeviceControl/DeviceAdapterCheckerImpl.cpp

@@ -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;
 }

+ 41 - 2
addin/res/ManagerDesktop/js/guide.js

@@ -667,6 +667,43 @@ $(function () {
         });
     }
 
+    function FinshedDevAdapterConfig()
+    {
+        let req = new Request();
+        req.preStep = CONST.DeployStep_AdapterConfig;
+        req.currStep = CONST.DeployStep_AdapterConfig;
+        req.nextStep = CONST.DeployStep_AdapterConfig;
+        req.param1 = parseInt(port, 10);
+        req.param2 = parseInt(baudrate, 10);
+        req.param3 = adapter;
+        req.param4 = '';
+        req.param5 = '';
+        req.array1 = [0];
+        req.array2 = [''];
+        req.options = 0;
+        req.additional = 0;
+        req.restartApp = false;
+        req.restartPC = false;
+
+        setSaveBtnStatus(false);
+        RVC.HealthmanagerEntityCtrl.DeployTerminal(req, function(ret) {
+            setSaveBtnStatus(true);
+            if(ret.errorCode === 0) {
+                let result = JSON.parse(ret[RVC.EntityController.sigResponseUUID])
+                if(result.result == 0) {
+                    globalLastRemberAdapterName = adapter;
+                    utilShowToast('已保存,将重新刷新', 1000, function() {
+                        LoadDeviceAdaptersWithEvent(true);
+                    });
+                } else {
+                    utilStartAlertDialog("操作失败:[" + result.result + "] " + result.additionalMsg);
+                }
+            } else {
+                RVC.HealthmanagerEntityCtrl.commErrorCallback(ret);
+            }
+        });
+    }
+
     RVC.GuideController = RVC.Object.extend({
         hideAllPage: function () {
             $('#guide_start_page').hide();
@@ -846,7 +883,9 @@ $(function () {
     });
 
     $(document).on('click', '#guide_adapter_config_next', function() {
-        SaveDevAdapterInfo(adapterName, paramPort, paramBaudrate);
+        utilStartConfirmDialog("后续步骤依赖【密码键盘】,请确认配置正确且该硬件调用正常! 确认要进入下一步?", function() {
+
+        });
     });
 
     $(document).on('click', '#guide_sync_centersetting_next', function() {
@@ -912,7 +951,7 @@ $(function () {
                 });
             }
         } else {
-            RVC.GuideController.gotoPage(CONST.DeployStep_AdapterConfig);
+            RVC.GuideController.gotoPage(CONST.DeployStep_Begin);
         }
     }