telephonyutils/etel3rdpartyapi/ExampleApps/IncomingCalls/CFlightModeInfo.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 "CFlightModeInfo.h"
       
    17 
       
    18 /**
       
    19 Factory constructor.
       
    20 
       
    21 @param  aController Pointer to MExecAsync object passed to constructor of
       
    22                     CISVAPIBase.
       
    23 @return             Instance of CFlightModeInfo class
       
    24 */
       
    25 CFlightModeInfo* CFlightModeInfo::NewL(MExecAsync* aController)
       
    26 	{
       
    27 	CFlightModeInfo* self = new(ELeave) CFlightModeInfo(aController);
       
    28 	CleanupStack::PushL(self);
       
    29 	self->ConstructL();
       
    30 	CleanupStack::Pop(self);
       
    31 	return self;
       
    32 	}
       
    33 
       
    34 /**
       
    35 Destructor.
       
    36 Calls Cancel() to cancel outstanding requests.
       
    37 */
       
    38 CFlightModeInfo::~CFlightModeInfo()
       
    39 	{
       
    40 	Cancel();
       
    41 	}
       
    42 
       
    43 /**
       
    44 Gets the flight mode status and stores it in the iFlightModeV1Pckg.
       
    45 */
       
    46 void CFlightModeInfo::DoStartRequestL()
       
    47 	{
       
    48 	iRequestNotify = EFalse;
       
    49 	
       
    50 	// Retrieves the current flight mode status.
       
    51 	iTelephony->GetFlightMode(iStatus, iFlightModeV1Pckg);
       
    52 	SetActive();
       
    53 	}
       
    54 
       
    55 /**
       
    56 Constructor called by CFlightModeInfo::NewL().
       
    57 
       
    58 @param aController Pointer to an MExecAsync object passed to constructor of 
       
    59                    CISVAPIBase.
       
    60 */
       
    61 CFlightModeInfo::CFlightModeInfo(MExecAsync* aController)
       
    62 	: CISVAPIAsync(aController, KFlightModeInfo)
       
    63 	, iFlightModeV1Pckg(iFlightModeV1)
       
    64 	{
       
    65 	// Empty method
       
    66 	}
       
    67 
       
    68 /**
       
    69 Second phase constructor.
       
    70 */
       
    71 void CFlightModeInfo::ConstructL()
       
    72 	{
       
    73 	// Empty method
       
    74 	}
       
    75 
       
    76 /**
       
    77 Displays the flight mode status if there is no error.
       
    78 */
       
    79 void CFlightModeInfo::RunL()
       
    80 	{
       
    81 	if(iStatus != KErrNone)
       
    82 		{
       
    83 		iConsole->Printf(KError);
       
    84 		
       
    85 		// Print the error status code
       
    86 		iConsole->Printf(_L("%d\n"), iStatus.Int());
       
    87 		}
       
    88 	else
       
    89 		{
       
    90 		if (iRequestNotify)
       
    91 	    	{
       
    92 	    	iConsole->Printf(_L("~*THIS IS A NOTIFICATION*~\n"));
       
    93 	    	}
       
    94 		switch (iFlightModeV1.iFlightModeStatus)
       
    95 			{
       
    96 		case CTelephony::EFlightModeOff:
       
    97 			iConsole->Printf(_L("FlightStatus Off, you can make a calls!\n"));
       
    98 			ExampleComplete();
       
    99 			break;
       
   100 		case CTelephony::EFlightModeOn:
       
   101 			iConsole->Printf(_L("FlightStatus On, you cannot make calls!\n"));
       
   102 			RequestNotificationL();
       
   103 			break;
       
   104 		default:
       
   105 			iConsole->Printf(KError);
       
   106 			}
       
   107 		}
       
   108 	}
       
   109 
       
   110 /**
       
   111 Requests to receive notifications of change in the flight mode.
       
   112 */
       
   113 void CFlightModeInfo::DoRequestNotificationL()
       
   114 	{
       
   115 	// Panic if this object is already performing an asynchronous operation.
       
   116 	// Application will panic if you call SetActive() on an already active object.
       
   117 	_LIT( KNotifyPanic, "CFlightModeInfo Notify Method" );
       
   118 	__ASSERT_ALWAYS( !IsActive(), User::Panic( KNotifyPanic, 1 ));
       
   119 	iRequestNotify = ETrue;
       
   120 	
       
   121 	// Registers interest in receiving change notifications for events.
       
   122 	iTelephony->NotifyChange(	iStatus,
       
   123 								CTelephony::EFlightModeChange,
       
   124 								iFlightModeV1Pckg );
       
   125 	SetActive();
       
   126 	}
       
   127 
       
   128 /**
       
   129 Cancels asynchronous request to CTelephony::GetFlightMode().
       
   130 */
       
   131 void CFlightModeInfo::DoCancel()
       
   132 	{
       
   133 	// Cancels an outstanding asynchronous request.
       
   134 	iTelephony->CancelAsync(CTelephony::EFlightModeChangeCancel);
       
   135 	}