telephonyutils/etel3rdpartyapi/ExampleApps/AutoDTMFDialler/CNetworkRegInfo.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 "CNetworkRegInfo.h"
       
    17 
       
    18 /**
       
    19 Factory constructor.
       
    20 
       
    21 @param  aController Pointer to MExecAsync object passed to constructor of
       
    22                     CISVAPIBase
       
    23 @return             Instance of CNetworkRegInfo class
       
    24 */
       
    25 CNetworkRegInfo* CNetworkRegInfo::NewL(MExecAsync* aController)
       
    26 	{
       
    27 	CNetworkRegInfo* self = new(ELeave) CNetworkRegInfo(aController);
       
    28 	CleanupStack::PushL(self);
       
    29 	self->ConstructL();
       
    30 	CleanupStack::Pop(self);
       
    31 	return self;
       
    32 	}
       
    33 
       
    34 /**
       
    35 Destructor.  Calls Cancel() to cancel outstanding requests.
       
    36 */
       
    37 CNetworkRegInfo::~CNetworkRegInfo()
       
    38 	{
       
    39 	Cancel();
       
    40 	}
       
    41 
       
    42 /**
       
    43 Kicks off request.
       
    44 */
       
    45 void CNetworkRegInfo::DoStartRequestL()
       
    46 	{
       
    47     iRequestNotify = EFalse;
       
    48     
       
    49     // Retrieves the current network registration status.
       
    50 	iTelephony->GetNetworkRegistrationStatus(iStatus, iNetworkRegV1Pckg);
       
    51 	SetActive();
       
    52 	}
       
    53 
       
    54 /**
       
    55 Constructor called by CNetworkRegInfo::NewL().
       
    56 
       
    57 @param aController Pointer to MExecAsync object passed to constructor of
       
    58                    CISVAPIBase
       
    59 */
       
    60 CNetworkRegInfo::CNetworkRegInfo(MExecAsync* aController)
       
    61 	: CISVAPIAsync(aController, KNetworkRegInfo),
       
    62 	  iNetworkRegV1Pckg(iNetworkRegV1)
       
    63 	{
       
    64 	// Empty method
       
    65 	}
       
    66 
       
    67 /**
       
    68 Second phase constructor. Sets iRequestNotify to EFalse.
       
    69 */
       
    70 void CNetworkRegInfo::ConstructL()
       
    71 	{
       
    72 	iRequestNotify = EFalse;
       
    73 	}
       
    74 
       
    75 /**
       
    76 Prints network registration status to the console.
       
    77 */
       
    78 void CNetworkRegInfo::RunL()
       
    79 	{
       
    80 	if(iStatus != KErrNone)
       
    81 		{
       
    82 		iConsole->Printf(KError);
       
    83 		
       
    84 		// Print the error status code
       
    85 		iConsole->Printf(_L("%d\n"), iStatus.Int());
       
    86 		}
       
    87 	else
       
    88 		{
       
    89 		// There is no error, so display the current registration status to the
       
    90 		// user.
       
    91 		TBuf<30> theStatus;
       
    92 		if(iRequestNotify)
       
    93 			{
       
    94 			iConsole->ClearScreen();
       
    95 			iConsole->Printf(_L("*~This is a notifcation\n~*"));
       
    96 			}
       
    97 		iConsole->Printf(KNetworkRegMsg);
       
    98 		switch(iNetworkRegV1.iRegStatus)
       
    99 			{
       
   100 		case CTelephony::ERegistrationUnknown:
       
   101 			theStatus.Append(_L("ERegistrationUnknown\n"));
       
   102 			break;
       
   103 		case CTelephony::ENotRegisteredNoService:
       
   104 			theStatus.Append(_L("ENotRegisteredNoService\n"));
       
   105 			break;
       
   106 		case CTelephony::ENotRegisteredEmergencyOnly:
       
   107 			theStatus.Append(_L("ENotRegisteredEmergencyOnly\n"));
       
   108 			break;
       
   109 		case CTelephony::ENotRegisteredSearching:
       
   110 			theStatus.Append(_L("ENotRegisteredSearching\n"));
       
   111 			break;
       
   112 		case CTelephony::ERegisteredBusy:
       
   113 			theStatus.Append(_L("ERegisteredBusy\n"));
       
   114 			break;
       
   115 		case CTelephony::ERegisteredOnHomeNetwork:
       
   116 			theStatus.Append(_L("ERegisteredOnHomeNetwork\n"));
       
   117 			break;
       
   118 		case CTelephony::ERegistrationDenied:
       
   119 			theStatus.Append(_L("ERegistrationDenied\n"));
       
   120 			break;
       
   121 		case CTelephony::ERegisteredRoaming:
       
   122 			theStatus.Append(_L("ERegisteredRoaming\n"));
       
   123 			break;
       
   124 		default:
       
   125 			break;
       
   126 	 		}
       
   127 		iConsole->Printf(theStatus);
       
   128 		}
       
   129 	if (iNetworkRegV1.iRegStatus == CTelephony::ERegisteredOnHomeNetwork)
       
   130 		{
       
   131 		ExampleNotify();
       
   132 		}
       
   133 	else
       
   134 		{
       
   135 		RequestNotificationL();
       
   136 		}
       
   137 	}
       
   138 
       
   139 /**
       
   140 Requests to receive notifications of change in the
       
   141 network registration information.
       
   142 */
       
   143 void CNetworkRegInfo::DoRequestNotificationL()
       
   144 	{
       
   145 	// Panic if this object is already performing an asynchronous operation.
       
   146 	// Application will panic if you call SetActive() on an already active object.
       
   147 	_LIT( KNotifyPanic, "CNetworkReg Notify Method" );
       
   148 	__ASSERT_ALWAYS( !IsActive(), User::Panic( KNotifyPanic, 1 ));
       
   149 	iRequestNotify = ETrue;
       
   150 	
       
   151 	// Notify if there is any change
       
   152 	iTelephony->NotifyChange(iStatus,
       
   153 	                         CTelephony::ENetworkRegistrationStatusChange,
       
   154 	                         iNetworkRegV1Pckg );
       
   155 	SetActive();
       
   156 	}
       
   157 
       
   158 /**
       
   159 Cancels asynchronous request to CTelephony::GetNetworkRegistrationStatus().
       
   160 */
       
   161 void CNetworkRegInfo::DoCancel()
       
   162 	{
       
   163 	iRequestNotify = EFalse;
       
   164 	
       
   165 	// Cancels an outstanding asynchronous request.
       
   166 	iTelephony->CancelAsync(CTelephony::ENetworkRegistrationStatusChangeCancel);
       
   167 	}