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