⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 directorynumber.cpp

📁 使用CT-C开发的一个CTI软电话系统,ActiveX形式的,仅供参考
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	return bReturn;
}

void CDirectoryNumber::DNPackFireEvent(ctcEventData* pEvent,BOOL& bNotFire,list<WPARAM>* eventList)
{
/////////////MARK by rick --begin
//	list<PHONE_STATE> routine;
//	routine.clear();
//	if (ValidateStateRoutin(&routine))
//	{//
//		if (routine.size()>1)
//		{// CTC server omit soem important event, but I've found a routine
//			//through which state can be converted to the current one
//		}else
//		{// ok, 
//		}
//
//		UINT preState=m_curState.state;
//		for (int i=1;i<routine.size()-1;i++)
//		{// CTC server omit soem important event, but I've found a routine
//			//through which state can be converted to the current one.All these
//			//middle default event should be fired out
//			DNFillAndFire(preState,routine.pop);
//		}
//	}else
//	{// Can't find a valid routine from previous state to current state.
//		//This case should never occurred. Just fire it out
//		bNotFie=FALSE;
//	}

/////////////MARK --end
	//temp

	list<PHONE_STATE> phoneState; // all state in this list will never be fired out
	phoneState.push_back(CTC_NULL);
	phoneState.push_back(CTC_INITIAL);
	phoneState.push_back(CTC_DELIVER);
	if (m_bInvokingApi && !InSet(pEvent->state,phoneState))
	{
		eventList->push_back(pEvent->state);
		bNotFire=TRUE;
	}
	else
		bNotFire=FALSE;
	return;
}

BOOL CDirectoryNumber::InSet(UINT ctcState,list<PHONE_STATE> phoneState)
{
	BOOL bRet=FALSE;


	PHONE_STATE ctc=GetPhoneState(ctcState);
	for (list<PHONE_STATE>::iterator i=phoneState.begin();i!=phoneState.end();i++)
	{
		if (ctc==*i)
		{
			bRet=TRUE;
			break;
		}
	}
	return bRet;
}


void CDirectoryNumber::RefreshSavedStatus(ctcEventData* pEvent)
{
	m_curState=*pEvent;
	return;
}


///////////////////////////////////////////////////////////////////////////
//The interface impletment
BOOL CDirectoryNumber::DefaultHandler(ctcEventData* pEvent,list<WPARAM>* eventList)
{
	if(m_posDN && strcmp(m_posDN->m_ThisDN,pEvent->monitorParty)==0)
		return(m_posDN->DefaultHandler(pEvent,eventList));
	BOOL bNotFire=FALSE; // This event should be fired out
	if (pEvent && strcmp(m_ThisDN,pEvent->monitorParty)==0)
	{
		//Refresh some info prepaired for VB
		switch (pEvent->state)
		{
		case ctcK_ReceiveState:
			m_ActiveCallRef=pEvent->refId;
			break;
		case ctcK_NullState:
			m_ActiveCallRef=0;
			m_HoldCallRef=0;
			break;
		case ctcK_ActiveState:
				m_ActiveCallRef=pEvent->refId;
				if (pEvent->event==ctcK_TpRetrieved)
				{//cancel hold call
					m_HoldCallRef=0;
				}
			break;
		case ctcK_HoldState:
			m_HoldCallRef=m_ActiveCallRef;
			m_ActiveCallRef=0;
			break;
		case ctcK_InitiateState:
		case ctcK_DeliverState:
			if (m_ActiveCallRef!=0)
			{ //in consultation call, a new call was established, so the old call was held
				m_HoldCallRef=m_ActiveCallRef;
			}
			m_ActiveCallRef=pEvent->refId;
		default:
			break;
		}

		//Event process
		switch (pEvent->event)
		{
		case ctcK_Offhook:
		case ctcK_DestSeized:
			//NULL-> ACTIVE: show dialing dialog, and this message will never fire
			while (!PostMessage(h_gPumpWnd,UM_DNDIALING,(WPARAM)this,0))
				Sleep(100);
			break;
		default:
			break;
		}
		
		//Decide fire how many fake events should be fired, maybe 0,
		//And decide whether fire this event
		DNPackFireEvent(pEvent,bNotFire,eventList);

		//Refresh this telephon state
		RefreshSavedStatus(pEvent);

		if (m_bInvokingApi)
		{
			//Notify the wait api that the current telephon state has been updated.
			SetEvent(m_hNotifyApi);
			ResetEvent(m_hConfirm);
			//Wait for the api's confirmation
			if (WaitForSingleObject(m_hConfirm,TIME_WAIT_API)==WAIT_TIMEOUT)
			{
				char temp[300]={0};
				PumpPhoneState(temp);
				char tp[300]={0};
				wsprintf(tp,"wait for api answer time out. pump:%s",temp);
				WriteLog(tp);
			}
		}
	}else
	{
		bNotFire=TRUE; // This event is NULL, and should not be fired out
	}
	if (bNotFire=TRUE && pEvent)
	{
		delete pEvent;
		pEvent=NULL;
	}
	return TRUE;
}

