eventsui/eventsutils/src/evtcallhandler.cpp
branchRCL_3
changeset 17 1fc85118c3ae
parent 16 8173571d354e
child 18 870918037e16
equal deleted inserted replaced
16:8173571d354e 17:1fc85118c3ae
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Incoming Call Handler.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // System Includes
       
    20 #include <ctsydomainpskeys.h>
       
    21 #include <e32property.h>
       
    22 
       
    23 // User Includes
       
    24 #include "evtcallhandler.h"
       
    25 #include "evtdebug.h"
       
    26 
       
    27 // ================ Member funtions for CEvtCallHandler class ===============
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // CEvtCallHandler::CEvtCallHandler
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 CEvtCallHandler::CEvtCallHandler( MEvtCallObserver& aObserver ): 
       
    34 									CActive(EPriorityStandard),
       
    35 									iObserver(aObserver),
       
    36     								iCallStatusPkg(iCallStatus)
       
    37     {
       
    38     }
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // CEvtCallHandler::~CEvtCallHandler
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CEvtCallHandler::~CEvtCallHandler()
       
    45 	{
       
    46     Cancel();
       
    47  
       
    48     if (iTelephony)
       
    49         delete iTelephony;
       
    50 	}
       
    51 	
       
    52 // ---------------------------------------------------------------------------
       
    53 // CEvtCallHandler::NewL
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CEvtCallHandler* CEvtCallHandler::NewL( MEvtCallObserver& aObserver )
       
    57     {
       
    58 	CEvtCallHandler* self = NewLC( aObserver );
       
    59 	CleanupStack::Pop( self );
       
    60 	return self;
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // CEvtCallHandler::NewLC
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 CEvtCallHandler* CEvtCallHandler::NewLC( MEvtCallObserver& aObserver )
       
    68     {
       
    69 	CEvtCallHandler* self = new ( ELeave )CEvtCallHandler( aObserver );
       
    70 	CleanupStack::PushL( self );
       
    71 	self->ConstructL( );
       
    72 	return self;
       
    73     } 
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // CEvtCallHandler::ConstructL
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 void CEvtCallHandler::ConstructL()
       
    80     {
       
    81     EVTUIDEBUG( "+ CEvtCallHandler::ConstructL()" );
       
    82     
       
    83     iTelephony = CTelephony::NewL();
       
    84  
       
    85     CActiveScheduler::Add(this);
       
    86 	
       
    87 	StartListening();
       
    88 	
       
    89     EVTUIDEBUG( "- CEvtCallHandler::ConstructL()" );
       
    90     }
       
    91     
       
    92 // ---------------------------------------------------------------------------
       
    93 // CEvtCallHandler::RunL
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 void CEvtCallHandler::RunL()
       
    97     {
       
    98     if (iStatus == KErrNone)
       
    99         {
       
   100         CTelephony::TCallStatus status = iCallStatus.iStatus;
       
   101  
       
   102         switch (status)
       
   103             {
       
   104             case CTelephony::EStatusRinging:
       
   105                 {
       
   106                 // The phone is ringing.
       
   107                 iObserver.HandleIncomingCallL();
       
   108                 break;
       
   109                 }
       
   110             default:
       
   111                 {
       
   112                 // Not interested in other events.
       
   113                 break;
       
   114                 }
       
   115             }
       
   116         // Start listening for the next call
       
   117         StartListening();
       
   118         }
       
   119     }
       
   120     
       
   121 // ---------------------------------------------------------------------------
       
   122 // CEvtCallHandler::RunError
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125 TInt CEvtCallHandler::RunError(TInt anError)
       
   126     {
       
   127     return anError;
       
   128     }
       
   129     
       
   130 // ---------------------------------------------------------------------------
       
   131 // CEvtCallHandler::DoCancel
       
   132 // ---------------------------------------------------------------------------
       
   133 //
       
   134 void CEvtCallHandler::DoCancel()
       
   135     {
       
   136     iTelephony->CancelAsync(CTelephony::EVoiceLineStatusChangeCancel);
       
   137     }
       
   138     
       
   139 // ---------------------------------------------------------------------------
       
   140 // CEvtCallHandler::StartListening
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 void CEvtCallHandler::StartListening()
       
   144     {
       
   145     iTelephony->NotifyChange(iStatus, CTelephony::EVoiceLineStatusChange,
       
   146             iCallStatusPkg);
       
   147     SetActive();
       
   148     }
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // CEvtCallHandler::IsCallActive
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 TBool CEvtCallHandler::IsCallActive( )
       
   155 	{
       
   156     TInt callActiveState = EPSCTsyCallTypeNone;
       
   157 
       
   158     // Get current call status from P&S
       
   159     const TInt errCode( RProperty::Get(
       
   160         KPSUidCtsyCallInformation,
       
   161         KCTsyCallType,
       
   162         callActiveState ) );
       
   163 
       
   164     // Check current call type
       
   165     TBool result(
       
   166         ( EPSCTsyCallTypeCSVoice == callActiveState ) &&
       
   167         ( KErrNone == errCode ) );
       
   168         
       
   169     EVTUIDEBUG1( "= CEvtCallHandler::IsCallActive() - %d", result );
       
   170 
       
   171     return result;
       
   172     }
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 // CEvtCallHandler::IsCallIncoming
       
   176 // ---------------------------------------------------------------------------
       
   177 //
       
   178 TBool CEvtCallHandler::IsCallIncoming( )
       
   179 	{
       
   180     TInt callActiveState = EPSCTsyCallStateNone;
       
   181 
       
   182     // Get current call status from P&S
       
   183     const TInt errCode( RProperty::Get(
       
   184         KPSUidCtsyCallInformation,
       
   185         KCTsyCallState,
       
   186         callActiveState ) );
       
   187 
       
   188     const TBool callIncoming(
       
   189         ( EPSCTsyCallStateAlerting == callActiveState ) ||
       
   190         ( EPSCTsyCallStateRinging == callActiveState ) );
       
   191 
       
   192     // Check current call status
       
   193     TBool result( callIncoming && ( KErrNone == errCode ) );
       
   194         
       
   195     EVTUIDEBUG1( "= CEvtCallHandler::IsCallIncoming() - %d", result );
       
   196     
       
   197     return result;
       
   198     }
       
   199