Explorar o código

!10208 卡机功能集的msg广播优化处理(增加功能集状态判断)
Merge pull request !10208 from 80174847/ST2_healthmanager_log

杨诗友80174847 hai 1 ano
pai
achega
64413ead21

+ 1 - 0
Module/mod_CardReadAdapter/CardReadAdapterFSM.cpp

@@ -554,6 +554,7 @@ unsigned int CCardReadAdapterFSM::s3_on_event(FSMEvent* pEvt)
 	case USER_EVT_CROSS_TERM_CALL_FINISHED:
 	case USER_EVT_PRINT_CARD_IM_FINISHED:
 	case USER_EVT_QUERY_CI_STATUS_FINISHED:
+	case USER_EVT_EJECT_FINISHED:
 		pEvt->SetHandled();
 		break;
 	default:

+ 53 - 16
Module/mod_CardReadAdapter/mod_CardReadAdapter.cpp

@@ -8,6 +8,8 @@
 #include "SpBase.h"
 #include "mod_CardReadAdapter.h"
 
+const int iCardIssuerFetchCard = 1;
+const int iContactlessFetchCard = 2;
 
 void CardReadAdapterServerSession::Handle_Read(SpReqAnsContext<CardReadAdapterService_Read_Req, CardReadAdapterService_Read_Ans>::Pointer ctx)
 {
@@ -263,24 +265,15 @@ void CCardReadAdapterEntity::OnBroadcastEvent(CUUID SubID, const char *pszEntity
 	if (dwMessageSignature != eMsgSig_FetchCard && dwMessageSignature != eMsgSig_SCIConnect)
 		return;
 
-	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("OnBroadcastEvent,msg:%s,%d,%d",pszEntityName,dwMessageId,dwMessageSignature);
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("OnBroadcastEvent,msg:%s,%d,%d",pszEntityName,dwMessageId,dwMessageSignature);
 	if (_strnicmp(pszEntityName, "CardIssuer", strlen("CardIssuer")) == 0)
 	{
 		if (dwMessageSignature == eMsgSig_FetchCard)
 		{
 			CardIssuer::FetchCard fc;
 			SpBuffer2Object(Buffer, fc);
-			CardIsserFetchCard evt;
-			evt.status = fc.status;
-			SpSendBroadcast(GetFunction(), SP_MSG_OF(CardIsserFetchCard), SP_MSG_SIG_OF(CardIsserFetchCard), evt);
-		}
-		else if (dwMessageSignature == eMsgSig_SCIConnect)
-		{
-			CardIssuer::SCIConnect scic;
-			SpBuffer2Object(Buffer, scic);
-			CardIssuerSCIConnect evt;
-			evt.status = scic.status;
-			SpSendBroadcast(GetFunction(), SP_MSG_OF(CardIssuerSCIConnect), SP_MSG_SIG_OF(CardIssuerSCIConnect), evt);
+			DoBroadMsgTask* task = new DoBroadMsgTask(this, iCardIssuerFetchCard,fc.status);
+			GetFunction()->PostThreadPoolTask(task);
 		}
 	}
 	else if (_strnicmp(pszEntityName, "ContactlessCard", strlen("ContactlessCard")) == 0)
@@ -299,17 +292,61 @@ void CCardReadAdapterEntity::OnBroadcastEvent(CUUID SubID, const char *pszEntity
 			}
 			else
 			{
-				ContactlessCardFetchCard evt;
-				evt.status = fc.status;
-				SpSendBroadcast(GetFunction(), SP_MSG_OF(ContactlessCardFetchCard), SP_MSG_SIG_OF(ContactlessCardFetchCard), evt);
+				DoBroadMsgTask* task = new DoBroadMsgTask(this, iContactlessFetchCard, fc.status);
+				GetFunction()->PostThreadPoolTask(task);
 			}
 		}
 	}
 	
 }