void CDirectoryNumber::PumpPhoneState(char* pData)
{
	return;
}

STDMETHODIMP_(BOOL) CDirectoryNumber::AgentLogin(BSTR AgentID, BSTR AgentPassword, BSTR ACDQ, AGENTMODES mode)
{
	return TRUE;
}

STDMETHODIMP_(BOOL) CDirectoryNumber::AgentLogout()
{
	return TRUE;
}

STDMETHODIMP_(BOOL) CDirectoryNumber::AgentSetReady(AGENTMODES mode)
{
	return TRUE;
}

STDMETHODIMP_(BOOL) CDirectoryNumber::AgentSetNotReady(AGENTMODES mode)
{
	return TRUE;
}

STDMETHODIMP_(BOOL) CDirectoryNumber::AlternateCall()
{
		return TRUE;
}

STDMETHODIMP_(BOOL) CDirectoryNumber::AnswerCall(BSTR connid)
{
	BOOL bRet=FALSE;
	return bRet;
}

STDMETHODIMP_(BOOL) CDirectoryNumber::AttachData(BSTR connid, LPKVLIST data)
{
	return TRUE;
}

STDMETHODIMP_(BOOL) CDirectoryNumber::CancelForward(FORWARDMODES mode)
{
	return TRUE;
}


STDMETHODIMP_(BOOL) CDirectoryNumber::CompleteConference()
{
	return TRUE;
}

STDMETHODIMP_(BOOL) CDirectoryNumber::CompleteTransfer()
{
	return TRUE;
}

STDMETHODIMP_(BOOL) CDirectoryNumber::DeleteAllData(BSTR connid)
{
	return TRUE;
}

STDMETHODIMP_(BOOL) CDirectoryNumber::DeleteData(BSTR connid, BSTR key)
{
	return TRUE;
}


STDMETHODIMP_(BOOL) CDirectoryNumber::DeleteFromConference(BSTR dn)
{
	return TRUE;
}


STDMETHODIMP_(BOOL) CDirectoryNumber::Forward(BSTR dn, FORWARDMODES mode)
{
	return TRUE;
}


STDMETHODIMP CDirectoryNumber::get_ACDQ(BSTR *pVal)
{
	return S_FALSE;
}


STDMETHODIMP CDirectoryNumber::get_ActiveConnID(BSTR *pVal)
{
	return S_FALSE;
}


STDMETHODIMP CDirectoryNumber::get_ActiveID(long *pVal)
{
	return S_FALSE;
}


STDMETHODIMP CDirectoryNumber::get_AgentID(BSTR *pVal)
{
	return S_FALSE;
}


STDMETHODIMP CDirectoryNumber::get_AgentMode(AGENTMODES *pVal)
{
	return S_FALSE;
}


STDMETHODIMP CDirectoryNumber::get_AgentState(AGENTSTATES *pVal)
{
	return S_FALSE;
}


