| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373 |
- #pragma once
- #include "SpHelper.h"
- #include "SpFSM.h"
- #include "SimpleString.h"
- #include "Blob.h"
- #include "SpBase.h"
- #include <regex>
- /*------20200221------*/
- //modify by LZM
- ErrorCodeEnum VendorLogControlerEx(CEntityBase* pEntity, CSimpleStringA moduleName)
- {
- #ifdef RVC_WIN_OS
- //get Device Information.
- CSystemStaticInfo DevInfo;
- pEntity->GetFunction()->GetSystemStaticInfo(DevInfo);
- Dbg("Terminal NUM=%s", DevInfo.strTerminalID);
- //read root.ini and get vendor,version,batch.
- CSmartPointer<IConfigInfo> 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<IConfigInfo> 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<CSimpleStringA> arrayWhiteNameSheet = strWhiteNameSheet.Split(',');
- for (int i = 0; i < arrayWhiteNameSheet.GetCount(); i++)
- {
- std::regex pattern(arrayWhiteNameSheet[i]);
- if (std::regex_match(DevInfo.strTerminalID.GetData(), pattern))
- {
- bWhiteNameSheet = true;
- break;
- }
- }
- //if this terminal is not at WhiteNameSheet,set level with "OFF".
- if (!bWhiteNameSheet) strVendorRecodeLevel = "OFF";
- }
- }
- eErrDev = centerConfig->ReadConfigValue(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.");
- }
- #else
- #endif
- return Error_Succeed;
- }
- ErrorCodeEnum VendorLogControler(FSMBase* pFSM, CSimpleStringA moduleName)
- {
- return VendorLogControlerEx(pFSM->GetEntityBase(), moduleName);
- }
- /*--------------------*/
- ErrorCodeEnum SpGetAllDevices(CEntityBase* pEntity, CAutoArray<CSimpleStringA>& devs)
- {
- CSmartPointer<IConfigInfo> 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; i < nCount; i++)
- {
- CSimpleStringA str = CSimpleStringA::Format("%d", i + 1);
- rc = pConfig->ReadConfigValue("Device", (const char*)str, devs[i]);
- }
- }
- }
- return rc;
- }
- ErrorCodeEnum SpGetDeviceInfo(CEntityBase* pCallerEntity, const CSimpleStringA& devDeviceName,
- CSimpleStringA& strModel, CSimpleStringA& strVendor, CSimpleStringA& strVersion)
- {
- CSmartPointer<IConfigInfo> 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<IConfigInfo> 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);
- #ifdef RVC_OS_WIN
- strDevAdaptorPath = CSimpleStringA::Format("%s\\%s.dll",
- (const char*)strDepPath,
- (const char*)strDevAdaptorPath);
- #else
- strDevAdaptorPath = CSimpleStringA::Format("%s/lib%s.so",
- (const char*)strDepPath,
- (const char*)strDevAdaptorPath);
- #endif
- }
- return rc;
- }
- // add by ly
- ErrorCodeEnum SpGetDevAdaptorPathByIndex(int nIndex,
- CEntityBase* pCallerEntity,
- const CSimpleStringA& devDeviceName,
- CSimpleStringA& strDevAdaptorPath)
- {
- CSmartPointer<IConfigInfo> 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<IConfigInfo> 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;
- }
- ErrorCodeEnum IsNeedOpenUsb(CEntityBase* pCallerEntity, bool& bNeedOpenUsb)
- {
- ErrorCodeEnum errCode = Error_Unexpect;
- CSystemStaticInfo sysDevInfo;
- errCode = pCallerEntity->GetFunction()->GetSystemStaticInfo(sysDevInfo);
- if (errCode != Error_Succeed) {
- Dbg("get device info failed while judge open usb or not");
- }
- else {
- CSimpleStringA strMachineType;
- strMachineType = sysDevInfo.strMachineType;
- WORD majorVersion = sysDevInfo.MachineVersion.GetMajor();
- WORD minorVersion = sysDevInfo.MachineVersion.GetMinor();
- CSimpleStringA machineVersion = CSimpleStringA::Format("%d.%d", majorVersion, minorVersion);
- Dbg("MachineType:%s, machineVersion:%s", strMachineType.GetData(), machineVersion.GetData());
- if (!strMachineType.Compare("RVC.PAD", true)
- || (!strMachineType.Compare("RVC.Desk2S", true) && !machineVersion.Compare("1.0")))
- {
- bNeedOpenUsb = false;
- }
- else if (!strMachineType.Compare("RVC.Stand2S", true) || !strMachineType.Compare("RVC.CardStore", true)
- || (!strMachineType.Compare("RVC.Desk2S", true) && !machineVersion.Compare("2.0"))
- || (!strMachineType.Compare("RVC.Desk2S", true) && !machineVersion.Compare("2.1"))
- || (!strMachineType.Compare("RVC.Desk1S", true) && !machineVersion.Compare("1.0")))
- {
- bNeedOpenUsb = true;
- }
- else
- {
- //TODO:: if add new machine type
- bNeedOpenUsb = true;
- }
- }
- return errCode;
- }
|