accessoryservices/accessoryserver/src/ChargerContext/AccSrvPSIntPropertyWatch.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2008-2008 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:  A class to watch changes of a integer property.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include    <e32base.h>
       
    21 #include    <e32def.h>
       
    22 
       
    23 
       
    24 #include "AccSrvPSIntPropertyWatch.h"
       
    25 #include "acc_debug.h"
       
    26 
       
    27 
       
    28 // ======== LOCAL FUNCTIONS ========
       
    29 
       
    30 
       
    31 // ======== MEMBER FUNCTIONS ========
       
    32 
       
    33 // ---------------------------------------------------------
       
    34 // Symbian two-phased constructor
       
    35 // ---------------------------------------------------------
       
    36 //
       
    37 CAccSrvPSIntPropertyWatch* CAccSrvPSIntPropertyWatch::NewL(
       
    38         MAccSrvPSIntPropertyObserver*   aObserver,
       
    39         TUid    aCategory,
       
    40         TInt    aKey,
       
    41         TOwnerType aType )
       
    42     {
       
    43     COM_TRACE_( "[AccFW:AccServer] CAccSrvPSIntPropertyWatch::NewL()" );
       
    44     CAccSrvPSIntPropertyWatch* self = new ( ELeave ) CAccSrvPSIntPropertyWatch();
       
    45     CleanupStack::PushL( self );
       
    46     self->ConstructL( aObserver, aCategory, aKey, aType );
       
    47     CleanupStack::Pop( self );
       
    48     COM_TRACE_1( "[AccFW:AccServer] CAccSrvPSIntPropertyWatch::NewL - return %p", self );
       
    49     return self;
       
    50     }
       
    51 
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // Symbian two-phased constructor
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 CAccSrvPSIntPropertyWatch* CAccSrvPSIntPropertyWatch::NewLC(
       
    58         MAccSrvPSIntPropertyObserver*   aObserver,
       
    59         TUid    aCategory,
       
    60         TInt    aKey,
       
    61         TOwnerType aType )
       
    62     {
       
    63     COM_TRACE_( "[AccFW:AccServer] CAccSrvPSIntPropertyWatch::NewLC()" );
       
    64     CAccSrvPSIntPropertyWatch* self = new( ELeave ) CAccSrvPSIntPropertyWatch;
       
    65     CleanupStack::PushL( self );
       
    66     self->ConstructL( aObserver, aCategory, aKey, aType );
       
    67     COM_TRACE_1( "[AccFW:AccServer] CAccSrvPSIntPropertyWatch::NewLC - return %p", self );
       
    68     return self;
       
    69     }
       
    70 
       
    71 
       
    72 // ---------------------------------------------------------
       
    73 // Destructor
       
    74 // ---------------------------------------------------------
       
    75 //
       
    76 CAccSrvPSIntPropertyWatch::~CAccSrvPSIntPropertyWatch()
       
    77     {
       
    78     COM_TRACE_( "[AccFW:AccServer] CAccSrvPSIntPropertyWatch::~CAccSrvPSIntPropertyWatch()" );
       
    79     Cancel();
       
    80     iProperty.Close();
       
    81     COM_TRACE_( "[AccFW:AccServer] CAccSrvPSIntPropertyWatch::~CAccSrvPSIntPropertyWatch" );
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------
       
    85 // SubscribeNotification
       
    86 // ---------------------------------------------------------
       
    87 //
       
    88 void CAccSrvPSIntPropertyWatch::Watch()
       
    89     {
       
    90     COM_TRACE_( "[AccFW:AccServer] CAccSrvPSIntPropertyWatch::Watch()" );
       
    91     iProperty.Subscribe(iStatus);
       
    92     SetActive();
       
    93     COM_TRACE_( "[AccFW:AccServer] CAccSrvPSIntPropertyWatch::Watch - return void" );
       
    94     return;
       
    95     }
       
    96 
       
    97 
       
    98 // ---------------------------------------------------------
       
    99 // Get current value.
       
   100 // ---------------------------------------------------------
       
   101 //
       
   102 TInt CAccSrvPSIntPropertyWatch::GetCurrentValue( TInt& aValue)
       
   103     {
       
   104     COM_TRACE_( "[AccFW:AccServer] CAccSrvPSIntPropertyWatch::GetCurrentValue()" );
       
   105     TInt value = 0;
       
   106     TInt error( iProperty.Get( value ) );
       
   107     if ( KErrNone == error )
       
   108         {
       
   109         // use new value ...
       
   110         COM_TRACE_1( "[AccFW:AccServer] CAccSrvPSIntPropertyWatch::GetCurrentValue - value 0x%x", value );
       
   111         aValue = value;
       
   112         }
       
   113     else if ( KErrNotFound == error )
       
   114         {
       
   115         // property deleted, do necessary actions here...
       
   116         iObserver->PSPropertyDeleted( iCategory, iKey );
       
   117         }
       
   118     COM_TRACE_1( "[AccFW:AccServer] CAccSrvPSIntPropertyWatch::GetCurrentValue - return aError %d", error );
       
   119     return error;
       
   120     }
       
   121 
       
   122 
       
   123 // ---------------------------------------------------------
       
   124 // From class CActive.
       
   125 // DoCancel
       
   126 // ---------------------------------------------------------
       
   127 //
       
   128 void CAccSrvPSIntPropertyWatch::DoCancel()
       
   129     {
       
   130     COM_TRACE_( "[AccFW:AccServer] CAccSrvPSIntPropertyWatch::DoCancel()" );
       
   131     iProperty.Cancel();
       
   132     COM_TRACE_( "[AccFW:AccServer] CAccSrvPSIntPropertyWatch::DoCancel - return void" );
       
   133     }
       
   134 
       
   135 
       
   136 // ---------------------------------------------------------
       
   137 // C++ constructor
       
   138 // ---------------------------------------------------------
       
   139 //
       
   140 CAccSrvPSIntPropertyWatch::CAccSrvPSIntPropertyWatch()
       
   141     :CActive ( EPriority )
       
   142     {
       
   143     COM_TRACE_( "[AccFW:AccServer] CAccSrvPSIntPropertyWatch::CAccSrvPSIntPropertyWatch()" );
       
   144     COM_TRACE_( "[AccFW:AccServer] CAccSrvPSIntPropertyWatch::CAccSrvPSIntPropertyWatch - return" );
       
   145     }
       
   146 
       
   147 
       
   148 // ---------------------------------------------------------
       
   149 // ConstructL
       
   150 // ---------------------------------------------------------
       
   151 //
       
   152 void CAccSrvPSIntPropertyWatch::ConstructL(
       
   153         MAccSrvPSIntPropertyObserver*   aObserver,
       
   154         TUid    aCategory,
       
   155         TInt    aKey,
       
   156         TOwnerType aType )
       
   157     {
       
   158     COM_TRACE_( "[AccFW:AccServer] CAccSrvPSIntPropertyWatch::ConstructL()" );
       
   159     iObserver = aObserver;
       
   160     iCategory = aCategory;
       
   161     iKey = aKey;    
       
   162     User::LeaveIfError( iProperty.Attach(iCategory,iKey, aType ) );
       
   163     CActiveScheduler::Add(this);
       
   164     COM_TRACE_( "[AccFW:AccServer] CAccSrvPSIntPropertyWatch::ConstructL - return void" );
       
   165     return;
       
   166    }
       
   167 
       
   168 // ---------------------------------------------------------
       
   169 // From class CActive.
       
   170 // RunL
       
   171 // ---------------------------------------------------------
       
   172 //
       
   173 void CAccSrvPSIntPropertyWatch::RunL()
       
   174     {
       
   175     COM_TRACE_( "[AccFW:AccServer] CAccSrvPSIntPropertyWatch::RunL()" );
       
   176 
       
   177     // resubscribe before processing new value to prevent missing updates
       
   178     iProperty.Subscribe(iStatus);
       
   179     SetActive();
       
   180     // property updated, get new value
       
   181     TInt value;
       
   182     if ( iProperty.Get( value ) == KErrNotFound )
       
   183         {
       
   184         // property deleted, do necessary actions here...
       
   185         iObserver->PSPropertyDeleted( iCategory, iKey );
       
   186         }
       
   187     else
       
   188         {
       
   189         // use new value ...
       
   190         iObserver->PSPropertyChanged( iCategory, iKey, value );
       
   191         }
       
   192     COM_TRACE_( "[AccFW:AccServer] CAccSrvPSIntPropertyWatch::RunL - return void" );
       
   193     }
       
   194 
       
   195 
       
   196 // ---------------------------------------------------------
       
   197 // From class CActive.
       
   198 // RunL
       
   199 // ---------------------------------------------------------
       
   200 //
       
   201 TInt CAccSrvPSIntPropertyWatch::RunError( TInt aError )
       
   202     {
       
   203     COM_TRACE_( "[AccFW:AccServer] CAccSrvPSIntPropertyWatch::RunError()" );
       
   204     // Avoid Panic in CActiveScheduler
       
   205     aError = KErrNone;
       
   206     COM_TRACE_1( "[AccFW:AccServer] CAccSrvPSIntPropertyWatch::RunError - return aError %d", aError );
       
   207     return aError;
       
   208     }
       
   209 
       
   210 
       
   211 // ======== GLOBAL FUNCTIONS ========
       
   212