imagehandlingutilities/thumbnailmanager/tmcommon/src/tmsrproptertyobserver.cpp
branchRCL_3
changeset 7 2eb74cf6572e
child 21 6257223ede8a
equal deleted inserted replaced
5:82749d516180 7:2eb74cf6572e
       
     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:  RPropery observer 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h>
       
    20 
       
    21 #include "tmrpropertyobserver.h"
       
    22 #include "thumbnailmanagerconstants.h"
       
    23 #include "thumbnaillog.h"
       
    24 
       
    25 // ---------------------------------------------------------------------------
       
    26 // CTMRPropertyObserver::NewL()
       
    27 // ---------------------------------------------------------------------------
       
    28 //
       
    29 CTMRPropertyObserver* CTMRPropertyObserver::NewL( MTMRPropertyObserver& aObserver,
       
    30                                                 const TUid& aKeyCategory,
       
    31                                                 const TInt aPropertyKey,
       
    32                                                 TBool aDefineKey)
       
    33     { 
       
    34     CTMRPropertyObserver* self = new( ELeave )CTMRPropertyObserver( aObserver, 
       
    35                                                                   aKeyCategory,
       
    36                                                                   aPropertyKey,
       
    37                                                                   aDefineKey);
       
    38     CleanupStack::PushL( self );
       
    39     self->ConstructL();
       
    40     CleanupStack::Pop( self );
       
    41     return self;
       
    42     }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // CTMRPropertyObserver::CTMRPropertyObserver()
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 CTMRPropertyObserver::CTMRPropertyObserver( MTMRPropertyObserver& aObserver,
       
    49                                           const TUid& aKeyCategory,
       
    50                                           const TInt aPropertyKey,
       
    51                                           TBool aDefineKey)
       
    52     : CActive( CActive::EPriorityStandard ), iObserver( aObserver ),
       
    53       iKeyCategory( aKeyCategory ), iPropertyKey(aPropertyKey), iDefineKey( aDefineKey )
       
    54     {   
       
    55     CActiveScheduler::Add( this );
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // CTMRPropertyObserver::ConstructL()
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 void CTMRPropertyObserver::ConstructL()
       
    63     { 
       
    64     TN_DEBUG1( "CTMRPropertyObserver::ConstructL()");
       
    65     // define P&S property types
       
    66     if (iDefineKey)
       
    67         {
       
    68         RProperty::Define(iKeyCategory,iPropertyKey,
       
    69                           RProperty::EInt);
       
    70         }
       
    71     
       
    72     // attach to the property
       
    73     TInt err = iProperty.Attach(iKeyCategory,iPropertyKey,EOwnerThread);
       
    74     User::LeaveIfError(err);
       
    75     
       
    76     SetActive();
       
    77     TRequestStatus* statusPtr = &iStatus;
       
    78     User::RequestComplete( statusPtr, KErrNone );
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CTMRPropertyObserver::~CTMRPropertyObserver()
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 CTMRPropertyObserver::~CTMRPropertyObserver()
       
    86     {
       
    87     TN_DEBUG1( "CTMRPropertyObserver::~CTMRPropertyObserver()");
       
    88     Cancel();
       
    89     iProperty.Close();
       
    90     }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // CTMRPropertyObserver::RunL()
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 void CTMRPropertyObserver::RunL()
       
    97     {
       
    98     TN_DEBUG1( "CTMRPropertyObserver::RunL()");
       
    99     // resubscribe before processing new value to prevent missing updates
       
   100     iProperty.Subscribe(iStatus);
       
   101     SetActive();
       
   102     
       
   103     // retrieve the value
       
   104     TInt value = 0;
       
   105     TInt ret = iProperty.Get(value);
       
   106 
       
   107     // observer callback
       
   108     iObserver.RPropertyNotification(ret, iKeyCategory, iPropertyKey, value);
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // CTMRPropertyObserver::DoCancel()
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 void CTMRPropertyObserver::DoCancel()
       
   116     {
       
   117     TN_DEBUG1( "CTMRPropertyObserver::DoCancel()");
       
   118     iProperty.Cancel();
       
   119     }
       
   120 
       
   121 // End of file