GetDevInfoHelper.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. #ifndef _RVC_COMMON_GETDEVINFOHELPER_H__
  2. #define _RVC_COMMON_GETDEVINFOHELPER_H__
  3. #pragma once
  4. #include "SpHelper.h"
  5. #include "SpFSM.h"
  6. #include "SimpleString.h"
  7. #include "Blob.h"
  8. #include "SpBase.h"
  9. #include <regex>
  10. /*------20200221------*/
  11. //modify by LZM
  12. ErrorCodeEnum VendorLogControlerEx(CEntityBase *pEntity,CSimpleStringA moduleName)
  13. {
  14. #ifdef _WIN32
  15. //get Device Information.
  16. CSystemStaticInfo DevInfo;
  17. pEntity->GetFunction()->GetSystemStaticInfo(DevInfo);
  18. Dbg("Terminal NUM=%s",DevInfo.strTerminalID);
  19. //read root.ini and get vendor,version,batch.
  20. CSmartPointer<IConfigInfo> rootConfig;
  21. ErrorCodeEnum eErrDev = pEntity->GetFunction()->OpenConfig(Config_Root,rootConfig);
  22. if (eErrDev != Error_Succeed) {
  23. Dbg("open Config_Root file failed!");
  24. return eErrDev;
  25. }
  26. CSimpleStringA strVendor,strVersion,strBatch;
  27. CSimpleStringA strTmp = CSimpleStringA::Format("Device.%s",moduleName.GetData());
  28. Dbg("strTmp=%s",strTmp);
  29. eErrDev = rootConfig->ReadConfigValue(strTmp,"Vendor",strVendor);
  30. if(eErrDev != Error_Succeed || strVendor.IsNullOrEmpty()){
  31. Dbg("read vendor failed!");
  32. return eErrDev;
  33. }
  34. eErrDev = rootConfig->ReadConfigValue(strTmp,"Version",strVersion);
  35. if(eErrDev != Error_Succeed || strVersion.IsNullOrEmpty()){
  36. Dbg("read version failed!");
  37. return eErrDev;
  38. }
  39. eErrDev = rootConfig->ReadConfigValue(strTmp,"Batch",strBatch);
  40. if(eErrDev != Error_Succeed || strBatch.IsNullOrEmpty()){
  41. Dbg("read batch failed!");
  42. return eErrDev;
  43. }
  44. Dbg("strVendor=%s",strVendor);
  45. Dbg("strVersion=%s",strVersion);
  46. Dbg("strBatch=%s",strBatch);
  47. //read CenterSetting get VendorRecodeLevel,VendorRecodeType,WhiteNameSheet.
  48. CSmartPointer<IConfigInfo> centerConfig;
  49. eErrDev = pEntity->GetFunction()->OpenConfig(Config_CenterSetting,centerConfig);
  50. if (eErrDev != Error_Succeed) {
  51. Dbg("open Config_CenterSetting file failed!");
  52. return eErrDev;
  53. }
  54. CSimpleStringA strVendorRecodeLevel,strVendorRecodeType,strVendorDllName,strVendorLogPath;
  55. eErrDev = centerConfig->ReadConfigValue(moduleName,strVendor.GetData(),strVendorRecodeLevel);
  56. if(eErrDev!=Error_Succeed || strVendorRecodeLevel.IsNullOrEmpty())
  57. {
  58. eErrDev = centerConfig->ReadConfigValue(moduleName,"All",strVendorRecodeLevel);
  59. if(eErrDev!=Error_Succeed || strVendorRecodeLevel.IsNullOrEmpty())
  60. {
  61. //default level:OFF.
  62. strVendorRecodeLevel = "OFF";
  63. }
  64. }
  65. //WhiteNameSheet is avaliable.
  66. if (strVendorRecodeLevel.Compare("OFF") != 0)
  67. {
  68. //get WhiteNameSheet
  69. CSimpleStringA strWhiteNameSheet;
  70. eErrDev = centerConfig->ReadConfigValue(moduleName,"AllowTerminals",strWhiteNameSheet);
  71. if (!strWhiteNameSheet.IsNullOrEmpty())
  72. {
  73. bool bWhiteNameSheet = false;
  74. CAutoArray<CSimpleStringA> arrayWhiteNameSheet = strWhiteNameSheet.Split(',');
  75. for (int i=0;i<arrayWhiteNameSheet.GetCount();i++)
  76. {
  77. std::regex pattern(arrayWhiteNameSheet[i]);
  78. if(std::regex_match(DevInfo.strTerminalID.GetData(),pattern))
  79. {
  80. bWhiteNameSheet = true;
  81. break;
  82. }
  83. }
  84. //if this terminal is not at WhiteNameSheet,set level with "OFF".
  85. if(!bWhiteNameSheet) strVendorRecodeLevel = "OFF";
  86. }
  87. }
  88. eErrDev = centerConfig->ReadConfigValue(moduleName,"Type",strVendorRecodeType);
  89. if(eErrDev!=Error_Succeed || strVendorRecodeType.IsNullOrEmpty())
  90. {
  91. //default type:FILE.
  92. strVendorRecodeType = "FILE";
  93. }
  94. strVendorDllName = moduleName + "." + strVendor+"."+strVersion+"."+strBatch+".dll";
  95. TCHAR szPath[MAX_PATH] = {0};
  96. GetModuleFileNameA(NULL, szPath, MAX_PATH);
  97. CSimpleStringA strDir = szPath;
  98. strVendorLogPath = strDir.SubString(0,1);
  99. strVendorLogPath += ":/rvc/dbg";
  100. Dbg("VENDOR_RECODE_LEVEL=%s",strVendorRecodeLevel);
  101. Dbg("VENDOR_RECODE_TYPE=%s",strVendorRecodeType);
  102. Dbg("VENDOR_DLL_NAME=%s",strVendorDllName);
  103. Dbg("VENDOR_LOG_PATH=%s",strVendorLogPath);
  104. if(!SetEnvironmentVariableA("VENDOR_RECODE_LEVEL",strVendorRecodeLevel.GetData())){
  105. Dbg("Set VENDOR_RECODE_LEVEL Variable Failed.");
  106. }
  107. if(!SetEnvironmentVariableA("VENDOR_RECODE_TYPE",strVendorRecodeType.GetData())){
  108. Dbg("Set VENDOR_RECODE_TYPE Variable Failed.");
  109. }
  110. if(!SetEnvironmentVariableA("VENDOR_DLL_NAME",strVendorDllName.GetData())){
  111. Dbg("Set VENDOR_DLL_NAME Variable Failed.");
  112. }
  113. if(!SetEnvironmentVariableA("VENDOR_LOG_PATH",strVendorLogPath.GetData())){
  114. Dbg("Set VENDOR_LOG_PATH Variable Failed.");
  115. }
  116. return Error_Succeed;
  117. #else
  118. return Error_NotSupport;
  119. #endif //_WIN32
  120. }
  121. ErrorCodeEnum VendorLogControler(FSMBase *pFSM,CSimpleStringA moduleName)
  122. {
  123. return VendorLogControlerEx(pFSM->GetEntityBase(),moduleName);
  124. }
  125. /*--------------------*/
  126. /** For AccessAuth and Initializer and UpgradeMgr*/
  127. ErrorCodeEnum SpGetAllDevices(CEntityBase *pEntity, CAutoArray<CSimpleStringA> &devs)
  128. {
  129. CSmartPointer<IConfigInfo> pConfig;
  130. ErrorCodeEnum rc = pEntity->GetFunction()->OpenConfig(Config_Root, pConfig);
  131. if (rc == Error_Succeed)
  132. {
  133. int nCount(0);
  134. rc = pConfig->ReadConfigValueInt("Device", "Number", nCount);
  135. if (rc == Error_Succeed && nCount>0)
  136. {
  137. devs.Init(nCount);
  138. for(int i=0; i<nCount; i++)
  139. {
  140. CSimpleStringA str = CSimpleStringA::Format("%d", i+1);
  141. rc = pConfig->ReadConfigValue("Device", (const char*)str, devs[i]);
  142. }
  143. }
  144. }
  145. return rc;
  146. }
  147. /** For AccessAuth and UpgradeMgr*/
  148. ErrorCodeEnum SpGetDeviceInfo(CEntityBase *pCallerEntity, const CSimpleStringA &devDeviceName,
  149. CSimpleStringA &strModel, CSimpleStringA &strVendor, CSimpleStringA &strVersion)
  150. {
  151. CSmartPointer<IConfigInfo> pConfig;
  152. ErrorCodeEnum rc = pCallerEntity->GetFunction()->OpenConfig(Config_Root, pConfig);
  153. if (rc == Error_Succeed)
  154. {
  155. CSimpleStringA strSection = CSimpleStringA("Device.") + devDeviceName;
  156. pConfig->ReadConfigValue(strSection, "Vendor", strVendor);
  157. pConfig->ReadConfigValue(strSection, "Version", strVersion);
  158. strModel = devDeviceName;
  159. if (!strVendor.IsNullOrEmpty())
  160. {
  161. strModel += ".";
  162. strModel += strVendor;
  163. }
  164. if (!strVersion.IsNullOrEmpty())
  165. {
  166. strModel += ".";
  167. strModel += strVersion;
  168. }
  169. }
  170. return rc;
  171. }
  172. ErrorCodeEnum SpGetDevAdaptorPath(CEntityBase *pCallerEntity,
  173. const CSimpleStringA &devDeviceName,
  174. CSimpleStringA &strDevAdaptorPath)
  175. {
  176. CSmartPointer<IConfigInfo> pConfig;
  177. ErrorCodeEnum rc = pCallerEntity->GetFunction()->OpenConfig(Config_Root, pConfig);
  178. if (rc == Error_Succeed)
  179. {
  180. CSimpleStringA strSection = CSimpleStringA("Device.") + devDeviceName;
  181. strDevAdaptorPath = devDeviceName;
  182. CSimpleStringA str;
  183. pConfig->ReadConfigValue(strSection, "Vendor", str);
  184. if (!str.IsNullOrEmpty())
  185. {
  186. strDevAdaptorPath += ".";
  187. strDevAdaptorPath += str;
  188. }
  189. str.Clear();
  190. pConfig->ReadConfigValue(strSection, "Version", str);
  191. if (!str.IsNullOrEmpty())
  192. {
  193. strDevAdaptorPath += ".";
  194. strDevAdaptorPath += str;
  195. }
  196. str.Clear();
  197. pConfig->ReadConfigValue(strSection, "Batch", str);
  198. if (!str.IsNullOrEmpty())
  199. {
  200. strDevAdaptorPath += ".";
  201. strDevAdaptorPath += str;
  202. }
  203. CSimpleStringA strDepPath;
  204. pCallerEntity->GetFunction()->GetPath("Dep", strDepPath);
  205. strDevAdaptorPath = CSimpleStringA::Format("%s\\%s.dll",
  206. (const char*)strDepPath,
  207. (const char*)strDevAdaptorPath);
  208. }
  209. return rc;
  210. }
  211. // add by ly
  212. ErrorCodeEnum SpGetDevAdaptorPathByIndex(int nIndex,
  213. CEntityBase *pCallerEntity,
  214. const CSimpleStringA &devDeviceName,
  215. CSimpleStringA &strDevAdaptorPath)
  216. {
  217. CSmartPointer<IConfigInfo> pConfig;
  218. ErrorCodeEnum rc = pCallerEntity->GetFunction()->OpenConfig(Config_Root, pConfig);
  219. if (rc == Error_Succeed)
  220. {
  221. char tmp[64] = {0};
  222. CSimpleStringA strSection = CSimpleStringA("Device.") + devDeviceName;
  223. strDevAdaptorPath = devDeviceName;
  224. CSimpleStringA str;
  225. sprintf(tmp, "Vendor_%d", nIndex);
  226. pConfig->ReadConfigValue(strSection, tmp, str);
  227. if (!str.IsNullOrEmpty())
  228. {
  229. strDevAdaptorPath += ".";
  230. strDevAdaptorPath += str;
  231. }
  232. str.Clear();
  233. sprintf(tmp, "Version_%d", nIndex);
  234. pConfig->ReadConfigValue(strSection, tmp, str);
  235. if (!str.IsNullOrEmpty())
  236. {
  237. strDevAdaptorPath += ".";
  238. strDevAdaptorPath += str;
  239. }
  240. str.Clear();
  241. sprintf(tmp, "Batch_%d", nIndex);
  242. pConfig->ReadConfigValue(strSection, tmp, str);
  243. if (!str.IsNullOrEmpty())
  244. {
  245. strDevAdaptorPath += ".";
  246. strDevAdaptorPath += str;
  247. }
  248. CSimpleStringA strDepPath;
  249. pCallerEntity->GetFunction()->GetPath("Dep", strDepPath);
  250. strDevAdaptorPath = CSimpleStringA::Format("%s\\%s.dll",
  251. (const char*)strDepPath,
  252. (const char*)strDevAdaptorPath);
  253. }
  254. return rc;
  255. }
  256. // BranchDevice [Josephus in 16:32:09 2016/6/22]
  257. ErrorCodeEnum SpGetBrDevAdaptorPath(CEntityBase *pCallerEntity,
  258. const CSimpleStringA &devDeviceName,
  259. CSimpleStringA &strDevAdaptorPath)
  260. {
  261. CSmartPointer<IConfigInfo> pConfig;
  262. ErrorCodeEnum rc = pCallerEntity->GetFunction()->OpenConfig(Config_Root, pConfig);
  263. if (rc == Error_Succeed)
  264. {
  265. CSimpleStringA strSection = CSimpleStringA("BranchDevice.") + devDeviceName;
  266. strDevAdaptorPath = devDeviceName;
  267. CSimpleStringA str;
  268. pConfig->ReadConfigValue(strSection, "Branch", str);
  269. if (!str.IsNullOrEmpty())
  270. {
  271. strDevAdaptorPath += ".";
  272. strDevAdaptorPath += str;
  273. }
  274. str.Clear();
  275. pConfig->ReadConfigValue(strSection, "Version", str);
  276. if (!str.IsNullOrEmpty())
  277. {
  278. strDevAdaptorPath += ".";
  279. strDevAdaptorPath += str;
  280. }
  281. str.Clear();
  282. pConfig->ReadConfigValue(strSection, "Batch", str);
  283. if (!str.IsNullOrEmpty())
  284. {
  285. strDevAdaptorPath += ".";
  286. strDevAdaptorPath += str;
  287. }
  288. CSimpleStringA strDepPath;
  289. pCallerEntity->GetFunction()->GetPath("Dep", strDepPath);
  290. //strDevAdaptorPath = CSimpleStringA::Format("%s\\%s.dll",
  291. // (const char*)strDepPath,
  292. // (const char*)strDevAdaptorPath);
  293. strDevAdaptorPath = CSimpleStringA::Format("%s.dll", (const char*)strDevAdaptorPath);
  294. }
  295. return rc;
  296. }
  297. #endif