telephonyutils/etel3rdpartyapi/ExampleApps/OutgoingCalls/CLineStatus.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 #include "CLineStatus.h"
       
    18 #include <simtsy.h>
       
    19 
       
    20 /**
       
    21 Factory constructor.
       
    22 
       
    23 @param  aController Pointer to MExecAsync object passed to constructor of 
       
    24                     CISVAPIBase
       
    25 @return             Instance of CLineStatus class
       
    26 */
       
    27 CLineStatus* CLineStatus::NewL(MExecAsync* aController)
       
    28 	{
       
    29 	CLineStatus* self = new(ELeave) CLineStatus(aController);
       
    30 	CleanupStack::PushL(self);
       
    31 	self->ConstructL();
       
    32 	CleanupStack::Pop(self);
       
    33 	return self;
       
    34 	}
       
    35 
       
    36 /**
       
    37 Destructor.
       
    38 Cancels outstanding requests.
       
    39 */
       
    40 CLineStatus::~CLineStatus()
       
    41 	{
       
    42 	Cancel();
       
    43 	}
       
    44 
       
    45 /**
       
    46 Gets the line status of the voice line, stores the result in
       
    47 iLineStatusV1Pckg and displays the result to the console.
       
    48 */
       
    49 void CLineStatus::DoStartRequestL()
       
    50 	{
       
    51     iRequestNotify = EFalse;
       
    52     CTelephony::TPhoneLine line = CTelephony::EVoiceLine;
       
    53    
       
    54    // Retrieves the status of the line selected by the specified argument
       
    55 	iTelephony->GetLineStatus(line, iLineStatusV1Pckg);
       
    56 	CTelephony::TCallStatus voiceLineStatus = iLineStatusV1.iStatus;
       
    57 	switch (voiceLineStatus)
       
    58 		{
       
    59 	case CTelephony::EStatusRinging:
       
    60 		iConsole->Printf(_L("RING RING RING\n"));
       
    61 		break;
       
    62 	case CTelephony::EStatusConnected:
       
    63 		iConsole->Printf(_L("Line Status: Connected\n"));
       
    64 		break;
       
    65 	case CTelephony::EStatusConnecting:
       
    66 		iConsole->Printf(_L("Line Status: Connecting\n"));
       
    67 		break;
       
    68 	case CTelephony::EStatusAnswering:
       
    69 		iConsole->Printf(_L("Line Status: Answering\n"));
       
    70 		break;
       
    71 	case CTelephony::EStatusIdle:
       
    72 		iConsole->Printf(_L("Line Status: Idle\n"));
       
    73 		break;
       
    74 	case CTelephony::EStatusDisconnecting:
       
    75 		iConsole->Printf(_L("Line Status: Disconnecting\n"));
       
    76 		break;
       
    77 	case CTelephony::EStatusHold:
       
    78 		iConsole->Printf(_L("Line Status: On Hold\n"));
       
    79 		break;
       
    80 	default:
       
    81 		iConsole->Printf(_L("Line status changed.\n"));
       
    82 		break;
       
    83 		}
       
    84 	if (voiceLineStatus == CTelephony::EStatusIdle)
       
    85 		{
       
    86 		ExampleNotify();
       
    87 		}
       
    88 	else
       
    89 		{
       
    90 		if (!IsActive())
       
    91 			{
       
    92 			RequestNotificationL();
       
    93 			}
       
    94 		}
       
    95 	}
       
    96 	
       
    97 /**
       
    98 Constructor.
       
    99 
       
   100 @param aController Pointer to an MExecAsync object passed to constructor of 
       
   101                    CISVAPIBase
       
   102 */
       
   103 CLineStatus::CLineStatus(MExecAsync* aController)
       
   104 	: CISVAPIAsync(aController, KLineStatus),
       
   105 	  iLineStatusV1Pckg(iLineStatusV1)
       
   106 	{
       
   107 	// Empty method
       
   108 	}
       
   109 
       
   110 /**
       
   111 Second phase constructor.
       
   112 */
       
   113 void CLineStatus::ConstructL()
       
   114 	{
       
   115 	// Empty method
       
   116 	}
       
   117 
       
   118 /**
       
   119 Checks the status of the active object and prints the voice line status to the 
       
   120 console if there is no error.
       
   121 */
       
   122 void CLineStatus::RunL()
       
   123 	{
       
   124 	CTelephony::TCallStatus voiceLineStatus = iLineStatusV1.iStatus;
       
   125 	// Print Line Information.
       
   126 	if(iStatus != KErrNone)
       
   127 		{
       
   128 		iConsole->Printf(KError);
       
   129 		
       
   130 		// Print the error status code
       
   131 		iConsole->Printf(_L("%d\n"), iStatus.Int());
       
   132 		}
       
   133 	else
       
   134 		{
       
   135 		switch (voiceLineStatus)
       
   136 			{
       
   137 		case CTelephony::EStatusRinging:
       
   138 			iConsole->Printf(_L("RING RING RING\n"));
       
   139 			break;
       
   140 		case CTelephony::EStatusConnected:
       
   141 			iConsole->Printf(_L("Line Status: Connected\n"));
       
   142 			break;
       
   143 		case CTelephony::EStatusConnecting:
       
   144 			iConsole->Printf(_L("Line Status: Connecting\n"));
       
   145 			break;
       
   146 		case CTelephony::EStatusAnswering:
       
   147 			iConsole->Printf(_L("Line Status: Answering\n"));
       
   148 			break;
       
   149 		case CTelephony::EStatusIdle:
       
   150 			iConsole->Printf(_L("Line Status: Idle\n"));
       
   151 			break;
       
   152 		case CTelephony::EStatusDisconnecting:
       
   153 			iConsole->Printf(_L("Line Status: Disconnecting\n"));
       
   154 			break;
       
   155 		case CTelephony::EStatusHold:
       
   156 			iConsole->Printf(_L("Line Status: On Hold\n"));
       
   157 			break;
       
   158 		default:
       
   159 			iConsole->Printf(_L("Line status changed.\n"));
       
   160 			break;
       
   161 			}
       
   162 		if (voiceLineStatus == CTelephony::EStatusIdle
       
   163 				||  voiceLineStatus == CTelephony::EStatusHold)
       
   164 			{
       
   165 			ExampleNotify();
       
   166 			}
       
   167 		else if (voiceLineStatus == CTelephony::EStatusRinging)
       
   168 			{
       
   169 			ExampleComplete();
       
   170 			}
       
   171 		else
       
   172 			{
       
   173 			if (!IsActive())
       
   174 				{
       
   175 				RequestNotificationL();
       
   176 				}
       
   177 			}
       
   178 		}
       
   179 	}
       
   180 
       
   181 /**
       
   182 Requests to receive notifications of change in the voice line
       
   183 status.
       
   184 */
       
   185 void CLineStatus::DoRequestNotificationL()
       
   186 	{
       
   187 	// Panic if this object is already performing an asynchronous operation. 
       
   188 	// Application will panic if you call SetActive() on an already active object.
       
   189 	_LIT( KNotifyPanic, "CLineStatus Notify Method" );
       
   190 	__ASSERT_ALWAYS( !IsActive(), User::Panic( KNotifyPanic, 1 ));
       
   191 	iRequestNotify = ETrue;
       
   192 	
       
   193 	// Registers interest in receiving change notifications for events.
       
   194 	iTelephony->NotifyChange(iStatus,
       
   195 								CTelephony::EVoiceLineStatusChange,
       
   196 								iLineStatusV1Pckg );
       
   197 	SetActive();
       
   198 	}
       
   199 
       
   200 /**
       
   201 Cancels asynchronous request to CTelephony::GetLineStatus()
       
   202 */
       
   203 void CLineStatus::DoCancel()
       
   204 	{
       
   205 	// Cancels an outstanding asynchronous request.
       
   206 	iTelephony->CancelAsync(CTelephony::EVoiceLineStatusChangeCancel);
       
   207 	}
       
   208