harvester/server/src/harvestershutdownobserver.cpp
changeset 0 c53acadfccc6
child 60 79f826a55db2
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2009 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 #include <e32base.h>
       
    19 
       
    20 #include "harvestershutdownobserver.h"
       
    21 #include "mdscommoninternal.h"
       
    22 #include "harvesterlog.h"
       
    23 
       
    24 // ---------------------------------------------------------------------------
       
    25 // CHarvesterShutdownObserver::NewL()
       
    26 // ---------------------------------------------------------------------------
       
    27 //
       
    28 CHarvesterShutdownObserver* CHarvesterShutdownObserver::NewL( MHarvesterShutdownObserver& aObserver/*, const TUid& aKeyCategory */)
       
    29     { 
       
    30     CHarvesterShutdownObserver* self = new( ELeave )CHarvesterShutdownObserver( aObserver/*, aKeyCategory */);
       
    31     CleanupStack::PushL( self );
       
    32     self->ConstructL();
       
    33     CleanupStack::Pop( self );
       
    34     return self;
       
    35     }
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // CHarvesterShutdownObserver::CHarvesterShutdownObserver()
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 CHarvesterShutdownObserver::CHarvesterShutdownObserver( MHarvesterShutdownObserver& aObserver/*, const TUid& aKeyCategory */)
       
    42     : CActive( CActive::EPriorityUserInput ), iObserver( aObserver ), iValue( KErrNone )/*, iKeyCategory( aKeyCategory )*/
       
    43     {       
       
    44     CActiveScheduler::Add( this );
       
    45     }
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // CHarvesterShutdownObserver::ConstructL()
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 void CHarvesterShutdownObserver::ConstructL()
       
    52     {
       
    53     WRITELOG( "CHarvesterShutdownObserver::ConstructL()" );
       
    54     
       
    55     const TInt error = RProperty::Define(KHarvesterPSShutdown, KShutdown,RProperty::EInt,KAllowAllPolicy,KPowerMgmtPolicy);
       
    56     
       
    57     WRITELOG1( "CHarvesterShutdownObserver::ConstructL, defineError = %d", error );
       
    58     
       
    59     // attach to the property    
       
    60     User::LeaveIfError( iProperty.Attach(KHarvesterPSShutdown,KShutdown,EOwnerThread) );
       
    61     
       
    62     // wait for the previously attached property to be updated
       
    63     iProperty.Subscribe(iStatus);       
       
    64     
       
    65     SetActive();
       
    66     
       
    67     WRITELOG("CHarvesterShutdownObserver::ConstructL() end");
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // CHarvesterShutdownObserver::~CHarvesterShutdownObserver()
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 CHarvesterShutdownObserver::~CHarvesterShutdownObserver()
       
    75     {
       
    76     WRITELOG( "CHarvesterShutdownObserver::~CHarvesterShutdownObserver()" );
       
    77     Cancel();
       
    78     iProperty.Close();
       
    79     WRITELOG( "CHarvesterShutdownObserver::~CHarvesterShutdownObserver() end" );
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // CHarvesterShutdownObserver::RunL()
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 void CHarvesterShutdownObserver::RunL()
       
    87     {
       
    88     // resubscribe before processing new value to prevent missing updates
       
    89     iProperty.Subscribe( iStatus );
       
    90     SetActive();
       
    91     
       
    92     // retrieve the Uid of the package going to be updated
       
    93     TInt value = 0;
       
    94     const TInt err = iProperty.Get(value);
       
    95     User::LeaveIfError(err);
       
    96 
       
    97 	iValue = value;
       
    98 
       
    99     // observer callback
       
   100     if (value)
       
   101         {
       
   102         iObserver.ShutdownNotification();
       
   103         }
       
   104     else
       
   105         {
       
   106         iObserver.RestartNotification();
       
   107         }
       
   108     }
       
   109 
       
   110 TInt CHarvesterShutdownObserver::RunError( TInt /*aError*/ )
       
   111     {
       
   112     return KErrNone;
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // CHarvesterShutdownObserver::DoCancel()
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 void CHarvesterShutdownObserver::DoCancel()
       
   120     {
       
   121     iProperty.Cancel();
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // CHarvesterShutdownObserver::UpdateInProgress()
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 TBool CHarvesterShutdownObserver::UpdateInProgress()
       
   129     {
       
   130     return iValue > 0 ? ETrue : EFalse;
       
   131     }
       
   132 
       
   133 // End of file