telephonyutils/etel3rdpartyapi/ExampleApps/OutgoingCalls/CCurrentNetworkInfo.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 "CCurrentNetworkInfo.h"
       
    18 
       
    19 /**
       
    20 Factory constructor.
       
    21 
       
    22 @param  aController Pointer to MExecAsync object passed to constructor of 
       
    23                     CISVAPIBase
       
    24 @return             Instance of CCurrentNetworkInfo class
       
    25 */
       
    26 CCurrentNetworkInfo* CCurrentNetworkInfo::NewL(MExecAsync* aController)
       
    27 	{
       
    28 	CCurrentNetworkInfo* self = new(ELeave) CCurrentNetworkInfo(aController);
       
    29 	CleanupStack::PushL(self);
       
    30 	self->ConstructL();
       
    31 	CleanupStack::Pop(self);
       
    32 	return self;
       
    33 	}
       
    34 
       
    35 /**
       
    36 Destructor.
       
    37 Cancels outstanding requests.
       
    38 */
       
    39 CCurrentNetworkInfo::~CCurrentNetworkInfo()
       
    40 	{
       
    41 	Cancel();
       
    42 	}
       
    43 
       
    44 /**
       
    45 Gets the current network information and stores it in the
       
    46 iCurrentNetworkInfoV1Pckg package.
       
    47 */
       
    48 void CCurrentNetworkInfo::DoStartRequestL()
       
    49 	{
       
    50 	_LIT( KNotifyPanic, "CCurrentNetworkInfo Notify Method" );
       
    51     __ASSERT_ALWAYS( !IsActive(), User::Panic( KNotifyPanic, 1 ));
       
    52     iRequestNotify = EFalse;
       
    53    
       
    54     // Retrieves over-the-air network information about the currently registered mobile network.
       
    55 	iTelephony->GetCurrentNetworkInfo(iStatus,
       
    56 	                                  iCurrentNetworkInfoV1Pckg);
       
    57 	SetActive();
       
    58 	}
       
    59 
       
    60 /**
       
    61 Constructor.
       
    62 
       
    63 @param aController Pointer to an MExecAsync object passed to constructor of 
       
    64                    CISVAPIBase
       
    65 */
       
    66 CCurrentNetworkInfo::CCurrentNetworkInfo(MExecAsync* aController)
       
    67 	: CISVAPIAsync(aController, KNetworkInfo),
       
    68 	  iCurrentNetworkInfoV1Pckg(iCurrentNetworkInfoV1)
       
    69 	{
       
    70 	// Empty method
       
    71 	}
       
    72 
       
    73 /**
       
    74 Second phase constructor.
       
    75 */
       
    76 void CCurrentNetworkInfo::ConstructL()
       
    77 	{
       
    78 	// Empty method
       
    79 	}
       
    80 
       
    81 /**
       
    82 Checks the status of the active object and prints the network information to
       
    83 the console if there is no error.
       
    84 */
       
    85 void CCurrentNetworkInfo::RunL()
       
    86 	{
       
    87 	if(iStatus != KErrNone)
       
    88 		{
       
    89 		iConsole->Printf(KError);
       
    90 		
       
    91 		// Print the error status code
       
    92 		iConsole->Printf(_L("%d\n"), iStatus.Int());
       
    93 		}
       
    94 	else
       
    95 		{
       
    96 		TBuf<30> theStatus;
       
    97 		if (iRequestNotify)
       
    98 	    	{
       
    99 	    	iConsole->ClearScreen();
       
   100 	    	iConsole->Printf(_L("~*THIS IS A NOTIFICATION*~\n"));
       
   101 	    	}
       
   102 
       
   103 		// Print the console message if there is no error
       
   104 		iConsole->Printf(KNetworkInfoMsg);
       
   105 		iConsole->Printf(iCurrentNetworkInfoV1.iDisplayTag);
       
   106 		iConsole->Printf(KNewLine);
       
   107 		switch (iCurrentNetworkInfoV1.iStatus)
       
   108 			{
       
   109 		case CTelephony::ENetworkStatusUnknown:
       
   110 			theStatus.Append(_L("ENetworkStatusUnknown\n"));
       
   111 			break;
       
   112 		case CTelephony::ENetworkStatusAvailable:
       
   113 			theStatus.Append(_L("ENetworkStatusUnavailable\n"));
       
   114 			break;
       
   115 		case CTelephony::ENetworkStatusCurrent:
       
   116 			theStatus.Append(_L("ENetworkStatusCurrent\n"));
       
   117 			break;
       
   118 		case CTelephony::ENetworkStatusForbidden:
       
   119 			theStatus.Append(_L("ENetworkStatusForbidden\n"));
       
   120 			break;
       
   121 			}
       
   122 		iConsole->Printf(theStatus);
       
   123 		if(iCurrentNetworkInfoV1.iAccess)
       
   124 			{
       
   125 			iConsole->Printf((_L("The Cell Id is : %d\n")),
       
   126 			                      iCurrentNetworkInfoV1.iCellId);
       
   127 			iConsole->Printf((_L("The Area Code is : %d\n")),
       
   128 			                      iCurrentNetworkInfoV1.iLocationAreaCode);
       
   129 			}
       
   130 		if (iRequestNotify)
       
   131 			{
       
   132 			ExampleNotify();
       
   133 			}
       
   134 		else
       
   135 			{
       
   136 			ExampleComplete();
       
   137 			}
       
   138 		}
       
   139 	}
       
   140 
       
   141 /**
       
   142 Requests to receive notifications of change in the current network information.
       
   143 */
       
   144 void CCurrentNetworkInfo::DoRequestNotificationL()
       
   145    {
       
   146 	// Panics if this object is already performing an asynchronous operation. 
       
   147 	// Application will panic if you call SetActive() on an already active object.
       
   148 	_LIT( KNotifyPanic, "CCurrentNetworkInfo Notify Method" );
       
   149 	__ASSERT_ALWAYS( !IsActive(), User::Panic( KNotifyPanic, 1 ));
       
   150 	iRequestNotify = ETrue;
       
   151 	
       
   152 	// Registers interest in receiving change notifications for events.
       
   153 	iTelephony->NotifyChange(	iStatus,
       
   154 								CTelephony::ECurrentNetworkInfoChange,
       
   155 								iCurrentNetworkInfoV1Pckg );
       
   156 	SetActive();
       
   157    }
       
   158 
       
   159 /**
       
   160 Cancels asynchronous request to CTelephony::GetCurrentNetworkInfo()
       
   161 */
       
   162 void CCurrentNetworkInfo::DoCancel()
       
   163 	{
       
   164 	iRequestNotify = EFalse;
       
   165 	
       
   166 	// Cancels an outstanding asynchronous request
       
   167 	iTelephony->CancelAsync(CTelephony::ECurrentNetworkInfoChangeCancel);
       
   168 	}
       
   169