60
|
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 |
#ifdef USE_S60_TNM
|
|
60 |
, public MThumbnailManagerObserver
|
|
61 |
#endif
|
|
62 |
{
|
|
63 |
public:
|
|
64 |
/**
|
|
65 |
* Return a reference-counted instance of CGlxCacheManager. User MUST Close() this when finished with it.
|
|
66 |
* @return Singleton cache manager object
|
|
67 |
*/
|
|
68 |
static CGlxCacheManager* InstanceL();
|
|
69 |
|
|
70 |
/**
|
|
71 |
* Called when a media item has new attributes
|
|
72 |
* @param aIdSpaceId Id space of media item
|
|
73 |
* @param aMedia The media object
|
|
74 |
* @param aError Error
|
|
75 |
*/
|
|
76 |
void HandleCollectionMediaL(const TGlxIdSpaceId& aIdSpaceId, const CMPXMedia& aMedia, TInt aError, TBool aRequestNextAttr = ETrue);
|
|
77 |
|
|
78 |
/**
|
|
79 |
* Informs that focus in the window of the list has changed. The lists
|
|
80 |
* calls this function so that the manager knows to start updating the cache
|
|
81 |
* to load the now needed items.
|
|
82 |
*
|
|
83 |
* @param aList List that has changed
|
|
84 |
*/
|
|
85 |
void HandleWindowChangedL(CGlxMediaList* aList);
|
|
86 |
|
|
87 |
/**
|
|
88 |
* Handles modification of item in a cache
|
|
89 |
*
|
|
90 |
* @param aIdSpaceId Id space of the cache containing the media item
|
|
91 |
* @param aMediaId Media item id
|
|
92 |
* @param aAttributes Attributes that have been modified
|
|
93 |
*/
|
|
94 |
void HandleItemModified(const TGlxIdSpaceId& aIdSpaceId, const TGlxMediaId& aMediaId, const RArray<TMPXAttribute>& aAttributes);
|
|
95 |
|
|
96 |
/**
|
|
97 |
* Returns the temporary thumbnail used in a thumbnail request
|
|
98 |
* @return The temporary thumbnail used in a thumbnail request
|
|
99 |
* @deprecated Temporary solution - waiting for global chunk solution
|
|
100 |
*/
|
|
101 |
CFbsBitmap* TempThumbnail();
|
|
102 |
|
|
103 |
/**
|
|
104 |
* The Id of the temporary thumbnail used in a thumbnail request
|
|
105 |
* @return The Id of the temporary thumbnail used in a thumbnail request
|
|
106 |
* @deprecated Temporary solution - waiting for global chunk solution
|
|
107 |
*/
|
|
108 |
TGlxMediaId TempThumbnailId();
|
|
109 |
|
|
110 |
/**
|
|
111 |
* Sets the temporary thumbnail to NULL. Thumbnail is not deleted, use when ownership has transfered to
|
|
112 |
* another object
|
|
113 |
* @deprecated Temporary solution - waiting for global chunk solution
|
|
114 |
*/
|
|
115 |
void SetTempThumbnailToNull();
|
|
116 |
|
|
117 |
/**
|
|
118 |
* New attributes are available for a media item: broadcast this to all observers
|
|
119 |
* @param aIdSpaceId The Id Space of the item
|
|
120 |
* @param aMediaId The media id of the item
|
|
121 |
* @param aAttributes The new attributes
|
|
122 |
* @param aMedia The media item
|
|
123 |
*/
|
|
124 |
void BroadcastAttributesAvailableL(const TGlxIdSpaceId& aIdSpaceId,
|
|
125 |
const TGlxMediaId& aMediaId,
|
|
126 |
const RArray<TMPXAttribute>& aAttributes,
|
|
127 |
const CGlxMedia* aMedia);
|
|
128 |
|
|
129 |
/**
|
|
130 |
* Cleanup the media of the given media id: broadcast this to all observers
|
|
131 |
* @param aMediaId The media id of the item
|
|
132 |
*/
|
|
133 |
void CleanupMedia(const TGlxMediaId& aMediaId);
|
|
134 |
|
|
135 |
/**
|
|
136 |
* Returns an array of all id-space caches currently in use.
|
|
137 |
* @return Array of all id-space caches currently in use.
|
|
138 |
*/
|
|
139 |
const RPointerArray<CGlxCache>& Caches();
|
|
140 |
|
|
141 |
/**
|
|
142 |
* Sets the temporary error flag. When set, this indicates that there is at least one temporary
|
|
143 |
* error on an item in the cache.
|
|
144 |
*/
|
|
145 |
void SetTemporaryErrorFlag();
|
|
146 |
|
|
147 |
/**
|
|
148 |
* Informs that a media list has been deleted. The lists
|
|
149 |
* calls this function so that the manager can check to
|
|
150 |
* see if the last request was from this list. If so, it
|
|
151 |
* should reset and continue with requests from other lists
|
|
152 |
*
|
|
153 |
* @param aList List that has been deleted
|
|
154 |
*/
|
|
155 |
void HandleListDeleted(CGlxMediaList* aList);
|
|
156 |
|
|
157 |
/**
|
|
158 |
* Inform cache manager to reserve space for a number of users
|
|
159 |
* for all items in a particular cache
|
|
160 |
*
|
|
161 |
* @param aIdSpaceId The Id space Id to determine which cache to reserve users
|
|
162 |
* @param aCount The number of users to reserve space for
|
|
163 |
*/
|
|
164 |
void ReserveUsersL(const TGlxIdSpaceId& aIdSpaceId, TInt aCount);
|
|
165 |
|
|
166 |
/**
|
|
167 |
* Check if the media item selected is NULL.
|
|
168 |
* If media item is NULL, cancel the pending requests
|
|
169 |
* and place a new request
|
|
170 |
*/
|
|
171 |
void CancelPreviousRequest();
|
|
172 |
|
|
173 |
public: // From MGlxCache
|
|
174 |
CGlxMedia* Media( const TGlxIdSpaceId& aIdSpaceId,
|
|
175 |
const TGlxMediaId& aMediaId ) const;
|
|
176 |
void AddObserverL( MGlxCacheObserver* aObserver );
|
|
177 |
void RemoveObserver( MGlxCacheObserver* aObserver );
|
|
178 |
void RefreshL();
|
|
179 |
void Close();
|
|
180 |
//OOM
|
|
181 |
void ReleaseRAML(TBool aFlushOnRequest = EFalse);
|
|
182 |
void StopRAMReleaseL();
|
|
183 |
//OOM
|
|
184 |
void ForceCleanupMedia(TGlxIdSpaceId aSpaceId,TGlxMediaId aId);
|
|
185 |
|
|
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 |
/**
|
|
291 |
* Gets the mime type of a given file.
|
|
292 |
* @param aFileName The file name for which a MIME type to be determined
|
|
293 |
* @aMimeType The MIME type associated with the given file will be returned
|
|
294 |
*/
|
|
295 |
void GetMimeTypeL(TFileName& aFileName, TDataType& aMimeType );
|
|
296 |
|
|
297 |
/**
|
|
298 |
* Creates the image viewer instance, if not created already.
|
|
299 |
*/
|
|
300 |
void CreateImageViewerInstanceL();
|
|
301 |
|
|
302 |
/**
|
|
303 |
* Deletes the image viewer instance, if created already.
|
|
304 |
*/
|
|
305 |
void DeleteImageViewerInstance();
|
|
306 |
|
|
307 |
#ifdef USE_S60_TNM
|
|
308 |
/*
|
|
309 |
* This function doesnt add up any value, added to reduce compiler warnings
|
|
310 |
*/
|
|
311 |
void ThumbnailReadyL(TInt aError, MThumbnailData& aThumbnail,
|
|
312 |
TThumbnailRequestId aId, TBool aQuality);
|
|
313 |
|
|
314 |
private: // From MThumbnailManagerObserver
|
|
315 |
|
|
316 |
void ThumbnailPreviewReady( MThumbnailData& aThumbnail,
|
|
317 |
TThumbnailRequestId aId );
|
|
318 |
void ThumbnailReady( TInt aError, MThumbnailData& aThumbnail,
|
|
319 |
TThumbnailRequestId aId );
|
|
320 |
|
|
321 |
TInt FindLoadingById(TThumbnailRequestId aId, TBool aRemove = EFalse);
|
|
322 |
#endif
|
|
323 |
|
|
324 |
private:
|
|
325 |
/// Single instance of the cache manager
|
|
326 |
static CGlxCacheManager* iCacheManager;
|
|
327 |
|
|
328 |
/// Current reference count
|
|
329 |
TInt iReferenceCount;
|
|
330 |
|
|
331 |
/// List of observers, not owned
|
|
332 |
RPointerArray<MGlxCacheObserver> iObserverList;
|
|
333 |
|
|
334 |
/// Caches, one per Id space. Owned.
|
|
335 |
RPointerArray<CGlxCache> iCaches;
|
|
336 |
|
|
337 |
/// Bitmap for pending thumbnail request
|
|
338 |
CFbsBitmap* iTempThumbnail;
|
|
339 |
/// ID of item whose thumbnail was requested
|
|
340 |
TGlxMediaId iThumbnailId;
|
|
341 |
|
|
342 |
/// Information if a request has been made to collection which
|
|
343 |
/// has not complete yet. (Currently, only one request is made at a time)
|
|
344 |
/// Stores the media list that owns the request
|
|
345 |
CGlxMediaList* iRequestOwner;
|
|
346 |
|
|
347 |
/// The requested Ids in the current request
|
|
348 |
RArray<TGlxMediaId> iRequestedItemIds;
|
|
349 |
/// The requested attributes in the current request
|
|
350 |
RArray<TMPXAttribute> iRequestedAttrs;
|
|
351 |
/// The Id Space of the items in the current request
|
|
352 |
TGlxIdSpaceId iRequestedItemsIdSpace;
|
|
353 |
|
|
354 |
/// Garbage collector
|
|
355 |
CGlxGarbageCollector* iGarbageCollector;
|
|
356 |
|
|
357 |
/// Temporary error flag
|
|
358 |
TBool iTempError;
|
|
359 |
|
|
360 |
// Clean up is On Going- Timer Started Or it is Cleaning Up
|
|
361 |
TBool iCleanUpOnGoing;
|
|
362 |
|
|
363 |
/// Temporary error timer
|
|
364 |
CPeriodic* iTempErrorTimer;
|
|
365 |
|
|
366 |
CAsyncCallBack* iMaintainCacheCallback;
|
|
367 |
|
|
368 |
RArray<TInt> iRequestedItemIndexes;
|
|
369 |
|
|
370 |
CGlxImageReader* iReader;
|
|
371 |
|
|
372 |
// For image viewer, not own
|
|
373 |
CGlxImageViewerManager* iImageViewerInstance;
|
|
374 |
|
|
375 |
#ifdef USE_S60_TNM
|
|
376 |
CThumbnailManager* iTnEngine; // Own
|
|
377 |
|
|
378 |
CMPXMedia* iMPXMedia;
|
|
379 |
|
|
380 |
// Loading information
|
|
381 |
class TLoadingTN
|
|
382 |
{
|
|
383 |
public:
|
|
384 |
TLoadingTN(TThumbnailRequestId aId, TGlxIdSpaceId aSpaceId,
|
|
385 |
TSize aSize, TGlxMediaId aThumbnailId)
|
|
386 |
: iId(aId), iSpaceId(aSpaceId),
|
|
387 |
iSize(aSize), iThumbnailId(aThumbnailId)
|
|
388 |
{
|
|
389 |
}
|
|
390 |
|
|
391 |
TThumbnailRequestId iId;
|
|
392 |
TGlxIdSpaceId iSpaceId;
|
|
393 |
TSize iSize;
|
|
394 |
TGlxMediaId iThumbnailId;
|
|
395 |
};
|
|
396 |
|
|
397 |
RArray<TLoadingTN> iThumbnailRequestIds;
|
|
398 |
#endif
|
|
399 |
|
|
400 |
#ifdef _DEBUG
|
|
401 |
TTime iStartTime;
|
|
402 |
TTime iStopTime;
|
|
403 |
#endif
|
|
404 |
};
|
|
405 |
|
|
406 |
#endif // C_GLXCACHEMANAGER_H
|