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

📄 tapiline.cpp

📁 基于TAPI 2.0的软电话源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	HRESULT tr = ::lineDevSpecific(m_hLine,0,NULL,buffer,length + 3);
	m_Parent.CheckError(tr, "DivertDestination");
}

// ----------------------------------------------------------------------------
// Set the divert settings, i.e. forwarding or Do Not Disturb
void TapiLine::SetDivertSettings(BOOL FwdAll, BOOL FwdBusy, BOOL FwdNoAnsw, BOOL DND)
{
	// Call lineDevSpecific for each of the four divert settings
	TCHAR buffer[3];

	// The first and last byte are the same for all four
	buffer[0] = 9;
	buffer[2] = 0; // NULL terminate

	// Forward All
	buffer[1] = (char)((FwdAll) ? 0 : 1);
	HRESULT tr = ::lineDevSpecific(m_hLine,0,NULL,buffer,3);
	m_Parent.CheckError(tr, "SetDivertSettings");

	// Forward Busy
	buffer[1] = (char)((FwdBusy) ? 2 : 3);
	tr = ::lineDevSpecific(m_hLine,0,NULL,buffer,3);
	m_Parent.CheckError(tr, "SetDivertSettings");

	// Forward No Answer
	buffer[1] = (char)((FwdNoAnsw) ? 4 : 5);
	tr = ::lineDevSpecific(m_hLine,0,NULL,buffer,3);
	m_Parent.CheckError(tr, "SetDivertSettings");

	// Do Not Disturb
	buffer[1] = (char)((DND) ? 7 : 8);
	tr = ::lineDevSpecific(m_hLine,0,NULL,buffer,3);
	m_Parent.CheckError(tr, "SetDivertSettings");
}

// ----------------------------------------------------------------------------
// Retrieve and display the Divert Settings
void TapiLine::GetDivertSettings()
{
	TCHAR buffer[sizeof(LINEDEVSTATUS) + 100];
	LPLINEDEVSTATUS lpLineDevStatus = reinterpret_cast<LPLINEDEVSTATUS>(buffer);
	lpLineDevStatus->dwTotalSize = sizeof(LINEDEVSTATUS) + 100;
	HRESULT tr = ::lineGetLineDevStatus(m_hLine, lpLineDevStatus);
	m_Parent.CheckError(tr, "GetDivertSettings");

	// Set the pointer to the start of the dev specific data
	TCHAR* pDevSpecific = (TCHAR*)lpLineDevStatus + lpLineDevStatus->dwDevSpecificOffset;

	CString txt;
	CString phoneExt(pDevSpecific);
	txt = CString("Divert Settings: Phone Ext(") + phoneExt + CString(")");

	// Move the pointer past the phone number
	pDevSpecific += phoneExt.GetLength() + 1;
	if (pDevSpecific[0]) // Forward On Busy
		txt += CString(", Fwd On Busy(On)");
	else
		txt += CString(", Fwd On Busy(Off)");

	if (pDevSpecific[1]) // Forward On No Answer
		txt += CString(", Fwd On No Answer(On)");
	else
		txt += CString(", Fwd On No Answer(Off)");

	if (pDevSpecific[2]) // Forward All
		txt += CString(", Fwd All(On)");
	else
		txt += CString(", Fwd All(Off)");

	if (pDevSpecific[4]) // Do Not Disturb
		txt += CString(", DND(On)");
	else
		txt += CString(", DND(Off)");

    CString msgs;
    msgs.Format(", Msgs(%d)", pDevSpecific[10]);
	txt += msgs;

	pDevSpecific += 26; // Move past the forward settings and other reserved data

	CString userExt(pDevSpecific);
	txt += CString(", User Ext(") + userExt + CString(")");
	
	// Move the pointer past the user number
	pDevSpecific += userExt.GetLength() + 1;

	CString locale(pDevSpecific);
	txt += CString(", Locale(") + locale + CString(")");

	// Move the pointer past the locale
	pDevSpecific += locale.GetLength() + 1;

	CString divertDestination(pDevSpecific);
	txt += CString(", Divert Dest(") + divertDestination + CString(")");
	m_Parent.m_Dlg.AddText(txt);

    // Get number of enabled groups
    int len = lpLineDevStatus->dwUsedSize;
    pDevSpecific = (TCHAR*)lpLineDevStatus;
    int numMemberGroups = pDevSpecific[len - 5];
    int numOutOfTimeGroups = pDevSpecific[len - 4];
    int numDisabledGroups = pDevSpecific[len - 3];
    int numOutOfSvcGroups = pDevSpecific[len - 2];
    int numNightSvcGroups = pDevSpecific[len - 1];
    txt.Format("Groups: Member(%d) OutOfHours(%d) Disabled(%d) OutOfSvc(%d) NightSvc(%d)",
        numMemberGroups, numOutOfTimeGroups, numDisabledGroups, numOutOfSvcGroups, numNightSvcGroups);
	m_Parent.m_Dlg.AddText(txt);


}

