|
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "UP_STD.H" |
|
17 #include <s32file.h> |
|
18 |
|
19 EXPORT_C RFilePagePool::RFilePagePool() |
|
20 /** Default constructor. */ |
|
21 {} |
|
22 |
|
23 EXPORT_C RFilePagePool::RFilePagePool(CPageCache& aCache) |
|
24 : TCachePagePool(aCache) |
|
25 /** Constructor with a page cache for the pool. |
|
26 |
|
27 @param aCache Page cache for the pool */ |
|
28 {} |
|
29 |
|
30 EXPORT_C void RFilePagePool::Close() |
|
31 /** Flushes cached pages to the file, and closes the file. */ |
|
32 { |
|
33 TCachePagePool::Flush(); |
|
34 Release(); |
|
35 } |
|
36 |
|
37 EXPORT_C void RFilePagePool::Release() |
|
38 /** Closes the file without flushing the cache. */ |
|
39 { |
|
40 Purge(); |
|
41 iFile.Close(); |
|
42 } |
|
43 |
|
44 EXPORT_C TInt RFilePagePool::Flush() |
|
45 /** Flushes the page cache and the file. |
|
46 |
|
47 @return KErrNone if successful, otherwise another of the system-wide error |
|
48 codes. */ |
|
49 { |
|
50 TInt r=TCachePagePool::Flush(); |
|
51 if (r==KErrNone) |
|
52 { |
|
53 r=iFile.Flush(); |
|
54 } |
|
55 return r; |
|
56 } |
|
57 |
|
58 EXPORT_C void RFilePagePool::FlushL() |
|
59 /** Flushes the page cache and the file, leaving with a system-wide error code |
|
60 if an error occurs. */ |
|
61 { |
|
62 TCachePagePool::FlushL(); |
|
63 __LEAVE_IF_ERROR(iFile.Flush()); |
|
64 } |
|
65 |
|
66 EXPORT_C TPageRef RFilePagePool::ExtendL(const TAny* aPage,TPageReclamation) |
|
67 { |
|
68 TInt pos=0; |
|
69 __LEAVE_IF_ERROR(iFile.Seek(ESeekEnd,pos)); |
|
70 __ASSERT_DEBUG(pos>=0,User::Invariant()); |
|
71 if (pos%KPoolPageSize!=0) |
|
72 __LEAVE(KErrCorrupt); |
|
73 // |
|
74 __LEAVE_IF_ERROR(iFile.Write(pos,TPtrC8((const TUint8*)aPage,KPoolPageSize))); |
|
75 return TPageRef(pos/KPoolPageSize+1); |
|
76 } |
|
77 |
|
78 EXPORT_C void RFilePagePool::WriteL(TPageRef aRef,const TAny* aPage,TPageChange) |
|
79 { |
|
80 TInt pos=(aRef.Value()-1)*KPoolPageSize; |
|
81 __LEAVE_IF_ERROR(iFile.Write(pos,TPtrC8((const TUint8*)aPage,KPoolPageSize))); |
|
82 } |
|
83 |
|
84 EXPORT_C void RFilePagePool::ReadL(TPageRef aRef,TAny* aPage) |
|
85 { |
|
86 TInt pos=(aRef.Value()-1)*KPoolPageSize; |
|
87 TPtr8 ptr((TUint8*)aPage,KPoolPageSize); |
|
88 __LEAVE_IF_ERROR(iFile.Read(pos,ptr)); |
|
89 if (ptr.Length()<KPoolPageSize) |
|
90 __LEAVE(KErrEof); |
|
91 } |
|
92 |