idlehomescreen/exths/src/plugincontainer/propertyobserver.cpp
changeset 0 f72a12da539e
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     1 /*
       
     2 * Copyright (c) 2002 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 
       
    19 // INCLUDE FILES
       
    20 #include "propertyobserver.h"
       
    21 
       
    22 
       
    23 // ============================ MEMBER FUNCTIONS ===============================
       
    24 
       
    25 // -----------------------------------------------------------------------------
       
    26 // CPropertyObserver::CPropertyObserver
       
    27 // C++ default constructor can NOT contain any code, that
       
    28 // might leave.
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 CPropertyObserver::CPropertyObserver(MPropertyChangeHandler& aHandler,
       
    32                                      const TUid& aCategory,
       
    33                                      const TUint& aKey)
       
    34 : CActive( CActive::EPriorityStandard ),
       
    35   iCategory( aCategory ),
       
    36   iKey( aKey ),
       
    37   iHandler( aHandler )
       
    38 {
       
    39 }
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CPropertyObserver::ConstructL
       
    43 // Symbian 2nd phase constructor can leave.
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 void CPropertyObserver::ConstructL(void)
       
    47 {
       
    48     CActiveScheduler::Add( this );
       
    49 
       
    50     User::LeaveIfError( iProperty.Attach( iCategory, iKey ) );
       
    51 
       
    52     // Start observing...
       
    53     Subscribe();
       
    54 
       
    55     // Notify the initial value if needed...
       
    56 //    NotifyCurrentValue();
       
    57 }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CPropertyObserver::NewL
       
    61 // Two-phased constructor.
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CPropertyObserver* CPropertyObserver::NewL(MPropertyChangeHandler& aHandler,
       
    65                                            const TUid& aCategory,
       
    66                                            const TUint& aKey)
       
    67 {
       
    68     CPropertyObserver* self = new( ELeave )CPropertyObserver( aHandler, aCategory, aKey );
       
    69     CleanupStack::PushL( self );
       
    70     self->ConstructL();
       
    71     CleanupStack::Pop( self );
       
    72     return self;
       
    73 }
       
    74 
       
    75 // Destructor
       
    76 CPropertyObserver::~CPropertyObserver()
       
    77 {
       
    78     Deque();
       
    79     iProperty.Cancel();
       
    80     iProperty.Close();
       
    81 }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // CPropertyObserver::RunL
       
    85 // (other items were commented in a header).
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 void CPropertyObserver::RunL(void)
       
    89 {
       
    90     if( iStatus.Int() == KErrNone )
       
    91     {
       
    92         Subscribe();
       
    93         NotifyCurrentValue();
       
    94     }
       
    95 }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CPropertyObserver::DoCancel
       
    99 // (other items were commented in a header).
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 void CPropertyObserver::DoCancel(void)
       
   103 {
       
   104     iProperty.Cancel();
       
   105 }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CPropertyObserver::Subscribe
       
   109 // (other items were commented in a header).
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 void CPropertyObserver::Subscribe(void)
       
   113 {
       
   114     iProperty.Subscribe( iStatus );
       
   115     SetActive();
       
   116 }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // CPropertyObserver::NotifyCurrentValue
       
   120 // (other items were commented in a header).
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 void CPropertyObserver::NotifyCurrentValue(void)
       
   124 {
       
   125     TInt value;
       
   126 
       
   127     if( iProperty.Get( iCategory, iKey, value ) == KErrNone )
       
   128     {
       
   129         iHandler.HandlePropertyChange( iCategory, iKey, value );
       
   130     }
       
   131 }
       
   132 
       
   133 
       
   134 // End of File