#ifndef _RVC_COMMON_GETDEVINFOHELPER_H__ #define _RVC_COMMON_GETDEVINFOHELPER_H__ #pragma once #include "SpHelper.h" #include "SpFSM.h" #include "SimpleString.h" #include "Blob.h" #include "SpBase.h" #include /*------20200221------*/ //modify by LZM ErrorCodeEnum VendorLogControlerEx(CEntityBase *pEntity,CSimpleStringA moduleName) { #ifdef _WIN32 //get Device Information. CSystemStaticInfo DevInfo; pEntity->GetFunction()->GetSystemStaticInfo(DevInfo); Dbg("Terminal NUM=%s",DevInfo.strTerminalID); //read root.ini and get vendor,version,batch. CSmartPointer rootConfig; ErrorCodeEnum eErrDev = pEntity->GetFunction()->OpenConfig(Config_Root,rootConfig); if (eErrDev != Error_Succeed) { Dbg("open Config_Root file failed!"); return eErrDev; } CSimpleStringA strVendor,strVersion,strBatch; CSimpleStringA strTmp = CSimpleStringA::Format("Device.%s",moduleName.GetData()); Dbg("strTmp=%s",strTmp); eErrDev = rootConfig->ReadConfigValue(strTmp,"Vendor",strVendor); if(eErrDev != Error_Succeed || strVendor.IsNullOrEmpty()){ Dbg("read vendor failed!"); return eErrDev; } eErrDev = rootConfig->ReadConfigValue(strTmp,"Version",strVersion); if(eErrDev != Error_Succeed || strVersion.IsNullOrEmpty()){ Dbg("read version failed!"); return eErrDev; } eErrDev = rootConfig->ReadConfigValue(strTmp,"Batch",strBatch); if(eErrDev != Error_Succeed || strBatch.IsNullOrEmpty()){ Dbg("read batch failed!"); return eErrDev; } Dbg("strVendor=%s",strVendor); Dbg("strVersion=%s",strVersion); Dbg("strBatch=%s",strBatch); //read CenterSetting get VendorRecodeLevel,VendorRecodeType,WhiteNameSheet. CSmartPointer centerConfig; eErrDev = pEntity->GetFunction()->OpenConfig(Config_CenterSetting,centerConfig); if (eErrDev != Error_Succeed) { Dbg("open Config_CenterSetting file failed!"); return eErrDev; } CSimpleStringA strVendorRecodeLevel,strVendorRecodeType,strVendorDllName,strVendorLogPath; eErrDev = centerConfig->ReadConfigValue(moduleName,strVendor.GetData(),strVendorRecodeLevel); if(eErrDev!=Error_Succeed || strVendorRecodeLevel.IsNullOrEmpty()) { eErrDev = centerConfig->ReadConfigValue(moduleName,"All",strVendorRecodeLevel); if(eErrDev!=Error_Succeed || strVendorRecodeLevel.IsNullOrEmpty()) { //default level:OFF. strVendorRecodeLevel = "OFF"; } } //WhiteNameSheet is avaliable. if (strVendorRecodeLevel.Compare("OFF") != 0) { //get WhiteNameSheet CSimpleStringA strWhiteNameSheet; eErrDev = centerConfig->ReadConfigValue(moduleName,"AllowTerminals",strWhiteNameSheet); if (!strWhiteNameSheet.IsNullOrEmpty()) { bool bWhiteNameSheet = false; CAutoArray arrayWhiteNameSheet = strWhiteNameSheet.Split(','); for (int i=0;iReadConfigValue(moduleName,"Type",strVendorRecodeType); if(eErrDev!=Error_Succeed || strVendorRecodeType.IsNullOrEmpty()) { //default type:FILE. strVendorRecodeType = "FILE"; } strVendorDllName = moduleName + "." + strVendor+"."+strVersion+"."+strBatch+".dll"; TCHAR szPath[MAX_PATH] = {0}; GetModuleFileNameA(NULL, szPath, MAX_PATH); CSimpleStringA strDir = szPath; strVendorLogPath = strDir.SubString(0,1); strVendorLogPath += ":/rvc/dbg"; Dbg("VENDOR_RECODE_LEVEL=%s",strVendorRecodeLevel); Dbg("VENDOR_RECODE_TYPE=%s",strVendorRecodeType); Dbg("VENDOR_DLL_NAME=%s",strVendorDllName); Dbg("VENDOR_LOG_PATH=%s",strVendorLogPath); if(!SetEnvironmentVariableA("VENDOR_RECODE_LEVEL",strVendorRecodeLevel.GetData())){ Dbg("Set VENDOR_RECODE_LEVEL Variable Failed."); } if(!SetEnvironmentVariableA("VENDOR_RECODE_TYPE",strVendorRecodeType.GetData())){ Dbg("Set VENDOR_RECODE_TYPE Variable Failed."); } if(!SetEnvironmentVariableA("VENDOR_DLL_NAME",strVendorDllName.GetData())){ Dbg("Set VENDOR_DLL_NAME Variable Failed."); } if(!SetEnvironmentVariableA("VENDOR_LOG_PATH",strVendorLogPath.GetData())){ Dbg("Set VENDOR_LOG_PATH Variable Failed."); } return Error_Succeed; #else return Error_NotSupport; #endif //_WIN32 } ErrorCodeEnum VendorLogControler(FSMBase *pFSM,CSimpleStringA moduleName) { return VendorLogControlerEx(pFSM->GetEntityBase(),moduleName); } /*--------------------*/ /** For AccessAuth and Initializer and UpgradeMgr*/ ErrorCodeEnum SpGetAllDevices(CEntityBase *pEntity, CAutoArray &devs) { CSmartPointer pConfig; ErrorCodeEnum rc = pEntity->GetFunction()->OpenConfig(Config_Root, pConfig); if (rc == Error_Succeed) { int nCount(0); rc = pConfig->ReadConfigValueInt("Device", "Number", nCount); if (rc == Error_Succeed && nCount>0) { devs.Init(nCount); for(int i=0; iReadConfigValue("Device", (const char*)str, devs[i]); } } } return rc; } /** For AccessAuth and UpgradeMgr*/ ErrorCodeEnum SpGetDeviceInfo(CEntityBase *pCallerEntity, const CSimpleStringA &devDeviceName, CSimpleStringA &strModel, CSimpleStringA &strVendor, CSimpleStringA &strVersion) { CSmartPointer pConfig; ErrorCodeEnum rc = pCallerEntity->GetFunction()->OpenConfig(Config_Root, pConfig); if (rc == Error_Succeed) { CSimpleStringA strSection = CSimpleStringA("Device.") + devDeviceName; pConfig->ReadConfigValue(strSection, "Vendor", strVendor); pConfig->ReadConfigValue(strSection, "Version", strVersion); strModel = devDeviceName; if (!strVendor.IsNullOrEmpty()) { strModel += "."; strModel += strVendor; } if (!strVersion.IsNullOrEmpty()) { strModel += "."; strModel += strVersion; } } return rc; } ErrorCodeEnum SpGetDevAdaptorPath(CEntityBase *pCallerEntity, const CSimpleStringA &devDeviceName, CSimpleStringA &strDevAdaptorPath) { CSmartPointer pConfig; ErrorCodeEnum rc = pCallerEntity->GetFunction()->OpenConfig(Config_Root, pConfig); if (rc == Error_Succeed) { CSimpleStringA strSection = CSimpleStringA("Device.") + devDeviceName; strDevAdaptorPath = devDeviceName; CSimpleStringA str; pConfig->ReadConfigValue(strSection, "Vendor", str); if (!str.IsNullOrEmpty()) { strDevAdaptorPath += "."; strDevAdaptorPath += str; } str.Clear(); pConfig->ReadConfigValue(strSection, "Version", str); if (!str.IsNullOrEmpty()) { strDevAdaptorPath += "."; strDevAdaptorPath += str; } str.Clear(); pConfig->ReadConfigValue(strSection, "Batch", str); if (!str.IsNullOrEmpty()) { strDevAdaptorPath += "."; strDevAdaptorPath += str; } CSimpleStringA strDepPath; pCallerEntity->GetFunction()->GetPath("Dep", strDepPath); strDevAdaptorPath = CSimpleStringA::Format("%s\\%s.dll", (const char*)strDepPath, (const char*)strDevAdaptorPath); } return rc; } // add by ly ErrorCodeEnum SpGetDevAdaptorPathByIndex(int nIndex, CEntityBase *pCallerEntity, const CSimpleStringA &devDeviceName, CSimpleStringA &strDevAdaptorPath) { CSmartPointer pConfig; ErrorCodeEnum rc = pCallerEntity->GetFunction()->OpenConfig(Config_Root, pConfig); if (rc == Error_Succeed) { char tmp[64] = {0}; CSimpleStringA strSection = CSimpleStringA("Device.") + devDeviceName; strDevAdaptorPath = devDeviceName; CSimpleStringA str; sprintf(tmp, "Vendor_%d", nIndex); pConfig->ReadConfigValue(strSection, tmp, str); if (!str.IsNullOrEmpty()) { strDevAdaptorPath += "."; strDevAdaptorPath += str; } str.Clear(); sprintf(tmp, "Version_%d", nIndex); pConfig->ReadConfigValue(strSection, tmp, str); if (!str.IsNullOrEmpty()) { strDevAdaptorPath += "."; strDevAdaptorPath += str; } str.Clear(); sprintf(tmp, "Batch_%d", nIndex); pConfig->ReadConfigValue(strSection, tmp, str); if (!str.IsNullOrEmpty()) { strDevAdaptorPath += "."; strDevAdaptorPath += str; } CSimpleStringA strDepPath; pCallerEntity->GetFunction()->GetPath("Dep", strDepPath); strDevAdaptorPath = CSimpleStringA::Format("%s\\%s.dll", (const char*)strDepPath, (const char*)strDevAdaptorPath); } return rc; } // BranchDevice [Josephus in 16:32:09 2016/6/22] ErrorCodeEnum SpGetBrDevAdaptorPath(CEntityBase *pCallerEntity, const CSimpleStringA &devDeviceName, CSimpleStringA &strDevAdaptorPath) { CSmartPointer pConfig; ErrorCodeEnum rc = pCallerEntity->GetFunction()->OpenConfig(Config_Root, pConfig); if (rc == Error_Succeed) { CSimpleStringA strSection = CSimpleStringA("BranchDevice.") + devDeviceName; strDevAdaptorPath = devDeviceName; CSimpleStringA str; pConfig->ReadConfigValue(strSection, "Branch", str); if (!str.IsNullOrEmpty()) { strDevAdaptorPath += "."; strDevAdaptorPath += str; } str.Clear(); pConfig->ReadConfigValue(strSection, "Version", str); if (!str.IsNullOrEmpty()) { strDevAdaptorPath += "."; strDevAdaptorPath += str; } str.Clear(); pConfig->ReadConfigValue(strSection, "Batch", str); if (!str.IsNullOrEmpty()) { strDevAdaptorPath += "."; strDevAdaptorPath += str; } CSimpleStringA strDepPath; pCallerEntity->GetFunction()->GetPath("Dep", strDepPath); //strDevAdaptorPath = CSimpleStringA::Format("%s\\%s.dll", // (const char*)strDepPath, // (const char*)strDevAdaptorPath); strDevAdaptorPath = CSimpleStringA::Format("%s.dll", (const char*)strDevAdaptorPath); } return rc; } #endif