devicediagnosticsfw/diagframework/src/diagnetworkregstatuswatcher.cpp
branchRCL_3
changeset 25 b183ec05bd8c
parent 24 13d7c31c74e0
child 26 19bba8228ff0
equal deleted inserted replaced
24:13d7c31c74e0 25:b183ec05bd8c
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  This is the implementation for the Diagnostics Network 
       
    15 *                 registration status watcher.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // CLASS DECLARATION
       
    21 #include <DiagNetworkRegStatusWatcher.h>
       
    22 
       
    23 // SYSTM INCLUDE FILES
       
    24 #include <e32base.h>                        
       
    25 #include <DiagFrameworkDebug.h>             // Debugging macros
       
    26 #include <DiagNetworkRegStatusObserver.h>   // MDiagNetworkRegStatusObserver
       
    27 
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS =============================
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // Static two-phase constructor.
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 EXPORT_C CDiagNetworkRegStatusWatcher* CDiagNetworkRegStatusWatcher::NewL(
       
    36     MDiagNetworkRegStatusObserver& aCallBack )
       
    37     {
       
    38     CDiagNetworkRegStatusWatcher* self = new ( ELeave )
       
    39                                        CDiagNetworkRegStatusWatcher( aCallBack );
       
    40     CleanupStack::PushL( self );
       
    41     self->ConstructL();
       
    42     CleanupStack::Pop( self );
       
    43     return self;
       
    44     }
       
    45 
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // Destructor.
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 EXPORT_C CDiagNetworkRegStatusWatcher::~CDiagNetworkRegStatusWatcher()
       
    52     {
       
    53     // cancel any pending request
       
    54     Cancel();
       
    55     
       
    56     delete iTelephony;
       
    57     iTelephony = NULL;
       
    58     
       
    59     LOGSTRING( "CDiagNetworkRegStatusWatcher::ConstructL() Destroying Network registration status watcher" )            
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // The default constructor.
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 CDiagNetworkRegStatusWatcher::CDiagNetworkRegStatusWatcher
       
    67     ( MDiagNetworkRegStatusObserver& aCallBack )
       
    68     : CActive( EPriorityStandard ),
       
    69     iState( EStateInit ),
       
    70     iRegV1(),
       
    71     iRegV1Pckg( iRegV1 ),
       
    72     iCallBack( aCallBack )
       
    73     {
       
    74     CActiveScheduler::Add( this );
       
    75     }
       
    76 
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // The second phase constructor.
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 
       
    83 void CDiagNetworkRegStatusWatcher::ConstructL()
       
    84     {
       
    85     LOGSTRING( "CDiagNetworkRegStatusWatcher::ConstructL() Creating Network registration status watcher" )
       
    86     iTelephony = CTelephony::NewL();     
       
    87     iPreviouslyRegistered = EFalse;
       
    88     }
       
    89 
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // This function starts the network registration status monitor process. This
       
    93 // involves first checking for the current status and then registering for any
       
    94 // changes that may occur.
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 
       
    98 EXPORT_C void CDiagNetworkRegStatusWatcher::StartObserver()
       
    99     {
       
   100     // get the current status of network registration
       
   101     iState = EStateWaitForInitialStatus;
       
   102     iTelephony->GetNetworkRegistrationStatus( iStatus, iRegV1Pckg );
       
   103     SetActive();        
       
   104     }
       
   105 
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // This function stops the network registration monitor process
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 EXPORT_C void CDiagNetworkRegStatusWatcher::StopObserver()
       
   112     {
       
   113     Cancel();
       
   114     }
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // Handles the completion of active requests.
       
   118 // ---------------------------------------------------------------------------
       
   119 //
       
   120 void CDiagNetworkRegStatusWatcher::RunL()
       
   121     {
       
   122     switch ( iState )
       
   123         {
       
   124         case EStateWaitForInitialStatus:
       
   125             {
       
   126             HandleInitialStatusL();
       
   127             }
       
   128             break;
       
   129 
       
   130         case EStateWaitForStatusChange:
       
   131             {
       
   132             HandleNetworkStatusChangeL();
       
   133             }
       
   134             break;
       
   135             
       
   136         default:
       
   137             break;                                    
       
   138         }
       
   139     }
       
   140 
       
   141 
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // Handles the request for initial network registration status
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 void CDiagNetworkRegStatusWatcher::HandleInitialStatusL()
       
   148     {
       
   149     if ( iStatus == KErrNone )
       
   150         {  
       
   151         // get the current registration status
       
   152         TBool currentRegStatus = IsDeviceRegisteredOnNetwork();
       
   153 
       
   154         LOGSTRING2( "CDiagNetworkRegStatusWatcher::HandleInitialStatus : current status = %d", currentRegStatus )
       
   155         
       
   156         // we have to continue monitoring changes in network registration status
       
   157         // so set the next asynchronous request
       
   158         iState = EStateWaitForStatusChange;            
       
   159         iTelephony->NotifyChange( iStatus, 
       
   160                     CTelephony::ENetworkRegistrationStatusChange, iRegV1Pckg );
       
   161         SetActive();
       
   162 
       
   163         // inform the client about the initial registration status
       
   164         iPreviouslyRegistered = currentRegStatus;
       
   165         iCallBack.InitialNetworkRegistrationStatusL( currentRegStatus );                
       
   166         }
       
   167     else
       
   168         {
       
   169         // inform the client that device is not registered
       
   170         iCallBack.InitialNetworkRegistrationStatusL( EFalse );
       
   171         iPreviouslyRegistered = EFalse;        
       
   172         }
       
   173     }
       
   174     
       
   175 
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // Handles the events related to Network registration status change
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 void CDiagNetworkRegStatusWatcher::HandleNetworkStatusChangeL()
       
   182     {
       
   183     if ( iStatus == KErrNone )
       
   184         {
       
   185         // get the current registration status
       
   186         TBool currentRegStatus = IsDeviceRegisteredOnNetwork();
       
   187 
       
   188         LOGSTRING2( "CDiagNetworkRegStatusWatcher::HandleNetworkStatusChange : current status = %d", currentRegStatus )
       
   189         
       
   190         // we have to continue monitoring changes in network registration status
       
   191         // so set the next asynchronous request
       
   192         iState = EStateWaitForStatusChange;            
       
   193         iTelephony->NotifyChange( iStatus, 
       
   194                     CTelephony::ENetworkRegistrationStatusChange, iRegV1Pckg );
       
   195         SetActive();
       
   196 
       
   197         // if the current registration state is different from previous state,
       
   198         // inform the client
       
   199         if ( currentRegStatus != iPreviouslyRegistered )
       
   200             {
       
   201             // inform the client about the network status change
       
   202             iCallBack.NetworkRegistrationStatusChangeL( currentRegStatus );
       
   203             }
       
   204         iPreviouslyRegistered = currentRegStatus;
       
   205         }
       
   206     else
       
   207         {
       
   208         iCallBack.NetworkRegistrationStatusChangeL( EFalse );
       
   209         iPreviouslyRegistered = EFalse;            
       
   210         }
       
   211     }
       
   212 
       
   213 
       
   214 
       
   215 // ---------------------------------------------------------------------------
       
   216 // This function wraps the logic if the device is currently registered or not
       
   217 // ---------------------------------------------------------------------------
       
   218 //
       
   219 TBool CDiagNetworkRegStatusWatcher::IsDeviceRegisteredOnNetwork()
       
   220     {
       
   221     TBool regStatus = EFalse;
       
   222     switch ( iRegV1.iRegStatus )
       
   223         {
       
   224             case CTelephony::ERegisteredOnHomeNetwork:
       
   225             case CTelephony::ERegisteredRoaming:
       
   226                 {    
       
   227                 regStatus = ETrue; 
       
   228                 }
       
   229                 break;
       
   230             default:
       
   231                 {
       
   232                 // the device lost the network coverage
       
   233                 regStatus = EFalse;
       
   234                 }
       
   235                 break;                    
       
   236         }
       
   237     return regStatus;
       
   238     }
       
   239 
       
   240 // ---------------------------------------------------------------------------
       
   241 // Handles the cancellation of active requests.
       
   242 // ---------------------------------------------------------------------------
       
   243 //
       
   244 void CDiagNetworkRegStatusWatcher::DoCancel()
       
   245     {
       
   246     switch ( iState )
       
   247         {
       
   248             case EStateWaitForInitialStatus:
       
   249                 {
       
   250                 iTelephony->CancelAsync( CTelephony::EGetNetworkRegistrationStatusCancel );
       
   251                 }
       
   252                 break;
       
   253 
       
   254             case EStateWaitForStatusChange:
       
   255                 {
       
   256                 iTelephony->CancelAsync( CTelephony::ENetworkRegistrationStatusChangeCancel );
       
   257                 }
       
   258                 break;
       
   259                 
       
   260             default:
       
   261                 break;                                    
       
   262         }
       
   263     }
       
   264 
       
   265 // End of file
       
   266