tactilefeedback/tactilefeedbackresolver/src/tactilepropertywatcher.cpp
changeset 0 d54f32e146dd
equal deleted inserted replaced
-1:000000000000 0:d54f32e146dd
       
     1 /*
       
     2 * Copyright (c) 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:  Class for monitoring P&S property changes.
       
    15 * Part of:      Tactile Feedback.
       
    16 *
       
    17 */
       
    18 
       
    19 #include <e32std.h>
       
    20 #include <e32cmn.h> 
       
    21 
       
    22 #include "tactilepropertywatcher.h"
       
    23 
       
    24 // ---------------------------------------------------------------------------
       
    25 // Constructor.
       
    26 // ---------------------------------------------------------------------------
       
    27 //
       
    28 CTactilePropertyWatcher::CTactilePropertyWatcher( 
       
    29         MTactilePropertyObserver& aObserver, 
       
    30         const TUid aCategory, 
       
    31         const TInt aKey,
       
    32         CActive::TPriority aPriority ) : 
       
    33             CActive( aPriority ), 
       
    34             iObserver( aObserver ), 
       
    35             iCategory( aCategory ), 
       
    36             iKey( aKey )
       
    37       
       
    38     {
       
    39     CActiveScheduler::Add( this );
       
    40     }
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 // 2nd phase constructor.
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 void CTactilePropertyWatcher::ConstructL()
       
    47     {
       
    48     User::LeaveIfError( iProperty.Attach( iCategory, iKey ) );
       
    49 
       
    50     Subscribe();
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // 2-phased constructor.
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 CTactilePropertyWatcher* CTactilePropertyWatcher::NewL( 
       
    58         MTactilePropertyObserver& aObserver, 
       
    59         const TUid aCategory, 
       
    60         const TInt aKey,
       
    61         CActive::TPriority aPriority )
       
    62     {
       
    63     CTactilePropertyWatcher* self = new (ELeave) 
       
    64         CTactilePropertyWatcher( aObserver, aCategory, aKey, aPriority );
       
    65     CleanupStack::PushL( self );
       
    66     self->ConstructL();
       
    67     CleanupStack::Pop( self );
       
    68     return self;
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // Destructor.
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 CTactilePropertyWatcher::~CTactilePropertyWatcher()
       
    76     {
       
    77     Cancel(); 
       
    78     iProperty.Close();
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // Retrieves an integer value associated with this property.
       
    83 // ---------------------------------------------------------------------------
       
    84 //       
       
    85 void CTactilePropertyWatcher::GetL( TInt& aValue )
       
    86     {
       
    87     User::LeaveIfError( iProperty.Get( aValue ) );
       
    88     }
       
    89 
       
    90     
       
    91 // ---------------------------------------------------------------------------
       
    92 // Retrieves a buffer associated with this property.
       
    93 // ---------------------------------------------------------------------------
       
    94 //       
       
    95 void CTactilePropertyWatcher::GetL( TDes8& aValue )
       
    96     {
       
    97     User::LeaveIfError( iProperty.Get( aValue ) );
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // Retrieves an integer value associated with this property.
       
   102 // ---------------------------------------------------------------------------
       
   103 //       
       
   104 TInt CTactilePropertyWatcher::Get( TInt& aValue )
       
   105     {
       
   106     return iProperty.Get( aValue );
       
   107     }
       
   108     
       
   109 // ---------------------------------------------------------------------------
       
   110 // Retrieves a buffer associated with this property.
       
   111 // ---------------------------------------------------------------------------
       
   112 //       
       
   113 TInt CTactilePropertyWatcher::Get( TDes8& aValue )
       
   114     {
       
   115     return iProperty.Get( aValue );
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // Sets a P&S property to an integer value. The attached version of
       
   120 // RProperty::Set is used which is faster than using RProperty::Set
       
   121 // directly without attach.
       
   122 // ---------------------------------------------------------------------------
       
   123 //       
       
   124 void CTactilePropertyWatcher::SetL( const TInt aValue )
       
   125     {
       
   126     User::LeaveIfError( iProperty.Set( aValue ) );
       
   127     }
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // Sets a P&S property to a (large)bytearray value. The attached version of
       
   131 // RProperty::Set is used which is faster than using RProperty::Set
       
   132 // directly without attach.
       
   133 // ---------------------------------------------------------------------------
       
   134 //       
       
   135 void CTactilePropertyWatcher::SetL( const TDesC8& aValue )
       
   136     {
       
   137     User::LeaveIfError( iProperty.Set( aValue ) );        
       
   138     }
       
   139 
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 void CTactilePropertyWatcher::Subscribe()
       
   145     {
       
   146     if ( !IsActive() )
       
   147         {
       
   148         iProperty.Subscribe( iStatus );
       
   149 
       
   150         SetActive();
       
   151         }
       
   152     }
       
   153 
       
   154 // ---------------------------------------------------------------------------
       
   155 // From class CActive
       
   156 // ---------------------------------------------------------------------------
       
   157 //
       
   158 void CTactilePropertyWatcher::DoCancel()
       
   159     {
       
   160     iProperty.Cancel();
       
   161     }
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // From class CActive
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 void CTactilePropertyWatcher::RunL()
       
   168     {
       
   169     if ( iStatus.Int() == KErrNone )
       
   170         {
       
   171         // Subscribe first, then notify the observer that a property
       
   172         //  has changed. 
       
   173         Subscribe();
       
   174         iObserver.PropertyChangedL( iCategory, iKey );
       
   175         }
       
   176     else if ( iStatus.Int() == KErrNotFound )
       
   177         {
       
   178         // We get here if a property gets deleted. We still need to subscribe
       
   179         // to it because it might get redefined later.
       
   180         Subscribe();        
       
   181         }
       
   182     }
       
   183 
       
   184 // End of File