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