os/ossrv/lowlevellibsandfws/pluginfw/Framework/DiscovererTest/DiscovererStateAccessor.inl
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// Access to the internal state of the CDiscoverer class
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
// ______________________________________________________________________________
sl@0
    19
//
sl@0
    20
_LIT(KTDiscoverer_DumpName,"C:\\System\\Data\\Logs\\TDiscoverer_StateDump.bin");
sl@0
    21
sl@0
    22
inline TInt TDiscoverer_StateAccessor::InvariantTest(TAny* aTestObject)
sl@0
    23
	{
sl@0
    24
	CDiscoverer* discoverer = REINTERPRET_CAST(CDiscoverer*, aTestObject);
sl@0
    25
sl@0
    26
	// The only invariants over all cases
sl@0
    27
	if(	discoverer						== NULL ||
sl@0
    28
		discoverer->iDirNotifier		== NULL ||
sl@0
    29
		discoverer->iScanningTimer		== NULL)
sl@0
    30
		return KTestBedFailedInvariant;
sl@0
    31
	return KErrNone;
sl@0
    32
	}
sl@0
    33
sl@0
    34
sl@0
    35
inline TInt TDiscoverer_StateAccessor::Internalize(TAny* aTestObject)
sl@0
    36
	{
sl@0
    37
	TInt error = KErrNone;
sl@0
    38
	CDiscoverer* discoverer = REINTERPRET_CAST(CDiscoverer*, aTestObject);
sl@0
    39
	if(discoverer)
sl@0
    40
		{
sl@0
    41
		TRAP(error,InternalizeL(discoverer));
sl@0
    42
		}
sl@0
    43
	return error;
sl@0
    44
	}
sl@0
    45
sl@0
    46
inline TInt TDiscoverer_StateAccessor::Externalize(TAny* aTestObject)
sl@0
    47
	{
sl@0
    48
	TInt error = KErrNone;
sl@0
    49
	CDiscoverer* discoverer = REINTERPRET_CAST(CDiscoverer*, aTestObject);
sl@0
    50
	if(discoverer)
sl@0
    51
		{
sl@0
    52
		TRAP(error,ExternalizeL(discoverer));
sl@0
    53
		}
sl@0
    54
	return error;
sl@0
    55
	}
sl@0
    56
sl@0
    57
// internal helpers
sl@0
    58
inline void TDiscoverer_StateAccessor::InternalizeL(CDiscoverer* aDiscoverer)
sl@0
    59
	{
sl@0
    60
	RFs fs;
sl@0
    61
	User::LeaveIfError(fs.Connect());
sl@0
    62
	CleanupClosePushL(fs);
sl@0
    63
	// Read the object dump
sl@0
    64
	TParse filename;
sl@0
    65
	filename.Set(KTDiscoverer_DumpName(),NULL,NULL);
sl@0
    66
	RFileReadStream stream;
sl@0
    67
	User::LeaveIfError(stream.Open(fs,filename.FullName(), EFileRead));
sl@0
    68
	CleanupClosePushL(stream);
sl@0
    69
	aDiscoverer->iDrivesDiscovered.Reset();
sl@0
    70
	TInt count = stream.ReadInt32L();
sl@0
    71
	for(TInt i = 0; i < count; ++i)
sl@0
    72
		{
sl@0
    73
		// Construct the drives discovered array
sl@0
    74
		TDriveUnit drive = stream.ReadInt32L();
sl@0
    75
		aDiscoverer->iDrivesDiscovered.Append(drive);
sl@0
    76
		}
sl@0
    77
	CleanupStack::PopAndDestroy();	// stream
sl@0
    78
	CleanupStack::PopAndDestroy();	// fs
sl@0
    79
	}
sl@0
    80
sl@0
    81
sl@0
    82
inline void TDiscoverer_StateAccessor::ExternalizeL(CDiscoverer* aDiscoverer)
sl@0
    83
	{
sl@0
    84
	// Dump the internal state of the CDiscoverer
sl@0
    85
	RFs fs;
sl@0
    86
	User::LeaveIfError(fs.Connect());
sl@0
    87
	CleanupClosePushL(fs);
sl@0
    88
	// Write out the object dump
sl@0
    89
	TParse filename;
sl@0
    90
	filename.Set(KTDiscoverer_DumpName(),NULL,NULL);
sl@0
    91
	RFileWriteStream stream;
sl@0
    92
	User::LeaveIfError(stream.Replace(fs,filename.FullName(), EFileWrite));
sl@0
    93
	CleanupClosePushL(stream);
sl@0
    94
	const TInt count = aDiscoverer->iDrivesDiscovered.Count();
sl@0
    95
	stream.WriteInt32L(count);
sl@0
    96
	for(TInt i = 0; i < count; ++i)
sl@0
    97
		{
sl@0
    98
		// Dump the drives discovered array
sl@0
    99
		stream.WriteInt32L((aDiscoverer->iDrivesDiscovered)[i]);
sl@0
   100
		}
sl@0
   101
	CleanupStack::PopAndDestroy(&stream);
sl@0
   102
	CleanupStack::PopAndDestroy(&fs);
sl@0
   103
	}