123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356 |
- #ifndef _RVC_DEVICE_ADAPTER_ENTITY_BASE_H__
- #define _RVC_DEVICE_ADAPTER_ENTITY_BASE_H__
- #pragma once
- #include "SpBase.h"
- #include "SpHelper.h"
- #include "DeviceBaseClass.h"
- #include "SimpleString.h"
- #include "ModuleMix.h"
- #include "path.h"
- #include "toolkit.h"
- #include <regex>
- struct VendorLibInfo
- {
- CSimpleStringA strDevice;
- CSimpleStringA strVendor;
- CSimpleStringA strVersion;
- CSimpleStringA strBatch;
- VendorLibInfo() :strDevice(true), strVendor(true), strVersion(true), strBatch(true) {}
- bool IsValid() const
- {
- return (!strDevice.IsNullOrEmpty()
- && !strVendor.IsNullOrEmpty()
- && !strVersion.IsNullOrEmpty()
- && !strBatch.IsNullOrEmpty());
- }
- bool IsNotConfig() const
- {
- return(strVendor.IsNullOrEmpty() && strVersion.IsNullOrEmpty() && strBatch.IsNullOrEmpty());
- }
- int GetVersionInt() const
- {
- int result = 0;
- if (!strVersion.IsNullOrEmpty())
- {
- result = atoi(strVersion.GetData());
- }
- return result;
- }
- int GetBatchInt() const
- {
- int result = 0;
- if (!strBatch.IsNullOrEmpty())
- {
- result = atoi(strBatch.GetData());
- }
- return result;
- }
- CSimpleStringA toLibNameString() const
- {
- CSimpleStringA strFullLibName(true);
- if (!strDevice.IsNullOrEmpty())
- {
- strFullLibName = strDevice;
- if (!strVendor.IsNullOrEmpty())
- {
- strFullLibName += ".";
- strFullLibName += strVendor;
- }
- if (!strVersion.IsNullOrEmpty())
- {
- strFullLibName += ".";
- strFullLibName += strVersion;
- }
- if (!strBatch.IsNullOrEmpty())
- {
- strFullLibName += ".";
- strFullLibName += strBatch;
- }
- #ifdef RVC_OS_WIN
- strFullLibName += ".dll";
- #else
- CSimpleStringA strPrefix("lib");
- strPrefix += strFullLibName;
- strPrefix += ".so";
- strFullLibName = strPrefix;
- #endif //RVC_OS_WIN
- }
- return strFullLibName;
- }
- };
- class CDevAdptEntityBase : public CEntityBase
- {
- public:
- CDevAdptEntityBase() { }
- virtual CSimpleStringA GetVendorLibName()
- {
- if (!vendorLibInfo.IsValid()) {
- ExtractVendorLibName();
- }
- return vendorLibInfo.toLibNameString();
- }
- virtual ErrorCodeEnum ExtractVendorLibFullPath(CSimpleStringA& csLibFullPath);
- virtual void InitializeVendorLogSwitch();
- virtual ~CDevAdptEntityBase() {}
- public:
- VendorLibInfo vendorLibInfo;
- protected:
- virtual ErrorCodeEnum CustomVendorLibInfo() { return Error_Succeed; }
- private:
- ErrorCodeEnum ExtractVendorLibName();
- bool IsNotConfigure() const
- {
- return vendorLibInfo.IsNotConfig();
- }
- };
- inline ErrorCodeEnum CDevAdptEntityBase::ExtractVendorLibName()
- {
- CSmartPointer<IConfigInfo> spRootConfig;
- ErrorCodeEnum erroCode = GetFunction()->OpenConfig(Config_Root, spRootConfig);
- if (IS_SUCCEED(erroCode))
- {
- CSimpleStringA strSection = CSimpleStringA("Device.") + GetEntityName();
- vendorLibInfo.strDevice = GetEntityName();
- spRootConfig->ReadConfigValue(strSection, "Vendor", vendorLibInfo.strVendor);
- spRootConfig->ReadConfigValue(strSection, "Version", vendorLibInfo.strVersion);
- spRootConfig->ReadConfigValue(strSection, "Batch", vendorLibInfo.strBatch);
- #if defined(_MSC_VER)
- int iVersion = 0;
- int iBatch = 0;
- if (!vendorLibInfo.strVersion.IsNullOrEmpty()) iVersion = atoi((const char*)vendorLibInfo.strVersion);
- if (!vendorLibInfo.strBatch.IsNullOrEmpty()) iBatch = atoi((const char*)vendorLibInfo.strBatch);
- CSystemStaticInfo sysInfo;
- erroCode = GetFunction()->GetSystemStaticInfo(sysInfo);
- if (IS_SUCCEED(erroCode)) {
- if (!sysInfo.strMachineType.Compare("RVC.Stand2S", true)) {
- CSimpleStringA strVendor(true);
- spRootConfig->ReadConfigValue("Device.PinPad", "Vendor", strVendor);
- //zss first,kxd second,keba third
- //TODO:kxd ,keba
- if (!strVendor.Compare("Zss", true)) {
- //如果配置大于等于7.1,直接读取root,否则映射加载7.1
- if ((iVersion != 0 && iBatch != 0) && !(iVersion > 7 || (iVersion == 7 && iBatch >= 1))) {
- //读取运行时信息
- CSimpleStringA deviceInfo(true);
- GetFunction()->GetSysVar("zssInfo", deviceInfo);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("zssInfo:%s", deviceInfo.GetData());
- if (!deviceInfo.Compare("ZSS9100", true)) {
- vendorLibInfo.strVendor = "ZSS";
- vendorLibInfo.strVersion = "7";
- vendorLibInfo.strBatch = "1";
- }
- }
- } else if (!strVendor.Compare("kxd", true)) {
- //如果配置大于等于7.1,直接读取root,否则映射加载7.1
- if ((iVersion != 0 && iBatch != 0) && !(iVersion > 7 || (iVersion == 7 && iBatch >= 1))) {
- //读取运行时信息
- CSimpleStringA deviceInfo(true);
- GetFunction()->GetSysVar("kxdInfo", deviceInfo);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("kxdInfo:%s", deviceInfo.GetData());
- if (!deviceInfo.Compare("KS218", true)) {
- vendorLibInfo.strVendor = "kxd";
- vendorLibInfo.strVersion = "7";
- vendorLibInfo.strBatch = "1";
- }
- }
- } else if (!strVendor.Compare("Keba", true)) {
- //如果配置大于等于7.1,直接读取root,否则映射加载7.1
- if ((iVersion != 0 && iBatch != 0) && !(iVersion > 7 || (iVersion == 7 && iBatch >= 1))) {
- //读取运行时信息
- CSimpleStringA deviceInfo(true);
- GetFunction()->GetSysVar("kebaInfo", deviceInfo);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("kebaInfo:%s", deviceInfo.GetData());
- if (!deviceInfo.Compare("E1080", true)) {
- vendorLibInfo.strVendor = "keba";
- vendorLibInfo.strVersion = "7";
- vendorLibInfo.strBatch = "1";
- }
- }
- }
- }
- }
- #endif //_MSC_VER
- }
- if (IS_SUCCEED(erroCode)) {
- erroCode = CustomVendorLibInfo();
- }
- return erroCode;
- }
- inline ErrorCodeEnum CDevAdptEntityBase::ExtractVendorLibFullPath(CSimpleStringA& csLibFullPath)
- {
- CSimpleStringA strLibName = GetVendorLibName();
- CSimpleStringA strDepPath;
- GetFunction()->GetPath("Dep", strDepPath);
- csLibFullPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (LPCTSTR)strDepPath, (LPCTSTR)strLibName);
- return IsNotConfigure() ? Error_NotConfig : Error_Succeed;
- }
- inline void CDevAdptEntityBase::InitializeVendorLogSwitch()
- {
- LOG_FUNCTION();
- if (!vendorLibInfo.IsValid()) {
- ExtractVendorLibName();
- }
- struct VendorLogConfig {
- VendorLogConfig() :strLevel("OFF"), strType("FILE"), strDllName(""), strLogPath("") {}
- CSimpleStringA strLevel;
- CSimpleStringA strType;
- CSimpleStringA strDllName;
- CSimpleStringA strLogPath;
- void Settle() {
- toolkit_setenv("VENDOR_RECODE_LEVEL", strLevel);
- toolkit_setenv("VENDOR_RECODE_TYPE", strType);
- toolkit_setenv("VENDOR_DLL_NAME", strDllName);
- toolkit_setenv("VENDOR_LOG_PATH", strLogPath);
- }
- } stLogConfig;
- stLogConfig.strDllName = vendorLibInfo.toLibNameString().GetData();
- CSmartPointer<IConfigInfo> centerConfig;
- GetFunction()->OpenConfig(Config_CenterSetting, centerConfig);
- CSimpleStringA str;
- centerConfig->ReadConfigValue(GetEntityName(), vendorLibInfo.strVendor, str);
- if (str.IsNullOrEmpty()) {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("To get all config");
- centerConfig->ReadConfigValue(GetEntityName(), "All", str);
- }
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("All: %s", str.GetData());
- if (!str.IsNullOrEmpty()) {
- stLogConfig.strLevel = str;
- }
- if (stLogConfig.strLevel.Compare("OFF", true) != 0) {
- CSystemStaticInfo sysInfo;
- GetFunction()->GetSystemStaticInfo(sysInfo);
- CSimpleStringA strWhiteNameSheet;
- centerConfig->ReadConfigValue(GetEntityName(), "AllowTerminals", strWhiteNameSheet);
- Dbg("AllowTerminals: %s", strWhiteNameSheet.GetData());
- /** 白名单存在,说明需要过滤终端号,但是集中配置改造后已经没有这种操作了,这个逻辑后续可以去掉 Gifur@2023328]*/
- 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(sysInfo.strTerminalID.GetData(), pattern)) {
- bWhiteNameSheet = true;
- break;
- }
- }
- //if this terminal is not at WhiteNameSheet,set level with "OFF".
- if (!bWhiteNameSheet) {
- stLogConfig.strLevel = "OFF";
- }
- }
- }
- bool fromLocal = false;
- /*从集中配置读取的开关为关闭,尝试读取本地的设置*/
- if (stLogConfig.strLevel.Compare("OFF", true) == 0) {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Try to read from global settings.");
- CSmartPointer<IConfigInfo> spConfig;
- ErrorCodeEnum erroCode = GetFunction()->OpenConfig(Config_Cache, spConfig);
- CAutoArray<CSimpleStringA> adapters;
- spConfig->ReadAllKeys("AdapterLogSwith", adapters);
- CSimpleStringA strKey(true);
- for (int i = 0; i < adapters.GetCount(); ++i) {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%d: %s, %s", i, adapters[i].GetData(), GetEntityName());
- if (adapters[i].Compare(GetEntityName(), true) == 0) {
- strKey = adapters[i];
- break;
- }
- }
- if (!strKey.IsNullOrEmpty()) {
- CSimpleStringA strValue(true);
- spConfig->ReadConfigValue("AdapterLogSwith", strKey, strValue);
- CAutoArray<CSimpleStringA> settings;
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Value: %s", strValue.GetData());
- if (!strValue.IsNullOrEmpty() && (settings = strValue.Split(',')).GetCount() == 2) {
- if (settings[0].GetLength() == 1 && atoi(settings[0]) >= 1 && settings[1].GetLength() == 1) {
- if (settings[1].Compare("1") == 0) stLogConfig.strLevel = "Fatal";
- else if (settings[1].Compare("2") == 0) stLogConfig.strLevel = "Error";
- else if (settings[1].Compare("3") == 0) stLogConfig.strLevel = "Warn";
- else if (settings[1].Compare("4") == 0) stLogConfig.strLevel = "Info";
- else if (settings[1].Compare("5") == 0) stLogConfig.strLevel = "Trace";
- else stLogConfig.strLevel = "All";
- fromLocal = true;
- }
- }
- }
- }
- if (stLogConfig.strLevel.Compare("OFF", true) != 0) {
- str.Clear();
- centerConfig->ReadConfigValue(GetEntityName(), "Type", str);
- if (!str.IsNullOrEmpty())
- stLogConfig.strType = str;
- GetFunction()->GetPath("Dbg", stLogConfig.strLogPath);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Dbg: %s", stLogConfig.strLogPath.GetData());
- stLogConfig.Settle();
- do {
- CEntityStaticInfo staticInfo;
- GetFunction()->GetEntityStaticInfo(GetEntityName(), staticInfo);
- DWORD dwUsrCode = fromLocal ? 0xFFFEE : 0xFFFEF;
- dwUsrCode |= (staticInfo.wEntityDevelopID << 20);
- LogWarn(Severity_Low, Error_Debug, dwUsrCode,
- CSimpleStringA::Format("{\"RecordLevel\":\"%s\", \"RecordType\":\"%s\", \"DeterminedBy\":\"%s\"}",
- stLogConfig.strLevel.GetData(),
- stLogConfig.strType.GetData(),
- fromLocal ? "LocalMaintain" : "CenterSettings"));
- } while (false);
- }
- }
- #define GET_DEV_ENTITY_BASE_POINTER() \
- (dynamic_cast<CDevAdptEntityBase*>(GetEntityBase()))
- #endif /*_RVC_DEVICE_ADAPTER_ENTITY_BASE_H__*/
|