telephonyutils/etel3rdpartyapi/ExampleApps/PhoneMonitoring/CSignalInfo.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 "CSignalInfo.h"
       
    17 
       
    18 /**
       
    19 Factory constructor.
       
    20 
       
    21 @param  aController Pointer to MExecAsync object passed to constructor of 
       
    22                     CISVAPIBase
       
    23 @return             Instance of CSignalInfo class
       
    24 */
       
    25 CSignalInfo* CSignalInfo::NewL(MExecAsync* aController)
       
    26 	{
       
    27 	CSignalInfo* self = new(ELeave) CSignalInfo(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 CSignalInfo::~CSignalInfo()
       
    39 	{
       
    40 	Cancel();
       
    41 	}
       
    42 
       
    43 /**
       
    44 Gets the signal strength and stores it in the iSignalStrengthV1Pckg package.
       
    45 */
       
    46 void CSignalInfo::DoStartRequestL()
       
    47 	{
       
    48 	_LIT(KDummyAnswerPanic, "CSignalInfo Get Method");
       
    49 	__ASSERT_ALWAYS(!IsActive(), User::Panic(KDummyAnswerPanic, 1));
       
    50 	iRequestNotify = EFalse;
       
    51 	
       
    52 	// Retrieves the phone's current signal strength via the aDes argument.
       
    53 	iTelephony->GetSignalStrength(iStatus, iSignalStrengthV1Pckg);
       
    54 	SetActive();
       
    55 	}
       
    56 
       
    57 /**
       
    58 Constructor.
       
    59 
       
    60 @param aController Pointer to an MExecAsync object passed to constructor of 
       
    61                    CISVAPIBase
       
    62 */
       
    63 CSignalInfo::CSignalInfo(MExecAsync* aController)
       
    64 	: CISVAPIAsync(aController, KSignalInfo),
       
    65 	  iSignalStrengthV1Pckg(iSignalStrengthV1)
       
    66 	{
       
    67 	// Empty method
       
    68 	}
       
    69 
       
    70 /**
       
    71 Second phase constructor.
       
    72 */
       
    73 void CSignalInfo::ConstructL()
       
    74 	{
       
    75 	// Empty method
       
    76 	}
       
    77 
       
    78 /**
       
    79 Checks the status of the active object and prints the signal strength (in bars)
       
    80 to the console if there is no error.
       
    81 */
       
    82 void CSignalInfo::RunL()
       
    83 	{
       
    84 	if(iStatus != KErrNone)
       
    85 		{
       
    86 		iConsole->Printf(KError);
       
    87 		
       
    88 		// Print the error status code
       
    89 		iConsole->Printf(_L("%d\n"), iStatus.Int());
       
    90 		}
       
    91 	else
       
    92 		{
       
    93 		TInt32 strength = iSignalStrengthV1.iSignalStrength;
       
    94 		TInt8 bars = iSignalStrengthV1.iBar;
       
    95 		if (iRequestNotify)
       
    96 			{
       
    97 			iConsole->ClearScreen();
       
    98 			iConsole->Printf(_L("~*THIS IS A NOTIFICATION*~\n"));
       
    99 			}
       
   100 		iConsole->Printf(KSignalStrengthMsg);
       
   101 		iConsole->Printf(_L("There are %d bars!\n"), bars);
       
   102 		iConsole->Printf(_L("Signal Strength is %d!\n"), strength);
       
   103 		if (iRequestNotify)
       
   104 			{
       
   105 			DoRequestNotificationL();
       
   106 			}
       
   107 		else
       
   108 			{
       
   109 			ExampleComplete();
       
   110 			}
       
   111 		}
       
   112 	}
       
   113 
       
   114 /**
       
   115 Requests to receive notifications of change in the signal strength.
       
   116 */
       
   117 void CSignalInfo::DoRequestNotificationL()
       
   118    {
       
   119 	// Panic if this object is already performing an asynchronous operation. 
       
   120 	// Application will panic if you call SetActive() on an already active object.
       
   121 	_LIT( KNotifyPanic, "CSignalInfo Notify Method" );
       
   122 	__ASSERT_ALWAYS( !IsActive(), User::Panic( KNotifyPanic, 1 ));
       
   123 	iRequestNotify = ETrue;
       
   124 	
       
   125 	// Registers interest in receiving change notifications for events.
       
   126 	iTelephony->NotifyChange( 	iStatus,
       
   127 								CTelephony::ESignalStrengthChange,
       
   128 								iSignalStrengthV1Pckg );
       
   129 	SetActive();
       
   130 	}
       
   131 
       
   132 /**
       
   133 Cancels asynchronous request to CTelephony::GetSignalStrength().
       
   134 */
       
   135 void CSignalInfo::DoCancel()
       
   136 	{
       
   137 	// Cancels an outstanding asynchronous request.
       
   138 	iTelephony->CancelAsync(CTelephony::ESignalStrengthChangeCancel);
       
   139 	}