satengine/SatServer/SystemState/src/csatnetworkregstatusmonitor.cpp
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     1 /*
       
     2 * Copyright (c) 2007-2008 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:  Network registration status monitor.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "csatnetworkregstatusmonitor.h"
       
    20 #include "SatLog.h"
       
    21 
       
    22 // ======== MEMBER FUNCTIONS ========
       
    23 
       
    24 // ---------------------------------------------------------------------------
       
    25 // C++ default constructor can NOT contain any code, that might leave.
       
    26 // ---------------------------------------------------------------------------
       
    27 //
       
    28 CSatNetworkRegStatusMonitor::CSatNetworkRegStatusMonitor(
       
    29     MSatMultiModeApi& aPhone ) :
       
    30     CActive( CActive::EPriorityStandard ),
       
    31     iRegistrationStatus( RMobilePhone::ERegistrationUnknown ),
       
    32     iWaitingRegistrationStatus( EFalse ),
       
    33     iPhone( aPhone )
       
    34     {
       
    35     LOG( SIMPLE, "SATSYSTEMSTATE: \
       
    36         CSatNetworkRegStatusMonitor::CSatNetworkRegStatusMonitor calling" )
       
    37 
       
    38     // Add to active scheduler.
       
    39     CActiveScheduler::Add( this );
       
    40 
       
    41     LOG( SIMPLE, "SATSYSTEMSTATE: \
       
    42         CSatNetworkRegStatusMonitor::CSatNetworkRegStatusMonitor exiting" )
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // Two-phased constructor.
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CSatNetworkRegStatusMonitor* CSatNetworkRegStatusMonitor::NewL(
       
    50     MSatMultiModeApi& aPhone )
       
    51     {
       
    52     LOG( SIMPLE, "SATSYSTEMSTATE: CSatNetworkRegStatusMonitor::NewL calling" )
       
    53 
       
    54     CSatNetworkRegStatusMonitor* self =
       
    55         new( ELeave ) CSatNetworkRegStatusMonitor( aPhone );
       
    56 
       
    57     LOG( SIMPLE, "SATSYSTEMSTATE: CSatNetworkRegStatusMonitor::NewL exiting" )
       
    58     return self;
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // Destructor
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 CSatNetworkRegStatusMonitor::~CSatNetworkRegStatusMonitor()
       
    66     {
       
    67     LOG( SIMPLE, "SATSYSTEMSTATE: \
       
    68         CSatNetworkRegStatusMonitor::~CSatNetworkRegStatusMonitor calling" )
       
    69 
       
    70     Cancel();
       
    71 
       
    72     LOG( SIMPLE, "SATSYSTEMSTATE: \
       
    73         CSatNetworkRegStatusMonitor::~CSatNetworkRegStatusMonitor exiting" )
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // Activate monitor.
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 void CSatNetworkRegStatusMonitor::Start()
       
    81     {
       
    82     LOG( SIMPLE,
       
    83         "SATSYSTEMSTATE: CSatNetworkRegStatusMonitor::Start calling" )
       
    84 
       
    85 #ifndef SAT_USE_DUMMY_TSY
       
    86     if ( !IsActive() )
       
    87         {
       
    88         iRegistrationStatus = RMobilePhone::ERegistrationUnknown;
       
    89 
       
    90         iPhone.GetNetworkRegistrationStatus( iStatus, iRegistrationStatus );
       
    91         SetActive();
       
    92         iWaitingRegistrationStatus = ETrue;
       
    93         LOG( SIMPLE, "SATSYSTEMSTATE:   Started" )
       
    94         }
       
    95 #else
       
    96     iRegistrationStatus = RMobilePhone::ERegisteredOnHomeNetwork;
       
    97     iWaitingRegistrationStatus = EFalse;
       
    98     LOG( SIMPLE, "SATSYSTEMSTATE:   Set for WINS Emulator" )
       
    99 #endif
       
   100 
       
   101     LOG( SIMPLE,
       
   102         "SATSYSTEMSTATE: CSatNetworkRegStatusMonitor::Start exiting" )
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // Get current value of network registration status.
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 RMobilePhone::TMobilePhoneRegistrationStatus
       
   110     CSatNetworkRegStatusMonitor::CurrentValue()
       
   111     {
       
   112     LOG( SIMPLE,
       
   113         "SATSYSTEMSTATE: CSatNetworkRegStatusMonitor::CurrentValue calling" )
       
   114 
       
   115     // In case network registration notification failed on startup, we need to 
       
   116     // check it again, if not registered on home network and we are observing
       
   117     // changes in registration status ( iWaitingRegistrationStatus == EFalse )
       
   118     if ( !iWaitingRegistrationStatus &&
       
   119          ( RMobilePhone::ERegisteredOnHomeNetwork != iRegistrationStatus &&
       
   120            RMobilePhone::ERegisteredRoaming != iRegistrationStatus ) )
       
   121         {
       
   122         LOG( NORMAL, "Not registered -> Going to check value again" )
       
   123         Cancel(); // Cancel pending request...
       
   124         Start();  // ... and start again
       
   125         }
       
   126 
       
   127     // Wait, initial value has not yet been got.
       
   128     if ( iWaitingRegistrationStatus )
       
   129         {
       
   130         LOG( SIMPLE,
       
   131         "SATSYSTEMSTATE: CSatNetworkRegStatusMonitor::CurrentValue \
       
   132         iWaitingRegistrationStatus true" )
       
   133         if ( !iWait.IsStarted() )
       
   134             {
       
   135             LOG( SIMPLE,
       
   136             "SATSYSTEMSTATE: CSatNetworkRegStatusMonitor::CurrentValue \
       
   137             start iWait" )
       
   138             iWait.Start();
       
   139             }
       
   140         }
       
   141 
       
   142     LOG2( SIMPLE,
       
   143         "SATSYSTEMSTATE: CSatNetworkRegStatusMonitor::CurrentValue exiting \
       
   144         (%d)", iRegistrationStatus )
       
   145     return iRegistrationStatus;
       
   146     }
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // CRegistrationMonitor::DoCancel
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 void CSatNetworkRegStatusMonitor::DoCancel()
       
   153     {
       
   154     LOG( SIMPLE,
       
   155         "SATSYSTEMSTATE: CSatNetworkRegStatusMonitor::DoCancel calling" )
       
   156 
       
   157     iPhone.CancelAsyncRequest(
       
   158         EMobilePhoneNotifyNetworkRegistrationStatusChange );
       
   159     if ( iWait.IsStarted() )
       
   160         {
       
   161         LOG( SIMPLE,
       
   162         "SATSYSTEMSTATE: CSatNetworkRegStatusMonitor::DoCancel stop iWait" )
       
   163         iWait.AsyncStop();
       
   164         }
       
   165 
       
   166     LOG( SIMPLE,
       
   167         "SATSYSTEMSTATE: CSatNetworkRegStatusMonitor::DoCancel exiting" )
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------------------------
       
   171 // From class CActive.
       
   172 // Marks status value valid and activates change notifier.
       
   173 // ---------------------------------------------------------------------------
       
   174 //
       
   175 void CSatNetworkRegStatusMonitor::RunL()
       
   176     {
       
   177     const TInt status( iStatus.Int() ); // Asynchronous status
       
   178     LOG2( SIMPLE,
       
   179         "SATSYSTEMSTATE: CSatNetworkRegStatusMonitor::RunL calling (%d)",
       
   180         status )
       
   181 
       
   182     // Restart request
       
   183     if ( KErrServerBusy == status )
       
   184         {
       
   185         iPhone.GetNetworkRegistrationStatus(
       
   186             iStatus,
       
   187             iRegistrationStatus );
       
   188         SetActive();
       
   189         }
       
   190     else if ( KErrCancel != status )
       
   191         {
       
   192         // (Re)start observing
       
   193         iPhone.NotifyNetworkRegistrationStatusChange(
       
   194             iStatus,
       
   195             iRegistrationStatus );
       
   196         SetActive();
       
   197         }
       
   198     else
       
   199         {
       
   200         LOG( SIMPLE, " Request cancelled" )
       
   201         }
       
   202 
       
   203     // Still waiting first value after start.
       
   204     if ( iWaitingRegistrationStatus )
       
   205         {
       
   206         LOG( SIMPLE, 
       
   207         "SATSYSTEMSTATE: CSatNetworkRegStatusMonitor::RunL \
       
   208         iWaitingRegistrationStatus true" )
       
   209         iWaitingRegistrationStatus = EFalse;
       
   210         if ( iWait.IsStarted() )
       
   211             {
       
   212             LOG( SIMPLE, 
       
   213             "SATSYSTEMSTATE: CSatNetworkRegStatusMonitor::RunL \
       
   214             stop iWait" )
       
   215             iWait.AsyncStop();
       
   216             }
       
   217         }
       
   218 
       
   219     LOG2( SIMPLE,
       
   220         "SATSYSTEMSTATE:   NetworkRegistrationStatus updated: %d",
       
   221         iRegistrationStatus )
       
   222 
       
   223     LOG( SIMPLE, "SATSYSTEMSTATE: CSatNetworkRegStatusMonitor::RunL exiting" )
       
   224     }
       
   225 
       
   226 // End of file