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

📄 tapiline.cpp

📁 最新的TAPI会议系统
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	TCHAR buffer[10];
	buffer[0] = 8;
	UINT length = strlen(pszAddress);
	for (UINT i=0; i < length; i++)
	{
		buffer[i + 1] = pszAddress[i];
	}
	buffer[length + 1] = 0; // NULL terminate

	HRESULT tr = ::lineDevSpecific(m_hLine,0,NULL,buffer,length + 2);
	m_Parent.CheckError(tr, "LogOn");
}

// ----------------------------------------------------------------------------
// Log Off an extension
void TapiLine::LogOff()
{
	TCHAR buffer[3];
	buffer[0] = 9;
	buffer[1] = 47;
	buffer[2] = 0; // NULL terminate

	HRESULT tr = ::lineDevSpecific(m_hLine,0,NULL,buffer,3);
	m_Parent.CheckError(tr, "LogOff");
}

// ----------------------------------------------------------------------------
// Display the IP Office TAPI Config Dialog
void TapiLine::ConfigDialog()
{
	HRESULT tr = ::lineConfigDialog(m_LineID, m_Parent.m_Dlg.m_hWnd, NULL);
	m_Parent.CheckError(tr, "ConfigDialog");
}

// ----------------------------------------------------------------------------
// Set the divert destination
void TapiLine::DivertDestination(LPCTSTR pszAddress)
{
	TCHAR buffer[10];
	buffer[0] = 9;
	buffer[1] = 6;
	UINT length = strlen(pszAddress);
	for (UINT i=0; i < length; i++)
	{
		buffer[i + 2] = pszAddress[i];
	}
	buffer[length + 2] = 0; // NULL terminate

	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)");

	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);
}

// ----------------------------------------------------------------------------
// 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 = 2 + _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 = 2 + _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");
	}
	
}

// ----------------------------------------------------------------------------
// 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()
{
	// This line (us) has been closed down
	m_hLine = 0;
	// Describe this event
	CString info;
	info.Format("Close()");
	m_Parent.m_Dlg.AddText(info);
}


// ----------------------------------------------------------------------------
// Handle a LINE_ADDRESSSTATE message from TAPI
void TapiLine::OnAddressState(DWORD AddressID, DWORD AddressState)
{
	CString state;
	CString info;
	info.Format("Address(%d, %s)", AddressID,
		DescribeAddressStatus(state, AddressState));
	m_Parent.m_Dlg.AddText(info);

	// Get further information about the address change
	LINEADDRESSSTATUS AddressStatus = { sizeof(LINEADDRESSSTATUS) };
	HRESULT hr = ::lineGetAddressStatus(m_hLine, AddressID, &AddressStatus);
	m_Parent.CheckError(hr, "GetAddressStatus");
	info.Format("[NumInUse=%d, NumActiveCalls=%d, NumOnHoldCalls=%d, "
		"NumOnHoldPendCalls=%d]",
		AddressStatus.dwNumInUse, AddressStatus.dwNumActiveCalls,
		AddressStatus.dwNumOnHoldCalls, AddressStatus.dwNumOnHoldPendCalls);

⌨️ 快捷键说明

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