|
@@ -2,14 +2,30 @@
|
|
|
#include "FlowControlFSM.h"
|
|
|
|
|
|
#define LOG_EVT_EXIT_ACM_FLOW 0x30500002 //退出坐席控制流程
|
|
|
+//错误码
|
|
|
+#define LOG_ERR_S0_ANSACMFLOW 0x30500080
|
|
|
+#define LOG_ERR_S0_REQAGENTFLOW 0x30500081
|
|
|
+#define LOG_ERR_S1_REQAGENTFLOW_FAILED 0x30500082
|
|
|
+#define LOG_ERR_S2_ANSAGENTFLOW_FAILED 0x30500083
|
|
|
+#define LOG_ERR_S2_NTFENTFLOW_FAILED 0x30500084
|
|
|
+#define LOG_ERR_S3_ANSACMFLOW_FAILED 0x30500085
|
|
|
+#define LOG_ERR_S5_DISCTRL_FAILED 0x30500086
|
|
|
+#define LOG_ERR_S5_REQAGENTFLOW_FAILED 0x30500087
|
|
|
+#define LOG_ERR_S7_ENTRY 0x30500088
|
|
|
+#define LOG_ERR_S1_ASSIS_IDEL 0x30500089
|
|
|
+#define LOG_ERR_S2_ASSIS_IDEL 0x3050008a
|
|
|
+#define LOG_ERR_S3_ASSIS_IDEL 0x3050008b
|
|
|
+#define LOG_ERR_S5_ASSIS_IDEL 0x3050008c
|
|
|
+#define LOG_EVT_CONNEC_ASSISTCHAN_FAILED 0x3050008d
|
|
|
+
|
|
|
|
|
|
void ChannelClient::OnMessage( ErrorCodeEnum Error, ChannelService_State_Info &Msg, CSmartPointer<IReleasable> pData )
|
|
|
{
|
|
|
- LOG_FUNCTION();
|
|
|
if (Error == Error_Succeed) {
|
|
|
if (Msg.state == eChannelState_Connected) {
|
|
|
m_pFSM->PostEventFIFO(new FSMEvent(USER_EVT_CHAN_ON));
|
|
|
- } else if (Msg.state == eChannelState_Idle) {
|
|
|
+ }
|
|
|
+ else if (Msg.state == eChannelState_Idle) {
|
|
|
m_pFSM->PostEventFIFO(new FSMEvent(USER_EVT_CHAN_OFF));
|
|
|
}
|
|
|
}
|
|
@@ -17,7 +33,6 @@ void ChannelClient::OnMessage( ErrorCodeEnum Error, ChannelService_State_Info &M
|
|
|
|
|
|
void ChannelClient::OnMessage( ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData )
|
|
|
{
|
|
|
- LOG_FUNCTION();
|
|
|
if (Error == Error_Succeed) {
|
|
|
m_pFSM->ProcessPacket(Msg.sub_type, Msg.data);
|
|
|
}
|
|
@@ -59,34 +74,13 @@ 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->SafeDelete();
|
|
|
- // m_pClient = NULL;
|
|
|
- // }
|
|
|
- //} else {
|
|
|
- // m_pClient->SafeDelete();
|
|
|
- // m_pClient = NULL;
|
|
|
- //}
|
|
|
-
|
|
|
- //if (Error == Error_Succeed)
|
|
|
- //{
|
|
|
- AddStateHooker(this);
|
|
|
- //}
|
|
|
-
|
|
|
+ m_bConnectAssit = false;
|
|
|
+
|
|
|
+ AddStateHooker(this);
|
|
|
+
|
|
|
return Error_Succeed;
|
|
|
}
|
|
|
+
|
|
|
ErrorCodeEnum CFlowControlFSM::OnExit()
|
|
|
{
|
|
|
if (m_pClient != NULL) {
|
|
@@ -103,84 +97,163 @@ ErrorCodeEnum CFlowControlFSM::OnExit()
|
|
|
return Error_Succeed;
|
|
|
}
|
|
|
|
|
|
-BOOL CFlowControlFSM::ReConnectionAssistchan()
|
|
|
+//BOOL CFlowControlFSM::ReConnectionAssistchan()
|
|
|
+//{
|
|
|
+// if (m_pClient != NULL){
|
|
|
+// m_pClient->GetFunction()->CloseSession();
|
|
|
+// m_pClient = NULL;
|
|
|
+// DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Close AssistChannel Session ");
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (m_pClient == NULL)
|
|
|
+// {
|
|
|
+// ErrorCodeEnum Error;
|
|
|
+// m_pClient = new ChannelClient(m_pEntity, this);
|
|
|
+// Error = m_pClient->Connect();
|
|
|
+// if (Error != Error_Succeed) {
|
|
|
+// 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)
|
|
|
+// {
|
|
|
+// ChannelService_BeginState_Sub ChannelSub;
|
|
|
+// Error = m_pClient->BeginState(ChannelSub);
|
|
|
+// if (Error != Error_Succeed)
|
|
|
+// {
|
|
|
+// 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)
|
|
|
+// {
|
|
|
+// ChannelService_BeginRecv_Sub Sub;
|
|
|
+// Sub.type = ACM_TYPE_FLW;
|
|
|
+// Error = m_pClient->BeginRecv(Sub);
|
|
|
+// if (Error != Error_Succeed)
|
|
|
+// {
|
|
|
+// DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("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!");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// return TRUE;
|
|
|
+//}
|
|
|
+
|
|
|
+bool CFlowControlFSM::IsAssistchanEntityAvailable()
|
|
|
{
|
|
|
- if (m_pClient != NULL)
|
|
|
- {
|
|
|
- m_pClient->GetFunction()->CloseSession();
|
|
|
- m_pClient = NULL;
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Close AssistChannel Session ");
|
|
|
+ if (Error_Succeed == ConnectToAssistchan()) {
|
|
|
+ return true;
|
|
|
}
|
|
|
+ else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
- if (m_pClient == NULL)
|
|
|
- {
|
|
|
- ErrorCodeEnum Error;
|
|
|
+ErrorCodeEnum CFlowControlFSM::ConnectToAssistchan(bool blogevt)
|
|
|
+{
|
|
|
+ if (!IsAssistchanConnectSessionOK()) {
|
|
|
+ FreeAssistchanClient();
|
|
|
m_pClient = new ChannelClient(m_pEntity, this);
|
|
|
- Error = m_pClient->Connect();
|
|
|
- if (Error != Error_Succeed)
|
|
|
- {
|
|
|
+ ErrorCodeEnum errorCode = m_pClient->Connect();
|
|
|
+ if (Error_Succeed != errorCode) {
|
|
|
+ m_pClient->SafeDelete();
|
|
|
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 (blogevt) {
|
|
|
+ LogWarn(Severity_Middle, Error_InvalidState, LOG_EVT_CONNEC_ASSISTCHAN_FAILED,
|
|
|
+ CSimpleStringA::Format("Connect to assistchan entity failed:0x%08x.", errorCode));
|
|
|
+ }
|
|
|
+ return Error_InvalidState;
|
|
|
}
|
|
|
-
|
|
|
- if(Error == Error_Succeed)
|
|
|
- {
|
|
|
+ else {
|
|
|
+ if (blogevt) {
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Connect to assistchan Client Succeed!");
|
|
|
+ }
|
|
|
+
|
|
|
ChannelService_BeginState_Sub ChannelSub;
|
|
|
- Error = m_pClient->BeginState(ChannelSub);
|
|
|
- if (Error != Error_Succeed)
|
|
|
+ errorCode = m_pClient->BeginState(ChannelSub);
|
|
|
+ if (Error_Succeed != errorCode)
|
|
|
{
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("BeginState biz channel failed!");
|
|
|
m_pClient->GetFunction()->CloseSession();
|
|
|
m_pClient = NULL;
|
|
|
- return FALSE;
|
|
|
+ return errorCode;
|
|
|
}
|
|
|
- else{
|
|
|
+ else {
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("BeginState biz channel success!");
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- if(Error == Error_Succeed)
|
|
|
- {
|
|
|
+
|
|
|
ChannelService_BeginRecv_Sub Sub;
|
|
|
Sub.type = ACM_TYPE_FLW;
|
|
|
- Error = m_pClient->BeginRecv(Sub);
|
|
|
- if (Error != Error_Succeed)
|
|
|
+ errorCode = m_pClient->BeginRecv(Sub);
|
|
|
+ if (Error_Succeed != errorCode)
|
|
|
{
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Register ACM_TYPE_FLW failed!");
|
|
|
m_pClient->GetFunction()->CloseSession();
|
|
|
m_pClient = NULL;
|
|
|
- return FALSE;
|
|
|
+ return errorCode;
|
|
|
}
|
|
|
- else{
|
|
|
+ else {
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Register ACM_TYPE_FLW success!");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return TRUE;
|
|
|
+ return Error_Succeed;
|
|
|
}
|
|
|
|
|
|
+bool CFlowControlFSM::IsAssistchanConnectSessionOK()
|
|
|
+{
|
|
|
+ return (m_pClient != NULL && !m_pClient->QuerySessionClosed());
|
|
|
+}
|
|
|
+
|
|
|
+void CFlowControlFSM::FreeAssistchanClient()
|
|
|
+{
|
|
|
+ if (m_pClient) {
|
|
|
+ m_pClient->GetFunction()->CloseSession();
|
|
|
+ m_pClient = NULL;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
unsigned int CFlowControlFSM::s0_on_event(FSMEvent* event)
|
|
|
{
|
|
|
if (event->iEvt == USER_EVT_ANSACMFLOW) {
|
|
|
AgentFlowResult evt;
|
|
|
evt.error = Error_NetBroken;
|
|
|
SpSendBroadcast(m_pEntity->GetFunction(), SP_MSG_OF(AgentFlowResult), SP_MSG_SIG_OF(AgentFlowResult), evt);
|
|
|
+ LogWarn(Severity_Low, Error_Debug, LOG_ERR_S0_ANSACMFLOW, "s0 receive ANSACMFLOW");
|
|
|
} else if (event->iEvt == USER_EVT_REQAGENTFLOW) {
|
|
|
AgentFlowResult evt;
|
|
|
evt.error = Error_NetBroken;
|
|
|
SpSendBroadcast(m_pEntity->GetFunction(), SP_MSG_OF(AgentFlowResult), SP_MSG_SIG_OF(AgentFlowResult), evt);
|
|
|
+ LogWarn(Severity_Low, Error_Debug, LOG_ERR_S0_REQAGENTFLOW, "s0 receive REQAGENTFLOW");
|
|
|
}
|
|
|
else if (event->iEvt == USER_EVT_ASSIS_IDEL)
|
|
|
{
|
|
|
- ReConnectionAssistchan();
|
|
|
+ if (Error_Succeed == ConnectToAssistchan(false)) {
|
|
|
+ m_bConnectAssit = true;
|
|
|
+ }
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
+
|
|
|
unsigned int CFlowControlFSM::s1_on_event(FSMEvent* event)
|
|
|
{
|
|
|
if (event->iEvt == USER_EVT_REQAGENTFLOW) {
|
|
@@ -199,12 +272,14 @@ unsigned int CFlowControlFSM::s1_on_event(FSMEvent* event)
|
|
|
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
|
|
|
- {
|
|
|
+ }
|
|
|
+ else {
|
|
|
Error = Error_NetBroken;
|
|
|
+ LogWarn(Severity_Low, Error_Debug, LOG_ERR_S1_REQAGENTFLOW_FAILED, "s1 receive REQAGENTFLOW but chan is off.");
|
|
|
}
|
|
|
return Error == Error_Succeed ? 1 : 0;
|
|
|
- } else if (event->iEvt == USER_EVT_NTFENTFLOW) {
|
|
|
+ }
|
|
|
+ else if (event->iEvt == USER_EVT_NTFENTFLOW) {
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("spbroadcast NotifyEnterFlowEvent");
|
|
|
NotifyEnterFlowEvent *nef = static_cast<NotifyEnterFlowEvent*>(event);
|
|
|
NotifyEnterFlow evt;
|
|
@@ -212,7 +287,10 @@ unsigned int CFlowControlFSM::s1_on_event(FSMEvent* event)
|
|
|
}
|
|
|
else if (event->iEvt == USER_EVT_ASSIS_IDEL)
|
|
|
{
|
|
|
- ReConnectionAssistchan();
|
|
|
+ LogWarn(Severity_Low, Error_Debug, LOG_ERR_S1_ASSIS_IDEL, "s1 ASSIS_IDEL.");
|
|
|
+ if (Error_Succeed == ConnectToAssistchan(false)) {
|
|
|
+ m_bConnectAssit = true;
|
|
|
+ }
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
@@ -240,11 +318,16 @@ unsigned int CFlowControlFSM::s2_on_event(FSMEvent* event)
|
|
|
SpSendBroadcast(m_pEntity->GetFunction(), SP_MSG_OF(ACMFlowInvoke), SP_MSG_SIG_OF(ACMFlowInvoke), evt);
|
|
|
} else if (event->iEvt == USER_EVT_NTFENTFLOW) {
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("notify enter flow, disallow control!");
|
|
|
- DisallowControl();
|
|
|
+ ErrorCodeEnum result = DisallowControl();
|
|
|
+ if (result != Error_Succeed){
|
|
|
+ LogWarn(Severity_Low, Error_Debug, LOG_ERR_S2_NTFENTFLOW_FAILED, "s2 send NTFENTFLOW error.");
|
|
|
+ }
|
|
|
}
|
|
|
- else if (event->iEvt == USER_EVT_ASSIS_IDEL)
|
|
|
- {
|
|
|
- ReConnectionAssistchan();
|
|
|
+ else if (event->iEvt == USER_EVT_ASSIS_IDEL){
|
|
|
+ LogWarn(Severity_Low, Error_Debug, LOG_ERR_S2_ASSIS_IDEL, "s2 ASSIS_IDEL.");
|
|
|
+ if (Error_Succeed == ConnectToAssistchan(false)) {
|
|
|
+ m_bConnectAssit = true;
|
|
|
+ }
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
@@ -282,6 +365,7 @@ unsigned int CFlowControlFSM::s3_on_event(FSMEvent* event)
|
|
|
Error = m_pClient->Send(Info);
|
|
|
} else {
|
|
|
Error = Error_NetBroken;
|
|
|
+ LogWarn(Severity_Low, Error_Debug, LOG_ERR_S3_ANSACMFLOW_FAILED, "s3 send ANSACMFLOW error.");
|
|
|
}
|
|
|
return Error == Error_Succeed ? 1 : 0;
|
|
|
} else if (event->iEvt == USER_EVT_CHAN_OFF) {
|
|
@@ -291,7 +375,10 @@ unsigned int CFlowControlFSM::s3_on_event(FSMEvent* event)
|
|
|
}
|
|
|
else if (event->iEvt == USER_EVT_ASSIS_IDEL)
|
|
|
{
|
|
|
- ReConnectionAssistchan();
|
|
|
+ LogWarn(Severity_Low, Error_Debug, LOG_ERR_S3_ASSIS_IDEL, "s3 ASSIS_IDEL.");
|
|
|
+ if (Error_Succeed == ConnectToAssistchan(false)) {
|
|
|
+ m_bConnectAssit = true;
|
|
|
+ }
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
@@ -299,13 +386,19 @@ void CFlowControlFSM::s5_on_entry()
|
|
|
{
|
|
|
|
|
|
}
|
|
|
+
|
|
|
void CFlowControlFSM::s5_on_exit() { }
|
|
|
+
|
|
|
unsigned int CFlowControlFSM::s5_on_event(FSMEvent* event)
|
|
|
{
|
|
|
if (event->iEvt == USER_EVT_DISCTRL) {
|
|
|
- DisallowControl();
|
|
|
- } else if (event->iEvt == USER_EVT_REQAGENTFLOW) {
|
|
|
- ReqAgentFlowEvent *rafe = static_cast<ReqAgentFlowEvent*>(event);
|
|
|
+ ErrorCodeEnum result = DisallowControl();
|
|
|
+ if (result != Error_Succeed) {
|
|
|
+ LogWarn(Severity_Low, Error_Debug, LOG_ERR_S5_DISCTRL_FAILED, "s5 send DISCTRL error.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (event->iEvt == USER_EVT_REQAGENTFLOW) {
|
|
|
+ ReqAgentFlowEvent* rafe = static_cast<ReqAgentFlowEvent*>(event);
|
|
|
ErrorCodeEnum Error;
|
|
|
if (m_pClient) {
|
|
|
ChannelService_Send_Info Info;
|
|
@@ -320,22 +413,34 @@ unsigned int CFlowControlFSM::s5_on_event(FSMEvent* event)
|
|
|
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 {
|
|
|
+ }
|
|
|
+ else {
|
|
|
Error = Error_NetBroken;
|
|
|
+ LogWarn(Severity_Low, Error_Debug, LOG_ERR_S5_REQAGENTFLOW_FAILED, "s5 send REQAGENTFLOW error.");
|
|
|
}
|
|
|
return Error == Error_Succeed ? 1 : 0;
|
|
|
}
|
|
|
else if (event->iEvt == USER_EVT_ASSIS_IDEL)
|
|
|
{
|
|
|
- ReConnectionAssistchan();
|
|
|
+ LogWarn(Severity_Low, Error_Debug, LOG_ERR_S5_ASSIS_IDEL, "s5 ASSIS_IDEL.");
|
|
|
+ if (Error_Succeed == ConnectToAssistchan(false)) {
|
|
|
+ m_bConnectAssit = true;
|
|
|
+ }
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+void CFlowControlFSM::s7_on_entry()
|
|
|
+{
|
|
|
+ LogWarn(Severity_Low, Error_Debug, LOG_ERR_S7_ENTRY, "s7 ENTRY.");
|
|
|
+}
|
|
|
+
|
|
|
unsigned int CFlowControlFSM::s7_on_event(FSMEvent* event)
|
|
|
{
|
|
|
if (event->iEvt == USER_EVT_ASSIS_IDEL){
|
|
|
- ReConnectionAssistchan();
|
|
|
+ if (Error_Succeed == ConnectToAssistchan(false)) {
|
|
|
+ m_bConnectAssit = true;
|
|
|
+ }
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
@@ -365,7 +470,7 @@ void CFlowControlFSM::ProcessPacket( int sub_type, CBlob &blob )
|
|
|
buf & e->context;
|
|
|
PostEventFIFO(e);
|
|
|
} else {
|
|
|
- LOG_TRACE("unknown sub_type from agent!");
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("unknown sub_type from agent!");
|
|
|
}
|
|
|
}
|
|
|
|