telephonyutils/etel3rdpartyapi/ExampleApps/OutgoingCalls/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 #include "CCallStatus.h"
       
    17 
       
    18 /**
       
    19 Factory constructor.
       
    20 
       
    21 @param  aController Pointer to MExecAsync object passed to constructor of 
       
    22                     CISVAPIBase
       
    23 @param  aCallId	Caller ID to retrieve the status                   
       
    24 @return             Instance of CCallStatus class
       
    25 */
       
    26 CCallStatus* CCallStatus::NewL(MExecAsync* aController, CTelephony::TCallId aCallId)
       
    27 	{
       
    28 	CCallStatus* self = new(ELeave) CCallStatus(aController, aCallId);
       
    29 	CleanupStack::PushL(self);
       
    30 	self->ConstructL();
       
    31 	CleanupStack::Pop(self);
       
    32 	return self;
       
    33 	}
       
    34 
       
    35 /**
       
    36 Destructor.
       
    37 Cancels outstanding requests.
       
    38 */
       
    39 CCallStatus::~CCallStatus()
       
    40 	{
       
    41 	Cancel();
       
    42 	}
       
    43 
       
    44 /**
       
    45 Gets the current call status, stores it in the iCallStatusV1Pckg package and
       
    46 prints it to the console.
       
    47 */
       
    48 void CCallStatus::DoStartRequestL()
       
    49 	{
       
    50 	// Retrieves the status of the selected call specified by the argument
       
    51 	iTelephony->GetCallStatus(iCallId, iCallStatusV1Pckg);
       
    52 	CTelephony::TCallStatus CallStatus = iCallStatusV1.iStatus;
       
    53 	
       
    54 	// Print the caller identification
       
    55 	iConsole->Printf((_L("%d ")), iCallId);
       
    56 	switch(CallStatus)
       
    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 	case CTelephony::EStatusHold:
       
    77 		iConsole->Printf(_L("Call Status on Hold\n"));
       
    78 		break;
       
    79 	default:
       
    80 		iConsole->Printf((_L("Call status changed is %d \n")), CallStatus);
       
    81 		break;
       
    82 		}
       
    83 	ExampleComplete();
       
    84 	}
       
    85 
       
    86 /**
       
    87 Constructor.
       
    88 
       
    89 @param aController Pointer to an MExecAsync object passed to constructor of 
       
    90                    CISVAPIBase
       
    91 @param  aCallId	Caller ID to retrieve the status                  
       
    92 */
       
    93 CCallStatus::CCallStatus(MExecAsync* aController,
       
    94                         CTelephony::TCallId aCallId)
       
    95 	: CISVAPIAsync(aController, KCallStatus),
       
    96 	  iCallId(aCallId),
       
    97 	  iCallStatusV1Pckg(iCallStatusV1)
       
    98 	{
       
    99 	// Empty method
       
   100 	}
       
   101 
       
   102 /**
       
   103 Second phase constructor.
       
   104 */
       
   105 void CCallStatus::ConstructL()
       
   106 	{
       
   107 	// Empty method
       
   108 	}
       
   109 
       
   110 /**
       
   111 Checks the status of the active object and prints the
       
   112 call information to the console if there is no
       
   113 error.
       
   114 */
       
   115 void CCallStatus::RunL()
       
   116 	{
       
   117 	// Print Call Info
       
   118 	if(iStatus != KErrNone)
       
   119 		{
       
   120 		iConsole->Printf(KError);
       
   121 		
       
   122 		// Print error status code
       
   123 		iConsole->Printf(_L("%d\n"), iStatus.Int());
       
   124 		}
       
   125 	else
       
   126 		{
       
   127 		CTelephony::TCallStatus CallStatus = iCallStatusV1.iStatus;
       
   128 		
       
   129 		// Print the caller identification
       
   130 		iConsole->Printf((_L("%d ")), iCallId);
       
   131 		switch(CallStatus)
       
   132 			{
       
   133 		case CTelephony::EStatusRinging:
       
   134 			iConsole->Printf(_L("RING RING RING\n"));
       
   135 			break;
       
   136 		case CTelephony::EStatusConnected:
       
   137 			iConsole->Printf(_L("Call Status connected\n"));
       
   138 			break;
       
   139 		case CTelephony::EStatusConnecting:
       
   140 			iConsole->Printf(_L("Call Status connecting\n"));
       
   141 			break;
       
   142 		case CTelephony::EStatusAnswering:
       
   143 			iConsole->Printf(_L("Call Status Answering\n"));
       
   144 			break;
       
   145 		case CTelephony::EStatusIdle:
       
   146 			iConsole->Printf(_L("Call Status Idle\n"));
       
   147 			break;
       
   148 		case CTelephony::EStatusDisconnecting:
       
   149 			iConsole->Printf(_L("Call Status Disconnecting\n"));
       
   150 			break;
       
   151 		case CTelephony::EStatusHold:
       
   152 			iConsole->Printf(_L("Call Status on Hold\n"));
       
   153 			break;
       
   154 		default:
       
   155 			iConsole->Printf((_L("Call status is %d \n")), CallStatus);
       
   156 			break;
       
   157 			}
       
   158 		if (CallStatus != CTelephony::EStatusDisconnecting)
       
   159 			{
       
   160 			RequestNotificationL();
       
   161 			}
       
   162 		else
       
   163 			{
       
   164 			ExampleNotify();
       
   165 			}
       
   166 		}
       
   167 	}
       
   168 
       
   169 /**
       
   170 Requests to receive notifications of change in the
       
   171 call status
       
   172 */
       
   173 void CCallStatus::DoRequestNotificationL()
       
   174    {
       
   175 	// Panic if this object is already performing an asynchronous operation. 
       
   176 	// Application will crash if you call SetActive() on an already active object.
       
   177 	_LIT( KNotifyPanic, "CCallStatus Notify Method" );
       
   178 	__ASSERT_ALWAYS( !IsActive(), User::Panic( KNotifyPanic, 1 ));
       
   179 	iRequestNotify = ETrue;
       
   180 	CTelephony::TNotificationEvent iEvent;
       
   181 	switch(iCallId)
       
   182 		{
       
   183 	case CTelephony::EISVCall1:
       
   184 		iEvent = CTelephony::EOwnedCall1StatusChange;
       
   185 		break;
       
   186 
       
   187 	case CTelephony::EISVCall2:
       
   188 		iEvent = CTelephony::EOwnedCall2StatusChange;
       
   189 		break;
       
   190 	default:
       
   191 		// We have not been given a valid call ID
       
   192 		break;
       
   193 		}
       
   194 
       
   195 	// Registers interest in receiving change notifications for events.
       
   196 	iTelephony->NotifyChange(iStatus, iEvent, iCallStatusV1Pckg);
       
   197 	SetActive();
       
   198 	}
       
   199 
       
   200 /**
       
   201 Cancels asynchronous request to CTelephony::GetCallStatus()
       
   202 */
       
   203 void CCallStatus::DoCancel()
       
   204 	{
       
   205 	switch(iCallId)
       
   206 		{
       
   207 	case CTelephony::EISVCall1:
       
   208 		iTelephony->CancelAsync(CTelephony::EOwnedCall1StatusChangeCancel);
       
   209 		break;
       
   210 	case CTelephony::EISVCall2:
       
   211 		iTelephony->CancelAsync(CTelephony::EOwnedCall2StatusChangeCancel);
       
   212 		break;
       
   213 	default:
       
   214 		// We have not been given a valid call ID
       
   215 		break;
       
   216 		}
       
   217 	}