// ----------------------------------------------------------------------------
// Set the App Specific value for a call. See below for the order in which the
// call is selected.
void TapiLine::SetAppSpecific(DWORD num)
{
	HCALL hCall = NULL;
	if (m_hConnectedCall)
		hCall = m_hConnectedCall;
	else if (m_hWaitingCall)
		hCall = m_hWaitingCall;
	else if (m_hHeldCall)
		hCall = m_hHeldCall;
	else if (m_hPendingCall)
		hCall = m_hPendingCall;
	else if (m_hConferenceCall)
		hCall = m_hConferenceCall;
	else if (m_hConsultationCall)
		hCall = m_hConsultationCall;

	if (hCall)
	{
		HRESULT tr = ::lineSetAppSpecific(hCall, num);
		m_Parent.CheckError(tr, "GetDivertSettings");
	}
	else
	{
		m_Parent.m_Dlg.AddText("SetAppSpecific: No call");
	}
}

void TapiLine::SetMsgWaitLamp(DWORD num)
{
	TCHAR buffer[50];

	buffer[0] = 9;
	buffer[1] = 73; // DisplayMsg
	strcpy(&(buffer[2]),";Mailbox Msgs=");
	buffer[16] = num + '0';
	buffer[17] = 0; // NULL terminate

	// Set Message Waiting Lamp
	HRESULT tr = ::lineDevSpecific(m_hLine,0,NULL,buffer,18);
	m_Parent.CheckError(tr, "lineDevSpecific");
}

void TapiLine::SetInGroup(LPCTSTR pszGroup)
{
	TCHAR buffer[50];
	DWORD len = 3;

	buffer[0] = 9;
	buffer[1] = 76; // HuntGroupEnable
	if ((pszGroup[0] == '0') || (pszGroup[0] == 0))
		buffer[2] = 0; // NULL terminate
	else
	{
		strcpy(&(buffer[2]),pszGroup);
		buffer[2 + strlen(pszGroup)] = 0; // NULL terminate
		len = 3 + _tcslen(pszGroup);
	}

	// Set In Group status
	HRESULT tr = ::lineDevSpecific(m_hLine,0,NULL,buffer,len);
	m_Parent.CheckError(tr, "lineDevSpecific");
}

void TapiLine::SetOutGroup(LPCTSTR pszGroup)
{
	TCHAR buffer[50];
	DWORD len = 3;

	buffer[0] = 9;
	buffer[1] = 77; // HuntGroupDisable
	if ((pszGroup[0] == '0') || (pszGroup[0] == 0))
		buffer[2] = 0; // NULL terminate
	else
	{
		strcpy(&(buffer[2]),pszGroup);
		buffer[2 + strlen(pszGroup)] = 0; // NULL terminate
		len = 3 + _tcslen(pszGroup);
	}

	// Set In Group status
	HRESULT tr = ::lineDevSpecific(m_hLine,0,NULL,buffer,len);
	m_Parent.CheckError(tr, "lineDevSpecific");
}

