filemanager/schbkup/src/fmsystemstatemonitor.cpp
branchRCL_3
changeset 14 efe289f793e7
equal deleted inserted replaced
13:5181328fad28 14:efe289f793e7
       
     1 /*
       
     2 * Copyright (c) 2002-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:  system state monitor
       
    15 *
       
    16 */
       
    17 
       
    18 #include <ssm/ssmstate.h>
       
    19 #include <ssm/ssmdomaindefs.h>
       
    20 #include "fmsystemstatemonitor.h"
       
    21 
       
    22 // ========================= MEMBER FUNCTIONS ==================================
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 // CFmSystemStateMonitor::NewL()
       
    26 // Two-phased constructor
       
    27 // -----------------------------------------------------------------------------
       
    28 CFmSystemStateMonitor* CFmSystemStateMonitor::NewL(
       
    29     MFmSystemStateMonitorObserver& aObserver )
       
    30     {
       
    31     CFmSystemStateMonitor* self = new ( ELeave ) CFmSystemStateMonitor( aObserver );
       
    32     CleanupStack::PushL( self );
       
    33     self->ConstructL();
       
    34     CleanupStack::Pop( self );
       
    35     return self;
       
    36     }
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CFmSystemStateMonitor::~CFmSystemStateMonitor()
       
    40 // Destructor.
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CFmSystemStateMonitor::~CFmSystemStateMonitor()
       
    44     {
       
    45     Cancel();
       
    46     iSAS.Close();
       
    47     }
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CFmSystemStateMonitor::StartMonitor()
       
    51 // Start monitor
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 void CFmSystemStateMonitor::StartMonitor( TUint aStateToMonitor )
       
    55     {
       
    56 	if( !IsActive() )
       
    57 	    {
       
    58 	    iStateToMonitor = aStateToMonitor;
       
    59 	    iSAS.RequestStateNotification( iStatus );
       
    60         SetActive();
       
    61 	    }
       
    62     }   
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CFmSystemStateMonitor::IsSystemStateNormal()
       
    66 // Indicate the system state normal or not
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 TBool CFmSystemStateMonitor::IsSystemStateNormal()
       
    70     {
       
    71     TSsmState state = iSAS.State();
       
    72     return ( state.MainState() == ESsmNormal );
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CFmSystemStateMonitor::CFmSystemStateMonitor()
       
    77 // C++ default constructor can NOT contain any code, that might leave.
       
    78 // -----------------------------------------------------------------------------
       
    79 CFmSystemStateMonitor::CFmSystemStateMonitor( MFmSystemStateMonitorObserver& aObserver ) :
       
    80         CActive( EPriorityStandard ),iObserver( aObserver )
       
    81     {
       
    82     CActiveScheduler::Add( this );
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CFmSystemStateMonitor::ConstructL()
       
    87 // Symbian 2nd phase constructor can leave.
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void CFmSystemStateMonitor::ConstructL()
       
    91     {
       
    92     User::LeaveIfError( iSAS.Connect( KSM2GenMiddlewareDomain3 ) );
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CFmSystemStateMonitor::RunL
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CFmSystemStateMonitor::RunL()
       
   100     {
       
   101     User::LeaveIfError( iStatus.Int() );
       
   102     	    
       
   103     TSsmState state = iSAS.State();
       
   104     if ( state.MainState() == iStateToMonitor )
       
   105         {
       
   106         iObserver.SystemStateChangedEvent();
       
   107         iSAS.AcknowledgeStateNotification( KErrNone );
       
   108         }
       
   109     else
       
   110         {
       
   111         iSAS.AcknowledgeAndRequestStateNotification( KErrNone, iStatus );
       
   112         SetActive();
       
   113         }        
       
   114     }
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CFmSystemStateMonitor::DoCancel()
       
   118 // From CActive.
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 void CFmSystemStateMonitor::DoCancel()
       
   122     {
       
   123     iSAS.RequestStateNotificationCancel();
       
   124     }      
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CFmSystemStateMonitor::RunError()
       
   128 // From CActive.
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 TInt CFmSystemStateMonitor::RunError( TInt aError )
       
   132     {
       
   133     return aError;
       
   134     }
       
   135 
       
   136 // End of File
       
   137