STDMETHODIMP CDirectoryNumber::get_DisableDialingDialog(VARIANT_BOOL *pVal)
{
	*pVal=m_bDisableDialing?VARIANT_TRUE:VARIANT_FALSE;
	return S_OK;
}


STDMETHODIMP CDirectoryNumber::get_DND(BOOL *pVal)
{
	return S_FALSE;
}


STDMETHODIMP CDirectoryNumber::get_ErrCode(long *pVal)
{
	return S_FALSE;
}


STDMETHODIMP CDirectoryNumber::get_ErrMsg(BSTR *pVal)
{
	return S_FALSE;
}

STDMETHODIMP CDirectoryNumber::get_ErrReport(BOOL *pVal)
{
	return S_FALSE;
}

STDMETHODIMP CDirectoryNumber::get_HoldConnID(BSTR *pVal)
{
	return S_FALSE;
}

STDMETHODIMP CDirectoryNumber::get_HoldID(long *pVal)
{
	return S_FALSE;
}


STDMETHODIMP CDirectoryNumber::get_Logged(BOOL *pVal)
{
	return S_FALSE;
}


STDMETHODIMP CDirectoryNumber::get_Number(BSTR *pVal)
{
	return S_FALSE;
}


STDMETHODIMP CDirectoryNumber::get_OnHook(BOOL *pVal)
{
	return S_FALSE;
}


STDMETHODIMP CDirectoryNumber::get_RaiseAllEvents(VARIANT_BOOL *pVal)
{
	return S_FALSE;
}


STDMETHODIMP CDirectoryNumber::get_Registered(BOOL *pVal)
{
	return S_FALSE;
}


STDMETHODIMP CDirectoryNumber::get_Type(ADDRTYPES *pVal)
{
	return S_FALSE;
}

STDMETHODIMP_(BOOL) CDirectoryNumber::HoldCall(BSTR connid)
{
	return FALSE;
}

STDMETHODIMP CDirectoryNumber::ID2ConnID(long id, BSTR *connid)
{
	return S_FALSE;
}

STDMETHODIMP_(BOOL) CDirectoryNumber::InitConferenceCall(BSTR dn, LPKVLIST data)
{
	return FALSE;
}


STDMETHODIMP_(BOOL) CDirectoryNumber::InitTransferCall(BSTR dn, LPKVLIST data)
{
	return FALSE;
}


STDMETHODIMP_(BOOL) CDirectoryNumber::MakeCall(BSTR dn, LPKVLIST data)
{
	BOOL bRet=FALSE;
	ctcDeviceString device;
	if (B2C(dn,device,sizeof(device)))
	{
		ctcApplString appStr={0};
		if (data!=NULL && !KVListToAppString(data,appStr,sizeof(appStr)-1))
		{//error
			memset(device,0,sizeof(device));
			WriteLog("Can't convert kvlist to app string");	
		}
		UINT CallId=0;
		DWORD dwState=0;
		try
		{
			dwState=ctcMakeCall(m_channelId,device,appStr,&CallId);
			if (dwState==ctcSuccess)
			{
				bRet=OnDialing();
			}else
			{
				m_lErrCode=CTC_MAKECALL_ERR;
				m_ErrMsg="make call failed";
			}
		}catch(...)
		{
			m_lErrCode=CTC_UNKNOWN_ERR;
			m_ErrMsg="Release call catch an exception";
		}
	}else
	{
		m_lErrCode=CTC_INVALID_PARAM;
		m_ErrMsg="Invalid parameter";
	}

	//confirm to defalut handler
	SetEvent(m_hConfirm);
	return bRet;
}

STDMETHODIMP_(BOOL) CDirectoryNumber::MergeCalls(MERGETYPES type)
{
	return FALSE;
}

STDMETHODIMP_(BOOL) CDirectoryNumber::MuteTransfer(BSTR dn, LPKVLIST data)
{
	return FALSE;
}

