DevEntityCommBase.hpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. #ifndef _RVC_DEVICE_ADAPTER_ENTITY_BASE_H__
  2. #define _RVC_DEVICE_ADAPTER_ENTITY_BASE_H__
  3. #pragma once
  4. #include "SpBase.h"
  5. #include "SpHelper.h"
  6. #include "DeviceBaseClass.h"
  7. #include "SimpleString.h"
  8. #include "ModuleMix.h"
  9. #include "path.h"
  10. #include "toolkit.h"
  11. #include <regex>
  12. struct VendorLibInfo
  13. {
  14. CSimpleStringA strDevice;
  15. CSimpleStringA strVendor;
  16. CSimpleStringA strVersion;
  17. CSimpleStringA strBatch;
  18. VendorLibInfo() :strDevice(true), strVendor(true), strVersion(true), strBatch(true) {}
  19. VendorLibInfo(const CSimpleStringA& strDeviceName) :strDevice(strDeviceName), strVendor(true), strVersion(true), strBatch(true) {}
  20. VendorLibInfo(const VendorLibInfo& rhs) :strDevice(rhs.strDevice), strVendor(rhs.strVendor), strVersion(rhs.strVersion), strBatch(rhs.strBatch) {}
  21. VendorLibInfo& operator = (const VendorLibInfo& rhs) {
  22. strDevice = rhs.strDevice;
  23. strVendor = rhs.strVendor;
  24. strVersion = rhs.strVersion;
  25. strBatch = rhs.strBatch;
  26. return *this;
  27. }
  28. bool IsValid() const
  29. {
  30. return (!strDevice.IsNullOrEmpty()
  31. && !strVendor.IsNullOrEmpty()
  32. && !strVersion.IsNullOrEmpty()
  33. && !strBatch.IsNullOrEmpty());
  34. }
  35. bool IsNotConfig() const
  36. {
  37. return(strVendor.IsNullOrEmpty() && strVersion.IsNullOrEmpty() && strBatch.IsNullOrEmpty());
  38. }
  39. int GetVersionInt() const
  40. {
  41. int result = 0;
  42. if (!strVersion.IsNullOrEmpty())
  43. {
  44. result = atoi(strVersion.GetData());
  45. }
  46. return result;
  47. }
  48. int GetBatchInt() const
  49. {
  50. int result = 0;
  51. if (!strBatch.IsNullOrEmpty())
  52. {
  53. result = atoi(strBatch.GetData());
  54. }
  55. return result;
  56. }
  57. CSimpleStringA toLibNameString() const
  58. {
  59. CSimpleStringA strFullLibName(true);
  60. if (!strDevice.IsNullOrEmpty())
  61. {
  62. strFullLibName = strDevice;
  63. if (!strVendor.IsNullOrEmpty())
  64. {
  65. strFullLibName += ".";
  66. strFullLibName += strVendor;
  67. }
  68. if (!strVersion.IsNullOrEmpty())
  69. {
  70. strFullLibName += ".";
  71. strFullLibName += strVersion;
  72. }
  73. if (!strBatch.IsNullOrEmpty())
  74. {
  75. strFullLibName += ".";
  76. strFullLibName += strBatch;
  77. }
  78. #ifdef RVC_OS_WIN
  79. strFullLibName += ".dll";
  80. #else
  81. CSimpleStringA strPrefix("lib");
  82. strPrefix += strFullLibName;
  83. strPrefix += ".so";
  84. strFullLibName = strPrefix;
  85. #endif //RVC_OS_WIN
  86. }
  87. return strFullLibName;
  88. }
  89. };
  90. class CDevAdptEntityBase : public CEntityBase
  91. {
  92. public:
  93. CDevAdptEntityBase() { }
  94. ErrorCodeEnum LoadVendorLibName()
  95. {
  96. if (!vendorLibInfo.IsValid()) {
  97. return ExtractVendorLibName();
  98. }
  99. return IsNotConfigure() ? Error_NotConfig : Error_Succeed;
  100. }
  101. virtual CSimpleStringA GetVendorLibName()
  102. {
  103. if (!vendorLibInfo.IsValid()) {
  104. ExtractVendorLibName();
  105. }
  106. return vendorLibInfo.toLibNameString();
  107. }
  108. virtual ErrorCodeEnum ExtractVendorLibFullPath(CSimpleStringA& csLibFullPath);
  109. virtual void InitializeVendorLogSwitch();
  110. virtual ~CDevAdptEntityBase() {}
  111. public:
  112. VendorLibInfo vendorLibInfo;
  113. protected:
  114. virtual ErrorCodeEnum CustomVendorLibInfo() { return Error_Succeed; }
  115. private:
  116. ErrorCodeEnum ExtractVendorLibName();
  117. bool IsNotConfigure() const
  118. {
  119. return vendorLibInfo.IsNotConfig();
  120. }
  121. };
  122. inline ErrorCodeEnum CDevAdptEntityBase::ExtractVendorLibName()
  123. {
  124. CSmartPointer<IConfigInfo> spRootConfig;
  125. ErrorCodeEnum erroCode = GetFunction()->OpenConfig(Config_Root, spRootConfig);
  126. if (IS_SUCCEED(erroCode))
  127. {
  128. CSimpleStringA strDeviceEntityName = GetEntityName();
  129. if (strDeviceEntityName.Compare("CardIssuerStore", true) == 0 || strDeviceEntityName.Compare("CardIssuerStand", true) == 0) {
  130. strDeviceEntityName = "CardIssuer";
  131. }
  132. CSimpleStringA strSection = CSimpleStringA("Device.") + strDeviceEntityName;
  133. vendorLibInfo.strDevice = strDeviceEntityName;
  134. spRootConfig->ReadConfigValue(strSection, "Vendor", vendorLibInfo.strVendor);
  135. spRootConfig->ReadConfigValue(strSection, "Version", vendorLibInfo.strVersion);
  136. spRootConfig->ReadConfigValue(strSection, "Batch", vendorLibInfo.strBatch);
  137. }
  138. if (IS_SUCCEED(erroCode)) {
  139. erroCode = CustomVendorLibInfo();
  140. }
  141. return erroCode;
  142. }
  143. inline ErrorCodeEnum CDevAdptEntityBase::ExtractVendorLibFullPath(CSimpleStringA& csLibFullPath)
  144. {
  145. CSimpleStringA strLibName = GetVendorLibName();
  146. CSimpleStringA strDepPath;
  147. GetFunction()->GetPath("Dep", strDepPath);
  148. csLibFullPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (LPCTSTR)strDepPath, (LPCTSTR)strLibName);
  149. return IsNotConfigure() ? Error_NotConfig : Error_Succeed;
  150. }
  151. inline void CDevAdptEntityBase::InitializeVendorLogSwitch()
  152. {
  153. LOG_FUNCTION();
  154. if (!vendorLibInfo.IsValid()) {
  155. ExtractVendorLibName();
  156. }
  157. struct VendorLogConfig {
  158. VendorLogConfig() :strLevel("OFF"), strType("FILE"), strDllName(""), strLogPath("") {}
  159. CSimpleStringA strLevel;
  160. CSimpleStringA strType;
  161. CSimpleStringA strDllName;
  162. CSimpleStringA strLogPath;
  163. void Settle() {
  164. toolkit_setenv("VENDOR_RECODE_LEVEL", strLevel);
  165. toolkit_setenv("VENDOR_RECODE_TYPE", strType);
  166. toolkit_setenv("VENDOR_DLL_NAME", strDllName);
  167. toolkit_setenv("VENDOR_LOG_PATH", strLogPath);
  168. }
  169. } stLogConfig;
  170. stLogConfig.strDllName = vendorLibInfo.toLibNameString().GetData();
  171. CSmartPointer<IConfigInfo> centerConfig;
  172. GetFunction()->OpenConfig(Config_CenterSetting, centerConfig);
  173. CSimpleStringA str;
  174. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("To get config [All] key...");
  175. centerConfig->ReadConfigValue(GetEntityName(), "All", str);
  176. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("All: %s", str.GetData());
  177. if (!str.IsNullOrEmpty()) {
  178. stLogConfig.strLevel = str;
  179. }
  180. bool fromLocal = false;
  181. if (stLogConfig.strLevel.Compare("OFF", true) != 0) {
  182. stLogConfig.strType = "UPLOAD";
  183. int nSaveFileOrNot(0);
  184. centerConfig->ReadConfigValueInt("Common", "SaveFile", nSaveFileOrNot);
  185. if ((nSaveFileOrNot & 1) == 1) {
  186. if (!stLogConfig.strType.IsNullOrEmpty()) stLogConfig.strType += "|";
  187. stLogConfig.strType += "FILE";
  188. }
  189. GetFunction()->GetPath("Dbg", stLogConfig.strLogPath);
  190. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("DbgPath: %s", stLogConfig.strLogPath.GetData());
  191. stLogConfig.Settle();
  192. do {
  193. CEntityStaticInfo staticInfo;
  194. GetFunction()->GetEntityStaticInfo(GetEntityName(), staticInfo);
  195. DWORD dwUsrCode = fromLocal ? 0xFFFEE : 0xFFFEF;
  196. dwUsrCode |= (staticInfo.wEntityDevelopID << 20);
  197. LogWarn(Severity_Low, Error_Debug, dwUsrCode,
  198. CSimpleStringA::Format("{\"RecordLevel\":\"%s\", \"RecordType\":\"%s\", \"DeterminedBy\":\"%s\"}",
  199. stLogConfig.strLevel.GetData(),
  200. stLogConfig.strType.GetData(),
  201. fromLocal ? "LocalMaintain" : "CenterSettings"));
  202. } while (false);
  203. }
  204. }
  205. #define GET_DEV_ENTITY_BASE_POINTER() \
  206. (dynamic_cast<CDevAdptEntityBase*>(GetEntityBase()))
  207. #endif /*_RVC_DEVICE_ADAPTER_ENTITY_BASE_H__*/