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