Browse Source

Z991239-4157 #comment mod_initiativetransfer启动优化

80274480 2 years ago
parent
commit
f915d0acb9

+ 52 - 44
Module/mod_initiativetransfer/FlowControlFSM.cpp

@@ -23,17 +23,19 @@ void ChannelClient::OnMessage( ErrorCodeEnum Error, ChannelService_Packet_Info &
 	}
 }
 
-CFlowControlFSM::CFlowControlFSM():	m_bIspad(FALSE)
+CFlowControlFSM::CFlowControlFSM():	m_bIspad(FALSE), m_pClient(NULL)
 {
-
+	
 }
+
 CFlowControlFSM::~CFlowControlFSM()
 {
+
 }
 
 void CFlowControlFSM::OnStateTrans( int iSrcState, int iDstState )
 {
-	LOG_TRACE("Trans from %s to %s", GetStateName(iSrcState), GetStateName(iDstState));
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Trans from %s to %s", GetStateName(iSrcState), GetStateName(iDstState));
 	switch (iDstState) {
 	case s0:
 		SetState("O", "Offline"); // offline
@@ -57,31 +59,33 @@ void CFlowControlFSM::OnStateTrans( int iSrcState, int iDstState )
 
 ErrorCodeEnum CFlowControlFSM::OnInit()
 {
-	ErrorCodeEnum Error;
-	m_pClient = new ChannelClient(m_pEntity, this);
-	Error = m_pClient->Connect();
-	if (Error == Error_Succeed) {
-		ChannelService_BeginState_Sub StateSub;
-		Error = m_pClient->BeginState(StateSub);
-		if (Error == Error_Succeed) {
-			ChannelService_BeginRecv_Sub Sub;
-			Sub.type = ACM_TYPE_FLW;
-			Error = m_pClient->BeginRecv(Sub);
-		}
-		if (Error != Error_Succeed) {
-			m_pClient->GetFunction()->CloseSession();
-			m_pClient = NULL;
-		}
-	} else {
-		m_pClient->SafeDelete();
-		m_pClient = NULL;
-	}
+	//ErrorCodeEnum Error;
+	//m_pClient = new ChannelClient(m_pEntity, this);
+	//Error = m_pClient->Connect();
+	//if (Error == Error_Succeed) {
+	//	ChannelService_BeginState_Sub StateSub;
+	//	Error = m_pClient->BeginState(StateSub);
+	//	if (Error == Error_Succeed) {
+	//		ChannelService_BeginRecv_Sub Sub;
+	//		Sub.type = ACM_TYPE_FLW;
+	//		Error = m_pClient->BeginRecv(Sub);
+	//	}
+	//	if (Error != Error_Succeed) {
+	//		m_pClient->GetFunction()->CloseSession();
+	//		m_pClient->SafeDelete();
+	//		m_pClient = NULL;
+	//	}
+	//} else {
+	//	m_pClient->SafeDelete();
+	//	m_pClient = NULL;
+	//}
 
-	if (Error == Error_Succeed) {
+	//if (Error == Error_Succeed) 
+	//{
 		AddStateHooker(this);
-	}
+	//}
 	
-	return Error;
+	return Error_Succeed;
 }
 ErrorCodeEnum CFlowControlFSM::OnExit()
 { 
@@ -105,21 +109,23 @@ BOOL CFlowControlFSM::ReConnectionAssistchan()
 	{
 		m_pClient->GetFunction()->CloseSession();
 		m_pClient = NULL;
-		Dbg("Close AssistChannel Session ");
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Close AssistChannel Session ");
 	}
 
 	if (m_pClient == NULL)
 	{
-		Dbg("ReConnection AssistChannel Session");
 		ErrorCodeEnum Error;
 		m_pClient = new ChannelClient(m_pEntity, this);
 		Error = m_pClient->Connect();
 		if (Error != Error_Succeed) 
 		{
-			m_pClient->SafeDelete();
-			Dbg("m_channelClient connect fail!");
+			m_pClient = NULL;
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("m_channelClient connect fail!");
 			return FALSE;
 		}
+		else{
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("m_channelClient connect success!");
+		}
 
 		if(Error == Error_Succeed)
 		{
@@ -127,11 +133,14 @@ BOOL CFlowControlFSM::ReConnectionAssistchan()
 			Error = m_pClient->BeginState(ChannelSub);
 			if (Error != Error_Succeed) 
 			{
-				LOG_TRACE("BeginState biz channel failed!");
+				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("BeginState biz channel failed!");
 				m_pClient->GetFunction()->CloseSession();
 				m_pClient = NULL;
 				return FALSE;
 			}
+			else{
+				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("BeginState biz channel success!");
+			}
 		}
 
 		if(Error == Error_Succeed)
@@ -141,11 +150,14 @@ BOOL CFlowControlFSM::ReConnectionAssistchan()
 			Error = m_pClient->BeginRecv(Sub);
 			if (Error != Error_Succeed) 
 			{
-				LOG_TRACE("BeginState biz channel failed!");
+				LOG_TRACE("Register ACM_TYPE_FLW failed!");
 				m_pClient->GetFunction()->CloseSession();
 				m_pClient = NULL;
 				return FALSE;
 			}
+			else{
+				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Register ACM_TYPE_FLW success!");
+			}
 		}
 	}
 
@@ -184,7 +196,7 @@ unsigned int CFlowControlFSM::s1_on_event(FSMEvent* event)
 			buf.OpenWrite();
 			CSimpleString16Bit reqContext = CSimpleStringW216Bit(rafe->req_context);
 			buf & reqContext;
-			Dbg("%s After convert: %s", __FUNCTION__, CSimpleString16Bit2A(reqContext).GetData());
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s After convert: %s", __FUNCTION__, CSimpleString16Bit2A(reqContext).GetData());
 			Info.data = buf.ToBlob();
 			Error = m_pClient->Send(Info);
 		} else 
@@ -193,7 +205,7 @@ unsigned int CFlowControlFSM::s1_on_event(FSMEvent* event)
 		}
 		return Error == Error_Succeed ? 1 : 0;
 	} else if (event->iEvt == USER_EVT_NTFENTFLOW) {
-		LOG_TRACE("spbroadcast NotifyEnterFlowEvent");
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("spbroadcast NotifyEnterFlowEvent");
 		NotifyEnterFlowEvent *nef = static_cast<NotifyEnterFlowEvent*>(event);
 		NotifyEnterFlow evt;
 		SpSendBroadcast(m_pEntity->GetFunction(), SP_MSG_OF(NotifyEnterFlow), SP_MSG_SIG_OF(NotifyEnterFlow), evt);
@@ -218,7 +230,7 @@ unsigned int CFlowControlFSM::s2_on_event(FSMEvent* event)
 		CSimpleStringW ans_context = CSimpleString16Bit2W(afe->ans_context);
 		evt.ans_context = ans_context;
 		evt.error = afe->err ? Error_Unexpect : Error_Succeed;
-		Dbg("AgentFlowResult!!!!!");
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("AgentFlowResult!!!!!");
 		SpSendBroadcast(m_pEntity->GetFunction(), SP_MSG_OF(AgentFlowResult), SP_MSG_SIG_OF(AgentFlowResult), evt);
 	} else if (event->iEvt == USER_EVT_REQACMFLOW) {
 		ReqACMFlowEvent *afe = static_cast<ReqACMFlowEvent *>(event);
@@ -227,7 +239,7 @@ unsigned int CFlowControlFSM::s2_on_event(FSMEvent* event)
 		evt.req_context = req_context;
 		SpSendBroadcast(m_pEntity->GetFunction(), SP_MSG_OF(ACMFlowInvoke), SP_MSG_SIG_OF(ACMFlowInvoke), evt);
 	} else if (event->iEvt == USER_EVT_NTFENTFLOW) {
-		LOG_TRACE("notify enter flow, disallow control!");
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("notify enter flow, disallow control!");
 		DisallowControl();
 	}
 	else if (event->iEvt == USER_EVT_ASSIS_IDEL)