STDMETHODIMP CDirectoryNumber::put_DisableDialingDialog(VARIANT_BOOL newVal)
{
	m_bDisableDialing=(newVal==VARIANT_TRUE)?TRUE:FALSE;
	return S_OK;
}

STDMETHODIMP CDirectoryNumber::put_DND(BOOL newVal)
{
	return S_OK;
}

STDMETHODIMP CDirectoryNumber::put_ErrReport(BOOL newVal)
{
	return S_OK;
}

STDMETHODIMP CDirectoryNumber::put_RaiseAllEvents(VARIANT_BOOL newVal)
{
	return S_OK;
}

STDMETHODIMP_(BOOL) CDirectoryNumber::ReconnectCall()
{
	return FALSE;
}

STDMETHODIMP_(BOOL) CDirectoryNumber::RedirectCall(BSTR dn, BSTR connid)
{
	return FALSE;
}

STDMETHODIMP_(BOOL) CDirectoryNumber::ReleaseCall(BSTR connid, BOOL hangup)
{
	BOOL bRet=FALSE;
	if (m_curState.refId==0 && m_posDN)
		m_posDN->ReleaseCall(connid,hangup);

	m_bInvokingApi=TRUE; // This should in the same level with the outest setevent.
	ClearApiInfo();
	UINT lastState=m_curState.state; // record the last phone state
	UINT nCallId=0;
	if (connid)
	{
		char temp[64]={0};
		if (B2C(connid,temp,sizeof(temp)))
		{
			nCallId=atoi(temp);
		}else
			nCallId=m_curState.refId;
	}else
	{
		nCallId=m_curState.refId;
	}

	DWORD dwState=0;
	try
	{
		dwState=ctcHangupCall(m_channelId,nCallId);

		list<PHONE_STATE> tempState;
		tempState.clear();
		tempState.push_back(CTC_ACTIVE);
		if (dwState==ctcSuccess)
		{
			DWORD dwWait=WaitForSingleObject(m_hNotifyApi,TIME_WAIT_MESSAGE);
			while (dwWait!=WAIT_TIMEOUT)
			{
				if (!InSet(m_curState.state,tempState))
				{// The current state has not belonged to this api's state routine
					break;
				}else
				{// update the current state as the last state
					lastState=m_curState.state;
					//notify the defaulthandler that this api has check the current state
					SetEvent(m_hConfirm);
				}
				dwWait=WaitForSingleObject(m_hNotifyApi,TIME_WAIT_MESSAGE);
			}
			if (dwWait==WAIT_TIMEOUT)
			{
				m_lErrCode=CTC_TIMEOUT_ERR;
				m_ErrMsg="This api invoke is time out";
			}else
			{
				list<UINT> routine;
				if (ValidateStateRoutine(lastState,m_curState.state,&routine))
				{//ok,quit
					bRet=TRUE;
				}else
				{//This state transmission is invailed
					m_lErrCode=CTC_RELEASECALL_ERR;
					m_ErrMsg="Release call reached an invaild state";
				}
			}
		}else
		{
			m_lErrCode=CTC_RELEASECALL_ERR;
			m_ErrMsg="Release call failed";
		}
	}catch(...)
	{
		m_lErrCode=CTC_UNKNOWN_ERR;
		m_ErrMsg="Release call catch an exception";
	}
	//notify the defaulthandler that this api has check the current state
	SetEvent(m_hConfirm);
	m_bInvokingApi=FALSE;
	return bRet;
}

STDMETHODIMP_(BOOL) CDirectoryNumber::RetrieveCall(BSTR connid)
{
	return FALSE;
}

STDMETHODIMP_(BOOL) CDirectoryNumber::SingleStepTransfer(BSTR dn, LPKVLIST data)
{
	return FALSE;
}

STDMETHODIMP_(BOOL) CDirectoryNumber::UpdateData(BSTR connid, LPKVLIST data)
{
	return FALSE;
}

STDMETHODIMP_(BOOL) CDirectoryNumber::SendDTMF(BSTR tone)
{
	return TRUE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -