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