×
Namespaces

Variants
Actions

How to handle call events using CTelephony 3rd Edition

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: AbuElElla (26 May 2009)
Last edited: hamishwillee (26 Jul 2012)

This article intends to explain how to handle most of the events on a call using CTelephony in 3rd Edition

Events handled here are:

  1. Call Ringing
  2. Call Answered
  3. Call connecting
  4. Call connected
  5. Call disconnected
  6. Dial call


The implementation is so simple. The idea is simply active object listening to change in voice line

Contents

Headers Required

#include <Etel3rdParty.h>

Libraries Required

LIBRARY etel3rdparty.lib

Capability Required

 Capability NetworkServices

Code

The following code assumes that you have a class for log text (CMyLog).

Define observer interface to be implemented by class you want it to be notified with events (if you like)


MPhoneReceiverObserver

#ifndef MPHONERECEIVEROBSERVER_H
#define MPHONERECEIVEROBSERVER_H
 
class MPhoneReceiverObserver
{
public:
virtual void CallRinging() {}
 
virtual void CallAnswered() {}
 
virtual void DialingCall() {}
 
virtual void CallConnecting() {}
 
virtual void CallConnected() {}
 
virtual void CallDisConnected() {}
 
};
 
#endif // MPHONERECEIVEROBSERVER_H


Define the active object that will listen to any change in voice line status


CPhoneReceiver Declaration

#include <e32base.h>	// For CActive, link against: euser.lib
#include "Etel3rdParty.h" //For CTelephony, link against etel3rdparty.lib
 
#include "MPhoneReceiverObserver.h"
#include "MyLog.h"
 
class CPhoneReceiver : public CActive
{
public:
// C++ constructor
CPhoneReceiver(MPhoneReceiverObserver& aPhoneReceiverObserver);
 
// Second-phase constructor
void ConstructL();
 
// Cancel and destroy
~CPhoneReceiver();
 
public: // New functions
// Function for making the initial request
void StartL();
 
private: // From CActive
// Handle completion
void RunL();
 
// How to cancel me
void DoCancel();
 
private:
//Define object to CTelephone to manage calls
CTelephony* iTelephony;
 
CTelephony::TCallInfoV1 iCurrentCallInfo;
CTelephony::TCallInfoV1Pckg iCurrentStatusPckg;
 
CTelephony::TCallId iCallID;
 
MPhoneReceiverObserver& iPhoneReceiverObserver;
 
 
};
 
#endif


CPhoneReceiver Implementation

#include "PhoneReceiver.h"
 
CPhoneReceiver::CPhoneReceiver(MPhoneReceiverObserver& aPhoneReceiverObserver)
: CActive(EPriorityStandard),
iCurrentStatusPckg(iCurrentCallInfo),
iPhoneReceiverObserver(aPhoneReceiverObserver)
{
}
 
void CPhoneReceiver::ConstructL()
{
//Create new object to telephony
iTelephony = CTelephony::NewL();
CActiveScheduler::Add(this); // Add to scheduler
}
 
CPhoneReceiver::~CPhoneReceiver()
{
Cancel(); // Cancel any request, if outstanding
 
delete iTelephony;
}
 
void CPhoneReceiver::DoCancel()
{
iTelephony->CancelAsync( CTelephony::EVoiceLineStatusChangeCancel );
}
 
void CPhoneReceiver::StartL()
{
Cancel(); // Cancel any request, just to be sure
 
//Notify of change in telephone line
iTelephony->NotifyChange( iStatus, CTelephony::EVoiceLineStatusChange,
iCurrentStatusPckg );
 
SetActive(); // Tell scheduler a request is active
}
 
void CPhoneReceiver::RunL()
{
if(iStatus.Int() == KErrNone)
{
//Get call status
CTelephony::TCallStatus callStatus = iCurrentStatusPckg().iStatus;
 
switch(callStatus)
{
case CTelephony::EStatusRinging:
iPhoneReceiverObserver.CallRinging();
break;
 
case CTelephony::EStatusAnswering:
iPhoneReceiverObserver.CallAnswered();
break;
 
case CTelephony::EStatusDialling:
iPhoneReceiverObserver.DialingCall();
break;
 
case CTelephony::EStatusConnecting:
iPhoneReceiverObserver.CallConnecting();
break;
 
case CTelephony::EStatusConnected:
iPhoneReceiverObserver.CallConnected();
break;
 
case CTelephony::EStatusDisconnecting:
iPhoneReceiverObserver.CallDisConnected();
break;
 
default:
#ifdef __USE_PHONE_RECEIVER_LOG__
TBuf<50> num;
num.Copy(_L("Default: "));
num.AppendNum(callStatus);
CMyLog::OpenAndWriteToFile(num);
#endif
break;
}
}
else
{
#ifdef __USE_PHONE_RECEIVER_LOG__
TBuf<50> num;
num.AppendNum(iStatus.Int());
num.Append(_L(" -- "));
CTelephony::TCallStatus callStatus = iCurrentStatusPckg().iStatus;
num.AppendNum(callStatus);
CMyLog::OpenAndWriteToFile(num);
#endif
}
 
//Notify every time before activate object
iTelephony->NotifyChange( iStatus, CTelephony::EVoiceLineStatusChange,
iCurrentStatusPckg );
 
if(!IsActive())
SetActive();
 
}

Output

The following is a sample for the log file written above

Log:25-4-2009-15-18-53
////////////////////
Call Ringing
////////////////////
Call Answered
////////////////////
Call connected
////////////////////
Call disconnected
////////////////////
Default: 1 //Line Idle
////////////////////

This page was last modified on 26 July 2012, at 03:43.
26 page views in the last 30 days.