diff -r 000000000000 -r 96e5fb8b040d kerneltest/f32test/smassstorage/src/cpropertywatch.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kerneltest/f32test/smassstorage/src/cpropertywatch.cpp Thu Dec 17 09:24:54 2009 +0200 @@ -0,0 +1,285 @@ +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// Implementation of MS drive state watcher +// +// + +/** + @file + @internalTechnology +*/ + +#include "t_ms_main.h" +#include "cpropertywatch.h" +#include "cstatemachine.h" + +LOCAL_D TInt testedDriveIndex = -1; + +/////////////////////////////////////////////////////////////////////////// +// class CPropertyWatch +/////////////////////////////////////////////////////////////////////////// + +CPropertyWatch* CPropertyWatch::NewLC(TUsbMsDriveState_Subkey aSubkey, CPropertyHandler& aHandler) + { + CPropertyWatch* me=new(ELeave) CPropertyWatch(aHandler); + CleanupStack::PushL(me); + me->ConstructL(aSubkey); + return me; + } + +CPropertyWatch::CPropertyWatch(CPropertyHandler& aHandler) + : CActive(0), iHandler(aHandler) + {} + +void CPropertyWatch::ConstructL(TUsbMsDriveState_Subkey aSubkey) + { + User::LeaveIfError(iProperty.Attach(KUsbMsDriveState_Category, aSubkey)); + CActiveScheduler::Add(this); + // initial subscription and process current property value + RunL(); + } + +CPropertyWatch::~CPropertyWatch() + { + Cancel(); + iProperty.Close(); + } + +void CPropertyWatch::DoCancel() + { + iProperty.Cancel(); + } + +void CPropertyWatch::RunL() + { + // resubscribe before processing new value to prevent missing updates + iProperty.Subscribe(iStatus); + iHandler.HandleStatusChange(iProperty); + SetActive(); + } + +/////////////////////////////////////////////////////////////////////////// +// class CPropertyHandler +/////////////////////////////////////////////////////////////////////////// + +CPropertyHandler::CPropertyHandler(TInt aDriveNo, CStateMachine& aSm) + : iDriveNo(aDriveNo) + , iStateMachine(aSm) + { + } + +CPropertyHandler::~CPropertyHandler() + { + } + +/////////////////////////////////////////////////////////////////////////// +// class CMsDriveStatusHandler +/////////////////////////////////////////////////////////////////////////// + +CMsDriveStatusHandler* +CMsDriveStatusHandler::NewLC(TInt aDriveNo, CStateMachine& aSm) + { + CMsDriveStatusHandler* self = new (ELeave) CMsDriveStatusHandler(aDriveNo, aSm); + CleanupStack::PushL(self); + return self; + }; + +CMsDriveStatusHandler::CMsDriveStatusHandler(TInt aDriveNo, CStateMachine& aSm) + : CPropertyHandler(aDriveNo, aSm) + { + } + +void +CMsDriveStatusHandler::HandleStatusChange(RProperty& aProperty) + { + TInt driveStatus = -1; + TInt currentStatus = iStateMachine.CurrentStateId(); + TBuf8<16> allDrivesStatus; + TInt ret = aProperty.Get(allDrivesStatus); + test.Printf(_L("Property.Get() return value: %d\n"), ret); + test(ret == KErrNone); + + if (testedDriveIndex < 0) + { + for(TInt i=0; i