sl@0: // Copyright (c) 1997-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 "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: // Access to the internal state of the CDiscoverer class sl@0: // sl@0: // sl@0: sl@0: // ______________________________________________________________________________ sl@0: // sl@0: _LIT(KTDiscoverer_DumpName,"C:\\System\\Data\\Logs\\TDiscoverer_StateDump.bin"); sl@0: sl@0: inline TInt TDiscoverer_StateAccessor::InvariantTest(TAny* aTestObject) sl@0: { sl@0: CDiscoverer* discoverer = REINTERPRET_CAST(CDiscoverer*, aTestObject); sl@0: sl@0: // The only invariants over all cases sl@0: if( discoverer == NULL || sl@0: discoverer->iDirNotifier == NULL || sl@0: discoverer->iScanningTimer == NULL) sl@0: return KTestBedFailedInvariant; sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: inline TInt TDiscoverer_StateAccessor::Internalize(TAny* aTestObject) sl@0: { sl@0: TInt error = KErrNone; sl@0: CDiscoverer* discoverer = REINTERPRET_CAST(CDiscoverer*, aTestObject); sl@0: if(discoverer) sl@0: { sl@0: TRAP(error,InternalizeL(discoverer)); sl@0: } sl@0: return error; sl@0: } sl@0: sl@0: inline TInt TDiscoverer_StateAccessor::Externalize(TAny* aTestObject) sl@0: { sl@0: TInt error = KErrNone; sl@0: CDiscoverer* discoverer = REINTERPRET_CAST(CDiscoverer*, aTestObject); sl@0: if(discoverer) sl@0: { sl@0: TRAP(error,ExternalizeL(discoverer)); sl@0: } sl@0: return error; sl@0: } sl@0: sl@0: // internal helpers sl@0: inline void TDiscoverer_StateAccessor::InternalizeL(CDiscoverer* aDiscoverer) sl@0: { sl@0: RFs fs; sl@0: User::LeaveIfError(fs.Connect()); sl@0: CleanupClosePushL(fs); sl@0: // Read the object dump sl@0: TParse filename; sl@0: filename.Set(KTDiscoverer_DumpName(),NULL,NULL); sl@0: RFileReadStream stream; sl@0: User::LeaveIfError(stream.Open(fs,filename.FullName(), EFileRead)); sl@0: CleanupClosePushL(stream); sl@0: aDiscoverer->iDrivesDiscovered.Reset(); sl@0: TInt count = stream.ReadInt32L(); sl@0: for(TInt i = 0; i < count; ++i) sl@0: { sl@0: // Construct the drives discovered array sl@0: TDriveUnit drive = stream.ReadInt32L(); sl@0: aDiscoverer->iDrivesDiscovered.Append(drive); sl@0: } sl@0: CleanupStack::PopAndDestroy(); // stream sl@0: CleanupStack::PopAndDestroy(); // fs sl@0: } sl@0: sl@0: sl@0: inline void TDiscoverer_StateAccessor::ExternalizeL(CDiscoverer* aDiscoverer) sl@0: { sl@0: // Dump the internal state of the CDiscoverer sl@0: RFs fs; sl@0: User::LeaveIfError(fs.Connect()); sl@0: CleanupClosePushL(fs); sl@0: // Write out the object dump sl@0: TParse filename; sl@0: filename.Set(KTDiscoverer_DumpName(),NULL,NULL); sl@0: RFileWriteStream stream; sl@0: User::LeaveIfError(stream.Replace(fs,filename.FullName(), EFileWrite)); sl@0: CleanupClosePushL(stream); sl@0: const TInt count = aDiscoverer->iDrivesDiscovered.Count(); sl@0: stream.WriteInt32L(count); sl@0: for(TInt i = 0; i < count; ++i) sl@0: { sl@0: // Dump the drives discovered array sl@0: stream.WriteInt32L((aDiscoverer->iDrivesDiscovered)[i]); sl@0: } sl@0: CleanupStack::PopAndDestroy(&stream); sl@0: CleanupStack::PopAndDestroy(&fs); sl@0: }