void TapiLine::SetCallData(LPCTSTR pszData)
{
	HCALL hCall = NULL;
	if (m_hConnectedCall)
		hCall = m_hConnectedCall;
	else if (m_hWaitingCall)
		hCall = m_hWaitingCall;
	else if (m_hHeldCall)
		hCall = m_hHeldCall;
	else if (m_hPendingCall)
		hCall = m_hPendingCall;
	else if (m_hConferenceCall)
		hCall = m_hConferenceCall;
	else if (m_hConsultationCall)
		hCall = m_hConsultationCall;

	if (hCall)
	{
		HRESULT tr = ::lineSetCallData(hCall,(void*)pszData,_tcslen(pszData));
		m_Parent.CheckError(tr, "SetCallData");
	}
	else
	{
		m_Parent.m_Dlg.AddText("SetCallData: No call");
	}
	
}

void TapiLine::Listen(LPCTSTR pszAddress)
{
	if (pszAddress)
	{
		TCHAR buffer[50];
		DWORD len = 0;

		buffer[0] = 9;
		buffer[1] = 100; // Listen
		strcpy(&(buffer[2]),pszAddress);
		buffer[2 + _tcslen(pszAddress)] = 0; // NULL terminate
		len = 3 + _tcslen(pszAddress);

		HRESULT tr = ::lineDevSpecific(m_hLine,0,NULL,buffer,len);
		m_Parent.CheckError(tr, "lineDevSpecific");
	}
	else
	{
		m_Parent.m_Dlg.AddText("Listen: Specify the extension to be listened to");
	}	
}

void TapiLine::Intrude(LPCTSTR pszAddress)
{
	if (pszAddress)
	{
		TCHAR buffer[50];
		DWORD len = 0;

		buffer[0] = 9;
		buffer[1] = 83; // Intrude
		strcpy(&(buffer[2]),pszAddress);
		buffer[2 + _tcslen(pszAddress)] = 0; // NULL terminate
		len = 3 + _tcslen(pszAddress);

		HRESULT tr = ::lineDevSpecific(m_hLine,0,NULL,buffer,len);
		m_Parent.CheckError(tr, "lineDevSpecific");
	}
	else
	{
		m_Parent.m_Dlg.AddText("Intrude: Specify the extension to be intruded upon");
	}	
}

void TapiLine::SetAccountCode(LPCTSTR pszAddress)
{
	if (pszAddress)
	{
		TCHAR buffer[50];
		DWORD len = 0;

		buffer[0] = 9;
		buffer[1] = 101; // Set Account Code
		strcpy(&(buffer[2]),pszAddress);
		buffer[2 + _tcslen(pszAddress)] = 0; // NULL terminate
		len = 3 + _tcslen(pszAddress);

		HRESULT tr = ::lineDevSpecific(m_hLine,0,NULL,buffer,len);
		m_Parent.CheckError(tr, "lineDevSpecific");
	}
	else
	{
		m_Parent.m_Dlg.AddText("SetAccountCode: Specify the account code");
	}	
}

void TapiLine::GenerateDigits(LPCTSTR pszAddress)
{
	if (pszAddress)
	{
		HRESULT tr1 = ::lineGenerateDigits(m_hConnectedCall,LINEDIGITMODE_DTMF,pszAddress,5000);
        //HRESULT tr2 = ::lineHold(m_hConnectedCall);
        //HRESULT tr2 = ::lineBlindTransfer(m_hConnectedCall,"518",0);
		m_Parent.CheckError(tr1, "lineGenerateDigits");
		/*if (tr2 > 0)
		{
			REQUEST_INFO ri = { "HoldCall", m_hConnectedCall };
			m_Requests.SetAt(tr2, ri);
		}
		m_Parent.CheckError(tr2, "HoldCall");*/

	}
	else
	{
		m_Parent.m_Dlg.AddText("GenerateDigits: Specify the digits to generate");
	}	
}


