examples/Telephony/ETel3rdPartyExample/NetworkInformation/CCurrentNetworkInfo.cpp

00001 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
00002 // All rights reserved.
00003 // This component and the accompanying materials are made available
00004 // under the terms of "Eclipse Public License v1.0"
00005 // which accompanies this distribution, and is available
00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00007 //
00008 // Initial Contributors:
00009 // Nokia Corporation - initial contribution.
00010 //
00011 // Contributors:
00012 //
00013 // Description:
00014 //
00015 
00016 
00017 #include "CCurrentNetworkInfo.h"
00018 
00026 CCurrentNetworkInfo* CCurrentNetworkInfo::NewL(MExecAsync* aController)
00027         {
00028         CCurrentNetworkInfo* self = new(ELeave) CCurrentNetworkInfo(aController);
00029         CleanupStack::PushL(self);
00030         self->ConstructL();
00031         CleanupStack::Pop(self);
00032         return self;
00033         }
00034 
00039 CCurrentNetworkInfo::~CCurrentNetworkInfo()
00040         {
00041         Cancel();
00042         }
00043 
00048 void CCurrentNetworkInfo::DoStartRequestL()
00049         {
00050         _LIT( KNotifyPanic, "CCurrentNetworkInfo Notify Method" );
00051     __ASSERT_ALWAYS( !IsActive(), User::Panic( KNotifyPanic, 1 ));
00052     iRequestNotify = EFalse;
00053    
00054     // Retrieves over-the-air network information about the currently registered mobile network.
00055         iTelephony->GetCurrentNetworkInfo(iStatus, iCurrentNetworkInfoV1Pckg);
00056         SetActive();
00057         }
00058 
00065 CCurrentNetworkInfo::CCurrentNetworkInfo(MExecAsync* aController)
00066         : CISVAPIAsync(aController, KNetworkInfo),
00067           iCurrentNetworkInfoV1Pckg(iCurrentNetworkInfoV1)
00068         {
00069         // Empty method
00070         }
00071 
00075 void CCurrentNetworkInfo::ConstructL()
00076         {
00077         // Empty method
00078         }
00079         
00084 void CCurrentNetworkInfo::RunL()
00085         {
00086         if(iStatus != KErrNone)
00087                 {
00088                 iConsole->Printf(KError);
00089                 
00090                 // Print the error status code
00091                 iConsole->Printf(_L("%d\n"), iStatus.Int());
00092                 }
00093         else
00094                 {
00095                 TBuf<30> theStatus;
00096                 if (iRequestNotify)
00097                 {
00098                 iConsole->ClearScreen();
00099                 iConsole->Printf(_L("~*THIS IS A NOTIFICATION*~\n"));
00100                 }
00101                 iConsole->Printf(KNetworkInfoMsg);
00102                 iConsole->Printf(iCurrentNetworkInfoV1.iDisplayTag);
00103                 iConsole->Printf(KNewLine);
00104                 switch (iCurrentNetworkInfoV1.iStatus)
00105                         {
00106                 case CTelephony::ENetworkStatusUnknown:
00107                         theStatus.Append(_L("ENetworkStatusUnknown\n"));
00108                         break;
00109                 case CTelephony::ENetworkStatusAvailable:
00110                         theStatus.Append(_L("ENetworkStatusUnavailable\n"));
00111                         break;
00112                 case CTelephony::ENetworkStatusCurrent:
00113                         theStatus.Append(_L("ENetworkStatusCurrent\n"));
00114                         break;
00115                 case CTelephony::ENetworkStatusForbidden:
00116                         theStatus.Append(_L("ENetworkStatusForbidden\n"));
00117                         break;
00118                         }
00119                 iConsole->Printf(theStatus);
00120                 if(iCurrentNetworkInfoV1.iAccess)
00121                         {
00122                         // Make any calls to change Phone profile here using iCellId parameter
00123                         iConsole->Printf((_L("The Cell Id is : %d\n")), iCurrentNetworkInfoV1.iCellId);
00124                         iConsole->Printf((_L("The Area Code is : %d\n")), iCurrentNetworkInfoV1.iLocationAreaCode);
00125                         }
00126                 if (iRequestNotify)
00127                         {
00128                         RequestNotificationL();
00129                         }
00130                 else
00131                         {
00132                         ExampleComplete();
00133                         }
00134                 }
00135         }
00136 
00140 void CCurrentNetworkInfo::DoRequestNotificationL()
00141    {
00142         // Panic if this object is already performing an asynchronous operation. 
00143         // Application will crash if you SetActive() an already active object.
00144         _LIT( KNotifyPanic, "CCurrentNetworkInfo Notify Method" );
00145         __ASSERT_ALWAYS( !IsActive(), User::Panic( KNotifyPanic, 1 ));
00146         iRequestNotify = ETrue;
00147         
00148         // Registers interest in receiving change notifications for events.
00149         iTelephony->NotifyChange(       iStatus,
00150                                                                 CTelephony::ECurrentNetworkInfoChange,
00151                                                                 iCurrentNetworkInfoV1Pckg );
00152         SetActive();
00153         }
00154         
00158 void CCurrentNetworkInfo::DoCancel()
00159         {
00160         iRequestNotify = EFalse;
00161         
00162         // Cancels an outstanding asynchronous request.
00163         iTelephony->CancelAsync(CTelephony::ECurrentNetworkInfoChangeCancel);
00164         }
00165 

Generated by  doxygen 1.6.2