resourcemgmt/hwresourcesmgr/test/utils/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 CPsPropertyObserver* CPsPropertyObserver::NewL(const TUid& aGroup, TInt aKey, MPsPropertyObserver& aObserver)
       
    19 	{
       
    20 	CPsPropertyObserver* self = new(ELeave) CPsPropertyObserver(aKey,aObserver);
       
    21 	CleanupStack::PushL(self);
       
    22 	self->ConstructL(aGroup);
       
    23 	CleanupStack::Pop(self);
       
    24 	return self;
       
    25 	}
       
    26 
       
    27 CPsPropertyObserver::CPsPropertyObserver(TInt aKey, MPsPropertyObserver& aObserver)
       
    28 	:CActive(EPriorityNormal),
       
    29 	iKey(aKey),
       
    30 	iObserver(aObserver)
       
    31 	{
       
    32 	}
       
    33 
       
    34 void CPsPropertyObserver::ConstructL(const TUid& aGroup)
       
    35 	{
       
    36 	User::LeaveIfError(iProperty.Attach(aGroup,iKey));
       
    37 	CActiveScheduler::Add(this);
       
    38 	// initial subscription and process current property value
       
    39 	Start();
       
    40 	}
       
    41 
       
    42 CPsPropertyObserver::~CPsPropertyObserver()
       
    43 	{
       
    44 	Cancel();
       
    45 	iProperty.Close();
       
    46 	}
       
    47 
       
    48 void CPsPropertyObserver::DoCancel()
       
    49 	{
       
    50 	iProperty.Cancel();
       
    51 	}
       
    52 
       
    53 void CPsPropertyObserver::RunL()
       
    54 	{
       
    55 	iProperty.Get(iValue);	
       
    56 	iObserver.PsPropertyChanged(iKey,iValue);
       
    57 	// resubscribe
       
    58 	Start();
       
    59 	}
       
    60 
       
    61 void CPsPropertyObserver::Start()
       
    62 	{
       
    63 	if (IsActive())
       
    64 		{
       
    65 		Cancel();
       
    66 		}
       
    67 	
       
    68 	iProperty.Subscribe(iStatus);
       
    69 	SetActive();		
       
    70 	}