// ----------------------------------------------------------------------------
// Handle messages from TAPI
void TapiLine::OnEvent(
	DWORD   Device,
	DWORD   Msg,
	DWORD   Param1,
	DWORD   Param2,
	DWORD   Param3)
{
	switch (Msg)
	{
		case LINE_REPLY: // Reply to an asynchronous TAPI function
			OnReply(Param1, Param2);
			break;

		case LINE_CLOSE: // A line has closed
			OnClose();
			break;

		case LINE_ADDRESSSTATE: // The address state has changed
			ASSERT(m_hLine == (HLINE) Device);
			OnAddressState(Param1, Param2);
			break;

		case LINE_CALLINFO: // The call info has changed
			OnCallInfo((HCALL) Device, Param1);
			break;

		case LINE_CALLSTATE: // The call state has changed
			OnCallState((HCALL) Device, Param1, Param2, Param3);
			GetCallStatus();
			break;

		case LINE_LINEDEVSTATE: // The device state has changed
			ASSERT(m_hLine == (HLINE) Device);
			OnLineDevState(Param1, Param2, Param3);
			break;

		case LINE_APPNEWCALL: // There is a new incoming call
			OnNewCall(Param1, (HCALL) Param2, Param3);
			// The following demonstrates screen pop!!!
			m_Parent.m_Dlg.ShowWindow(SW_SHOWNORMAL);
			break;

		case LINE_DEVSPECIFIC: // The device specific data has changed
		case LINE_DEVSPECIFICFEATURE: // The device specific features have changed
			TRACE("Device Specific Event\n");
			break;

		case LINE_GATHERDIGITS: // A digit has been received
			TRACE("Gather Digits Event\n");
			break;

		case LINE_GENERATE: // A tone has been generated
			TRACE("Generate Event\n");
			break;

		case LINE_MONITORDIGITS: // A digit has been received
			TRACE("Monitor Digits Event\n");
			break;

		case LINE_MONITORMEDIA:
			TRACE("Monitor Media Event\n");
			break;

		case LINE_MONITORTONE: // A tone has been detected
			TRACE("Monitor Tone Event\n");
			break;

		case LINE_REQUEST:
			TRACE("Assisted Telephony Request Event\n");
			break;

		case PHONE_BUTTON: // Phone events are not supported
		case PHONE_CLOSE:
		case PHONE_DEVSPECIFIC:
		case PHONE_REPLY:
		case PHONE_STATE:
		case PHONE_CREATE: 
		case PHONE_REMOVE:
			TRACE("Phone Event\n");
			break;

		case LINE_CREATE: // Not supported
			TRACE("Line Create Event\n");
			break;

		case LINE_AGENTSPECIFIC: // Not Supported
		case LINE_AGENTSTATUS:  // Not supported
			TRACE("Agent Event\n");
			break;

		case LINE_PROXYREQUEST: // Not supported
			TRACE("Proxy Request Event\n");
			break;

		case LINE_REMOVE: // Not supported
			TRACE("Line Remove Event\n");
			break;

		default:
			ASSERT(FALSE);
			break;
	}
}

// ----------------------------------------------------------------------------
// Handle a LINE_REPLY message from TAPI
void TapiLine::OnReply(LONG RequestID, HRESULT Result)
{
	CString info;
	REQUEST_INFO ri = { "Unknown", 0 };
	if (m_Requests.Lookup(RequestID, ri))
		m_Requests.RemoveKey(RequestID);

	if (Result == 0)
		info.Format("Reply(%s: OK)", ri.Name);
	else
	{
		// Describe the error message returned from TAPI
		info.Format("Reply(%s: 0x%08lx = %s)", ri.Name,
			Result, DescribeError(Result));
	}
	m_Parent.m_Dlg.AddText(info);
}

// ----------------------------------------------------------------------------
// Handle a LINE_CLOSE message from TAPI
void TapiLine::OnClose()

⌨️ 快捷键说明

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