|
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: Cache implementation for media items sharing the same Id space |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #ifndef C_GLXCACHE_H |
|
22 #define C_GLXCACHE_H |
|
23 |
|
24 #include <e32base.h> |
|
25 |
|
26 #include "glxmediaid.h" |
|
27 |
|
28 // Forward declarations |
|
29 class CMPXMedia; |
|
30 class CGlxMedia; |
|
31 class T_CacheTestHelpers; |
|
32 class TMPXAttribute; |
|
33 class CGlxCacheManager; |
|
34 |
|
35 /** |
|
36 * CGlxCache |
|
37 * |
|
38 * Individual cache of media items sharing the same Id space |
|
39 */ |
|
40 NONSHARABLE_CLASS( CGlxCache ) : public CBase |
|
41 { |
|
42 public: |
|
43 /** |
|
44 * Constructor |
|
45 * @param aIdSpaceId The id of the id address space of this cache |
|
46 * @param aCacheManager Instance of cachemanager to cleanup the media |
|
47 */ |
|
48 CGlxCache( const TGlxIdSpaceId& aIdSpaceId, CGlxCacheManager* aCacheManager ); |
|
49 |
|
50 /** |
|
51 * Destructor |
|
52 */ |
|
53 ~CGlxCache(); |
|
54 |
|
55 /** |
|
56 * Returns the Id space covered by this cache |
|
57 * @return The Id space covered by this cache |
|
58 */ |
|
59 TGlxIdSpaceId IdSpaceId() const; |
|
60 |
|
61 /** |
|
62 * Notify the cache that attributes have changed on media item(s) |
|
63 * @param aMedia The updated media item or array of updated media items |
|
64 */ |
|
65 void MediaUpdatedL( const CMPXMedia& aMedia ); |
|
66 |
|
67 /** |
|
68 * Update media item |
|
69 * |
|
70 * @param aMedia The updated media item |
|
71 */ |
|
72 void UpdateMediaL( const CMPXMedia& aMedia ); |
|
73 |
|
74 /** |
|
75 * Cleanup the media of the given media id: broadcast this to all observers |
|
76 * @param aMediaId The media id of the item |
|
77 */ |
|
78 void CleanupMedia(const TGlxMediaId& aMediaId); |
|
79 |
|
80 /** |
|
81 * Handles modifications of item in cache |
|
82 * |
|
83 * @param aId Media item id |
|
84 * @param aAttributes Attributes that have been modified |
|
85 */ |
|
86 void HandleItemModified( const TGlxMediaId& aId, const RArray<TMPXAttribute>& aAttributes ); |
|
87 |
|
88 /** |
|
89 * Access to the items stored in the cache: return the item matching the given media Id |
|
90 * @param aId The media Id |
|
91 * @return The media item, or NULL if not found |
|
92 */ |
|
93 CGlxMedia* Media( const TGlxMediaId& aId ) const; |
|
94 |
|
95 /** |
|
96 * Access to the items stored in the cache: return the item matching the given media Id. |
|
97 * If not found, a new item is created |
|
98 * @param aId The media Id |
|
99 * @return The media item |
|
100 */ |
|
101 CGlxMedia* FindItemForceCreateL( const TGlxMediaId& aId ); |
|
102 |
|
103 /** |
|
104 * Number of items in cache |
|
105 * @return Number of items in cache |
|
106 */ |
|
107 TInt Count(); |
|
108 |
|
109 /** |
|
110 * Cached item by index |
|
111 * @param aIndex index of the item |
|
112 * @return Cached item |
|
113 */ |
|
114 CGlxMedia& Media( TInt aIndex ); |
|
115 |
|
116 /** |
|
117 * Delete an item at index from the cache. |
|
118 * @param aIndex Index of the item to delete |
|
119 */ |
|
120 void Delete( TInt aIndex ); |
|
121 |
|
122 /** |
|
123 * Reserve space for a number of users, for all items in the cache |
|
124 * |
|
125 * @param aCount The number of users to reserve space for |
|
126 */ |
|
127 void ReserveUsersL( TInt aCount ); |
|
128 |
|
129 /** |
|
130 * Finds the media index present in cache |
|
131 * @returns the index of media |
|
132 */ |
|
133 TInt FindMediaIndexInCache(TGlxMediaId aMediaId); |
|
134 |
|
135 private: |
|
136 /** |
|
137 * Copy the new and modified attributes from aSource to aTarget |
|
138 * @param aTarget The target media item |
|
139 * @param aSource The source media item |
|
140 * @param aNewAttributes The new and modified attributes |
|
141 */ |
|
142 void CopyNewAndModifiedL( CGlxMedia& aTarget, const CMPXMedia& aSource, |
|
143 RArray<TMPXAttribute>& aNewAttributes ); |
|
144 |
|
145 /** |
|
146 * Function for TLinearOrder() for comparing two CGlxMedias |
|
147 * Used from ordering the iItemPool by id |
|
148 * @param aItem1 The first item to compare |
|
149 * @param aItem2 The second item to compare |
|
150 * @return -1 if aItem1 < aItem2; 1 if aItem1 > aItem2; 0 if aItem1 == aItem2 |
|
151 */ |
|
152 static TInt MediaItemOrderById( const CGlxMedia& aItem1, const CGlxMedia& aItem2 ); |
|
153 |
|
154 /** |
|
155 * Function for comparing a TGlxMediaId with a CGlxMedia |
|
156 * Used from ordering iItemPool by media id |
|
157 * @param aMediaId The media id to compare against aItem2 |
|
158 * @param aItem2 The second item to compare |
|
159 * @return -1 if aMediaId < aItem2.Id(); 1 if aMediaId > aItem2.Id(); 0 if aMediaId == aItem2.Id() |
|
160 */ |
|
161 static TInt MediaItemOrderByKey( const TGlxMediaId* aMediaId, const CGlxMedia& aItem2 ); |
|
162 |
|
163 /** |
|
164 * Create and add an item to the item pool |
|
165 * @param aId Id for the new item |
|
166 * @return Pointer to the created item |
|
167 */ |
|
168 CGlxMedia* CreateItemL( const TGlxMediaId& aId ); |
|
169 |
|
170 private: |
|
171 /// Id space that this cache covers |
|
172 TGlxIdSpaceId iIdSpaceId; |
|
173 |
|
174 /// Pool of media items. Owned |
|
175 RPointerArray<CGlxMedia> iItemPool; |
|
176 |
|
177 ///Instance of cacheManager to cleanup cache |
|
178 CGlxCacheManager* iCacheManager; |
|
179 |
|
180 friend class T_CacheTestHelpers; |
|
181 }; |
|
182 |
|
183 #endif // C_GLXCACHE_H |