imagehandlingutilities/thumbnailmanager/tmcommon/src/tmshutdownobserver.cpp
changeset 54 48dd0f169f0d
parent 42 2e2a89493e2b
equal deleted inserted replaced
42:2e2a89493e2b 54:48dd0f169f0d
     1 /*
       
     2 * Copyright (c) 2006-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:  Processor 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h>
       
    20 
       
    21 #include "tmshutdownobserver.h"
       
    22 #include "thumbnailmanagerconstants.h"
       
    23 #include "thumbnaillog.h"
       
    24 #include "OstTraceDefinitions.h"
       
    25 #ifdef OST_TRACE_COMPILER_IN_USE
       
    26 #include "tmshutdownobserverTraces.h"
       
    27 #endif
       
    28 
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // CTMShutdownObserver::NewL()
       
    32 // ---------------------------------------------------------------------------
       
    33 //
       
    34 CTMShutdownObserver* CTMShutdownObserver::NewL( MTMShutdownObserver& aObserver,
       
    35                                                 const TUid& aKeyCategory,
       
    36                                                 const TInt aPropertyKey,
       
    37                                                 TBool aDefineKey)
       
    38     { 
       
    39     CTMShutdownObserver* self = new( ELeave )CTMShutdownObserver( aObserver, 
       
    40                                                                   aKeyCategory,
       
    41                                                                   aPropertyKey,
       
    42                                                                   aDefineKey);
       
    43     CleanupStack::PushL( self );
       
    44     self->ConstructL();
       
    45     CleanupStack::Pop( self );
       
    46     return self;
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // CTMShutdownObserver::CTMShutdownObserver()
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CTMShutdownObserver::CTMShutdownObserver( MTMShutdownObserver& aObserver,
       
    54                                           const TUid& aKeyCategory,
       
    55                                           const TInt aPropertyKey,
       
    56                                           TBool aDefineKey)
       
    57     : CActive( CActive::EPriorityStandard ), iObserver( aObserver ),
       
    58       iKeyCategory( aKeyCategory ), iPropertyKey(aPropertyKey), iDefineKey( aDefineKey )
       
    59     {   
       
    60     CActiveScheduler::Add( this );
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // CTMShutdownObserver::ConstructL()
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 void CTMShutdownObserver::ConstructL()
       
    68     { 
       
    69     TN_DEBUG1( "CTMShutdownObserver::ConstructL()" );
       
    70     OstTrace0( TRACE_NORMAL, CTMSHUTDOWNOBSERVER_CONSTRUCTL, "CTMShutdownObserver::ConstructL" );
       
    71     // define P&S property types
       
    72     if (iDefineKey)
       
    73         {
       
    74         TN_DEBUG1( "CTMShutdownObserver::ConstructL() define" );
       
    75         OstTrace0( TRACE_NORMAL, DUP1_CTMSHUTDOWNOBSERVER_CONSTRUCTL, "CTMShutdownObserver::ConstructL - define" );
       
    76         RProperty::Define(iKeyCategory,iPropertyKey,
       
    77                           RProperty::EInt,KAllowAllPolicy,KPowerMgmtPolicy);
       
    78         }
       
    79     
       
    80     // attach to the property
       
    81     TInt err = iProperty.Attach(iKeyCategory,iPropertyKey,EOwnerThread);
       
    82     TN_DEBUG2( "CTMShutdownObserver::ConstructL() attach err = %d", err );
       
    83     OstTrace1( TRACE_NORMAL, DUP2_CTMSHUTDOWNOBSERVER_CONSTRUCTL, "CTMShutdownObserver::ConstructL - attach;err=%d", err );
       
    84     User::LeaveIfError(err);
       
    85     
       
    86     // wait for the previously attached property to be updated
       
    87     iProperty.Subscribe(iStatus);
       
    88     TN_DEBUG1( "CTMShutdownObserver::ConstructL() subscribe" );
       
    89     OstTrace0( TRACE_NORMAL, DUP3_CTMSHUTDOWNOBSERVER_CONSTRUCTL, "CTMShutdownObserver::ConstructL - subscribe" );
       
    90     SetActive();
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // CTMShutdownObserver::~CTMShutdownObserver()
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 CTMShutdownObserver::~CTMShutdownObserver()
       
    98     {
       
    99     TN_DEBUG1( "CTMShutdownObserver::~CTMShutdownObserver()" );
       
   100     OstTrace0( TRACE_NORMAL, CTMSHUTDOWNOBSERVER_CTMSHUTDOWNOBSERVER, "CTMShutdownObserver::~CTMShutdownObserver" );
       
   101     Cancel();
       
   102     iProperty.Close();
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // CTMShutdownObserver::RunL()
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 void CTMShutdownObserver::RunL()
       
   110     {
       
   111     TN_DEBUG2( "CTMShutdownObserver::RunL(%d)", iStatus.Int() );
       
   112     OstTrace1( TRACE_NORMAL, CTMSHUTDOWNOBSERVER_RUNL, "CTMShutdownObserver::RunL;iStatus.Int()=%d", iStatus.Int() );
       
   113     // resubscribe before processing new value to prevent missing updates
       
   114     iProperty.Subscribe(iStatus);
       
   115     SetActive();
       
   116     
       
   117     // retrieve the value
       
   118     TInt value = 0;
       
   119     TInt err = iProperty.Get(value);
       
   120     
       
   121     TN_DEBUG2( "CTMShutdownObserver::RunL() Get err = %d", err );
       
   122     OstTrace1( TRACE_NORMAL, DUP1_CTMSHUTDOWNOBSERVER_RUNL, "CTMShutdownObserver::RunL - get err;err=%d", err );
       
   123 
       
   124     // observer callback
       
   125     if (value)
       
   126         {
       
   127         iObserver.ShutdownNotification();
       
   128         }
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // CTMShutdownObserver::DoCancel()
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 void CTMShutdownObserver::DoCancel()
       
   136     {
       
   137     TN_DEBUG1( "CTMShutdownObserver::DoCancel()" );
       
   138     OstTrace0( TRACE_NORMAL, CTMSHUTDOWNOBSERVER_DOCANCEL, "CTMShutdownObserver::DoCancel" );
       
   139     iProperty.Cancel();
       
   140     }
       
   141 
       
   142 // End of file