|
1 /* |
|
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Manager of media item cache |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #ifndef C_GLXCACHEMANAGER_H |
|
22 #define C_GLXCACHEMANAGER_H |
|
23 |
|
24 #include <e32base.h> |
|
25 |
|
26 #include "mglxcache.h" |
|
27 #include "mglxcacheobserver.h" |
|
28 #include "mglxmediapool.h" |
|
29 #include "glximagereader.h" |
|
30 |
|
31 #include <apmstd.h> |
|
32 |
|
33 #ifdef USE_S60_TNM |
|
34 #include <thumbnailmanager.h> |
|
35 #include <thumbnailmanagerobserver.h> |
|
36 #endif |
|
37 |
|
38 // Forward declarations |
|
39 class CFbsBitmap; |
|
40 class CGlxCache; |
|
41 class CGlxGarbageCollector; |
|
42 class CGlxMedia; |
|
43 class CGlxMediaList; |
|
44 class CMPXCollectionPath; |
|
45 class CMPXMedia; |
|
46 class MGlxMediaList; |
|
47 class CGlxImageViewerManager; |
|
48 |
|
49 /** |
|
50 * CGlxCacheManager |
|
51 * |
|
52 * Manager of item caches |
|
53 * |
|
54 * @lib glxmedialists.lib |
|
55 */ |
|
56 class CGlxCacheManager : public CBase, |
|
57 public MGlxCache, |
|
58 public MGlxMediaPool, |
|
59 public MImageReadyCallBack |
|
60 #ifdef USE_S60_TNM |
|
61 , public MThumbnailManagerObserver |
|
62 #endif |
|
63 { |
|
64 public: |
|
65 /** |
|
66 * Return a reference-counted instance of CGlxCacheManager. User MUST Close() this when finished with it. |
|
67 * @return Singleton cache manager object |
|
68 */ |
|
69 static CGlxCacheManager* InstanceL(); |
|
70 |
|
71 /** |
|
72 * Called when a media item has new attributes |
|
73 * @param aIdSpaceId Id space of media item |
|
74 * @param aMedia The media object |
|
75 * @param aError Error |
|
76 */ |
|
77 void HandleCollectionMediaL(const TGlxIdSpaceId& aIdSpaceId, const CMPXMedia& aMedia, TInt aError); |
|
78 |
|
79 /** |
|
80 * Informs that focus in the window of the list has changed. The lists |
|
81 * calls this function so that the manager knows to start updating the cache |
|
82 * to load the now needed items. |
|
83 * |
|
84 * @param aList List that has changed |
|
85 */ |
|
86 void HandleWindowChangedL(CGlxMediaList* aList); |
|
87 |
|
88 /** |
|
89 * Handles modification of item in a cache |
|
90 * |
|
91 * @param aIdSpaceId Id space of the cache containing the media item |
|
92 * @param aMediaId Media item id |
|
93 * @param aAttributes Attributes that have been modified |
|
94 */ |
|
95 void HandleItemModified(const TGlxIdSpaceId& aIdSpaceId, const TGlxMediaId& aMediaId, const RArray<TMPXAttribute>& aAttributes); |
|
96 |
|
97 /** |
|
98 * Returns the temporary thumbnail used in a thumbnail request |
|
99 * @return The temporary thumbnail used in a thumbnail request |
|
100 * @deprecated Temporary solution - waiting for global chunk solution |
|
101 */ |
|
102 CFbsBitmap* TempThumbnail(); |
|
103 |
|
104 /** |
|
105 * The Id of the temporary thumbnail used in a thumbnail request |
|
106 * @return The Id of the temporary thumbnail used in a thumbnail request |
|
107 * @deprecated Temporary solution - waiting for global chunk solution |
|
108 */ |
|
109 TGlxMediaId TempThumbnailId(); |
|
110 |
|
111 /** |
|
112 * Sets the temporary thumbnail to NULL. Thumbnail is not deleted, use when ownership has transfered to |
|
113 * another object |
|
114 * @deprecated Temporary solution - waiting for global chunk solution |
|
115 */ |
|
116 void SetTempThumbnailToNull(); |
|
117 |
|
118 /** |
|
119 * New attributes are available for a media item: broadcast this to all observers |
|
120 * @param aIdSpaceId The Id Space of the item |
|
121 * @param aMediaId The media id of the item |
|
122 * @param aAttributes The new attributes |
|
123 * @param aMedia The media item |
|
124 */ |
|
125 void BroadcastAttributesAvailableL(const TGlxIdSpaceId& aIdSpaceId, |
|
126 const TGlxMediaId& aMediaId, |
|
127 const RArray<TMPXAttribute>& aAttributes, |
|
128 const CGlxMedia* aMedia); |
|
129 |
|
130 /** |
|
131 * Cleanup the media of the given media id: broadcast this to all observers |
|
132 * @param aMediaId The media id of the item |
|
133 */ |
|
134 void CleanupMedia(const TGlxMediaId& aMediaId); |
|
135 |
|
136 /** |
|
137 * Returns an array of all id-space caches currently in use. |
|
138 * @return Array of all id-space caches currently in use. |
|
139 */ |
|
140 const RPointerArray<CGlxCache>& Caches(); |
|
141 |
|
142 /** |
|
143 * Sets the temporary error flag. When set, this indicates that there is at least one temporary |
|
144 * error on an item in the cache. |
|
145 */ |
|
146 void SetTemporaryErrorFlag(); |
|
147 |
|
148 /** |
|
149 * Informs that a media list has been deleted. The lists |
|
150 * calls this function so that the manager can check to |
|
151 * see if the last request was from this list. If so, it |
|
152 * should reset and continue with requests from other lists |
|
153 * |
|
154 * @param aList List that has been deleted |
|
155 */ |
|
156 void HandleListDeleted(CGlxMediaList* aList); |
|
157 |
|
158 /** |
|
159 * Inform cache manager to reserve space for a number of users |
|
160 * for all items in a particular cache |
|
161 * |
|
162 * @param aIdSpaceId The Id space Id to determine which cache to reserve users |
|
163 * @param aCount The number of users to reserve space for |
|
164 */ |
|
165 void ReserveUsersL(const TGlxIdSpaceId& aIdSpaceId, TInt aCount); |
|
166 |
|
167 /** |
|
168 * Check if the media item selected is NULL. |
|
169 * If media item is NULL, cancel the pending requests |
|
170 * and place a new request |
|
171 */ |
|
172 void CancelPreviousRequest(); |
|
173 |
|
174 public: // From MGlxCache |
|
175 CGlxMedia* Media( const TGlxIdSpaceId& aIdSpaceId, |
|
176 const TGlxMediaId& aMediaId ) const; |
|
177 void AddObserverL( MGlxCacheObserver* aObserver ); |
|
178 void RemoveObserver( MGlxCacheObserver* aObserver ); |
|
179 void RefreshL(); |
|
180 void Close(); |
|
181 //OOM |
|
182 void ReleaseRAML(TBool aFlushOnRequest = EFalse); |
|
183 void StopRAMReleaseL(); |
|
184 //OOM |
|
185 void ForceCleanupMedia(TGlxIdSpaceId aSpaceId,TGlxMediaId aId); |
|
186 |
|
187 public: |
|
188 void ImageSizeReady(TInt aError, const TSize aSz); |
|
189 |
|
190 private: |
|
191 /** |
|
192 * Constructor |
|
193 */ |
|
194 CGlxCacheManager(); |
|
195 |
|
196 /** |
|
197 * All Garbage Clean-up,Cancel Garbage Cleanup is Centralised Here |
|
198 * It can be used to Cancel Garbage if there is Enough Memory Else it starts Flushing 30 items Together, |
|
199 * It can be used to start Garbage Clean-up if there is Not Enough Memory |
|
200 * |
|
201 * @param aStart |
|
202 */ |
|
203 void HandleGarbageCollectionL(TBool aStart); |
|
204 |
|
205 /** |
|
206 * Two-phase construction |
|
207 */ |
|
208 static CGlxCacheManager* NewL(); |
|
209 |
|
210 /** |
|
211 * Second-phase constructor |
|
212 */ |
|
213 void ConstructL(); |
|
214 |
|
215 /** |
|
216 * Destructor |
|
217 */ |
|
218 virtual ~CGlxCacheManager(); |
|
219 |
|
220 /** |
|
221 * Deletes unused items in all id-space caches, requests new attributes |
|
222 */ |
|
223 void MaintainCacheL(); |
|
224 static TInt MaintainCacheL(TAny* aPtr); |
|
225 |
|
226 /** |
|
227 * Compares two paths to see if their levels match |
|
228 */ |
|
229 static TBool Match(const CMPXCollectionPath& aPath1, const CMPXCollectionPath& aPath2); |
|
230 |
|
231 /** |
|
232 * Returns the cache for the given id space. Create one if it doesn't exist. |
|
233 * @param aIdSpaceId The id space |
|
234 * @return The cache for the id space |
|
235 */ |
|
236 CGlxCache* FindCacheForceCreateL(const TGlxIdSpaceId& aIdSpaceId); |
|
237 |
|
238 /** |
|
239 * Finds a media item based on id-space and media id. Creates one if none found |
|
240 * @param aIdSpaceId The id space of the media item |
|
241 * @param aMediaId The id of the media item |
|
242 * @return The media item |
|
243 */ |
|
244 CGlxMedia* MediaForceCreateL(const TGlxIdSpaceId& aIdSpaceId, const TGlxMediaId& aMediaId); |
|
245 |
|
246 /** |
|
247 * Function for TLinearOrder() for comparing two CGlxCaches |
|
248 * Used from ordering iCaches by id-space id |
|
249 * @param aItem1 The first item to compare |
|
250 * @param aItem2 The second item to compare |
|
251 * @return -1 if aItem1 < aItem2; 1 if aItem1 > aItem2; 0 if aItem1 == aItem2 |
|
252 */ |
|
253 static TInt CacheOrderById(const CGlxCache& aItem1, const CGlxCache& aItem2); |
|
254 |
|
255 /** |
|
256 * Function for comparing a TGlxIdSpaceId with a CGlxCache |
|
257 * Used from ordering iCaches by id-space id |
|
258 * @param aIdSpaceId The id space id to compare against aItem2 |
|
259 * @param aItem2 The second item to compare |
|
260 * @return -1 if aIdSpaceId < aItem2.Id(); 1 if aIdSpaceId > aItem2.Id(); 0 if aIdSpaceId == aItem2.Id() |
|
261 */ |
|
262 static TInt CacheOrderByKey(const TGlxIdSpaceId* aIdSpaceId, const CGlxCache& aItem2); |
|
263 |
|
264 /** |
|
265 * Returns whether any requests are being made on errored attributes |
|
266 * @return Whether any requests are being made on errored attributes |
|
267 */ |
|
268 TBool ErrorsOnRequestedItemsL(); |
|
269 |
|
270 /** |
|
271 * Timer callback for temporary error reminder |
|
272 * @param aPtr Pointer to object that started the timer |
|
273 * @return 0 to signal that further callbacks are unnecessary, 1 otherwise |
|
274 */ |
|
275 static TInt TempErrorTimerCallbackL(TAny* aPtr); |
|
276 |
|
277 /** |
|
278 * Starts the temporary error timer. When complete, the caches are checked again for any missing attributes |
|
279 */ |
|
280 void StartTempErrorTimer(); |
|
281 |
|
282 /** |
|
283 * Called when the temporary error timer completes: forces a re-examination of all caches |
|
284 */ |
|
285 void TempErrorTimerCompleteL(); |
|
286 |
|
287 /** |
|
288 * Create a path with the request items |
|
289 * |
|
290 * @param aList list to obtain the path |
|
291 */ |
|
292 CMPXCollectionPath* RequestAsPathLC(const CGlxMediaList& aList); |
|
293 |
|
294 /** |
|
295 * Gets the mime type of a given file. |
|
296 * @param aFileName The file name for which a MIME type to be determined |
|
297 * @aMimeType The MIME type associated with the given file will be returned |
|
298 */ |
|
299 void GetMimeTypeL(TFileName& aFileName, TDataType& aMimeType ); |
|
300 |
|
301 |
|
302 #ifdef USE_S60_TNM |
|
303 /* |
|
304 * This function doesnt add up any value, added to reduce compiler warnings |
|
305 */ |
|
306 void ThumbnailReadyL(TInt aError, MThumbnailData& aThumbnail, |
|
307 TThumbnailRequestId aId, TBool aQuality); |
|
308 |
|
309 private: // From MThumbnailManagerObserver |
|
310 |
|
311 void ThumbnailPreviewReady( MThumbnailData& aThumbnail, |
|
312 TThumbnailRequestId aId ); |
|
313 void ThumbnailReady( TInt aError, MThumbnailData& aThumbnail, |
|
314 TThumbnailRequestId aId ); |
|
315 |
|
316 TInt FindLoadingById(TThumbnailRequestId aId, TBool aRemove = EFalse); |
|
317 #endif |
|
318 |
|
319 private: |
|
320 /// Single instance of the cache manager |
|
321 static CGlxCacheManager* iCacheManager; |
|
322 |
|
323 /// Current reference count |
|
324 TInt iReferenceCount; |
|
325 |
|
326 /// List of observers, not owned |
|
327 RPointerArray<MGlxCacheObserver> iObserverList; |
|
328 |
|
329 /// Caches, one per Id space. Owned. |
|
330 RPointerArray<CGlxCache> iCaches; |
|
331 |
|
332 /// Bitmap for pending thumbnail request |
|
333 CFbsBitmap* iTempThumbnail; |
|
334 /// ID of item whose thumbnail was requested |
|
335 TGlxMediaId iThumbnailId; |
|
336 |
|
337 /// Information if a request has been made to collection which |
|
338 /// has not complete yet. (Currently, only one request is made at a time) |
|
339 /// Stores the media list that owns the request |
|
340 CGlxMediaList* iRequestOwner; |
|
341 |
|
342 /// The requested Ids in the current request |
|
343 RArray<TGlxMediaId> iRequestedItemIds; |
|
344 /// The requested attributes in the current request |
|
345 RArray<TMPXAttribute> iRequestedAttrs; |
|
346 /// The Id Space of the items in the current request |
|
347 TGlxIdSpaceId iRequestedItemsIdSpace; |
|
348 |
|
349 /// Garbage collector |
|
350 CGlxGarbageCollector* iGarbageCollector; |
|
351 |
|
352 /// Temporary error flag |
|
353 TBool iTempError; |
|
354 |
|
355 // Clean up is On Going- Timer Started Or it is Cleaning Up |
|
356 TBool iCleanUpOnGoing; |
|
357 |
|
358 /// Temporary error timer |
|
359 CPeriodic* iTempErrorTimer; |
|
360 |
|
361 CAsyncCallBack* iMaintainCacheCallback; |
|
362 |
|
363 RArray<TInt> iRequestedItemIndexes; |
|
364 CGlxImageReader* iReader; |
|
365 TSize iImgSz; |
|
366 /** |
|
367 * Active scheduler wait object. (Owned) |
|
368 */ |
|
369 CActiveSchedulerWait* iSchedulerWait; |
|
370 #ifdef USE_S60_TNM |
|
371 CThumbnailManager* iTnEngine; // Own |
|
372 CMPXMedia* iMPXMedia; |
|
373 |
|
374 // Loading information |
|
375 class TLoadingTN |
|
376 { |
|
377 public: |
|
378 TLoadingTN(TThumbnailRequestId aId, TGlxIdSpaceId aSpaceId, |
|
379 TSize aSize, TGlxMediaId aThumbnailId) |
|
380 : iId(aId), iSpaceId(aSpaceId), |
|
381 iSize(aSize), iThumbnailId(aThumbnailId) |
|
382 { |
|
383 } |
|
384 |
|
385 TThumbnailRequestId iId; |
|
386 TGlxIdSpaceId iSpaceId; |
|
387 TSize iSize; |
|
388 TGlxMediaId iThumbnailId; |
|
389 }; |
|
390 |
|
391 RArray<TLoadingTN> iThumbnailRequestIds; |
|
392 #endif |
|
393 |
|
394 #ifdef _DEBUG |
|
395 TTime iStartTime; |
|
396 TTime iStopTime; |
|
397 #endif |
|
398 }; |
|
399 |
|
400 #endif // C_GLXCACHEMANAGER_H |