telephonyutils/etel3rdpartyapi/ExampleApps/AutoDTMFDialler/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.  Cancels outstanding requests.
       
    41 */
       
    42 CCallStatus::~CCallStatus()
       
    43 	{
       
    44 	Cancel();
       
    45 	}
       
    46 
       
    47 /**
       
    48 Gets the call status of call specified in iCallId and displays output
       
    49 to console.
       
    50 */
       
    51 void CCallStatus::DoStartRequestL()
       
    52 	{
       
    53 	iTelephony->GetCallStatus(iCallId, iCallStatusV1Pckg);
       
    54 	iConsole->Printf((_L("%d ")), iCallId);
       
    55 	CTelephony::TCallStatus callStatus = iCallStatusV1.iStatus;
       
    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 
       
    84 	if(callStatus == CTelephony::EStatusConnected)
       
    85 		{
       
    86 		ExampleComplete();
       
    87 		}
       
    88 	else
       
    89 		{
       
    90 		RequestNotificationL();
       
    91 		}
       
    92 	}
       
    93 
       
    94 /**
       
    95 Default constructor.
       
    96 
       
    97 @param aController Pointer to MExecAsync object passed to constructor of 
       
    98                    CISVAPIBase.
       
    99 @param aCallId     Call ID of the call whose status will be retrieved.
       
   100 */
       
   101 CCallStatus::CCallStatus(MExecAsync* aController, CTelephony::TCallId aCallId)
       
   102 	: CISVAPIAsync(aController, KCallStatus),
       
   103 	iCallId(aCallId),
       
   104 	iCallStatusV1Pckg(iCallStatusV1)
       
   105 	{
       
   106 	// Empty method
       
   107 	}
       
   108 
       
   109 /**
       
   110 Second phase constructor.
       
   111 */
       
   112 void CCallStatus::ConstructL()
       
   113 	{
       
   114 	// Empty method
       
   115 	}
       
   116 
       
   117 /**
       
   118 Checks status and prints output to the console.
       
   119 */
       
   120 void CCallStatus::RunL()
       
   121 	{
       
   122 	// Print Call Info
       
   123 	if(iStatus != KErrNone)
       
   124 		{
       
   125 		// Return error
       
   126 		iConsole->Printf(KError);
       
   127 		
       
   128 		// Print the error status code
       
   129 		iConsole->Printf(_L("%d\n"), iStatus.Int());
       
   130 		}
       
   131 	else
       
   132 		{
       
   133 		// Print the console output if there is no error
       
   134 		iConsole->Printf((_L("%d ")), iCallId);
       
   135 		CTelephony::TCallStatus CallStatus = iCallStatusV1.iStatus;
       
   136 		switch(CallStatus)
       
   137 			{
       
   138 		case CTelephony::EStatusRinging:
       
   139 			iConsole->Printf(_L("RING RING RING\n"));
       
   140 			break;
       
   141 		case CTelephony::EStatusConnected:
       
   142 			iConsole->Printf(_L("Call Status connected\n"));
       
   143 			break;
       
   144 		case CTelephony::EStatusConnecting:
       
   145 			iConsole->Printf(_L("Call Status connecting\n"));
       
   146 			break;
       
   147 		case CTelephony::EStatusAnswering:
       
   148 			iConsole->Printf(_L("Call Status Answering\n"));
       
   149 			break;
       
   150 		case CTelephony::EStatusIdle:
       
   151 			iConsole->Printf(_L("Call Status Idle\n"));
       
   152 			break;
       
   153 		case CTelephony::EStatusDisconnecting:
       
   154 			iConsole->Printf(_L("Call Status Disconnecting\n"));
       
   155 			break;
       
   156 		case CTelephony::EStatusHold:
       
   157 			iConsole->Printf(_L("Call Status on Hold\n"));
       
   158 			break;
       
   159 		default:
       
   160 			iConsole->Printf((_L("Call status is %d \n")), CallStatus);
       
   161 			break;
       
   162 			}
       
   163 		if (CallStatus == CTelephony::EStatusDisconnecting)
       
   164 			{
       
   165 			ExampleNotify();
       
   166 			}
       
   167 		else if(CallStatus == CTelephony::EStatusConnected)
       
   168 			{
       
   169 			ExampleComplete();
       
   170 			}
       
   171 		else
       
   172 			{
       
   173 			RequestNotificationL();
       
   174 			}
       
   175 		}
       
   176 	}
       
   177 
       
   178 /**
       
   179 Registers interest in receiving change notifications of the call status
       
   180 by calling CTelephony::NotifyChange.
       
   181 */
       
   182 void CCallStatus::DoRequestNotificationL()
       
   183 	{
       
   184 	// Panic if this object is already performing an asynchronous
       
   185 	// operation. Application will crash if you SetActive() an already
       
   186 	// active object.
       
   187 	_LIT( KNotifyPanic, "CCallStatus Notify Method" );
       
   188 	__ASSERT_ALWAYS( !IsActive(), User::Panic( KNotifyPanic, 1 ));
       
   189 	iRequestNotify = ETrue;
       
   190 	CTelephony::TNotificationEvent iEvent;
       
   191 
       
   192 	switch(iCallId)
       
   193 		{
       
   194 	case CTelephony::EISVCall1:
       
   195 		iEvent = CTelephony::EOwnedCall1StatusChange;
       
   196 		break;
       
   197 	case CTelephony::EISVCall2:
       
   198 		iEvent = CTelephony::EOwnedCall2StatusChange;
       
   199 		break;
       
   200 	default:
       
   201 		// We have not been given a valid call ID
       
   202 		break;
       
   203 		}
       
   204 
       
   205 	// Notify if there is any change in call status
       
   206 	iTelephony->NotifyChange(iStatus, iEvent, iCallStatusV1Pckg);
       
   207 	SetActive();
       
   208 	}
       
   209 
       
   210 /**
       
   211 Cancels a pending asychronous request depending on iCallId.
       
   212 */
       
   213 void CCallStatus::DoCancel()
       
   214 	{
       
   215 	switch(iCallId)
       
   216 		{
       
   217 	case CTelephony::EISVCall1:
       
   218 		iTelephony->CancelAsync(CTelephony::EOwnedCall1StatusChangeCancel);
       
   219 		break;
       
   220 	case CTelephony::EISVCall2:
       
   221 		iTelephony->CancelAsync(CTelephony::EOwnedCall2StatusChangeCancel);
       
   222 		break;
       
   223 	default:
       
   224 		// We have not been given a valid call ID
       
   225 		break;
       
   226 		}
       
   227 	}