os/persistentdata/persistentstorage/store/UPAGE/UP_FILE.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/store/UPAGE/UP_FILE.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,92 @@
     1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include "UP_STD.H"
    1.20 +#include <s32file.h>
    1.21 +
    1.22 +EXPORT_C RFilePagePool::RFilePagePool()
    1.23 +/** Default constructor. */
    1.24 +	{}
    1.25 +
    1.26 +EXPORT_C RFilePagePool::RFilePagePool(CPageCache& aCache)
    1.27 +	: TCachePagePool(aCache)
    1.28 +/** Constructor with a page cache for the pool.
    1.29 +
    1.30 +@param aCache Page cache for the pool */
    1.31 +	{}
    1.32 +
    1.33 +EXPORT_C void RFilePagePool::Close()
    1.34 +/** Flushes cached pages to the file, and closes the file. */
    1.35 +	{
    1.36 +	TCachePagePool::Flush();
    1.37 +	Release();
    1.38 +	}
    1.39 +
    1.40 +EXPORT_C void RFilePagePool::Release()
    1.41 +/** Closes the file without flushing the cache. */
    1.42 +	{
    1.43 +	Purge();
    1.44 +	iFile.Close();
    1.45 +	}
    1.46 +
    1.47 +EXPORT_C TInt RFilePagePool::Flush()
    1.48 +/** Flushes the page cache and the file.
    1.49 +
    1.50 +@return KErrNone if successful, otherwise another of the system-wide error 
    1.51 +codes. */
    1.52 +	{
    1.53 +	TInt r=TCachePagePool::Flush();
    1.54 +	if (r==KErrNone)
    1.55 +		{
    1.56 +		r=iFile.Flush();
    1.57 +		}
    1.58 +	return r;
    1.59 +	}
    1.60 +
    1.61 +EXPORT_C void RFilePagePool::FlushL()
    1.62 +/** Flushes the page cache and the file, leaving with a system-wide error code 
    1.63 +if an error occurs. */
    1.64 +	{
    1.65 +	TCachePagePool::FlushL();
    1.66 +	__LEAVE_IF_ERROR(iFile.Flush());
    1.67 +	}
    1.68 +
    1.69 +EXPORT_C TPageRef RFilePagePool::ExtendL(const TAny* aPage,TPageReclamation)
    1.70 +	{
    1.71 +	TInt pos=0;
    1.72 +	__LEAVE_IF_ERROR(iFile.Seek(ESeekEnd,pos));
    1.73 +	__ASSERT_DEBUG(pos>=0,User::Invariant());
    1.74 +	if (pos%KPoolPageSize!=0)
    1.75 +		__LEAVE(KErrCorrupt);
    1.76 +//
    1.77 +	__LEAVE_IF_ERROR(iFile.Write(pos,TPtrC8((const TUint8*)aPage,KPoolPageSize)));
    1.78 +	return TPageRef(pos/KPoolPageSize+1);
    1.79 +	}
    1.80 +
    1.81 +EXPORT_C void RFilePagePool::WriteL(TPageRef aRef,const TAny* aPage,TPageChange)
    1.82 +	{
    1.83 +	TInt pos=(aRef.Value()-1)*KPoolPageSize;
    1.84 +	__LEAVE_IF_ERROR(iFile.Write(pos,TPtrC8((const TUint8*)aPage,KPoolPageSize)));
    1.85 +	}
    1.86 +
    1.87 +EXPORT_C void RFilePagePool::ReadL(TPageRef aRef,TAny* aPage)
    1.88 +	{
    1.89 +	TInt pos=(aRef.Value()-1)*KPoolPageSize;
    1.90 +	TPtr8 ptr((TUint8*)aPage,KPoolPageSize);
    1.91 +	__LEAVE_IF_ERROR(iFile.Read(pos,ptr));
    1.92 +	if (ptr.Length()<KPoolPageSize)
    1.93 +		__LEAVE(KErrEof);
    1.94 +	}
    1.95 +