|
1 // Copyright (c) 2008-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 the License "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 // f32\sfat\sl_dir_cache.inl |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalTechnology |
|
21 */ |
|
22 |
|
23 #ifndef SL_DIR_CACHE_INL |
|
24 #define SL_DIR_CACHE_INL |
|
25 |
|
26 #include "sl_dir_cache.h" |
|
27 |
|
28 /** |
|
29 Get function of TDynamicDirCachePage. |
|
30 @return TInt64 the starting media address of the page content. |
|
31 */ |
|
32 TInt64 TDynamicDirCachePage::StartPos() const |
|
33 { |
|
34 return iStartMedPos; |
|
35 } |
|
36 |
|
37 /** |
|
38 Get function of TDynamicDirCachePage. |
|
39 @return TUint8* the starting ram content of the page content. |
|
40 */ |
|
41 TUint8* TDynamicDirCachePage::StartPtr() const |
|
42 { |
|
43 return iStartRamAddr; |
|
44 } |
|
45 |
|
46 /** |
|
47 Set function of TDynamicDirCachePage. |
|
48 @param aPtr starting RAM Ptr that holds the cache page data. |
|
49 */ |
|
50 void TDynamicDirCachePage::SetStartPtr(TUint8* aPtr) |
|
51 { |
|
52 iStartRamAddr = aPtr; |
|
53 } |
|
54 |
|
55 /** |
|
56 Set function of TDynamicDirCachePage. |
|
57 @param aIsValid boolean value to set validity of the page content. |
|
58 */ |
|
59 void TDynamicDirCachePage::SetValid(TBool aIsValid) |
|
60 { |
|
61 iValid = aIsValid; |
|
62 } |
|
63 |
|
64 /** |
|
65 Get function of TDynamicDirCachePage. |
|
66 @return TBool boolean value that indicates validity of the page content. |
|
67 */ |
|
68 TBool TDynamicDirCachePage::IsValid() const |
|
69 { |
|
70 return iValid; |
|
71 } |
|
72 |
|
73 /** |
|
74 Set function of TDynamicDirCachePage. |
|
75 @param aLocked flag that sets if the page is locked or not. |
|
76 */ |
|
77 void TDynamicDirCachePage::SetLocked(TBool aLocked) |
|
78 { |
|
79 iLocked = aLocked; |
|
80 } |
|
81 |
|
82 /** |
|
83 Get function of TDynamicDirCachePage. |
|
84 @return TBool boolean value that indicates if the page is locked. |
|
85 */ |
|
86 TBool TDynamicDirCachePage::IsLocked() const |
|
87 { |
|
88 return iLocked; |
|
89 } |
|
90 |
|
91 /** |
|
92 Set function of TDynamicDirCachePage. |
|
93 @param aType set page type: EUnknown, ELocked, EUnlocked or EActivePage. |
|
94 */ |
|
95 void TDynamicDirCachePage::SetPageType(TDynamicDirCachePage::TPageType aType) |
|
96 { |
|
97 iType = aType; |
|
98 } |
|
99 |
|
100 /** |
|
101 Get function of TDynamicDirCachePage. |
|
102 @return TPageType get page type: EUnknown, ELocked, EUnlocked or EActivePage. |
|
103 */ |
|
104 TDynamicDirCachePage::TPageType TDynamicDirCachePage::PageType() |
|
105 { |
|
106 return iType; |
|
107 } |
|
108 |
|
109 /** |
|
110 Get function of TDynamicDirCachePage. |
|
111 @return TUint32 page size in bytes. |
|
112 */ |
|
113 TUint32 TDynamicDirCachePage::PageSizeInBytes() const |
|
114 { |
|
115 return 1 << iOwnerCache->PageSizeInBytesLog2(); |
|
116 } |
|
117 |
|
118 /** |
|
119 Deque the page from its queue. |
|
120 @see TDblQueLink::Deque() |
|
121 */ |
|
122 void TDynamicDirCachePage::Deque() |
|
123 { |
|
124 iLink.Deque(); |
|
125 } |
|
126 |
|
127 /** |
|
128 Get function of TDynamicDirCachePage. |
|
129 @return TUint32 page size in segments. |
|
130 */ |
|
131 TUint32 TDynamicDirCachePage::PageSizeInSegs() const |
|
132 { |
|
133 return iOwnerCache->PageSizeInSegs(); |
|
134 } |
|
135 |
|
136 /** |
|
137 Interpret the media address into ram address. |
|
138 @param aPos the media address to be interpreted |
|
139 @return TUint8* the ram content pointer that contains that media content. |
|
140 */ |
|
141 TUint8* TDynamicDirCachePage::PtrInPage(TInt64 aPos) const |
|
142 { |
|
143 ASSERT(PosCachedInPage(aPos)); |
|
144 return iStartRamAddr + (((TUint32)aPos - (TUint32)iStartMedPos) & (PageSizeInBytes() - 1)); |
|
145 } |
|
146 |
|
147 /** |
|
148 Query function, to check if the media address is contained in the page. |
|
149 @param aPos the media address to be queried. |
|
150 @return TBool ETrue if the media address is cached in the page, otherwise EFalse. |
|
151 */ |
|
152 TBool TDynamicDirCachePage::PosCachedInPage(TInt64 aPos) const |
|
153 { |
|
154 return (aPos >= iStartMedPos && aPos < iStartMedPos + PageSizeInBytes()); |
|
155 } |
|
156 |
|
157 /** |
|
158 Reset the media address to 0, invalidate page content. |
|
159 */ |
|
160 void TDynamicDirCachePage::ResetPos() |
|
161 { |
|
162 iStartMedPos = 0; |
|
163 SetValid(EFalse); |
|
164 } |
|
165 |
|
166 /** |
|
167 Set page starting media address, invalidate page content. |
|
168 @param aPos the new media address to be set. |
|
169 */ |
|
170 void TDynamicDirCachePage::SetPos(TInt64 aPos) |
|
171 { |
|
172 iStartMedPos = aPos; |
|
173 SetValid(EFalse); |
|
174 return; |
|
175 } |
|
176 |
|
177 |
|
178 //======================================================================== |
|
179 /** |
|
180 Calculate the page starting media address, aligned with page size. |
|
181 @param aPos the media address to be aligned. |
|
182 @return TInt64 the aligned media address. |
|
183 */ |
|
184 TInt64 CDynamicDirCache::CalcPageStartPos(TInt64 aPos) const |
|
185 { |
|
186 ASSERT(aPos >= iCacheBasePos); |
|
187 return (((aPos - iCacheBasePos) >> iPageSizeLog2) << iPageSizeLog2) + iCacheBasePos; |
|
188 } |
|
189 |
|
190 /** |
|
191 Check if the cache has reached its limited page number. |
|
192 @return TBool ETrue if cache is full, otherwise EFalse. |
|
193 */ |
|
194 TBool CDynamicDirCache::CacheIsFull() const |
|
195 { |
|
196 // active page, locked page and unlocked page |
|
197 return (iLockedQCount + iUnlockedQCount + 1 >= iMaxSizeInPages); |
|
198 } |
|
199 |
|
200 /** |
|
201 Return the maximum allowed page number of the cache. |
|
202 */ |
|
203 TUint32 CDynamicDirCache::MaxCacheSizeInPages() const |
|
204 { |
|
205 return iMaxSizeInPages; |
|
206 } |
|
207 |
|
208 #endif //SL_DIR_CACHE_INL |
|
209 |