123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- #ifndef __DEVICEBASE_HELPER_H
- #define __DEVICEBASE_HELPER_H
- #pragma once
- #include "DeviceBaseClass.h"
- enum DeviceType
- {
- PinPadClassType
- };
- class DeviceBaseHelper
- {
- public:
- static DeviceBaseClass* QueryDevComponent(const char *lpszRVCRunPath, DeviceType eDevType)
- {
- char root_path[MAX_PATH];
- sprintf(root_path, "%s\\hardwarecfg\\root.ini", lpszRVCRunPath);
- }
- static ErrorCodeEnum GetAndSplitDevErrInfo(
- DeviceBaseClass* inst,
- CSimpleStringA& csErrMsg,
- WORD& wdDevErrCode,
- LPCTSTR lpszFuncNameForDisplay = ""
- )
- {
- csErrMsg = "";
- wdDevErrCode = 0;
- BOOL bDisplayFunName = TRUE;
- if( lpszFuncNameForDisplay == NULL || strlen(lpszFuncNameForDisplay) == 0 )
- bDisplayFunName = FALSE;
- if(inst == NULL)
- {
- Dbg("inst occurs nullptr !!!");
- return Error_Param;
- }
- DevErrorInfo devErrInfo;
- ZeroMemory(&devErrInfo, sizeof(DevErrorInfo));
- ErrorCodeEnum erroCode = inst->GetLastErr(devErrInfo);
- if(erroCode == Error_Succeed)
- {
- if(strlen(devErrInfo.szErrMsg) > 0)
- {
- csErrMsg = devErrInfo.szErrMsg;
- }
- if(devErrInfo.dwErrMsgLen > MAX_DEV_ERROR_MSG_LEN)
- {
- //oiltmp@20200520 comment the following line
- //wdDevErrCode = (WORD)((devErrInfo.dwErrMsgLen >> 16) & 0x0000FFFF);
- }
- if(bDisplayFunName)
- {
- Dbg("Invoke <%s> failed, Dev_GLE: DevErrCode[%d], ErrMsg[%s]",
- lpszFuncNameForDisplay, wdDevErrCode, (LPCTSTR)csErrMsg);
- }
- else
- {
- Dbg("Dev_GLE: DevErrCode[%d], ErrMsg[%s]", wdDevErrCode, (LPCTSTR)csErrMsg);
- }
- }
- else
- {
- if(bDisplayFunName)
- {
- Dbg("Invoke <%s> failed, and unfortunately Dev_GLE failed returned EC: %d(0x%X)",
- lpszFuncNameForDisplay, erroCode, erroCode);
- csErrMsg = CSimpleStringA::Format("Invoke <%s> failed", lpszFuncNameForDisplay);
- }
- else
- {
- Dbg("Dev_GLE failed returned EC: %d(0x%X)",
- erroCode, erroCode);
- }
- }
- return erroCode;
- }
- static ErrorCodeEnum LogDevErrInfo(DeviceBaseClass* inst, LPCTSTR lpszFuncName = "")
- {
- CSimpleStringA csMsg;
- WORD wdErrorCode = 0;
- return GetAndSplitDevErrInfo(inst, csMsg, wdErrorCode, lpszFuncName);
- }
- static BOOL GetDevErrorCode(DeviceBaseClass* inst, WORD& wdErrorCode)
- {
- CSimpleStringA csMsg;
- ErrorCodeEnum eRet = GetAndSplitDevErrInfo(inst, csMsg, wdErrorCode);
- return ((eRet == Error_Succeed) ? (TRUE) : (FALSE));
- }
- #ifndef _WIN32
- static VendorNameType GetCurVendorType(LPCTSTR vendorName)
- {
- if(vendorName == NULL || strlen(vendorName) == 0) {
- return Vendor_Invalide;
- }
- int idx = -1;
- for(int i=0; i<sizeof(VendorNameStr)/sizeof(VendorNameStr[0]); ++i)
- {
- if(strnicmp(vendorName, VendorNameStr[i], strlen(VendorNameStr[i])) == 0) {
- idx = i;
- break;
- }
- }
- if(idx == -1) {
- /*历史遗留原因,怡化厂商有两个适配器名字*/
- if(strnicmp(vendorName, "yihua", strlen("yihua")) == 0) {
- idx = Vendor_YiHua;
- } else {
- idx = Vendor_Invalide;
- }
- }
- return (VendorNameType)idx;
- }
- //1:报错累计到上限,需要返回错误码给业务
- //0:报错累计未到上限,或者不需要计数
- //-1:出现错误
- static int CountDevError(CSmartPointer<IEntityFunction> spEntityFunction, int& iCurErrNum)
- {
- CSmartPointer<IConfigInfo> spCenterConfig;
- ErrorCodeEnum eErrDev = spEntityFunction->OpenConfig(Config_CenterSetting, spCenterConfig);
- int iErrNumLimit;
- if (eErrDev != Error_Succeed) {
- Dbg("open centersetting file failed!");
- return -1;
- }
- else {
- spCenterConfig->ReadConfigValueInt("Common", "ErrUpperLimit", iErrNumLimit);
- if (0 == iErrNumLimit) {
- iErrNumLimit = 5;
- Dbg("iErrNumLimit=%d", iErrNumLimit);
- }
- else if (iErrNumLimit < 0)
- return 0;
- }
- iCurErrNum++;
- if (iCurErrNum >= iErrNumLimit) {
- return 1;
- }
- else {
- return 0;
- }
- }
- #endif //NOT _WIN32
- };
- #ifndef _WIN32
- struct HardwareEntityCode {
- DWORD dwEntityId;
- DWORD dwVendorId;
- DWORD dwVendorErroCode;
- DWORD dwReserved;
- };
- #endif //NOT _WIN32
- #endif // __DEVICEBASE_HELPER_H
|