telephonyutils/etel3rdpartyapi/ExampleApps/IncomingCalls/CCallStatus.cpp
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18 */
       
    19 
       
    20 #include "CCallStatus.h"
       
    21 
       
    22 /**
       
    23 Factory constructor.
       
    24 
       
    25 @param  aController Pointer to MExecAsync object passed to constructor of 
       
    26                     CISVAPIBase
       
    27 @param  aCallId	Caller ID to retrieve the status                     
       
    28 @return             Instance of CCallStatus class
       
    29 */
       
    30 CCallStatus* CCallStatus::NewL(MExecAsync* aController, CTelephony::TCallId aCallId)
       
    31 	{
       
    32 	CCallStatus* self = new(ELeave) CCallStatus(aController, aCallId);
       
    33 	CleanupStack::PushL(self);
       
    34 	self->ConstructL();
       
    35 	CleanupStack::Pop(self);
       
    36 	return self;
       
    37 	}
       
    38 
       
    39 /**
       
    40 Default destructor.
       
    41 Cancels outstanding requests.
       
    42 */
       
    43 CCallStatus::~CCallStatus()
       
    44 	{
       
    45 	Cancel();
       
    46 	}
       
    47 
       
    48 /**
       
    49 Gets the current call status, stores it in the iCallStatusV1Pckg package and
       
    50 prints it to the console.
       
    51 */
       
    52 void CCallStatus::DoStartRequestL()
       
    53 	{
       
    54 	// Retrieves the status of the selected call specified by the argument
       
    55 	iTelephony->GetCallStatus(iCallId, iCallStatusV1Pckg);
       
    56 	switch(iCallStatusV1.iStatus)
       
    57 		{
       
    58 	case CTelephony::EStatusRinging:
       
    59 		iConsole->Printf(_L("RING RING RING\n"));
       
    60 		break;
       
    61 	case CTelephony::EStatusConnected:
       
    62 		iConsole->Printf(_L("Call Status: Connected\n"));
       
    63 		break;
       
    64 	case CTelephony::EStatusConnecting:
       
    65 		iConsole->Printf(_L("Call Status: Connecting\n"));
       
    66 		break;
       
    67 	case CTelephony::EStatusAnswering:
       
    68 		iConsole->Printf(_L("Call Status: Answering\n"));
       
    69 		break;
       
    70 	case CTelephony::EStatusIdle:
       
    71 		iConsole->Printf(_L("Call Status: Idle\n"));
       
    72 		break;
       
    73 	case CTelephony::EStatusDisconnecting:
       
    74 		iConsole->Printf(_L("Call Status: Disconnecting\n"));
       
    75 		break;
       
    76 	default:
       
    77 		iConsole->Printf(_L("Call status changed\n"));
       
    78 		break;
       
    79 		}
       
    80 	ExampleComplete();
       
    81 	}
       
    82 
       
    83 /**
       
    84 Default constructor.
       
    85 
       
    86 @param aController Pointer to an MExecAsync object passed to constructor of
       
    87                    CISVAPIBase
       
    88 @param  aCallId	Caller ID to retrieve the status                     
       
    89 */
       
    90 CCallStatus::CCallStatus(MExecAsync* aController,
       
    91 						 CTelephony::TCallId aCallId)
       
    92 	: CISVAPIAsync(aController, KCallStatus),
       
    93 	  iCallStatusV1Pckg(iCallStatusV1),
       
    94 	  iCallId(aCallId)
       
    95 	{
       
    96 	// Empty method
       
    97 	}
       
    98 
       
    99 /**
       
   100 Second phase constructor.
       
   101 */
       
   102 void CCallStatus::ConstructL()
       
   103 	{
       
   104 	// Empty method
       
   105 	}
       
   106 
       
   107 /**
       
   108 Checks the status of the active object and prints the call status to the
       
   109 console if there is no error.
       
   110 */
       
   111 void CCallStatus::RunL()
       
   112 	{
       
   113 	CTelephony::TCallStatus CallStatus = iCallStatusV1.iStatus;
       
   114 	// Print Call Info
       
   115 	if(iStatus != KErrNone)
       
   116 		{
       
   117 		iConsole->Printf(KError);
       
   118 		
       
   119 		// Print the error status code
       
   120 		iConsole->Printf(_L("%d\n"), iStatus.Int());
       
   121 		}
       
   122 	else
       
   123 		{
       
   124 		switch(CallStatus)
       
   125 			{
       
   126 		case CTelephony::EStatusRinging:
       
   127 			iConsole->Printf(_L("RING RING RING\n"));
       
   128 			break;
       
   129 		case CTelephony::EStatusConnected:
       
   130 			iConsole->Printf(_L("Call Status: Connected\n"));
       
   131 			break;
       
   132 		case CTelephony::EStatusConnecting:
       
   133 			iConsole->Printf(_L("Call Status: Connecting\n"));
       
   134 			break;
       
   135 		case CTelephony::EStatusAnswering:
       
   136 			iConsole->Printf(_L("Call Status: Answering\n"));
       
   137 			break;
       
   138 		case CTelephony::EStatusIdle:
       
   139 			iConsole->Printf(_L("Call Status: Idle\n"));
       
   140 			break;
       
   141 		case CTelephony::EStatusDisconnecting:
       
   142 			iConsole->Printf(_L("Call Status: Disconnecting\n"));
       
   143 			break;
       
   144 		default:
       
   145 			iConsole->Printf(_L("Call status changed\n"));
       
   146 			break;
       
   147 			}
       
   148 		if (CallStatus == CTelephony::EStatusIdle)
       
   149 			{
       
   150 			ExampleNotify();
       
   151 			}
       
   152 		else
       
   153 			{
       
   154 			RequestNotificationL();
       
   155 			}
       
   156 		}
       
   157 	}
       
   158 
       
   159 /**
       
   160 Requests to receive notifications of change in the call status
       
   161 */
       
   162 void CCallStatus::DoRequestNotificationL()
       
   163 	{
       
   164 	// Panic if this object is already performing an asynchronous operation. 
       
   165 	// Application will panic if you SetActive() an already active object.
       
   166 	_LIT( KNotifyPanic, "CCallStatus Notify Method" );
       
   167 	__ASSERT_ALWAYS( !IsActive(), User::Panic( KNotifyPanic, 1 ));
       
   168 	iRequestNotify = ETrue;
       
   169 	CTelephony::TNotificationEvent iEvent;
       
   170 	switch(iCallId)
       
   171 		{
       
   172 	case CTelephony::EISVCall1:
       
   173 		iEvent = CTelephony::EOwnedCall1StatusChange;
       
   174 		break;
       
   175 	case CTelephony::EISVCall2:
       
   176 		iEvent = CTelephony::EOwnedCall2StatusChange;
       
   177 		break;
       
   178 	default:
       
   179 		// We have not been given a valid call ID
       
   180 		return;
       
   181 		}
       
   182 	
       
   183 	// Registers interest in receiving change notifications for events.
       
   184 	iTelephony->NotifyChange(iStatus, iEvent, iCallStatusV1Pckg);
       
   185 	SetActive();
       
   186 	}
       
   187 
       
   188 /**
       
   189 Cancel asynchronous request to CTelephony::GetCallStatus()
       
   190 */
       
   191 void CCallStatus::DoCancel()
       
   192 	{
       
   193 	switch(iCallId)
       
   194 		{
       
   195 	case CTelephony::EISVCall1:
       
   196 		iTelephony->CancelAsync(CTelephony::EOwnedCall1StatusChangeCancel);
       
   197 		break;
       
   198 	case CTelephony::EISVCall2:
       
   199 		iTelephony->CancelAsync(CTelephony::EOwnedCall2StatusChangeCancel);
       
   200 		break;
       
   201 	default:
       
   202 		// We have not been given a valid call ID
       
   203 		break;
       
   204 		}
       
   205 	}