@@ -265,7 +277,7 @@ unsigned int CFlowControlFSM::s3_on_event(FSMEvent* event)
 			buf.OpenWrite();
             CSimpleString16Bit ansContext = CSimpleStringW216Bit(afe->ans_context);
             buf& ansContext;
-            Dbg("%s After convert: %s", __FUNCTION__, CSimpleString16Bit2A(ansContext).GetData());
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s After convert: %s", __FUNCTION__, CSimpleString16Bit2A(ansContext).GetData());
 			Info.data = buf.ToBlob();
 			Error = m_pClient->Send(Info);
 		} else {
@@ -305,7 +317,7 @@ unsigned int CFlowControlFSM::s5_on_event(FSMEvent* event)
 			buf.OpenWrite();
             CSimpleString16Bit reqContext = CSimpleStringW216Bit(rafe->req_context);
             buf& reqContext;
-            Dbg("%s After convert: %s", __FUNCTION__, CSimpleString16Bit2A(reqContext).GetData());
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s After convert: %s", __FUNCTION__, CSimpleString16Bit2A(reqContext).GetData());
 			Info.data = buf.ToBlob();
 			Error = m_pClient->Send(Info);
 		} else {
@@ -322,9 +334,8 @@ unsigned int CFlowControlFSM::s5_on_event(FSMEvent* event)
 
 unsigned int CFlowControlFSM::s7_on_event(FSMEvent* event)
 {
-	if (event->iEvt == USER_EVT_ASSIS_IDEL)
-	{
-			ReConnectionAssistchan();
+	if (event->iEvt == USER_EVT_ASSIS_IDEL){
+		ReConnectionAssistchan();
 	}
 	return 0;
 }
@@ -360,7 +371,7 @@ void CFlowControlFSM::ProcessPacket( int sub_type, CBlob &blob )
 
 ErrorCodeEnum CFlowControlFSM::SetState(const char *s, const char *sdesc)
 {
-	LOG_TRACE("set BackInitiative to %s, %s", s, sdesc);
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("set BackInitiative to %s, %s", s, sdesc);
 	return m_pEntity->GetFunction()->SetSysVar("BackInitiative", s);
 }
 
@@ -380,9 +391,6 @@ ErrorCodeEnum CFlowControlFSM::DisallowControl()
 	}	
 }
 
