3,120
社区成员
发帖
与我相关
我的任务
分享
CPhoneAO.cpp
#include "CPhoneAO.h"
CPhoneAO::CPhoneAO() :
CActive(EPriorityStandard), // Standard priority
m_oLineStatusPckg(m_oLineStatus)
{
}
CPhoneAO* CPhoneAO::NewLC()
{
CPhoneAO* self = new ( ELeave ) CPhoneAO();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
CPhoneAO* CPhoneAO::NewL()
{
CPhoneAO* self = CPhoneAO::NewLC();
CleanupStack::Pop(); // self;
return self;
}
void CPhoneAO::ConstructL()
{
User::LeaveIfError(iTimer.CreateLocal() ); // Initialize timer
CActiveScheduler::Add( this); // Add to scheduler
m_pTelephony = CTelephony::NewL();
}
CPhoneAO::~CPhoneAO()
{
Cancel(); // Cancel any request, if outstanding
delete m_pTelephony;
}
void CPhoneAO::DoCancel()
{
iTimer.Cancel();
}
void CPhoneAO::StartL()
{
Cancel(); // Cancel any request, just to be sure
m_pTelephony->NotifyChange(iStatus, CTelephony::EVoiceLineStatusChange,
m_oLineStatusPckg);
SetActive(); // Tell scheduler a request is active
}
void CPhoneAO::RunL()
{
m_pTelephony->NotifyChange(iStatus, CTelephony::EVoiceLineStatusChange,
m_oLineStatusPckg);
SetActive(); // Tell scheduler a request is active
}
TInt CPhoneAO::RunError(TInt aError)
{
return aError;
}
void CPhoneAO::Stop()
{
Cancel();
//m_pTelephony
}
CPhoneAO.h
#include <e32base.h> // For CActive, link against: euser.lib
#include <e32std.h> // For RTimer, link against: euser.lib
#include <Etel3rdParty.h>
class CPhoneAO : public CActive
{
private:
/**
* CTelephony对象指针,用于获取电话事件
*/
CTelephony* m_pTelephony;
/**
* 线路状态
*/
CTelephony::TCallStatusV1 m_oLineStatus;
/**
* 线路状态包
*/
CTelephony::TCallStatusV1Pckg m_oLineStatusPckg;
public:
// Cancel and destroy
~CPhoneAO();
// Two-phased constructor.
static CPhoneAO* NewL();
// Two-phased constructor.
static CPhoneAO* NewLC();
public:
// New functions
// Function for making the initial request
void StartL();
void Stop();
private:
// C++ constructor
CPhoneAO();
// Second-phase constructor
void ConstructL();
private:
// From CActive
// Handle completion
void RunL();
// How to cancel me
void DoCancel();
// Override to handle leaves from RunL(). Default implementation causes
// the active scheduler to panic.
TInt RunError(TInt aError);
private:
enum TNewClassState
{
EUninitialized, // Uninitialized
EInitialized, // Initalized
EError // Error condition
};
private:
TInt iState; // State of the active object
RTimer iTimer; // Provides async timing service
};
TestAppUi.cpp
void CTestAppUi::HandleCommandL(TInt aCommand)
{
switch (aCommand)
{
case EEikCmdExit:
case EAknSoftkeyExit:
Exit();
break;
case ECommand1:
{
m_pPhoneAO = CPhoneAO::NewL();
m_pPhoneAO->StartL();
}
break;
case ECommand2:
{
m_pPhoneAO->Deque();
//
}
...