1 /* |
|
2 * Copyright (c) 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 the License "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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include <e32std.h> |
|
22 #include <e32base.h> |
|
23 #include <e32hashtab.h> |
|
24 #include <liwvariant.h> |
|
25 |
|
26 #include "videochpublishabledataitem.h" |
|
27 #include "videochpublishabledata.h" |
|
28 |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // TPtrC8Hash() |
|
32 // Local function used to call hash function for creating hash value to |
|
33 // the key provided. |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 TUint32 TPtrC8Hash(const TBuf8< KTvVideoMaxValueKeyLen >& aPtr) |
|
37 { |
|
38 return DefaultHash::Des8(aPtr); |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // TPtrC8Ident() |
|
43 // Local function used to call indentification function for comparing items |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 TBool TPtrC8Ident(const TBuf8< KTvVideoMaxValueKeyLen >& aL, |
|
47 const TBuf8< KTvVideoMaxValueKeyLen >& aR) |
|
48 { |
|
49 return DefaultIdentity::Des8(aL, aR); |
|
50 } |
|
51 |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CVcxNsPublishableDataItem::NewLC |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 CVcxNsPublishableDataItem* CVcxNsPublishableDataItem::NewLC( TPtrC aContentType ) |
|
58 { |
|
59 CVcxNsPublishableDataItem* self = new ( ELeave )CVcxNsPublishableDataItem( aContentType ); |
|
60 CleanupStack::PushL( self ); |
|
61 self->ConstructL(); |
|
62 return self; |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CVcxNsPublishableDataItem::NewL |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 CVcxNsPublishableDataItem* CVcxNsPublishableDataItem::NewL( TPtrC aContentType ) |
|
70 { |
|
71 CVcxNsPublishableDataItem* self = CVcxNsPublishableDataItem::NewLC( aContentType ); |
|
72 CleanupStack::Pop( self ); // self; |
|
73 return self; |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CVcxNsPublishableDataItem::CVcxNsPublishableDataItem |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 CVcxNsPublishableDataItem::CVcxNsPublishableDataItem( TPtrC aContentType ) : |
|
81 iContentType( aContentType ) |
|
82 { |
|
83 // NOP |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CVcxNsPublishableDataItem::~CVcxNsPublishableDataItem |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 CVcxNsPublishableDataItem::~CVcxNsPublishableDataItem() |
|
91 { |
|
92 if( iIntData ) |
|
93 { |
|
94 iIntData->Close(); |
|
95 delete iIntData; |
|
96 } |
|
97 |
|
98 if( iDescData ) |
|
99 { |
|
100 THashMapIter< TBuf8< KTvVideoMaxValueKeyLen >, HBufC* > iter( *iDescData ); |
|
101 for( HBufC* const* value = iter.NextValue(); value; value = iter.NextValue() ) |
|
102 { |
|
103 delete *value; |
|
104 } |
|
105 iDescData->Close(); |
|
106 delete iDescData; |
|
107 } |
|
108 |
|
109 } |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // CVcxNsPublishableDataItem::ConstructL |
|
113 // ----------------------------------------------------------------------------- |
|
114 // |
|
115 void CVcxNsPublishableDataItem::ConstructL() |
|
116 { |
|
117 |
|
118 iIntData = |
|
119 new( ELeave )RHashMap< TBuf8< KTvVideoMaxValueKeyLen >, TInt > |
|
120 (&TPtrC8Hash, &TPtrC8Ident); |
|
121 |
|
122 iDescData = |
|
123 new( ELeave )RHashMap< TBuf8< KTvVideoMaxValueKeyLen >, HBufC* > |
|
124 (&TPtrC8Hash, &TPtrC8Ident); |
|
125 } |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // CVcxNsPublishableDataItem::ContentType |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 TPtrC CVcxNsPublishableDataItem::ContentType() const |
|
132 { |
|
133 return iContentType; |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CVcxNsPublishableDataItem::SetDataL |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 void CVcxNsPublishableDataItem::SetDataL( TPtrC8 aKey, TInt aValue ) |
|
141 { |
|
142 iIntData->InsertL( aKey, aValue ); |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CVcxNsPublishableDataItem::SetDataL |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 void CVcxNsPublishableDataItem::SetDataL( TPtrC8 aKey, const TDesC& aData ) |
|
150 { |
|
151 HBufC** item = iDescData->Find( aKey ); |
|
152 if( item && *item ) |
|
153 { |
|
154 delete *item; |
|
155 } |
|
156 |
|
157 iDescData->InsertL( aKey, aData.AllocL() ); |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // CVcxNsPublishableDataItem::GetIntDataL |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 TInt CVcxNsPublishableDataItem::GetIntDataL( TPtrC8 aKey ) const |
|
165 { |
|
166 TInt* item = iIntData->Find( aKey ); |
|
167 if( !item ) |
|
168 { |
|
169 User::Leave( KErrNotFound ); |
|
170 } |
|
171 return *item; |
|
172 } |
|
173 |
|
174 // ----------------------------------------------------------------------------- |
|
175 // CVcxNsPublishableDataItem::GetDesCDataL |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 const TDesC& CVcxNsPublishableDataItem::GetDesCDataL( TPtrC8 aKey ) const |
|
179 { |
|
180 HBufC** item = iDescData->Find( aKey ); |
|
181 |
|
182 if( !item || !( *item ) ) |
|
183 { |
|
184 User::Leave( KErrNotFound ); |
|
185 } |
|
186 return **item; |
|
187 } |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // CVcxNsPublishableDataItem::ClearData |
|
191 // ----------------------------------------------------------------------------- |
|
192 // |
|
193 void CVcxNsPublishableDataItem::ClearData() |
|
194 { |
|
195 |
|
196 THashMapIter< TBuf8< KTvVideoMaxValueKeyLen >, HBufC* > descIter( *iDescData ); |
|
197 for( HBufC* const* value = descIter.NextValue(); value; value = descIter.NextValue() ) |
|
198 { |
|
199 TRAP_IGNORE( SetDataL( *( descIter.CurrentKey() ), KNullDesC ) ); |
|
200 } |
|
201 THashMapIter< TBuf8< KTvVideoMaxValueKeyLen >, TInt > intIter( *iIntData ); |
|
202 for( const TInt* intValue = intIter.NextValue(); intValue; intValue = intIter.NextValue() ) |
|
203 { |
|
204 TRAP_IGNORE( SetDataL( *( intIter.CurrentKey() ), 0 ) ); |
|
205 } |
|
206 } |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // CVcxNsPublishableDataItem::FillCPDataMapL |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 void CVcxNsPublishableDataItem::FillCPDataMapL( CLiwDefaultMap& aDataMap ) |
|
213 { |
|
214 // fill descriptor data |
|
215 THashMapIter< TBuf8< KTvVideoMaxValueKeyLen >, HBufC* > descIter( *iDescData ); |
|
216 for( HBufC* const* value = descIter.NextValue(); value; value = descIter.NextValue() ) |
|
217 { |
|
218 aDataMap.InsertL( *( descIter.CurrentKey() ) , TLiwVariant( **value ) ); |
|
219 } |
|
220 |
|
221 THashMapIter< TBuf8< KTvVideoMaxValueKeyLen >, TInt > intIter( *iIntData ); |
|
222 TInt32 value; |
|
223 for( const TInt* intValue = intIter.NextValue(); intValue; intValue = intIter.NextValue() ) |
|
224 { |
|
225 value = *intValue; |
|
226 aDataMap.InsertL( *( intIter.CurrentKey() ) , TLiwVariant( value ) ); |
|
227 } |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // CVcxNsPublishableDataItem::ReadCPDataMapL |
|
232 // ----------------------------------------------------------------------------- |
|
233 // |
|
234 void CVcxNsPublishableDataItem::ReadCPDataMapL( CLiwDefaultMap& aDataMap ) |
|
235 { |
|
236 // read all data keys saved to this item, extract the corresponding |
|
237 // data from the liwdefaultmap and save it to this object |
|
238 |
|
239 // clear first |
|
240 ClearData(); |
|
241 |
|
242 TInt count = aDataMap.Count(); |
|
243 |
|
244 for( TInt i = 0; i < count; i++ ) |
|
245 { |
|
246 TPtrC8 key = aDataMap.AtL( i ); |
|
247 |
|
248 TLiwVariant variant; |
|
249 variant.PushL(); |
|
250 ExtractVariant( key, aDataMap, variant ); |
|
251 |
|
252 if( variant.TypeId() == LIW::EVariantTypeDesC ) |
|
253 { |
|
254 SetDataL( key, variant.AsDes() ); |
|
255 } |
|
256 else if( variant.TypeId() == LIW::EVariantTypeTInt32 ) |
|
257 { |
|
258 SetDataL( key, variant.AsTInt32() ); |
|
259 } |
|
260 CleanupStack::PopAndDestroy( &variant ); |
|
261 } |
|
262 } |
|
263 |
|
264 // ----------------------------------------------------------------------------- |
|
265 // CVcxNsPublishableDataItem::ExtractVariant |
|
266 // ----------------------------------------------------------------------------- |
|
267 // |
|
268 TInt CVcxNsPublishableDataItem::ExtractVariant( const TDesC8& aKey, |
|
269 CLiwDefaultMap& aDataMap, |
|
270 TLiwVariant& aVariant ) |
|
271 { |
|
272 TInt err( KErrNotFound ); |
|
273 TBool found( EFalse ); |
|
274 TRAP( err, found = aDataMap.FindL( aKey, aVariant ) ); |
|
275 if( err == KErrNone && found ) |
|
276 { |
|
277 return KErrNone; |
|
278 } |
|
279 return err; |
|
280 } |
|
281 |
|