-
-
-
 void NotifyEnterFlowEvent::OnUnhandled()
 {
 	LOG_FUNCTION();

+ 17 - 6
Module/mod_initiativetransfer/mod_initiativetransfer.cpp

@@ -4,10 +4,10 @@
 
 #include "InitiativeTransfer_server_g.h"
 #include "InitiativeTransfer_msg_g.h"
+#include "../include/EventCode.h"
 
 using namespace InitiativeTransfer;
 
-#define LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE		0x50500001  //协助通道重启
 #define LOG_EVT_ENTER_ACM_FLOW	 0x30500001          //进入坐席控制流程
 
 #define LOG_EVT_UI_RETURNMENU		0x30B00006				//退出到主菜单
@@ -46,7 +46,7 @@ public:
 		int i = 0;
 		CSmartPointer<IEntityFunction> spFunction = GetFunction();
 		m_arrListener.Init(2);
-		spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE,NULL,false);
+		spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_MOD_ASSISCHAN_STARTED_SUCCESS,NULL,false);
 		spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_RETURNMENU,NULL,false);
 		
 			//is Pad Version
@@ -65,6 +65,16 @@ public:
 		pTransactionContext->SendAnswer(Error);
 	}
 
+	void OnStarted()
+	{
+		if (m_fsm->ReConnectionAssistchan()){
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("OnStarted ConnectionAssistchan success!");
+		}
+		else{
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("OnStarted ConnectionAssistchan failed!");
+		}
+	}
+
 	virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext) 
 	{ 
 		m_fsm->PostEventFIFO(new FSMEvent(USER_EVT_EXIT));
@@ -90,14 +100,15 @@ public:
 		const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID, 
 		const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext& pLinkInfo)
 	{
-		if (dwUserCode == LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE)
+		if (dwUserCode == LOG_EVT_MOD_ASSISCHAN_STARTED_SUCCESS)
 		{
-			Dbg("recv LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE");
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("recv LOG_EVT_MOD_ASSISCHAN_STARTED_SUCCESS");
+			Sleep(1000);
 			m_fsm->PostEventFIFO(new FSMEvent(USER_EVT_ASSIS_IDEL));
 		}
 		else if (dwUserCode == LOG_EVT_UI_RETURNMENU)
 		{
-			Dbg("return main menu");
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("return main menu");
 			m_fsm->PostEventFIFO(new FSMEvent(USER_EVT_MENU_RETURN));
 		}
 	}
@@ -111,7 +122,7 @@ public:
 	void SwitchToAgentFlow(CSimpleStringW req_context)
 	{
 		CSimpleStringA str_req = CSimpleStringW2A(req_context);
-		Dbg("SwitchToAgentFlow, req_context:%s", str_req.GetData());
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SwitchToAgentFlow, req_context:%s", str_req.GetData());
 		ReqAgentFlowEvent *e = new ReqAgentFlowEvent();
 		e->req_context = req_context;
 		e->m_pEntityBase = this;