+void CCardReadAdapterEntity::DoBroadMsg(int msgType,int status)
+{
+	ULLINT ullStart = SP::Module::Comm::RVCGetTickCount();
+	ULLINT ullEnd;
+	do
+	{
+		//in not "Working" (S3) state , means have done work
+		if (_stricmp(m_fsm.GetCurrStateName(), "Working") != 0)
+			break;
+		else
+		{
+			Sleep(200);
+			ullEnd = SP::Module::Comm::RVCGetTickCount();
+		}
+	} while (ullEnd - ullStart < m_msgMaxInterval);//need to set in center setting or not?
 
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("DoBroadcastMsg cost:%d(ms)", ullEnd - ullStart);
 
-
+	if (msgType == iCardIssuerFetchCard)
+	{
+		CardIsserFetchCard evt;
+		evt.status = status;
+		SpSendBroadcast(GetFunction(), SP_MSG_OF(CardIsserFetchCard), SP_MSG_SIG_OF(CardIsserFetchCard), evt);
+	}
+	else if (msgType == iContactlessFetchCard)
+	{
+		ContactlessCardFetchCard evt;
+		evt.status = status;
+		SpSendBroadcast(GetFunction(), SP_MSG_OF(ContactlessCardFetchCard), SP_MSG_SIG_OF(ContactlessCardFetchCard), evt);
+	}
+}
+void CCardReadAdapterEntity::DoStart()
+{
+	CSmartPointer<IConfigInfo> spCerConfig;
+	ErrorCodeEnum eErr = GetFunction()->OpenConfig(Config_CenterSetting, spCerConfig);
+	if (eErr != Error_Succeed) {
+		DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("open CenterSetting file failed!");
+		return;
+	}
+	do
+	{
+		int value(0);
+		spCerConfig->ReadConfigValueInt(GetEntityName(), "MsgMaxInterval", value);
+		if (value > 1000 && value < 10000) {
+			m_msgMaxInterval = value;
+		}
+	} while (false);
+}
 SP_BEGIN_ENTITY_MAP()
 	SP_ENTITY(CCardReadAdapterEntity)
 SP_END_ENTITY_MAP()

+ 16 - 1
Module/mod_CardReadAdapter/mod_CardReadAdapter.h

@@ -51,7 +51,7 @@ private:
 class CCardReadAdapterEntity : public CEntityBase,public IBroadcastListener
 {
 public:
-	CCardReadAdapterEntity() :bInitialized(false)//, m_bCIMsg(false), m_bCCMsg(false), m_bCSMsg(false)
+	CCardReadAdapterEntity() :bInitialized(false),m_msgMaxInterval(5000)//, m_bCIMsg(false), m_bCCMsg(false), m_bCSMsg(false)
 	{
 		//MessageBoxA(NULL, "", "", MB_OK);
 	}
@@ -64,6 +64,7 @@ public:
 		ErrorCodeEnum eStart = m_fsm.Init(this);
 		if (eStart == Error_Succeed)
 		{
+			DoStart();
 			GetFunction()->SubscribeBroadcast("CardIssuer", "", this, m_uuidCIMsg);
 			GetFunction()->SubscribeBroadcast("ContactlessCard", "", this, m_uuidCCMsg);
 		}
@@ -404,13 +405,27 @@ public:
 	virtual bool IsService()const{return true;}
 	virtual bool IsMultiThread()const{return true;}
 	virtual void OnBroadcastEvent(CUUID SubID, const char *pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, CAutoBuffer Buffer);
+	void DoBroadMsg(int msgType, int status);
+	void DoStart();
 protected:
 private:
 	
 	CCardReadAdapterFSM m_fsm;
 	CUUID m_uuidCIMsg, m_uuidCSMsg, m_uuidCCMsg;
 	bool bInitialized, m_bNewSessionInit;// , m_bCIMsg, m_bCCMsg, m_bCSMsg;
+	int m_msgMaxInterval;
 
 private:
 
 };
+struct DoBroadMsgTask : public ITaskSp
+{
+	CCardReadAdapterEntity* pEntity;
+	int m_msgType;
+	int m_status;
+	DoBroadMsgTask(CCardReadAdapterEntity* f, int msgType, int status) : pEntity(f),m_msgType(msgType),m_status(status) {}
+	void Process()
+	{
+		pEntity->DoBroadMsg(m_msgType, m_status);
+	}
+};