Browse Source

Merge branch 'gifur_fixed_everything' into 0_0_3_st1

gifur 3 years ago
parent
commit
e30d254596

+ 0 - 1
Module/mod_IDCertificate/IDCertificate_client_g.h

@@ -32,7 +32,6 @@ public:
 	}
 	void OnClose(ErrorCodeEnum)
 	{
-		Dbg("session closed.");
 		bSessionClosed = true;
 	}
 	bool QuerySessionClosed()

+ 0 - 1
Module/mod_gpio/Gpio_client_g.h

@@ -32,7 +32,6 @@ public:
 	}
 	void OnClose(ErrorCodeEnum)
 	{
-		Dbg("session closed.");
 		bSessionClosed = true;
 	}
 	bool QuerySessionClosed()

+ 103 - 177
Module/mod_pinpad/PinPadFSM.cpp

@@ -49,7 +49,7 @@ ErrorCodeEnum CPinPadFSM::OnInit()
 	m_csMachineType = sysInfo.strMachineType;
 	m_csSite = sysInfo.strSite;
 	m_terminalNo = sysInfo.strTerminalID;
-	Dbg("machineType:%s,site:%s,terminalNo:%s", 
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("machineType:%s,site:%s,terminalNo:%s", 
 		(const char*)m_csMachineType, (const char*)m_csSite, (const char*)m_terminalNo);
 	if (_strnicmp((const char*)m_csMachineType, "RPM.Stand1S", strlen("RPM.Stand1S")) == 0)
 		m_bPinPadNeedless = TRUE;
@@ -109,7 +109,7 @@ void CPinPadFSM::s1_on_exit()
 unsigned int CPinPadFSM::s1_on_event(FSMEvent* evt)
 {
 	LOG_FUNCTION();
-	Dbg("s1 event %d",evt->iEvt);
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("s1 event %d",evt->iEvt);
 	int ret = 0;
 	if (evt->iEvt == USER_EVT_INITFINISHED) {
 		evt->SetHandled();
@@ -143,13 +143,12 @@ void CPinPadFSM::s2_on_exit()
 {
 	LOG_FUNCTION();
 	ErrorCodeEnum eErrCode = CancelTimer(PINPAD_ANY_INPUT_TIMER);
-	Dbg("s2 cancel timer %d.",eErrCode);
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("s2 cancel timer %d.",eErrCode);
 }
 unsigned int CPinPadFSM::s2_on_event(FSMEvent* pEvt)
 {
-	//LOG_FUNCTION();
 	if (pEvt->iEvt != 1) 
-		Dbg("s2 %d,%d",pEvt->iEvt,pEvt->param1);
+		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("s2 %d,%d",pEvt->iEvt,pEvt->param1);
 	switch(pEvt->iEvt)
 	{
 	case USER_EVT_GETINPUT:
@@ -164,7 +163,7 @@ unsigned int CPinPadFSM::s2_on_event(FSMEvent* pEvt)
 		{
 			if (m_bLoadKey || m_bEncrypt)
 			{
-				Dbg("Load,Encrypt:%d,%d",m_bLoadKey,m_bEncrypt);
+				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Load,Encrypt:%d,%d",m_bLoadKey,m_bEncrypt);
 				break;
 			}
 			void *pTmp = NULL;
@@ -175,7 +174,7 @@ unsigned int CPinPadFSM::s2_on_event(FSMEvent* pEvt)
 		break;
 	case USER_EVT_LOADKEY:
 		{
-			Dbg("USER_EVT_LOADKEY");
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("USER_EVT_LOADKEY");
 			pEvt->SetHandled();
 			m_bLoadKey = true;
 			LoadKeyTask* task = new LoadKeyTask(this);
@@ -186,7 +185,7 @@ unsigned int CPinPadFSM::s2_on_event(FSMEvent* pEvt)
 		}
 	case USER_EVT_ENCRYPT:
 		{
-			Dbg("USER_EVT_ENCRYPT");
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("USER_EVT_ENCRYPT");
 			pEvt->SetHandled();
 			m_bEncrypt = true;
 			EncryptTask* task = new EncryptTask(this);
@@ -204,7 +203,7 @@ unsigned int CPinPadFSM::s2_on_event(FSMEvent* pEvt)
 		}
 	case USER_EVT_LOADKEY_SM:
 		{
-			Dbg("USER_EVT_LOADKEY(SM)");
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("USER_EVT_LOADKEY(SM)");
 			pEvt->SetHandled();
 			m_bLoadKey = true;
 			LoadKeySMTask* task = new LoadKeySMTask(this);
@@ -215,7 +214,7 @@ unsigned int CPinPadFSM::s2_on_event(FSMEvent* pEvt)
 		}
 	case USER_EVT_ENCRYPT_SM:
 		{
-			Dbg("USER_EVT_ENCRYPT(SM)");
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("USER_EVT_ENCRYPT(SM)");
 			pEvt->SetHandled();
 			m_bEncrypt = true;
 			EncryptSMTask* task = new EncryptSMTask(this);
@@ -247,7 +246,7 @@ void CPinPadFSM::s3_on_entry()
 	LOG_FUNCTION();
 	GetEntityBase()->GetFunction()->SetUserDefineState(USER_PINPAD_PININPUT);
 	ErrorCodeEnum eErrCode = CancelTimer(PINPAD_ANY_INPUT_TIMER);
-	Dbg("s3 cancel timer %d.",eErrCode);
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("s3 cancel timer %d.",eErrCode);
 }
 void CPinPadFSM::s3_on_exit()
 {
@@ -256,7 +255,7 @@ void CPinPadFSM::s3_on_exit()
 unsigned int CPinPadFSM::s3_on_event(FSMEvent* evt)
 {
 	LOG_FUNCTION();
-	Dbg("s3 event %d",evt->iEvt);
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("s3 event %d",evt->iEvt);
 	switch(evt->iEvt)
 	{
 	case USER_EVT_GETINPUTFINISHED:
@@ -287,7 +286,7 @@ void CPinPadFSM::s4_on_entry()
 	LOG_FUNCTION();
 	GetEntityBase()->GetFunction()->SetUserDefineState(USER_PINPAD_PARAM_ENCRYPTE);
 	ErrorCodeEnum eErrCode = CancelTimer(PINPAD_ANY_INPUT_TIMER);
-	Dbg("s4 cancel timer %d.",eErrCode);
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("s4 cancel timer %d.",eErrCode);
 
 }
 void CPinPadFSM::s4_on_exit()
@@ -332,7 +331,7 @@ void CPinPadFSM::s5_on_entry()
 	GetEntityBase()->GetFunction()->SetUserDefineState(USER_PINPAD_FAILED);
 	m_testResult = Error_InvalidState;
 	ErrorCodeEnum eErrCode = CancelTimer(PINPAD_ANY_INPUT_TIMER);
-	Dbg("s5 cancel timer %d.",eErrCode);
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("s5 cancel timer %d.",eErrCode);
 }
 void CPinPadFSM::s5_on_exit()
 {
@@ -340,7 +339,7 @@ void CPinPadFSM::s5_on_exit()
 }
 unsigned int CPinPadFSM::s5_on_event(FSMEvent* pEvt)
 {
-	Dbg("s5 evt %d",pEvt->iEvt);
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("s5 evt %d",pEvt->iEvt);
 	switch (pEvt->iEvt)
 	{
 	case USER_EVT_GETINPUT:
@@ -369,12 +368,12 @@ int CPinPadFSM::Initial()
 	LOG_FUNCTION();
 	if (m_bRVCIL)
 	{
-		Dbg("is RVC.IL.");
+		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("is RVC.IL.");
 		return 0;
 	}
 #ifdef _WIN32
 	DWORD dwCurrThId = GetCurrentThreadId();
-	Dbg("Initial thread id:%d", dwCurrThId);
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Initial thread id:%d", dwCurrThId);
 #endif //_WIN32
 	ErrorCodeEnum eErrDev;
 
@@ -382,7 +381,7 @@ int CPinPadFSM::Initial()
 	CSmartPointer<IConfigInfo> spConfig;
 	eErrDev = spEntityFunction->OpenConfig(Config_Root, spConfig);
 	if (eErrDev != Error_Succeed) {
-		Dbg("open cfg file failed!");
+		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("open cfg file failed! %s", SpStrError(eErrDev));
 		LogWarn(Severity_Middle, eErrDev, PinPad_UserErrorCode_Open_Root_File_Failed, "Initial:OpenConfig");
 		return eErrDev;
 	}
@@ -396,31 +395,22 @@ int CPinPadFSM::Initial()
 		tmpDLLVersion = "8.1";
 	if (tmpDevSN.GetLength() > 12 && tmpDevSN.IndexOf("FWB") > 2)
 	{
-		Dbg("This is fwb device.");
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("This is fwb device.");
 		GetEntityBase()->GetFunction()->GetPath("Dep", csDepPath);
 #ifdef _WIN32
 		dllName = csDepPath + csBackslash + "PinPad." + tmpVendor + "." + tmpDLLVersion + ".dll";//oiltmp
 #else
 		dllName = csDepPath + csBackslash + "libPinPad." + tmpVendor + "." + tmpDLLVersion + ".so";
 #endif //_WIN32
-		Dbg("%s", (const char*)dllName);
+		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s", (const char*)dllName);
 		LogWarn(Severity_Low, Error_Unexpect, PinPad_UserErrorCode_RootInfo, dllName.GetData());
 		HARDWARE_ENTITY_SET_VENDOR_NAME(m_entCode, tmpVendor);
 	}
 	else
 	{
-		Dbg("This is normal AllInOne device.");
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("This is normal AllInOne device.");
 		auto pEntity = GET_DEV_ENTITY_BASE_POINTER();
 		pEntity->ExtractVendorLibFullPath(dllName);
-
-		//eErrDev = SpGetDevAdaptorPath(m_pEntity, GetEntityBase()->GetEntityName(), dllName);
-		//if (eErrDev != Error_Succeed)
-		//{
-		//	Dbg("SpGetDevAdaptorPath(%d) failed.", eErrDev);
-		//	LogWarn(Severity_Middle, eErrDev, AlarmDECToBusiness(MEC_DLL_GET_PATH_FAILED), "Initial:SpGetDevAdaptorPath");
-		//	return Error_DevLoadFileFailed;
-		//}
-		//Dbg("%s", (LPCTSTR)dllName);
 		LogWarn(Severity_Low, Error_Unexpect, PinPad_UserErrorCode_RootInfo, dllName.GetData());
 
 		CSimpleStringA strSection = CSimpleStringA("Device.") + GetEntityBase()->GetEntityName();
@@ -436,33 +426,30 @@ int CPinPadFSM::Initial()
 	spConfig->ReadConfigValueInt("Device.PinPad", "Port", port);
 	spConfig->ReadConfigValue("Terminal", "TerminalNo", m_deviceNo);
 	spConfig->ReadConfigValue("Device.PinPad", "Checkdata", m_devCheckData);
-	Dbg("to load vendor dll.");
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to load vendor dll.");
 	if (Error_Succeed != m_hDevHelper.LoadLibAddress(dllName)) {
-		Dbg("load %s failed.", (const char*)dllName);
+		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("load %s failed.", (const char*)dllName);
 		if (!m_bPinPadNeedless) {
 			if (tmpDevSN.GetLength() < 10 || tmpDevSN.IndexOf("FWB") < 1)
 				GetEntityBase()->GetFunction()->ShowFatalError("密码键盘加载厂商适配器失败!请检查root.ini配置是否正确。");
-			//LogWarn(Severity_Middle,Error_NotInit,LOG_ERR_PINPAD_FAILED,"PinPad init failed.");
 			LogWarn(Severity_Middle, Error_NotInit, PinPad_UserErrorCode_Load_Dll_File_Failed, "PinPad init failed.");
 		}
 		return Error_DevLoadFileFailed;
 	} else {
-        Dbg("load vendor dll: %s suc.", dllName.GetData());
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("load vendor dll: %s suc.", dllName.GetData());
         //MAKEINTRESOURCE
 	}
 
-
-
 	int initTries = 0;
 	ErrorCodeEnum hr;
 	ErrorCodeEnum eErrCode;
 	do
 	{
-		Dbg("dodo");
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("dodo");
 		if (!m_hDevHelper) {
 			eErrCode = m_hDevHelper.CreateDevAdptObject();
 			if(eErrCode != Error_Succeed) {
-				Dbg("create pinpad module failed %s", SpStrError(eErrCode));
+				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("create pinpad module failed %s", SpStrError(eErrCode));
 				LogWarn(Severity_Middle, eErrDev, PinPad_UserErrorCode_Create_Object_Failed, "Initial:CreateDevComponent");
 				initTries++;
 				continue;
@@ -471,7 +458,7 @@ int CPinPadFSM::Initial()
 		//PinPadInitParam initParam;
 
 
-		Dbg("port: %d, baudRate:%d",port,baudRate);
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("port: %d, baudRate:%d",port,baudRate);
 		hr = m_hDevHelper->DevOpen(port,baudRate);
 
 		if (hr == Error_Succeed)
@@ -507,7 +494,7 @@ int CPinPadFSM::Initial()
 				}
 				return 1;
 			}
-			Dbg("SetParam suc.");
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SetParam suc.");
 			break;
 		}
 		else
@@ -523,7 +510,7 @@ int CPinPadFSM::Initial()
 	if (initTries != 0)
 	{
 		//LOG_PINPAD_ERROR_MSG_MACRO(hr, DevOpen);
-		Dbg("Open pinpad failed.%s",(const char*)tmpDevSN);
+		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Open pinpad failed.%s",(const char*)tmpDevSN);
 		if (tmpDevSN.GetLength() < 10 || tmpDevSN.IndexOf("FWB") < 1)
 			GetEntityBase()->GetFunction()->ShowFatalError("密码键盘打开失败!请检查键盘是否连接,配置是否正确。");
 		return 1;
@@ -537,7 +524,7 @@ int CPinPadFSM::Initial()
 	eErrDev = spEntityFunction->OpenConfig(Config_Run, spConfig);
 	if (eErrDev != Error_Succeed)
 	{
-		Dbg("read run cfg failed(sm).");
+		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("read run cfg failed(sm).");
 		m_b3DESLoaded = false;
 		m_bSMLoaded = false;
 		LogWarn(Severity_Middle, eErrDev, PinPad_UserErrorCode_Open_RunCfgFile_Failed, "Initial:OpenConfig");
@@ -555,7 +542,7 @@ int CPinPadFSM::Initial()
 		spConfig->ReadConfigValue("Load", "SN_3DES", m_keySN);
 		spConfig->ReadConfigValue("Load", "SN_SM", m_keySNSM);
 	}
-	Dbg("encrypt key :%d,load key :%d,%d", m_encryptkey,m_b3DESLoaded,m_bSMLoaded);
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("encrypt key :%d,load key :%d,%d", m_encryptkey,m_b3DESLoaded,m_bSMLoaded);
 	DevCategoryInfo devInfo;
 	ZeroMemory(devInfo.szModel, MAX_DEV_MODEL_LEN);
 	ZeroMemory(devInfo.szType, MAX_DEV_TYPE_LEN);
@@ -566,7 +553,7 @@ int CPinPadFSM::Initial()
 		m_szModel = devInfo.szModel;
 		m_szType = devInfo.szType;
 		m_szVendor = devInfo.szVendor;
-		Dbg("szModel:%s, szType:%s, szVendor:%s", devInfo.szModel, devInfo.szType, devInfo.szVendor);
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("szModel:%s, szType:%s, szVendor:%s", devInfo.szModel, devInfo.szType, devInfo.szVendor);
 		m_adapterInfo.devCatInfo = devInfo;
 	}
 	else
@@ -596,20 +583,20 @@ void CPinPadFSM::DoWork()
 		}
 		else
 		{
-			Dbg("getinput in thread start");
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("getinput in thread start");
 			SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx;
 			SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctxSM;
 			bool smFlag = false;
 			bool bRet = this->GetCtx(ctx,ctxSM,smFlag);
-			Dbg("sm ctx or not[%d]",smFlag);
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("sm ctx or not[%d]",smFlag);
 			if (!bRet)
 			{
-				Dbg("get ctx failed.doing nothing");
+				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("get ctx failed.doing nothing");
 				continue;
 			}
 			ret = this->GetInput(ctx,ctxSM,smFlag);
 			evt = new FSMEvent(USER_EVT_GETINPUTFINISHED);
-			Dbg("getinput in thread end");
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("getinput in thread end");
 		}
 		if (ret == 0)
 			evt->param1 = 0;
@@ -644,7 +631,7 @@ static int h2i(char *s)
 
 void CPinPadFSM::push_char(char *buf, int *len, int c)
 {
-	Dbg("len:%d",*len);
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("len:%d",*len);
 	buf[*len] = c;
 	*len = *len + 1;
 	buf[*len] = 0;
@@ -654,11 +641,8 @@ void CPinPadFSM::push_char(char *buf, int *len, int c)
 }
 void CPinPadFSM::PushInputChar(char *buf,int c)
 {
-	//Dbg("len:%d",*len);
 	buf[0] = c;
-	Dbg("anyinput[%d][%s]",c,buf);
-	//*len = *len + 1;
-	//buf[*len] = 0;
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("anyinput[%d][%s]",c,buf);
 	InputContent evt;
 	evt.data = buf;
 	SpSendBroadcast(GetEntityBase()->GetFunction(), SP_MSG_OF(InputContent), SP_MSG_SIG_OF(InputContent), evt);
@@ -773,7 +757,7 @@ ErrorCodeEnum CPinPadFSM::GetEncryptText(SpReqAnsContext<PinPadService_GetInput_
 		confirm = ctxSM->Req.confirm;
 		if (ctxSM->Req.smflag == 1)
 		{
-			Dbg("has smflag true,to use sm.");
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("has smflag true,to use sm.");
 			bSMFlag = true;
 		}
 	}
@@ -808,14 +792,14 @@ ErrorCodeEnum CPinPadFSM::GetEncryptText(SpReqAnsContext<PinPadService_GetInput_
 	}
 
 	accInfo.dwAccLen = 12;
-	Dbg("acc(%s)",accInfo.account);
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("acc(%s)",accInfo.account);
 	errCode = m_hDevHelper->SetAccNo(accInfo);
 	if (errCode != Error_Succeed)
 	{
 		if (!bSM)
-			Dbg("set accout(%s)(%s) failed(%d).",(const char*)ctx->Req.account,accInfo.account,errCode);
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("set accout(%s)(%s) failed(%d).",(const char*)ctx->Req.account,accInfo.account,errCode);
 		else
-			Dbg("[sm]set accout(%s)(%s) failed(%d).",(const char*)ctxSM->Req.account,accInfo.account,errCode);
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("[sm]set accout(%s)(%s) failed(%d).",(const char*)ctxSM->Req.account,accInfo.account,errCode);
 		SetErrPackage(m_errPkg, "GetEncryptText::SetAccNo", m_devSN, errCode, MEC_DEVAPI_EPP_SetAccNo);
 		AlarmDEC(m_errPkg, true);
 		return Error_DevCommFailed;
@@ -846,7 +830,7 @@ ErrorCodeEnum CPinPadFSM::GetEncryptText(SpReqAnsContext<PinPadService_GetInput_
 		AlarmDEC(m_errPkg, true);
 		return Error_DevCommFailed;
 	}
-	Dbg("to start pininput...");
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("to start pininput...");
 	errCode = m_hDevHelper->StartPinInput(len);
 	if (errCode != Error_Succeed)
 	{
@@ -854,7 +838,7 @@ ErrorCodeEnum CPinPadFSM::GetEncryptText(SpReqAnsContext<PinPadService_GetInput_
 		AlarmDEC(m_errPkg, true);
 		return Error_DevCommFailed;
 	}
-	Dbg("start pininput end");
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("start pininput end");
 	char *buf = new char[len+1];
 	memset(buf,0,len+1);
 	int readed = 0;
@@ -863,17 +847,17 @@ ErrorCodeEnum CPinPadFSM::GetEncryptText(SpReqAnsContext<PinPadService_GetInput_
 	DWORD dwTimeStamp = dwStart;
 	ErrorCodeEnum ec4KeyRead(Error_Succeed);
 	bool bCancelInput = false;
-	Dbg("reqqqq(pin) len: %d, timeout:%d, confirm or not: %d",len,timeout,confirm);
-	Dbg("exit flag: %d",m_bExit);
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("reqqqq(pin) len: %d, timeout:%d, confirm or not: %d",len,timeout,confirm);
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("exit flag: %d",m_bExit);
 	while (elapsed < MAX_PINPAD_INPUT_TIMEOUT) 
 	{
 		if (m_bExit) {
-			Dbg("exit read routine.");
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("exit read routine.");
 			break;
 		}
 			
 		if (!confirm && readed >= len) {
-			Dbg("has been fulfill, exit");
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("has been fulfill, exit");
 			break;
 		}
 			
@@ -887,7 +871,7 @@ ErrorCodeEnum CPinPadFSM::GetEncryptText(SpReqAnsContext<PinPadService_GetInput_
 		if (m_bFrontCancel)
 		{
 			bCancelInput = true;
-			Dbg("detect cancel cmd!");
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("detect cancel cmd!");
 			goto Err;
 		}
 
@@ -917,7 +901,7 @@ ErrorCodeEnum CPinPadFSM::GetEncryptText(SpReqAnsContext<PinPadService_GetInput_
 					elapsed = GetTickCount() - dwStart;
 					continue;
 				}
-				Dbg("clear input");
+				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("clear input");
 				pop_char(buf, &readed,true);
 			} else if (btCh == 0x1b) { // quit
 				if (confirm)
@@ -940,12 +924,12 @@ ErrorCodeEnum CPinPadFSM::GetEncryptText(SpReqAnsContext<PinPadService_GetInput_
 				}
 				push_char(buf, &readed, '*');
 			}else{
-				Dbg("else[%d]",btCh);
+				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("else[%d]",btCh);
 			}
 		} else {
 			DWORD dwTmp = GetTickCount();
 			if ((dwTmp - dwTimeStamp) >= 1000) {
-				Dbg("KeyRead returned error: %s", SpStrError(ec4KeyRead));
+				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("KeyRead returned error: %s", SpStrError(ec4KeyRead));
 				dwTimeStamp = dwTmp;
 			}
 		}
@@ -959,7 +943,7 @@ Err:
 
 	if (m_bExit)
 	{
-		Dbg("exit");
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("exit");
         if (ec4KeyRead != Error_Succeed) {
             LOG_PINPAD_ERROR_MSG_MACRO(ec4KeyRead, KeyRead);
         }
@@ -970,7 +954,7 @@ Err:
 		delete []buf;
 	if (bCancelInput)
 	{
-		Dbg("input cancel(pin)");
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("input cancel(pin)");
 		return Error_Cancel;
 	}
 	if (readed < len) {
@@ -982,10 +966,10 @@ Err:
 		}
 	}
 	PinBlock pinBlk;
-	Dbg("to getpinblk");
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to getpinblk");
 	Sleep(500);//nantian
 	errCode = m_hDevHelper->GetPinBlock(pinBlk);
-	Dbg("getpinblock(%d),size:%d",errCode,pinBlk.dwSize);
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("getpinblock(%d),size:%d",errCode,pinBlk.dwSize);
 	if (errCode == Error_Succeed)
 	{
 		char *tmpPinData = new char[MAX_PIN_BLOCK_SIZE];
@@ -997,7 +981,6 @@ Err:
 			ctx->Ans.data = tmpPinData;
 		else
 			ctxSM->Ans.data = tmpPinData;
-		//Dbg("pinblk(%s)",tmpPinData);
 		if (tmpPinData != NULL)
 		{
 			delete []tmpPinData;
@@ -1005,15 +988,7 @@ Err:
 		}
 		EnDecryptInfo srcInfo,dstInfo;
 		memset(srcInfo.data,0,MAX_EN_DECRYPT_DATA_SIZE);
-		//memcpy(srcInfo.data,"0000000000000000",16);
-		//PBYTE tmpCheckData = new BYTE[MAX_EN_DECRYPT_DATA_SIZE];
-		//if (tmpCheckData == NULL)
-		//	return Error_Resource;
-		//memset(tmpCheckData,0,MAX_EN_DECRYPT_DATA_SIZE);
-		//int len = StrBuf2HexBuf(const_cast<char*>(m_devCheckData.GetData()),&tmpCheckData);
-		//memcpy(srcInfo.data,tmpCheckData,len);
-		//srcInfo.dwSize = len;
-		Dbg("encryptdata[%s]",(LPCTSTR)m_devCheckData);
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("encryptdata[%s]",(LPCTSTR)m_devCheckData);
 		memcpy(srcInfo.data,m_devCheckData,m_devCheckData.GetLength());
 		srcInfo.dwSize = m_devCheckData.GetLength();
 		memset(dstInfo.data,0,MAX_EN_DECRYPT_DATA_SIZE);
@@ -1031,12 +1006,7 @@ Err:
 			AlarmDEC(m_errPkg, true);
 			return Error_Param;
 		}
-			errCode = m_hDevHelper->EncryptData(srcInfo,dstInfo);
-		//if (tmpCheckData != NULL)
-		//{
-		//	delete []tmpCheckData;
-		//	tmpCheckData = NULL;
-		//}
+		errCode = m_hDevHelper->EncryptData(srcInfo,dstInfo);
 		if (errCode != Error_Succeed)
 		{
 			SetErrPackage(m_errPkg, "GetEncryptText::EncryptData", m_devSN, errCode, MEC_DEVAPI_EPP_EncryptData);
@@ -1050,7 +1020,7 @@ Err:
 		memset(tmpCheckCode,0,MAX_PIN_BLOCK_SIZE);
 		//HexBuf2StrBuf(dstInfo.data,&tmpCheckCode,dstInfo.dwSize);
 		memcpy(tmpCheckCode,dstInfo.data,dstInfo.dwSize);
-		Dbg("ckckck[%s]",tmpCheckCode);
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ckckck[%s]",tmpCheckCode);
 		if (!bSM)
 		{
 			if (strnicmp(tmpCheckCode, "8CA64DE9C1B123A7", strlen("8CA64DE9C1B123A7")) == 0)
@@ -1086,20 +1056,14 @@ Err:
 		AlarmDEC(m_errPkg, true);
 		return Error_DevCommFailed;
 	}
-	Dbg("pin input succeed");
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("pin input succeed");
 	return Error_Succeed;
 }
 
 void CPinPadFSM::OpenInputText(void *pUserdata)
 {
-	//Dbg("any input in");
-	//char *m_buf = new char[4];
 	memset(m_buf, 0, 4);
-
-	//m_bPinInput = false;//???
 	ErrorCodeEnum err;
-	//while (elapsed < MAX_PINPAD_INPUT_TIMEOUT) {
-	//while(1){
 	if (m_bPinInput)
 		return;
 
@@ -1108,7 +1072,7 @@ void CPinPadFSM::OpenInputText(void *pUserdata)
 		err = m_hDevHelper->StartPlainInput();
 		if (err == Error_Succeed)
 		{
-			Dbg("start any input");
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start any input");
 			GetEntityBase()->GetFunction()->SetUserDefineState(USER_PINPAD_IDLE);
 			m_testResult = Error_Succeed;
 			m_dwDevCommFailCount = 0;
@@ -1118,7 +1082,6 @@ void CPinPadFSM::OpenInputText(void *pUserdata)
 		{
 			GetEntityBase()->GetFunction()->SetUserDefineState(USER_PINPAD_FAILED_RECOVERING);
 			m_dwDevCommFailCount++;
-			//Dbg("start any input err:%d",err);
 			if (m_dwDevCommFailCount > 10 * 3)
 			{
 				SetErrPackage(m_errPkg, "GetEncryptText::StartPlainInput(over 3 minutes)", m_devSN, err, MEC_DEVAPI_EPP_StartPlainInput);
@@ -1127,19 +1090,6 @@ void CPinPadFSM::OpenInputText(void *pUserdata)
 			}
 		}
 	}
-	//commented by oilyang 20160628
-	//don't open/stop pinpad any input periodly any more
-
-	//m_dwPinPadRunCount++;
-	////30 minutes.about every 1.5s call this function once...so...
-	//if (m_dwPinPadRunCount > 40*30)
-	//{
-	//	m_dwPinPadRunCount = 0;
-	//	Dbg("stop input in period");
-	//	m_hDevHelper->StopInput();
-	//	m_bPlainOpen = false;
-	//}
-
 
 	BYTE btCh;
 	INT64 i64Start = GetTickCount();
@@ -1152,18 +1102,12 @@ void CPinPadFSM::OpenInputText(void *pUserdata)
 		PushInputChar(m_buf, btCh);
 	}
 	else {
-		//Dbg("else[%s]", buf);
 	}
-	//}
-
 
-	//delete [] buf;
-
-	//Dbg("input succeed");
-	//GetEntityBase()->GetFunction()->ResetTimer(PINPAD_ANY_INPUT_TIMER,PINPAD_ANY_INPUT_TIMEOUT);
 	ScheduleTimer(PINPAD_ANY_INPUT_TIMER, PINPAD_ANY_INPUT_TIMEOUT);
 	return;
 }
+
 ErrorCodeEnum CPinPadFSM::GetText(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx,SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctxSM,bool bSM)
 {
 	LOG_FUNCTION();
@@ -1189,19 +1133,16 @@ ErrorCodeEnum CPinPadFSM::GetText(SpReqAnsContext<PinPadService_GetInput_Req, Pi
 	DWORD dwStart = GetTickCount();
 	DWORD dwEnd = GetTickCount();
 	bool bCancelInput = false;
-	//Dbg("reqqqq[%d][%d][%d]",len,timeout,confirm);
-	//bool bPlainOpen = false;
 	ErrorCodeEnum err;
 	//the following several lines just for Nantian as they close pinpad while mag encrypted improve. oilyang 20150513
 	err = m_hDevHelper->StopInput();
 	m_bPlainOpen = false;
-	Dbg("plain input for nt.%d",err);
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("plain input for nt.%d",err);
 	Sleep(100);
 	while (elapsed < MAX_PINPAD_INPUT_TIMEOUT) {
-	//while(1){
 		if (m_bExit)
 		{
-			Dbg("Exit");
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Exit");
 			bCancelInput = true;
 			goto Err;
 		}
@@ -1209,7 +1150,7 @@ ErrorCodeEnum CPinPadFSM::GetText(SpReqAnsContext<PinPadService_GetInput_Req, Pi
 			break;
 		if (m_bWaitingMore)
 		{
-			Dbg("WaitMore");
+			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("WaitMore");
 			dwStart = GetTickCount();
 			elapsed = 0;
 			m_bWaitingMore = false;
@@ -1217,13 +1158,13 @@ ErrorCodeEnum CPinPadFSM::GetText(SpReqAnsContext<PinPadService_GetInput_Req, Pi
 		}
 		if (m_bFrontCancel)
 		{
-			Dbg("Front Cancel");
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Front Cancel");
 			bCancelInput = true;
 			goto Err;
 		}
 		if (!m_bPlainOpen)
 		{
-			Dbg("start plain input");
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start plain input");
 			err = m_hDevHelper->StartPlainInput();
 			if (err == Error_Succeed)
 				m_bPlainOpen = true;
@@ -1235,13 +1176,8 @@ ErrorCodeEnum CPinPadFSM::GetText(SpReqAnsContext<PinPadService_GetInput_Req, Pi
 		}
 		BYTE btCh;
 		Sleep(100);//oiltest
-		//Dbg("start plain KeyRead");
 		err = m_hDevHelper->KeyRead(btCh);
-		//Dbg("end plain KeyRead");
 		if (err == Error_Succeed) {
-			//DevErrorInfo devErrInfo;
-			//m_hDevHelper->GetLastErr(devErrInfo);
-			//Dbg("[%s]",devErrInfo.szErrMsg);
 			LogEvent(Severity_Middle,LOG_EVT_PINPAD_OP,"PinPad op(T).");
 			if (btCh == 0x0d) {
 				if (confirm)
@@ -1336,7 +1272,7 @@ Err:
 	delete [] buf;
 	if (bCancelInput)
 	{
-		Dbg("input cancel");
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("input cancel");
 		return Error_Cancel;
 	}
 	if (readed < len) {
@@ -1344,20 +1280,17 @@ Err:
 			return Error_TimeOut;
 		}
 	}
-	Dbg("input succeed");
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("input succeed");
 	return Error_Succeed;
 }
 int CPinPadFSM::GetInput(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx,SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctxSM,bool bSM)
 {
-	//GetEntityBase()->GetFunction()->ResetTimer(PINPAD_ANY_INPUT_TIMER,MAX_INPUT_TIMER_TIMEOUT);
 	DWORD dwCurrThId = GetCurrentThreadId();
-	Dbg("GetInput thread id:%d",dwCurrThId);
-	//ctx = m_ctx;
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("GetInput thread id:%d",dwCurrThId);
 	m_bWaitingMore = false;
 	m_bFrontCancel = false;
 	m_bExit = false;
 	LogEvent(Severity_Middle,LOG_EVT_PINPAD_GREEN_ON,"PinPad light on.");
-	//LogEvent(Severity_Middle,LOG_EVT_PINPAD_GREEN_ON,"PinPad green light on.");
 	if (!m_hDevHelper)
 	{
 		LOG_TRACE("PinPad is not available!");
@@ -1370,7 +1303,6 @@ int CPinPadFSM::GetInput(SpReqAnsContext<PinPadService_GetInput_Req, PinPadServi
 			m_inputSMCtx->Answer(Error_Unexpect, AlarmDEC(m_errPkg, true));
 		}
 		LogEvent(Severity_Middle,LOG_EVT_PINPAD_GREEN_OFF,"PinPad light off.");
-		//LogEvent(Severity_Middle,LOG_EVT_PINPAD_GREEN_OFF,"PinPad green light off.");
 		m_bPinInput = false;
 		return 1;
 	}
@@ -1395,7 +1327,7 @@ int CPinPadFSM::GetInput(SpReqAnsContext<PinPadService_GetInput_Req, PinPadServi
 		//if (m_bPlainOpen)
 		{
 			ErrorCodeEnum errClosePinPad = m_hDevHelper->StopInput();
-			Dbg("close pinpad(%d).",errClosePinPad);
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("close pinpad(%d).",errClosePinPad);
 			Sleep(100);
 			m_bPlainOpen = false;
 		}
@@ -1428,9 +1360,6 @@ int CPinPadFSM::GetInput(SpReqAnsContext<PinPadService_GetInput_Req, PinPadServi
 	}
 	m_bPinInput = false;
 	LogEvent(Severity_Middle,LOG_EVT_PINPAD_GREEN_OFF,"PinPad light off.");
-	//GetEntityBase()->GetFunction()->ResetTimer(PINPAD_ANY_INPUT_TIMER,1);
-	//LogEvent(Severity_Middle,LOG_EVT_PINPAD_GREEN_OFF,"PinPad green light off.");
-
 	return 0;
 }
 int CPinPadFSM::LoadKey(SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadService_LoadKeys_Ans>::Pointer ctx)
@@ -1441,7 +1370,7 @@ int CPinPadFSM::LoadKey(SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadServic
 	eErr = spEntityFunction->OpenConfig(Config_Run, spConfig);
 	if (eErr != Error_Succeed)
 	{
-		Dbg("read run cfg failed.");
+		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("read run cfg failed.");
 		spConfig = NULL;
 	}
 	if (m_bPlainOpen)
@@ -1454,7 +1383,7 @@ int CPinPadFSM::LoadKey(SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadServic
 		mkParam.smFlag = 0;
 		memset(mkParam.key,0,MAX_MASTER_KEY_SIZE);
 		memcpy(mkParam.key,ctx->Req.masterkey,strlen(ctx->Req.masterkey));
-		//Dbg("%s,%d",mkParam.key,mkParam.dwSN);
+		//DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s,%d",mkParam.key,mkParam.dwSN);
 		eErr = m_hDevHelper->LoadMasterKey(mkParam);
 		if (eErr != Error_Succeed)
 		{
@@ -1465,7 +1394,7 @@ int CPinPadFSM::LoadKey(SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadServic
 			m_bLoadKey = false;
 			return 0;
 		}
-		Dbg("Load master key suc.");
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Load master key suc.");
 		//oilyang@20170424 if load 3des master key succeed,clear load key status both of 3des and sm
 		spConfig->WriteConfigValueInt("Load", "3DES", 0);
 		spConfig->WriteConfigValueInt("Load", "SM", 0);
@@ -1489,7 +1418,7 @@ int CPinPadFSM::LoadKey(SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadServic
 		m_bLoadKey = false;
 		return 0;
 	}
-	Dbg("Load working key1 suc.");
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Load working key1 suc.");
 	wkParam2.smFlag = 0;
 	eErr = m_hDevHelper->LoadWorkingKey(wkParam2);
 	if (eErr != Error_Succeed)
@@ -1501,7 +1430,7 @@ int CPinPadFSM::LoadKey(SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadServic
 		m_bLoadKey = false;
 		return 0;
 	}
-	Dbg("Load working key2 suc.");
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Load working key2 suc.");
 	if (spConfig != NULL)
 	{
 		eErr = spConfig->WriteConfigValueInt("Load", "3DES", 1);
@@ -1533,7 +1462,7 @@ int CPinPadFSM::Encrypt(SpReqAnsContext<PinPadService_EncryptData_Req, PinPadSer
 		m_bEncrypt = false;
 		return 0;
 	}
-	Dbg("SetParam ok.");
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("SetParam ok.");
 	eErr = m_hDevHelper->ActiveWorkingKey(0, 1);
 	if (eErr  != Error_Succeed)
 	{
@@ -1542,7 +1471,7 @@ int CPinPadFSM::Encrypt(SpReqAnsContext<PinPadService_EncryptData_Req, PinPadSer
 		m_bEncrypt = false;
 		return 0;
 	}
-	Dbg("Active ok.");
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("Active ok.");
 	EnDecryptInfo srcData,dstData;
 	ZeroMemory(srcData.data,MAX_EN_DECRYPT_DATA_SIZE);
 	ZeroMemory(dstData.data,MAX_EN_DECRYPT_DATA_SIZE);
@@ -1557,10 +1486,9 @@ int CPinPadFSM::Encrypt(SpReqAnsContext<PinPadService_EncryptData_Req, PinPadSer
 		m_bEncrypt = false;
 		return 0;
 	}
-	//Dbg("%d,%s",dstData.dwSize,dstData.data);
-
+	//DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_USER)("%d,%s",dstData.dwSize,dstData.data);
 	ctx->Ans.ciphertext = (char*)dstData.data;
-	Dbg("Encrypt ok.");
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("Encrypt ok.");
 	m_bEncrypt = false;
 	ctx->Answer(Error_Succeed);
 	return 0;
@@ -1568,7 +1496,7 @@ int CPinPadFSM::Encrypt(SpReqAnsContext<PinPadService_EncryptData_Req, PinPadSer
 int CPinPadFSM::LoadKeySM(SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadService_LoadKeysSM_Ans>::Pointer ctx)
 {
 	LOG_FUNCTION();
-	//Dbg("bOpen(%d),initflag(%d),mk(%s),wk1(%s),wk2(%s)",m_bPlainOpen,ctx->Req.initializeflag,(LPCTSTR)ctx->Req.masterkey,(LPCTSTR)ctx->Req.workingkey1,(LPCTSTR)ctx->Req.workingkey2);
+	//DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_USER)("bOpen(%d),initflag(%d),mk(%s),wk1(%s),wk2(%s)",m_bPlainOpen,ctx->Req.initializeflag,(LPCTSTR)ctx->Req.masterkey,(LPCTSTR)ctx->Req.workingkey1,(LPCTSTR)ctx->Req.workingkey2);
 	ErrorCodeEnum eErr;
 	CSmartPointer<IEntityFunction> spEntityFunction = GetEntityBase()->GetFunction();
 	CSmartPointer<IConfigInfo> spConfig;
@@ -1594,13 +1522,13 @@ int CPinPadFSM::LoadKeySM(SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadSe
 			mkParam.dwSN = 1;
 		mkParam.smFlag = ctx->Req.smflag;
 		memset(mkParam.key,0,MAX_MASTER_KEY_SIZE);
-		Dbg("mkey len:%d", strlen(ctx->Req.masterkey));
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("mkey len:%d", strlen(ctx->Req.masterkey));
 		memcpy(mkParam.key,ctx->Req.masterkey,strlen(ctx->Req.masterkey));
-		//Dbg("%s,%d",mkParam.key,mkParam.dwSN);
+		//DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_USER)("%s,%d",mkParam.key,mkParam.dwSN);
 		eErr = m_hDevHelper->LoadMasterKey(mkParam);
 		if (eErr != Error_Succeed)
 		{
-			Dbg("Load master key(%d),mkeysn:%d failed(%d).",bSM,mkParam.dwSN,eErr);
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("Load master key(%d),mkeysn:%d failed(%d).",bSM,mkParam.dwSN,eErr);
 			LOG_PINPAD_ERROR_MSG_MACRO(eErr, LoadMasterKey);
 			ctx->Ans.result = 0;
 			SetErrPackage(m_errPkg, "LoadKeySM::LoadMasterKey", m_devSN, eErr, MEC_DEVAPI_EPP_LoadMasterKey);
@@ -1608,7 +1536,7 @@ int CPinPadFSM::LoadKeySM(SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadSe
 			m_bLoadKey = false;
 			return 0;
 		}
-		Dbg("Load master key(%d) suc.",bSM);
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("Load master key(%d) suc.",bSM);
 		//after load Master key,clear the load key status.add by oilyang 20160922
 		//oilyang@20170424 if load 3des master key succeed,clear load key status both of 3des and sm
 		if (!bSM)
@@ -1687,7 +1615,7 @@ int CPinPadFSM::LoadKeySM(SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadSe
 int CPinPadFSM::EncryptSM(SpReqAnsContext<PinPadService_EncryptDataSM_Req, PinPadService_EncryptDataSM_Ans>::Pointer ctx)
 {
 	LOG_FUNCTION();
-	Dbg("smflag [%d]",ctx->Req.smflag);
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("smflag [%d]",ctx->Req.smflag);
 	ErrorCodeEnum eErr;
 	bool bSM = false;
 	if (ctx->Req.smflag == 1)
@@ -1708,7 +1636,7 @@ int CPinPadFSM::EncryptSM(SpReqAnsContext<PinPadService_EncryptDataSM_Req, PinPa
 		m_bEncrypt = false;
 		return 0;
 	}
-	Dbg("SetParam ok.");
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("SetParam ok.");
 	if (!bSM)
 		eErr = m_hDevHelper->ActiveWorkingKey(0, 1);
 	else
@@ -1720,7 +1648,7 @@ int CPinPadFSM::EncryptSM(SpReqAnsContext<PinPadService_EncryptDataSM_Req, PinPa
 		m_bEncrypt = false;
 		return 0;
 	}
-	Dbg("Active ok.");
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("Active ok.");
 	EnDecryptInfo srcData,dstData;
 	ZeroMemory(srcData.data,MAX_EN_DECRYPT_DATA_SIZE);
 	ZeroMemory(dstData.data,MAX_EN_DECRYPT_DATA_SIZE);
@@ -1735,10 +1663,10 @@ int CPinPadFSM::EncryptSM(SpReqAnsContext<PinPadService_EncryptDataSM_Req, PinPa
 		m_bEncrypt = false;
 		return 0;
 	}
-	//Dbg("%d,%s",dstData.dwSize,dstData.data);
-
+	//DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%d,%s",dstData.dwSize,dstData.data);
+	
 	ctx->Ans.ciphertext = (char*)dstData.data;
-	Dbg("Encrypt ok.");
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Encrypt ok.");
 	m_bEncrypt = false;
 	ctx->Answer(Error_Succeed);
 	return 0;
@@ -1751,7 +1679,7 @@ int CPinPadFSM::GetCheckCode(SpReqAnsContext<PinPadService_GetCheckCode_Req, Pin
 	ctx->Ans.checkcode.Init(ctx->Req.mSN.GetCount());
 	for (int i = 0; i < ctx->Req.mSN.GetCount(); i++)
 	{
-		Dbg("mSN:%d,wSN:%d", ctx->Req.mSN[i], ctx->Req.wSN[i]);
+		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("mSN:%d,wSN:%d", ctx->Req.mSN[i], ctx->Req.wSN[i]);
 		//set param
 		if (ctx->Req.mSN[i] == 1)
 			eErr = m_hDevHelper->SetParam(EPP_PT_SET_ENCRYPT_METHOD, EPP_ALGO_METHOD_SM4);
@@ -1777,7 +1705,7 @@ int CPinPadFSM::GetCheckCode(SpReqAnsContext<PinPadService_GetCheckCode_Req, Pin
 		{
 			EnDecryptInfo srcInfo, dstInfo;
 			memset(srcInfo.data, 0, MAX_EN_DECRYPT_DATA_SIZE);
-			Dbg("encryptdata[%s]", (LPCTSTR)m_devCheckData);
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("encryptdata[%s]", (LPCTSTR)m_devCheckData);
 			memcpy(srcInfo.data, m_devCheckData, m_devCheckData.GetLength());
 			srcInfo.dwSize = m_devCheckData.GetLength();
 			memset(dstInfo.data, 0, MAX_EN_DECRYPT_DATA_SIZE);
@@ -1814,7 +1742,7 @@ bool CPinPadFSM::GetDevInfo(DevCategoryInfo &devInfo)
 		m_szModel = info.szModel;
 		m_szType = info.szType;
 		m_szVendor = info.szVendor;
-		Dbg("%d,%d,%d", strlen(info.szModel), strlen(info.szType), strlen(info.szVendor));
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("%d,%d,%d", strlen(info.szModel), strlen(info.szType), strlen(info.szVendor));
 	}
 	else
 	{
@@ -1863,12 +1791,12 @@ void CPinPadFSM::SetEnterMainPage(bool bValue)
 		if (m_bInMainPage)
 		{
 			eErr = CancelTimer(PINPAD_ANY_INPUT_TIMER);
-			Dbg("Cancel any input timer%d.", eErr);
+			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Cancel any input timer%d.", eErr);
 		}
 		else
 		{
 			eErr = ScheduleTimer(PINPAD_ANY_INPUT_TIMER, PINPAD_ANY_INPUT_TIMEOUT);
-			Dbg("Start any input timer%d.", eErr);
+			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Start any input timer%d.", eErr);
 		}
 	}
 }
@@ -1879,14 +1807,12 @@ void CPinPadFSM::SelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionCon
 		pTransactionContext->SendAnswer(Error_Succeed);
 	else
 		pTransactionContext->SendAnswer(m_testResult);
-	//DevCategoryInfo devCatInfo;
-	//ErrorCodeEnum eErr = m_pPinPad->GetDevCategory(devCatInfo);
 }
 
 void CPinPadFSM::CrossTermCall(SpReqAnsContext<PinPadService_CrossTermCall_Req, PinPadService_CrossTermCall_Ans>::Pointer cctx)
 {
 	ErrorCodeEnum eErr = Error_Unexpect;
-	Dbg("CrossTermCall,type:%x", cctx->Req.type);
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("CrossTermCall,type:%x", cctx->Req.type);
 	switch (cctx->Req.type)
 	{
 	case PinPadService_Method_GetInputSM:
@@ -1895,12 +1821,12 @@ void CPinPadFSM::CrossTermCall(SpReqAnsContext<PinPadService_CrossTermCall_Req,
 		if ((eErr = SpBlob2Object(cctx->Req.paramX, ctx->Req)) == Error_Succeed) {
 			SetCtx(NULL, ctx, true);
 			if (this->GetInput(NULL,ctx,true) != 0) {
-				Dbg("GetInput failed.");
+				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("GetInput failed.");
 				eErr = Error_Unexpect;
 			}
 			else {
 				eErr = SpObject2Blob(ctx->Ans, cctx->Ans.retParamX);
-				Dbg("after GetInput,eErr:%d,paramX.len:%d", eErr, cctx->Ans.retParamX.m_iLength);
+				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("after GetInput,eErr:%d,paramX.len:%d", eErr, cctx->Ans.retParamX.m_iLength);
 			}
 		}
 		cctx->Answer(eErr);
@@ -1922,7 +1848,7 @@ void CPinPadFSM::CrossTermCall(SpReqAnsContext<PinPadService_CrossTermCall_Req,
 void CPinPadFSM::CrossTermInvokeInfo(SpOnewayCallContext<PinPadService_CrossTermInvokeInfo_Info>::Pointer ctx)
 {
 	LOG_FUNCTION();
-	Dbg("entity sn:%x,type:%d,errcode:%x", ctx->Info.nEntityID, ctx->Info.type, ctx->Info.result);
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("entity sn:%x,type:%d,errcode:%x", ctx->Info.nEntityID, ctx->Info.type, ctx->Info.result);
 	if (ctx->Info.paramX.m_iLength <= 1)
 	{
 
@@ -1939,7 +1865,7 @@ void CPinPadFSM::CrossTermInvokeInfo(SpOnewayCallContext<PinPadService_CrossTerm
 		//	PinPadService_GetInputSM_Ans>::Pointer xctx;
 		//xctx.Attach(pt);
 		eErr = SpBlob2Object(ctx->Info.paramX, m_inputSMCtx->Ans);
-		Dbg("eErr:%d,Y len:%d", eErr, ctx->Info.paramX.m_iLength);
+		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErr:%d,Y len:%d", eErr, ctx->Info.paramX.m_iLength);
 		m_inputSMCtx->Answer((ErrorCodeEnum)ctx->Info.result);
 	}
 	break;
@@ -1955,14 +1881,14 @@ int CPinPadFSM::LocalCallHeartBeat(int method, CBlob &bbSend, bool bTwoWay)
 	HeartBeatService_ClientBase* pClient = new HeartBeatService_ClientBase(GetEntityBase());
 	if (pClient == NULL)
 	{
-		Dbg("create HeartBeat client failed.GetLastError:%d", GetLastError());
+		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("create HeartBeat client failed.GetLastError:%d", GetLastError());
 		return -1;
 	}
 	ErrorCodeEnum eErr = Error_Unexpect;
 	eErr = pClient->Connect();
 	if (eErr != Error_Succeed)
 	{
-		Dbg("client connect to HeartBeat failed:%x", eErr);
+		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("client connect to HeartBeat failed:%x", eErr);
 		return -1;
 	}
 	HeartBeatService_CrossTermCall_Req req;
@@ -1977,7 +1903,7 @@ int CPinPadFSM::LocalCallHeartBeat(int method, CBlob &bbSend, bool bTwoWay)
 	req.paramX = bbSend;
 	req.type = method;
 	eErr = pClient->CrossTermCall(req, ans, 20000);
-	Dbg("CrossTermCall to HeartBeat from %s to %s, result:%x", (const char*)req.fromTerminalNo, (const char*)req.toTerminalNo, eErr);
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("CrossTermCall to HeartBeat from %s to %s, result:%x", (const char*)req.fromTerminalNo, (const char*)req.toTerminalNo, eErr);
 	return 0;
 }
 bool CPinPadFSM::GetAttachedTerminal(CSimpleStringA &csTerm)

+ 4 - 5
Module/mod_pinpad/PinPadFSM.h

@@ -231,7 +231,6 @@ public:
 			ZeroMemory(&m_adapterInfo, sizeof(m_adapterInfo));
 	}
 	~CPinPadFSM(){
-		Dbg("~CPinPadFSM");
 		m_bEntityExit = true;
 		m_hInputConVar.Broadcast();
 	}
@@ -287,15 +286,15 @@ public:
 			m_ctx = ctx;
 			if (!ctx->Req.encrypt)
 				m_inputCtx = ctx;
-			Dbg("confirm,encrypt,len,timeout:%d,%d,%d,%d", m_ctx->Req.confirm, m_ctx->Req.encrypt, m_ctx->Req.length, m_ctx->Req.timeout);
+			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("confirm,encrypt,len,timeout:%d,%d,%d,%d", m_ctx->Req.confirm, m_ctx->Req.encrypt, m_ctx->Req.length, m_ctx->Req.timeout);
 		}
 		else
 		{
 			m_ctx = NULL;
 			m_inputSMCtx = ctxSM;
-			Dbg("sm ctx,confirm,encrypt,len,timeout:%d,%d,%d,%d", m_inputSMCtx->Req.confirm, m_inputSMCtx->Req.encrypt, m_inputSMCtx->Req.length, m_inputSMCtx->Req.timeout);
+			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("sm ctx,confirm,encrypt,len,timeout:%d,%d,%d,%d", m_inputSMCtx->Req.confirm, m_inputSMCtx->Req.encrypt, m_inputSMCtx->Req.length, m_inputSMCtx->Req.timeout);
 		}
-		Dbg("setpininput true");
+		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("setpininput true");
 		m_bPinInput = true;
 	}
 	bool GetCtx(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer &ctx
@@ -303,7 +302,7 @@ public:
 	{
 		if (m_ctx == NULL && m_inputSMCtx == NULL)
 		{
-			Dbg("both ctx is null");
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("both ctx is null");
 			return false;
 		}
 		if (m_inputSMCtx != NULL)

+ 0 - 1
Module/mod_pinpad/PinPad_client_g.h

@@ -32,7 +32,6 @@ public:
 	}
 	void OnClose(ErrorCodeEnum)
 	{
-		Dbg("session closed.");
 		bSessionClosed = true;
 	}
 	bool QuerySessionClosed()

+ 1 - 1
Module/mod_pinpad/mod_PinPad.h

@@ -186,7 +186,7 @@ public:
 			{
 				ctx->Ans.model = devInfo.szModel;
 				ctx->Ans.type = devInfo.szType;
-				Dbg("szModel:%s", (const char*)ctx->Ans.model);
+				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("szModel:%s", (const char*)ctx->Ans.model);
 			}
 			ctx->Ans.state = devInfo.eState;
 		}

+ 3 - 3
Module/mod_pinpad/mod_pinpad.cpp

@@ -19,7 +19,7 @@ void PinPadServerSession::Handle_InputCancel(SpOnewayCallContext<PinPadService_I
 {
 	LOG_FUNCTION();
 	m_pEntity->InputCancel(ctx);
-	Dbg("handle front cancel");
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("handle front cancel");
 }
 void PinPadServerSession::Handle_Exit(SpOnewayCallContext<PinPadService_Exit_Info>::Pointer ctx)
 {
@@ -83,12 +83,12 @@ void CPinPadEntity::OnSysVarEvent(const char *pszKey,
 	{
 		if (_strnicmp(pszValue, "M", strlen("M")) == 0)
 		{
-			Dbg("enter main page");
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("enter main page");
 			m_fsm.SetEnterMainPage(true);
 		}
 		else
 		{
-			Dbg("not main page[%s]", pszValue);
+			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("not main page[%s]", pszValue);
 			m_fsm.SetEnterMainPage(false);
 		}
 	}