cbs/CbsServer/ServerSrc/CCbsShutdownMonitor.cpp
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     1 /*
       
     2 * Copyright (c) 2004 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 CCbsShutdownMonitor class 
       
    15 *                member functions.    
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32property.h>
       
    22 #include "CCbsShutdownMonitor.h"
       
    23 #include "CCbsServer.h"
       
    24 #include <startupdomainpskeys.h>
       
    25 #include "CbsLogger.h"
       
    26 
       
    27 // ================= MEMBER FUNCTIONS =======================
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CCbsShutdownMonitor::CCbsShutdownMonitor
       
    31 // C++ default constructor can NOT contain any code, that
       
    32 // might leave.
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 CCbsShutdownMonitor::CCbsShutdownMonitor( CCbsServer& aServer )
       
    36     : CActive( EPriorityStandard ),
       
    37     iServer( aServer )
       
    38     {
       
    39     }
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CCbsShutdownMonitor::ConstructL
       
    43 // Symbian 2nd phase constructor can leave.
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 void CCbsShutdownMonitor::ConstructL()
       
    47     {
       
    48     CActiveScheduler::Add( this );
       
    49     
       
    50     // Attach to startup property
       
    51     iProperty.Attach( KPSUidStartup, KPSGlobalSystemState );    
       
    52     IssueRequest();
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CCbsShutdownMonitor::NewL
       
    57 // Two-phased constructor.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CCbsShutdownMonitor* CCbsShutdownMonitor::NewL( CCbsServer& aServer )
       
    61     {
       
    62     CCbsShutdownMonitor* self = 
       
    63         new ( ELeave ) CCbsShutdownMonitor( aServer );
       
    64     CleanupStack::PushL( self );
       
    65     self->ConstructL();
       
    66     CleanupStack::Pop();
       
    67     return self;
       
    68     }
       
    69     
       
    70 // Destructor
       
    71 CCbsShutdownMonitor::~CCbsShutdownMonitor()
       
    72     {
       
    73     CBSLOGSTRING("CBSSERVER: >>> CCbsShutdownMonitor::~CCbsShutdownMonitor()"); 
       
    74     Cancel();
       
    75 	iProperty.Close();
       
    76 	CBSLOGSTRING("CBSSERVER: <<< CCbsShutdownMonitor::~CCbsShutdownMonitor()"); 
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // CCbsShutdownMonitor::IssueRequest
       
    81 // Requests that we are notified when the system state changes.
       
    82 // (other items were commented in a header).
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 void CCbsShutdownMonitor::IssueRequest() 
       
    86     {
       
    87     if ( !IsActive() )
       
    88         {
       
    89         // Subscribe again
       
    90     	iProperty.Subscribe( iStatus );
       
    91 	    SetActive();
       
    92         }
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CCbsShutdownMonitor::RunL
       
    97 // Becomes active when the system state changes.
       
    98 // (other items were commented in a header).
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 void CCbsShutdownMonitor::RunL()
       
   102     {
       
   103     if ( iStatus == KErrNone )
       
   104         {
       
   105         // Resubscribe before processing new value to prevent missing updates        
       
   106         IssueRequest();
       
   107         
       
   108         // Property updated, get new value
       
   109     	TInt state( 0 );
       
   110     	TInt error( KErrNone );
       
   111     	error = iProperty.Get( state );
       
   112     	
       
   113     	if ( !error )
       
   114     	    {
       
   115 #ifdef RD_STARTUP_CHANGE
       
   116         	if ( state == ESwStateShuttingDown )
       
   117         		{
       
   118         		iServer.Shutdown();
       
   119         		}
       
   120 #endif   	    
       
   121     	    }
       
   122         }        
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CCbsShutdownMonitor::DoCancel
       
   127 // Cancels an outstanding Subscribe request.  
       
   128 // (other items were commented in a header).
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 void CCbsShutdownMonitor::DoCancel()
       
   132     {
       
   133     iProperty.Cancel();   
       
   134     }
       
   135 
       
   136 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   137 
       
   138 //  End of File