calendarui/inc/PropertyObserver.h
changeset 0 f979ecb2b13e
child 18 c198609911f9
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 /*
       
     2 * Copyright (c) 2002, 2003 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: Property Observer class for handling property change events.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef CPROPERTYOBSERVER_H
       
    21 #define CPROPERTYOBSERVER_H
       
    22 
       
    23 // INCLUDES
       
    24 #include <e32base.h>
       
    25 #include <e32property.h>
       
    26 
       
    27 // CLASS DECLARATION
       
    28 
       
    29 /**
       
    30  * MPropertyChangeHandler.
       
    31  * Abstract interface for handling property change events.
       
    32  **/
       
    33 NONSHARABLE_CLASS( MPropertyChangeHandler )
       
    34 {
       
    35  public:
       
    36     /**
       
    37      * This is a callback function which is called when a property is changed.
       
    38      *
       
    39      * @param aCategory  UID of the category.
       
    40      * @param aKey       changed key
       
    41      * @param aValue     the new value
       
    42      *
       
    43      * Note! references aKey and aValue are only valid while executing
       
    44      * HandlePropertyChange(). After that the data in which they refer can change.
       
    45      **/
       
    46     virtual void HandlePropertyChange(const TUid& aCategory, const TUint& aKey, const TInt& aValue) = 0;
       
    47 
       
    48 };
       
    49 
       
    50 
       
    51 // CLASS DECLARATION
       
    52 
       
    53 /**
       
    54  * ?one_line_short_description.
       
    55  * ?other_description_lines
       
    56  *
       
    57  * @since Series 60 3.0
       
    58  **/
       
    59 NONSHARABLE_CLASS(CPropertyObserver) : public CActive
       
    60 {
       
    61  public:  // Constructors and destructor
       
    62     /**
       
    63      * Two-phased constructor.
       
    64      * @since Series 60 3.0
       
    65      * @param ?arg1 ?description
       
    66      * @param ?arg2 ?description
       
    67      **/
       
    68     static CPropertyObserver* NewL(MPropertyChangeHandler& aHandler, const TUid& aCategory, const TUint& aKey, const TBool aSkipValue=EFalse)
       
    69     {
       
    70         CPropertyObserver* self = new( ELeave )CPropertyObserver( aHandler, aCategory, aKey, aSkipValue );
       
    71         CleanupStack::PushL( self );
       
    72         self->ConstructL();
       
    73         CleanupStack::Pop( self );
       
    74         return self;
       
    75     };
       
    76 
       
    77     /**
       
    78      * Destructor.
       
    79      **/
       
    80     ~CPropertyObserver()
       
    81     {
       
    82         Deque();
       
    83         iProperty.Cancel();
       
    84         iProperty.Close();
       
    85     };
       
    86 
       
    87  private:
       
    88     /**
       
    89      * C++ default constructor overload.
       
    90      **/
       
    91     CPropertyObserver(MPropertyChangeHandler& aHandler, const TUid& aCategory, const TUint& aKey, const TBool aSkipValue)
       
    92     : CActive( CActive::EPriorityStandard ),
       
    93       iCategory( aCategory ),
       
    94       iKey( aKey ),
       
    95       iHandler( aHandler ),
       
    96       iSkipValue( aSkipValue )
       
    97     {
       
    98     };
       
    99 
       
   100     /**
       
   101      * By default Symbian 2nd phase constructor is private.
       
   102      **/
       
   103     void ConstructL(void)
       
   104     {
       
   105         CActiveScheduler::Add( this );
       
   106 
       
   107         User::LeaveIfError( iProperty.Attach( iCategory, iKey ) );
       
   108 
       
   109         //NotifyCurrentValue(); // notify initial value
       
   110 
       
   111         // Start observing...
       
   112         Subscribe();
       
   113     };
       
   114 
       
   115  protected:  // Functions from base classes
       
   116     /**
       
   117      * From CActive ?member_description
       
   118      **/
       
   119     inline void RunL(void);
       
   120 
       
   121     /**
       
   122      * From CActive ?member_description
       
   123      **/
       
   124     inline void DoCancel(void);
       
   125 
       
   126  private:  // New functions
       
   127     /**
       
   128      * ?member_description.
       
   129      * @since Series 60 3.0
       
   130      **/
       
   131     inline void Subscribe(void);
       
   132 
       
   133     /**
       
   134      * ?member_description.
       
   135      * @since Series 60 3.0
       
   136      **/
       
   137     inline void NotifyCurrentValue(void);
       
   138 
       
   139  private:  // Data
       
   140     // ?one_line_short_description_of_data
       
   141     RProperty iProperty;
       
   142 
       
   143     // ?one_line_short_description_of_data
       
   144     const TUid iCategory;
       
   145 
       
   146     // ?one_line_short_description_of_data
       
   147     const TUint iKey;
       
   148 
       
   149     // ?one_line_short_description_of_data
       
   150     MPropertyChangeHandler& iHandler;
       
   151 
       
   152     // ?one_line_short_description_of_data
       
   153     const TBool iSkipValue;
       
   154 
       
   155 };
       
   156 
       
   157 #include "PropertyObserver.inl"
       
   158 
       
   159 #endif  // CPROPERTYOBSERVER_H
       
   160 
       
   161 
       
   162 // End of File