nwnotifier/src/nwregistrationstatusmonitor.cpp
branchRCL_3
changeset 3 a4a774cb6ea7
child 6 1b9ee3c7442d
equal deleted inserted replaced
0:ff3b6d0fd310 3:a4a774cb6ea7
       
     1 /*
       
     2 * Copyright (c) 2010 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 module contains the implementation of CNWRegistrationStatusMonitor 
       
    15 *              class member functions.
       
    16 *
       
    17 */
       
    18 
       
    19 //  INCLUDE FILES
       
    20 #include "nwregistrationstatusmonitor.h"
       
    21 // System 
       
    22 #include <exterror.h>
       
    23 #include <MmTsy_names.h> // KMmTsyModuleName
       
    24 
       
    25 // ================= MEMBER FUNCTIONS =======================================
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // CNWRegistrationStatusMonitor::CNWRegistrationStatusMonitor
       
    29 // C++ default constructor can NOT contain any code, that
       
    30 // might leave.
       
    31 //
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 CNWRegistrationStatusMonitor::CNWRegistrationStatusMonitor() : 
       
    35     CActive( EPriorityStandard )
       
    36     {
       
    37     }
       
    38     
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CNWRegistrationStatusMonitor::ConstructL
       
    42 // Symbian 2nd phase constructor can leave.
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 void CNWRegistrationStatusMonitor::ConstructL()
       
    46     {  
       
    47     // Add to scheduler.    
       
    48     CActiveScheduler::Add( this );
       
    49     
       
    50     // Open connection to ETel
       
    51     OpenConnectionL();
       
    52     
       
    53     // Start monitoring
       
    54     IssueRequest();
       
    55     }
       
    56 
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CNWRegistrationStatusMonitor::NewL
       
    60 // Two-phased constructor.
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 CNWRegistrationStatusMonitor* CNWRegistrationStatusMonitor::NewL()
       
    64     {
       
    65     RDebug::Print( _L("NW: CNWRegistrationStatusMonitor::NewL -START") );
       
    66     
       
    67     CNWRegistrationStatusMonitor* self = new ( ELeave ) CNWRegistrationStatusMonitor();
       
    68     CleanupStack::PushL( self );
       
    69     self->ConstructL();
       
    70     CleanupStack::Pop( self );
       
    71     
       
    72     RDebug::Print( _L("NW: CNWRegistrationStatusMonitor::NewL -END") );
       
    73     return self;
       
    74     }
       
    75  
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // Destructor
       
    79 // 
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 CNWRegistrationStatusMonitor::~CNWRegistrationStatusMonitor()
       
    83     {
       
    84     Cancel();     
       
    85     
       
    86     CloseConnection();
       
    87     
       
    88     delete iNoteWrapper;
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CNWRegistrationStatusMonitor::OpenConnectionL()
       
    93 // Open connection to ETel
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 void CNWRegistrationStatusMonitor::OpenConnectionL()
       
    97     {
       
    98     // Connect ETel server
       
    99     User::LeaveIfError( iTelServer.Connect() );
       
   100 
       
   101     // Load ETel TSY module
       
   102     User::LeaveIfError( iTelServer.LoadPhoneModule( KMmTsyModuleName ) );
       
   103 
       
   104     // Set this session to receive detailed errors
       
   105     User::LeaveIfError( iTelServer.SetExtendedErrorGranularity(
       
   106             RTelServer::EErrorExtended ) );
       
   107 
       
   108     // Opens a phone subsession by name, 
       
   109     User::LeaveIfError( iPhone.Open( iTelServer, KMmTsyPhoneName ) );
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CNWRegistrationStatusMonitor::CloseConnection()
       
   114 // Closes the connection to ETel
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 void CNWRegistrationStatusMonitor::CloseConnection()
       
   118     {
       
   119     iPhone.Close();
       
   120         
       
   121     if ( iTelServer.Handle() )
       
   122         {
       
   123         iTelServer.UnloadPhoneModule( KMmTsyModuleName );
       
   124         iTelServer.Close();
       
   125         }
       
   126     }
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // CNWRegistrationStatusMonitor::DoCancel
       
   130 // Cancels the pending async. command.
       
   131 // (other items were commented in a header).
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 void CNWRegistrationStatusMonitor::DoCancel()
       
   135     {
       
   136     RDebug::Print( _L("NW: CNWRegistrationStatusMonitor::DoCancel -START") );
       
   137     
       
   138     iPhone.CancelAsyncRequest( EMobilePhoneNotifyNetworkRegistrationStatusChange );
       
   139     
       
   140     RDebug::Print( _L("NW: CNWRegistrationStatusMonitor::DoCancel -END") );
       
   141     }
       
   142 
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CNWRegistrationStatusMonitor::RunL
       
   146 // Receives the completion of the pending async. command,
       
   147 // saves possible values from async.
       
   148 // 
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 void CNWRegistrationStatusMonitor::RunL()
       
   152     {
       
   153     RDebug::Print( _L("NW: CNWRegistrationStatusMonitor::RunL -START") );
       
   154     
       
   155     if( iStatus.Int() != KErrNone ) // Display only errors
       
   156         {
       
   157         // Parse error code to iResId
       
   158         ParseErrCode();
       
   159         
       
   160         if( !iNoteWrapper )
       
   161             { // Instantiate a notewrapper and pass err code to be displayed
       
   162             iNoteWrapper = CNetworkNotifierNoteWrapper::NewL( *this, iResID );
       
   163             }
       
   164         else // If note wrapper exists already, add error code -stack in wrapper
       
   165             {
       
   166             iNoteWrapper->AppendNote( iResID );
       
   167             }
       
   168         }
       
   169     else
       
   170         {
       
   171         if( iStatus.Int() == KErrBadHandle || 
       
   172             iStatus.Int() == KErrServerBusy )
       
   173             {
       
   174             // Close the session to ETel
       
   175             CloseConnection();
       
   176             // Reconnect
       
   177             OpenConnectionL();
       
   178             }
       
   179         }
       
   180     
       
   181     // Keep monitoring
       
   182     IssueRequest();
       
   183         
       
   184     RDebug::Print( _L("NW: CNWRegistrationStatusMonitor::RunL -END") );
       
   185     }
       
   186 
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CNWRegistrationStatusMonitor::ParseErrorCode()
       
   190 // 
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 void CNWRegistrationStatusMonitor::ParseErrCode()
       
   194     {
       
   195     switch( iStatus.Int() )
       
   196         {
       
   197         case KErrGsmMMImsiUnknownInHlr:
       
   198             {
       
   199             iResID = R_SIM_NOT_PROV_MM2;
       
   200             RDebug::Print( _L("NW: CNWRegistrationStatusMonitor::ParseErrCode() : R_SIM_NOT_PROV_MM2") );
       
   201             break;
       
   202             }
       
   203         case KErrGsmMMIllegalMs:
       
   204             {
       
   205             iResID = R_SIM_NOT_ALLOW_MM3;
       
   206             RDebug::Print( _L("NW: CNWRegistrationStatusMonitor::ParseErrCode() : R_SIM_NOT_ALLOW_MM3") );
       
   207             break;
       
   208             }
       
   209         case KErrGsmMMImsiUnknownInVlr:
       
   210             {
       
   211             iResID = R_CALL_FAILED_MM4;
       
   212             RDebug::Print( _L("NW: CNWRegistrationStatusMonitor::ParseErrCode() : R_CALL_FAILED_MM4") );
       
   213             break;       
       
   214             }
       
   215         case KErrGsmMMImeiNotAccepted:
       
   216             {
       
   217             iResID = R_PHONE_NOT_ALLOW_MM5;
       
   218             RDebug::Print( _L("NW: CNWRegistrationStatusMonitor::ParseErrCode() : R_PHONE_NOT_ALLOW_MM5") );
       
   219             break; 
       
   220             }
       
   221         case KErrGsmMMIllegalMe:
       
   222             {
       
   223             iResID = R_PHONE_NOT_ALLOW_MM6;
       
   224             RDebug::Print( _L("NW: CNWRegistrationStatusMonitor::ParseErrCode() : R_PHONE_NOT_ALLOW_MM6") );
       
   225             break;
       
   226             }
       
   227         default:
       
   228             {
       
   229             case KErrGeneral:
       
   230                 {
       
   231                 RDebug::Print( _L("NW: CNWRegistrationStatusMonitor::ParseErrCode() : R_SIM_NOT_ALLOW") );
       
   232                 iResID = R_SIM_NOT_ALLOW;
       
   233                 break;  
       
   234                 }
       
   235             }
       
   236         }
       
   237     }
       
   238 
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // CNWRegistrationStatusMonitor::IssueRequest
       
   242 // Executes the async. NotifyNetworkRegistrationStatusChange function.
       
   243 // 
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 void CNWRegistrationStatusMonitor::IssueRequest()
       
   247     {
       
   248     RDebug::Print( _L("NW: CNWRegistrationStatusMonitor::IssueRequest -START") );
       
   249     
       
   250     if ( !IsActive() )
       
   251         {
       
   252         iPhone.NotifyNetworkRegistrationStatusChange( iStatus, iRegistrationStatus ); 
       
   253         SetActive();
       
   254         RDebug::Print( _L("NW: CNWRegistrationStatusMonitor::IssueRequest : NotifyChange()-request set active - pending !") );
       
   255         }
       
   256     
       
   257     RDebug::Print( _L("NW: CNWRegistrationStatusMonitor::IssueRequest -END") );
       
   258     }
       
   259  
       
   260 
       
   261 // -----------------------------------------------------------------------------
       
   262 // CNWRegistrationStatusMonitor::PopupNoteClosed
       
   263 // 
       
   264 // Callback from note wrapper class : all error notes are displayed since this monitor
       
   265 // class can destruct note wrapper
       
   266 // -----------------------------------------------------------------------------
       
   267 //
       
   268 void CNWRegistrationStatusMonitor::PopupNoteClosed()
       
   269     {
       
   270     RDebug::Print( _L("NW: CNWRegistrationStatusMonitor::PopupNoteClosed -START") );
       
   271     
       
   272     delete iNoteWrapper;
       
   273     iNoteWrapper = NULL;
       
   274     
       
   275     RDebug::Print( _L("NW: CNWRegistrationStatusMonitor::PopupNoteClosed -END") );
       
   276     }
       
   277 
       
   278 
       
   279 // -----------------------------------------------------------------------------
       
   280 // CNWRegistrationStatusMonitor::RunError()
       
   281 // Processes any errors.
       
   282 // -----------------------------------------------------------------------------
       
   283 //
       
   284 TInt CNWRegistrationStatusMonitor::RunError( TInt /*aError*/ )
       
   285     {
       
   286     RDebug::Print( _L("NW: CNWRegistrationStatusMonitor::RunError -START") );
       
   287     
       
   288     // Keep monitoring
       
   289     IssueRequest();
       
   290     
       
   291     RDebug::Print( _L("NW: CNWRegistrationStatusMonitor::RunError -END") );
       
   292     return KErrNone;    // Handled the error fully
       
   293     }
       
   294 
       
   295 //  End of File