/*
============================================================================
Name : TelephoneListener.h
Author :
Version : 1.0
Copyright : Your copyright notice
Description : CTelephoneListener declaration
============================================================================
*/
#ifndef TELEPHONELISTENER_H
#define TELEPHONELISTENER_H
#include <e32base.h> // For CActive, link against: euser.lib
#include <Etel3rdParty.h>
class MTelephoneListenerObserver
{
public:
virtual void TelephoneStatusChanged(CTelephony::TCallStatus aStatus) = 0;
};
class CTelephoneListener : public CActive
{
public:
// Cancel and destroy
~CTelephoneListener();
// Two-phased constructor.
static CTelephoneListener* NewL(MTelephoneListenerObserver& aObserver);
// Two-phased constructor.
static CTelephoneListener* NewLC(MTelephoneListenerObserver& aObserver);
public:
// New functions
// Function for making the initial request
void StartL(TTimeIntervalMicroSeconds32 aDelay);
private:
// C++ constructor
CTelephoneListener(MTelephoneListenerObserver& aObserver);
// 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 TTelephoneListenerState
{
EUninitialized, // Uninitialized
EInitialized, // Initalized
EError
// Error condition
};
private:
TInt iState; // State of the active object
MTelephoneListenerObserver* iObserver;
CTelephony* iTel;
CTelephony::TCallStatusV1 iCallStatus;
CTelephony::TCallStatusV1Pckg iCallStatusPckg;
};
#endif // TELEPHONELISTENER_H
/*
============================================================================
Name : TelephoneListener.h
Author :
Version : 1.0
Copyright : Your copyright notice
Description : CTelephoneListener declaration
============================================================================
*/
#ifndef TELEPHONELISTENER_H
#define TELEPHONELISTENER_H
#include <e32base.h> // For CActive, link against: euser.lib
#include <Etel3rdParty.h>
class MTelephoneListenerObserver
{
public:
virtual void TelephoneStatusChanged(CTelephony::TCallStatus aStatus) = 0;
};
class CTelephoneListener : public CActive
{
public:
// Cancel and destroy
~CTelephoneListener();
// Two-phased constructor.
static CTelephoneListener* NewL(MTelephoneListenerObserver& aObserver);
// Two-phased constructor.
static CTelephoneListener* NewLC(MTelephoneListenerObserver& aObserver);
public:
// New functions
// Function for making the initial request
void StartL(TTimeIntervalMicroSeconds32 aDelay);
private:
// C++ constructor
CTelephoneListener(MTelephoneListenerObserver& aObserver);
// 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 TTelephoneListenerState
{
EUninitialized, // Uninitialized
EInitialized, // Initalized
EError
// Error condition
};
private:
TInt iState; // State of the active object
MTelephoneListenerObserver* iObserver;
CTelephony* iTel;
CTelephony::TCallStatusV1 iCallStatus;
CTelephony::TCallStatusV1Pckg iCallStatusPckg;
};
#endif // TELEPHONELISTENER_H
view plaincopy to clipboardprint?
·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150
/*
============================================================================
Name : TelephoneListener.cpp
Author :
Version : 1.0
Copyright : Your copyright notice
Description : CTelephoneListener implementation
============================================================================
*/
#include "TelephoneListener.h"
CTelephoneListener::CTelephoneListener(MTelephoneListenerObserver& aObserver)
:CActive(EPriorityStandard), // Standard priority
iObserver(&aObserver),
iCallStatusPckg(iCallStatus)
{
iCallStatus.iStatus = CTelephony::EStatusUnknown;
}
CTelephoneListener* CTelephoneListener::NewLC(MTelephoneListenerObserver& aObserver)
{
CTelephoneListener* self = new (ELeave) CTelephoneListener(aObserver);
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
CTelephoneListener* CTelephoneListener::NewL(MTelephoneListenerObserver& aObserver)
{
CTelephoneListener* self = CTelephoneListener::NewLC(aObserver);
CleanupStack::Pop(); // self;
return self;
}
void CTelephoneListener::ConstructL()
{
//User::LeaveIfError(iTimer.CreateLocal()); // Initialize timer
iTel = CTelephony::NewL();
CActiveScheduler::Add(this); // Add to scheduler
}
CTelephoneListener::~CTelephoneListener()
{
Cancel(); // Cancel any request, if outstanding
DoCancel();
delete iTel;
iTel = NULL;
}
void CTelephoneListener::DoCancel()
{
iTel->CancelAsync(CTelephony::EVoiceLineStatusChangeCancel);
}
void CTelephoneListener::StartL(TTimeIntervalMicroSeconds32 aDelay)
{
Cancel();
iState = EUninitialized;
iTel->NotifyChange( iStatus,
CTelephony::EVoiceLineStatusChange,
iCallStatusPckg );
SetActive();
}
void CTelephoneListener::RunL()
{
if( iStatus == KErrNone )
{
iObserver->TelephoneStatusChanged(iCallStatus.iStatus);
iTel->NotifyChange( iStatus,
CTelephony::EVoiceLineStatusChange,
iCallStatusPckg );
}
SetActive();
}
TInt CTelephoneListener::RunError(TInt aError)
{
return aError;
}
本文来自优快云博客,转载请标明出处:http://blog.youkuaiyun.com/sariy/archive/2009/12/01/4913409.aspx