123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- #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) {}
- VendorLibInfo(const CSimpleStringA& strDeviceName) :strDevice(strDeviceName), strVendor(true), strVersion(true), strBatch(true) {}
- VendorLibInfo(const VendorLibInfo& rhs) :strDevice(rhs.strDevice), strVendor(rhs.strVendor), strVersion(rhs.strVersion), strBatch(rhs.strBatch) {}
- VendorLibInfo& operator = (const VendorLibInfo& rhs) {
- strDevice = rhs.strDevice;
- strVendor = rhs.strVendor;
- strVersion = rhs.strVersion;
- strBatch = rhs.strBatch;
- return *this;
- }
- 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() { }
- ErrorCodeEnum LoadVendorLibName()
- {
- if (!vendorLibInfo.IsValid()) {
- return ExtractVendorLibName();
- }
- return IsNotConfigure() ? Error_NotConfig : Error_Succeed;
- }
- 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 strDeviceEntityName = GetEntityName();
-
- #ifndef DEVOPS_ON_PRD
- //非生产情况下,才支持测试模式
- CSystemRunInfo runInfo = { 0 };
- ErrorCodeEnum ec = GetFunction()->GetSystemRunInfo(runInfo);
- if (ec == Error_Succeed && runInfo.autoTest) //识别成测试模式的条件
- {
- vendorLibInfo.strDevice = strDeviceEntityName;
- vendorLibInfo.strVendor = "simulator";
- vendorLibInfo.strVersion = "1";
- vendorLibInfo.strBatch = "1";
- }
- else
- #endif
- {
- if (strDeviceEntityName.Compare("CardIssuerStore", true) == 0 || strDeviceEntityName.Compare("CardIssuerStand", true) == 0) {
- strDeviceEntityName = "CardIssuer";
- }
- CSimpleStringA strSection = CSimpleStringA("Device.") + strDeviceEntityName;
- vendorLibInfo.strDevice = strDeviceEntityName;
- spRootConfig->ReadConfigValue(strSection, "Vendor", vendorLibInfo.strVendor);
- spRootConfig->ReadConfigValue(strSection, "Version", vendorLibInfo.strVersion);
- spRootConfig->ReadConfigValue(strSection, "Batch", vendorLibInfo.strBatch);
- }
- }
- 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;
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("To get config [All] key...");
- centerConfig->ReadConfigValue(GetEntityName(), "All", str);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("All: %s", str.GetData());
- if (!str.IsNullOrEmpty()) {
- stLogConfig.strLevel = str;
- }
- bool fromLocal = false;
- if (stLogConfig.strLevel.Compare("OFF", true) != 0) {
- stLogConfig.strType = "UPLOAD";
- int nSaveFileOrNot(0);
- centerConfig->ReadConfigValueInt("Common", "SaveFile", nSaveFileOrNot);
- if ((nSaveFileOrNot & 1) == 1) {
- if (!stLogConfig.strType.IsNullOrEmpty()) stLogConfig.strType += "|";
- stLogConfig.strType += "FILE";
- }
- GetFunction()->GetPath("Dbg", stLogConfig.strLogPath);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("DbgPath: %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__*/
|