sipplugins/sippsystemstatemonitor/src/sipsystemstatemonitorao.cpp
changeset 0 307788aac0a8
child 2 1e1cc61f56c3
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDE FILES
       
    20 #include "sipsystemstatemonitorao.h"
       
    21 #include <startupdomainpskeys.h>
       
    22 
       
    23 #ifndef RD_STARTUP_CHANGE
       
    24     #include <sysstartup.h>
       
    25     const TInt KSipSystemShuttingDown = ESWStateShuttingDown;
       
    26 #else
       
    27     const TInt KSipSystemShuttingDown = ESwStateShuttingDown;
       
    28 #endif
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CSipSystemStateMonitorAo::NewL
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 CSipSystemStateMonitorAo* CSipSystemStateMonitorAo::NewL()
       
    35     {
       
    36     CSipSystemStateMonitorAo* self = new( ELeave )CSipSystemStateMonitorAo();
       
    37     CleanupStack::PushL ( self );
       
    38     self->ConstructL();
       
    39     CleanupStack::Pop( self );
       
    40     return self;
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CSipSystemStateMonitorAo::ConstructL
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 void CSipSystemStateMonitorAo::ConstructL ()
       
    48     {
       
    49 	User::LeaveIfError( 
       
    50 	    iProperty.Attach( KPSUidStartup, KPSGlobalSystemState ) );
       
    51 	TInt state ( 0 );    
       
    52 	if ( iProperty.Get( state ) == KErrNone && IsSystemReady( state ) )
       
    53 	    {
       
    54         iState = CSipSystemStateMonitor::ESystemReady;
       
    55 	    }
       
    56 	iProperty.Subscribe( iStatus );
       
    57 	SetActive();
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CSipSystemStateMonitorAo::CSipSystemStateMonitorAo
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CSipSystemStateMonitorAo::CSipSystemStateMonitorAo():
       
    65 	CActive(EPriorityStandard)
       
    66     {
       
    67 	CActiveScheduler::Add( this );
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CSipSystemStateMonitorAo::~CSipSystemStateMonitorAo
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 CSipSystemStateMonitorAo::~CSipSystemStateMonitorAo()
       
    75     {
       
    76 	CActive::Cancel();
       
    77 	iProperty.Close();
       
    78 	iObservers.Close();
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CSipSystemStateMonitorAo::State
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 CSipSystemStateMonitor::TSystemState CSipSystemStateMonitorAo::State() const
       
    86     {
       
    87     return iState;
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CSipSystemStateMonitorAo::AddObserverL
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 void CSipSystemStateMonitorAo::AddObserverL( 
       
    95     MSipSystemStateObserver& aObserver )
       
    96     {
       
    97     iObservers.InsertInAddressOrderL( &aObserver );
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CSipSystemStateMonitorAo::RemoveObserver
       
   102 // -----------------------------------------------------------------------------
       
   103 //    
       
   104 void CSipSystemStateMonitorAo::RemoveObserver(
       
   105     MSipSystemStateObserver& aObserver )
       
   106     {
       
   107     TInt index = iObservers.Find( &aObserver );
       
   108     if ( index >= 0 )
       
   109         {
       
   110         iObservers.Remove( index ); 
       
   111         }
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CSipSystemStateMonitorAo::RunL
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 void CSipSystemStateMonitorAo::RunL()
       
   119     {
       
   120 	TInt state ( 0 );  
       
   121 	if ( KErrNone == iProperty.Get( state ) )
       
   122         {
       
   123         if ( IsSystemReady( state ) )
       
   124             {
       
   125             iState = CSipSystemStateMonitor::ESystemReady;
       
   126             NotifyObservers();
       
   127             }
       
   128         else
       
   129             {
       
   130             if ( state == KSipSystemShuttingDown )
       
   131                 {
       
   132 			    iState = CSipSystemStateMonitor::ESystemShuttingDown;
       
   133                 NotifyObservers();
       
   134 				return; // Stop monitoring
       
   135                 }
       
   136 			}
       
   137 		}
       
   138     iProperty.Subscribe( iStatus );
       
   139 	SetActive();	
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CSipSystemStateMonitorAo::RunError
       
   144 // -----------------------------------------------------------------------------
       
   145 //	   
       
   146 TInt CSipSystemStateMonitorAo::RunError( TInt /*aError*/ )
       
   147     {
       
   148     return KErrNone; // RunL cannot leave at the moment
       
   149     }
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // CSipSystemStateMonitorAo::DoCancel
       
   153 // -----------------------------------------------------------------------------
       
   154 //	
       
   155 void CSipSystemStateMonitorAo::DoCancel()
       
   156     {
       
   157 	iProperty.Cancel();
       
   158     }
       
   159 
       
   160 // -----------------------------------------------------------------------------
       
   161 // CSipSystemStateMonitorAo::NotifyObservers
       
   162 // -----------------------------------------------------------------------------
       
   163 //
       
   164 void CSipSystemStateMonitorAo::NotifyObservers()
       
   165     {
       
   166     for ( TInt i = iObservers.Count()-1; i >= 0; i-- )
       
   167         {
       
   168         iObservers[i]->SystemVariableUpdated( 
       
   169             CSipSystemStateMonitor::ESystemState, 
       
   170             0,
       
   171             iState );
       
   172         }     
       
   173     }
       
   174 
       
   175 // -----------------------------------------------------------------------------
       
   176 // CSipSystemStateMonitorAo::IsSystemReady
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 TBool CSipSystemStateMonitorAo::IsSystemReady( TInt aSystemState ) const
       
   180     {
       
   181     return ( aSystemState == ESwStateNormalRfOn ||
       
   182              aSystemState == ESwStateNormalRfOff ||
       
   183              aSystemState == ESwStateNormalBTSap );
       
   184     }