resourcemgmt/hwresourcesmgr/common/src/pspropertyobserver.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "pspropertyobserver.h"
       
    17 
       
    18 EXPORT_C CPsPropertyObserver* CPsPropertyObserver::NewL(const TUid& aGroup, TInt aKey, MPsPropertyObserver& aObserver)
       
    19 	{
       
    20 	CPsPropertyObserver* self = new(ELeave) CPsPropertyObserver(aGroup,aKey,aObserver);
       
    21 	CleanupStack::PushL(self);
       
    22 	self->ConstructL(aGroup);
       
    23 	CleanupStack::Pop(self);
       
    24 	return self;
       
    25 	}
       
    26 
       
    27 CPsPropertyObserver::CPsPropertyObserver(TUid aGroup, TInt aKey, MPsPropertyObserver& aObserver)
       
    28 	:CActive(EPriorityNormal),
       
    29 	iGroup(aGroup),
       
    30 	iKey(aKey),
       
    31 	iObserver(aObserver)
       
    32 	{
       
    33 	}
       
    34 
       
    35 void CPsPropertyObserver::ConstructL(const TUid& aGroup)
       
    36 	{
       
    37 	User::LeaveIfError(iProperty.Attach(aGroup,iKey));
       
    38 	CActiveScheduler::Add(this);
       
    39 	// initial subscription and process current property value
       
    40 	Start();
       
    41 	}
       
    42 
       
    43 CPsPropertyObserver::~CPsPropertyObserver()
       
    44 	{
       
    45 	Cancel();
       
    46 	iProperty.Close();
       
    47 	}
       
    48 
       
    49 void CPsPropertyObserver::DoCancel()
       
    50 	{
       
    51 	iProperty.Cancel();
       
    52 	}
       
    53 
       
    54 void CPsPropertyObserver::RunL()
       
    55 	{
       
    56 	if(KErrNone == iStatus.Int())
       
    57     {
       
    58     iProperty.Get(iValue);	
       
    59     }
       
    60 	iObserver.PsPropertyChanged(iKey,iValue, iStatus.Int());
       
    61 	// resubscribe
       
    62 	Start();
       
    63 	}
       
    64 
       
    65 void CPsPropertyObserver::Start()
       
    66 	{
       
    67 	if (IsActive())
       
    68 		{
       
    69 		Cancel();
       
    70 		}
       
    71 	
       
    72 	iProperty.Subscribe(iStatus);
       
    73 	SetActive();		
       
    74 	}
       
    75 
       
    76 EXPORT_C TInt CPsPropertyObserver::Get(const TUid& aGroup, TInt aKey, TInt& value)
       
    77     {
       
    78     return RProperty::Get(aGroup, aKey, value);
       
    79     }
       
    80 
       
    81 EXPORT_C TInt CPsPropertyObserver::Get(TInt& value)
       
    82     {
       
    83     return Get(iGroup, iKey, value);
       
    84     }
       
    85