|
1 /* |
|
2 * Copyright (c) 2008-2008 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: Manages MCP plugins, and content publishing. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "musiccontentmap.h" |
|
19 |
|
20 #include <mpxlog.h> |
|
21 |
|
22 // ======== TRACING MACROS ======== |
|
23 |
|
24 // These extend macros in <mpxlog.h> |
|
25 |
|
26 #ifdef _DEBUG |
|
27 #define MPX_DEBUG2_8(cstr, p) RDebug::Printf(cstr, p) |
|
28 #else |
|
29 #define MPX_DEBUG2_8(cstr, p) |
|
30 #endif |
|
31 |
|
32 // ======== MEMBER FUNCTIONS ======== |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // Constructor |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 RMusicContentVariant::RMusicContentVariant():iType(ETypeNull),iModified(EFalse){} |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // Reset value to null |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 void RMusicContentVariant::Reset() |
|
45 { |
|
46 switch (iType) |
|
47 { |
|
48 case ETypeNull: |
|
49 return; |
|
50 case ETypeInt: |
|
51 break; |
|
52 case ETypeBufC: |
|
53 delete iValue.iBufC; |
|
54 iValue.iBufC = 0; |
|
55 break; |
|
56 case ETypeMap: |
|
57 if ( iValue.iMap ) |
|
58 { |
|
59 iValue.iMap->Close(); |
|
60 iValue.iMap = 0; |
|
61 } |
|
62 break; |
|
63 } |
|
64 iType = ETypeNull; |
|
65 iModified = ETrue; |
|
66 }; |
|
67 |
|
68 // --------------------------------------------------------------------------- |
|
69 // Set value |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 TBool RMusicContentVariant::SetL( TInt aInt) |
|
73 { |
|
74 if (iType != ETypeInt || iValue.iInt != aInt) |
|
75 { |
|
76 Reset(); |
|
77 iValue.iInt = aInt; |
|
78 iType = ETypeInt; |
|
79 iModified = ETrue; |
|
80 return ETrue; |
|
81 } |
|
82 else |
|
83 { |
|
84 return EFalse; |
|
85 } |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // Set value |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 TBool RMusicContentVariant::SetL( const TDesC& aDesc ) |
|
93 { |
|
94 if (iType != ETypeBufC || iValue.iBufC->Compare(aDesc) ) |
|
95 { |
|
96 Reset(); |
|
97 iValue.iBufC = aDesc.AllocL(); |
|
98 iType = ETypeBufC; |
|
99 iModified = ETrue; |
|
100 return ETrue; |
|
101 } |
|
102 else |
|
103 { |
|
104 return EFalse; |
|
105 } |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------------------------- |
|
109 // Set value |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 TBool RMusicContentVariant::SetL( CLiwMap * aMap ) |
|
113 { |
|
114 if (iType != ETypeMap || ! ( *iValue.iMap == *aMap ) ) |
|
115 { |
|
116 Reset(); |
|
117 TLiwVariant variant; |
|
118 variant.SetL ( TLiwVariant (aMap) ); // increase CLiwMap reference counter |
|
119 iValue.iMap = aMap; |
|
120 iType = ETypeMap; |
|
121 iModified = ETrue; |
|
122 return ETrue; |
|
123 } |
|
124 else |
|
125 { |
|
126 return EFalse; |
|
127 } |
|
128 } |
|
129 |
|
130 // --------------------------------------------------------------------------- |
|
131 // Return whether value has been modified |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 TBool RMusicContentVariant::IsModified() const |
|
135 { |
|
136 return iModified; |
|
137 } |
|
138 |
|
139 // --------------------------------------------------------------------------- |
|
140 // Reset modified flag |
|
141 // --------------------------------------------------------------------------- |
|
142 // |
|
143 void RMusicContentVariant::ResetModified() |
|
144 { |
|
145 iModified = EFalse; |
|
146 } |
|
147 |
|
148 // --------------------------------------------------------------------------- |
|
149 // Return whether value is null |
|
150 // --------------------------------------------------------------------------- |
|
151 // |
|
152 TBool RMusicContentVariant::IsNull() const |
|
153 { |
|
154 return iType == ETypeNull; |
|
155 } |
|
156 |
|
157 // --------------------------------------------------------------------------- |
|
158 // Return variant value |
|
159 // --------------------------------------------------------------------------- |
|
160 // |
|
161 TLiwVariant RMusicContentVariant::LiwVariant() const |
|
162 { |
|
163 switch (iType) |
|
164 { |
|
165 case ETypeNull: |
|
166 return TLiwVariant(); |
|
167 case ETypeInt: |
|
168 return TLiwVariant( iValue.iInt ); |
|
169 case ETypeBufC: |
|
170 return TLiwVariant( iValue.iBufC ); |
|
171 case ETypeMap: |
|
172 return TLiwVariant( iValue.iMap ); |
|
173 } |
|
174 return TLiwVariant(); |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------------------------- |
|
178 // Hash function for the map |
|
179 // --------------------------------------------------------------------------- |
|
180 // |
|
181 static inline TUint32 HashFunction(const TPtrC8& aKey) |
|
182 { |
|
183 return DefaultHash::Des8(aKey); |
|
184 } |
|
185 |
|
186 // --------------------------------------------------------------------------- |
|
187 // Identity relation for the map |
|
188 // --------------------------------------------------------------------------- |
|
189 // |
|
190 static inline TBool IdentityRelation(const TPtrC8& aLeft, const TPtrC8& aRight) |
|
191 { |
|
192 return DefaultIdentity::Des8(aLeft, aRight); |
|
193 } |
|
194 |
|
195 // --------------------------------------------------------------------------- |
|
196 // Constructor |
|
197 // --------------------------------------------------------------------------- |
|
198 // |
|
199 RMusicContentMap::RMusicContentMap(): |
|
200 iMap( |
|
201 THashFunction32< TPtrC8 >(&HashFunction), |
|
202 TIdentityRelation< TPtrC8 >(&IdentityRelation) ), |
|
203 iModified( EFalse ) |
|
204 {} |
|
205 |
|
206 // --------------------------------------------------------------------------- |
|
207 // Reset a value in the map |
|
208 // --------------------------------------------------------------------------- |
|
209 // |
|
210 void RMusicContentMap::Reset( TPtrC8 aKey ) |
|
211 { |
|
212 MPX_DEBUG2_8("RMusicContentMap::Reset %S", &aKey); |
|
213 RMusicContentVariant * value = iMap.Find( aKey ); |
|
214 if ( value ) |
|
215 { |
|
216 iModified |= !value->IsNull(); |
|
217 value->Reset(); |
|
218 } |
|
219 } |
|
220 |
|
221 // --------------------------------------------------------------------------- |
|
222 // Set a value in the map |
|
223 // --------------------------------------------------------------------------- |
|
224 // |
|
225 void RMusicContentMap::SetL( TPtrC8 aKey, const TDesC& aValue ) |
|
226 { |
|
227 MPX_DEBUG2_8("RMusicContentMap::SetL %S", &aKey); |
|
228 iModified |= AtL( aKey ).SetL( aValue ); |
|
229 } |
|
230 |
|
231 // --------------------------------------------------------------------------- |
|
232 // Set a value in the map |
|
233 // --------------------------------------------------------------------------- |
|
234 // |
|
235 void RMusicContentMap::SetL( TPtrC8 aKey, const TInt& aValue ) |
|
236 { |
|
237 MPX_DEBUG2_8("RMusicContentMap::SetL %S", &aKey); |
|
238 iModified |= AtL( aKey ).SetL( aValue ); |
|
239 } |
|
240 |
|
241 // --------------------------------------------------------------------------- |
|
242 // Set a value in the map |
|
243 // --------------------------------------------------------------------------- |
|
244 // |
|
245 void RMusicContentMap::SetL( TPtrC8 aKey, CLiwMap * aMap ) |
|
246 { |
|
247 MPX_DEBUG2_8("RMusicContentMap::SetL %S", &aKey); |
|
248 iModified |= AtL( aKey ).SetL( aMap ); |
|
249 } |
|
250 |
|
251 // --------------------------------------------------------------------------- |
|
252 // Return whether map has been modified |
|
253 // --------------------------------------------------------------------------- |
|
254 // |
|
255 TBool RMusicContentMap::IsModified() const |
|
256 { |
|
257 return iModified; |
|
258 } |
|
259 |
|
260 // --------------------------------------------------------------------------- |
|
261 // Get modified values |
|
262 // --------------------------------------------------------------------------- |
|
263 // |
|
264 CLiwMap * RMusicContentMap::GetModifiedLC() |
|
265 { |
|
266 MPX_FUNC("RMusicContentMap::GetModifiedLC"); |
|
267 CLiwMap * result = NULL; |
|
268 if (iModified) |
|
269 { |
|
270 result = CLiwDefaultMap::NewLC(); |
|
271 THashMapIter<TPtrC8, RMusicContentVariant> iter( iMap ); |
|
272 while( const RMusicContentVariant * ptr = iter.NextValue() ) |
|
273 { |
|
274 if ( ! ptr->IsModified() ) continue; |
|
275 /* |
|
276 if ( ptr->IsNull() ) |
|
277 { |
|
278 MPX_DEBUG2_8("RMusicContentMap::GetModifiedL skipping %S (is null)", iter.CurrentKey()); |
|
279 } |
|
280 else |
|
281 */ |
|
282 { |
|
283 MPX_DEBUG2_8("RMusicContentMap::GetModifiedL publishing %S", iter.CurrentKey()); |
|
284 result->InsertL( *iter.CurrentKey(), ptr->LiwVariant() ); |
|
285 } |
|
286 iter.CurrentValue()->ResetModified(); |
|
287 } |
|
288 iModified = EFalse; |
|
289 } |
|
290 return result; |
|
291 } |
|
292 |
|
293 // --------------------------------------------------------------------------- |
|
294 // Get all values |
|
295 // --------------------------------------------------------------------------- |
|
296 // |
|
297 CLiwMap * RMusicContentMap::GetAllLC() |
|
298 { |
|
299 MPX_FUNC("RMusicContentMap::GetAllL"); |
|
300 CLiwMap * result = NULL; |
|
301 result = CLiwDefaultMap::NewLC(); |
|
302 THashMapIter<TPtrC8, RMusicContentVariant> iter( iMap ); |
|
303 while( const RMusicContentVariant * ptr = iter.NextValue() ) |
|
304 { |
|
305 /* if ( ptr->IsNull() ) |
|
306 { |
|
307 MPX_DEBUG2_8("RMusicContentMap::GetAllL skipping %S (is null)", iter.CurrentKey()); |
|
308 } |
|
309 else |
|
310 */ { |
|
311 MPX_DEBUG2_8("RMusicContentMap::GetAllL publishing %S", iter.CurrentKey()); |
|
312 result->InsertL( *iter.CurrentKey(), ptr->LiwVariant() ); |
|
313 } |
|
314 iter.CurrentValue()->ResetModified(); |
|
315 } |
|
316 iModified = EFalse; |
|
317 return result; |
|
318 } |
|
319 |
|
320 // --------------------------------------------------------------------------- |
|
321 // Close map |
|
322 // --------------------------------------------------------------------------- |
|
323 // |
|
324 void RMusicContentMap::Close() |
|
325 { |
|
326 MPX_FUNC("RMusicContentMap::Close"); |
|
327 THashMapIter<TPtrC8, RMusicContentVariant> iter( iMap ); |
|
328 while( iter.NextValue() ) |
|
329 { |
|
330 iter.CurrentValue()->Reset(); |
|
331 } |
|
332 iMap.Close(); |
|
333 } |
|
334 |
|
335 RMusicContentVariant& RMusicContentMap::AtL (TPtrC8 aKey) |
|
336 { |
|
337 RMusicContentVariant * value = iMap.Find( aKey ); |
|
338 if (! value ) |
|
339 { |
|
340 iMap.InsertL ( aKey, RMusicContentVariant() ); |
|
341 value = iMap.Find( aKey ); |
|
342 } |
|
343 return *value; |
|
344 } |