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

📄 ansphonecallwatcher.cpp

📁 s60 接打电话代码,很有学习价值的,可以移植到不同平台
💻 CPP
字号:
/**
*
* @brief Definition of CAnsPhoneCallWatcher
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/

#include "AnsPhoneCallWatcher.h"

CAnsPhoneCallWatcher::CAnsPhoneCallWatcher(MAnsPhoneCallWatcherObserver& aObserver, RLine& aLine)
:CActive(EPriorityNormal),
 iObserver(aObserver),
 iLine(aLine),
 iState(EWaiting)
	{
	}

CAnsPhoneCallWatcher::~CAnsPhoneCallWatcher()
	{
	Cancel();
	}

CAnsPhoneCallWatcher* CAnsPhoneCallWatcher::NewL(MAnsPhoneCallWatcherObserver& aObserver, RLine& aLine)
	{
	CAnsPhoneCallWatcher* self = new (ELeave) CAnsPhoneCallWatcher(aObserver, aLine);
	CleanupStack::PushL(self);
	self->ConstructL();
	CleanupStack::Pop(self);
	return self;
	}

void CAnsPhoneCallWatcher::ConstructL()
	{
	CActiveScheduler::Add(this);
	StartL();
	}

///////////////////////////////////////////////////////////////////////////////////////////////////////
// CActive
//
///////////////////////////////////////////////////////////////////////////////////////////////////////

void CAnsPhoneCallWatcher::RunL()
	{
	if(iStatus.Int() != KErrNone)
		return;

	switch(iState)
		{
		case EWaiting:
			{
			// answer the call
			iState = EAnswering;
			StartL();
			break;
			}
		case EAnswering:
			{
			iState = EWatching;
			StartL();
			iObserver.HandleCallInChangeL(RCall::EStatusConnected);
			break;
			}
		case EWatching:
			{
			User::LeaveIfError(iCall.GetStatus(iCallStatus));
			if (iCallStatus == RCall::EStatusHangingUp)
				{
				iObserver.HandleCallInChangeL(iCallStatus);
				iCall.Close();
				iState = EWaiting;
				}
			StartL();
			break;
			}
		}
	}

void CAnsPhoneCallWatcher::DoCancel()
	{
	Stop();
	}

void CAnsPhoneCallWatcher::StartL()
	{
	switch(iState)
		{
		case EWaiting:
			// sets iCallName when it receives an incoming call
			iLine.NotifyIncomingCall(iStatus, iCallName);
			break;
		case EAnswering:
			User::LeaveIfError(iCall.OpenExistingCall(iLine, iCallName));
			iCall.AnswerIncomingCall(iStatus);
			break;
		case EWatching:
			iCall.NotifyStatusChange(iStatus, iCallStatus);
			break;
		}
	SetActive();
	}

void CAnsPhoneCallWatcher::Stop()
	{
	switch(iState)
		{
		case EWaiting:
			iLine.NotifyIncomingCallCancel();
			break;
		case EAnswering:
			iCall.Close();
			break;
		case EWatching:
			iCall.NotifyStatusChangeCancel();
			iCall.Close();
			break;
		}
	}

⌨️ 快捷键说明

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