|
1 /* |
|
2 * Copyright (c) 2007-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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <liwservicehandler.h> |
|
20 #include <liwvariant.h> |
|
21 |
|
22 #include "hnsimplecondition.h" |
|
23 #include "hnsimpleconditionequal.h" |
|
24 #include "hnsimpleconditiondifferent.h" |
|
25 #include "hnsimpleconditiongreater.h" |
|
26 #include "hnsimpleconditionhas.h" |
|
27 #include "hnsimpleconditionhasnot.h" |
|
28 #include "hnsimpleconditionsmaller.h" |
|
29 #include "hnliwutils.h" |
|
30 #include "hnglobals.h" |
|
31 #include "hnconvutils.h" |
|
32 #include "hnstringhandler.h" |
|
33 |
|
34 // ======== MEMBER FUNCTIONS ======== |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 CHnSimpleCondition* CHnSimpleCondition::NewL( TDesC8 & aElement ) |
|
41 { |
|
42 CHnSimpleCondition* self = CHnSimpleCondition::CreateImplementationL( aElement ); |
|
43 CleanupStack::PushL(self); |
|
44 self->ConstructL( aElement ); |
|
45 CleanupStack::Pop(self); |
|
46 return self; |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 CHnSimpleCondition* CHnSimpleCondition::CreateImplementationL( |
|
54 TDesC8 & aElement ) |
|
55 { |
|
56 TPtrC8 buffer = aElement; |
|
57 CHnSimpleCondition* ret = NULL; |
|
58 if ( buffer.Find( HnLogicalRelations::KLogicalGreater8 )!= KErrNotFound ) |
|
59 { |
|
60 ret = new( ELeave ) CHnSimpleConditionGreater(); |
|
61 } |
|
62 else if ( buffer.Find( HnLogicalRelations::KLogicalDifferent8 ) != |
|
63 KErrNotFound ) |
|
64 { |
|
65 ret = new( ELeave ) CHnSimpleConditionDifferent(); |
|
66 } |
|
67 else if ( buffer.Find( HnLogicalRelations::KLogicalEqual8 ) != |
|
68 KErrNotFound ) |
|
69 { |
|
70 ret = new( ELeave ) CHnSimpleConditionEqual(); |
|
71 } |
|
72 else if ( buffer.Find( HnLogicalRelations::KLogicalLess8 )!= |
|
73 KErrNotFound ) |
|
74 { |
|
75 ret = new( ELeave ) CHnSimpleConditionSmaller(); |
|
76 } |
|
77 else if ( buffer.Find( HnLogicalRelations::KLogicalHas8 )!= |
|
78 KErrNotFound ) |
|
79 { |
|
80 ret = new( ELeave ) CHnSimpleConditionHas(); |
|
81 } |
|
82 else if ( buffer.Find( HnLogicalRelations::KLogicalHasNot8 )!= |
|
83 KErrNotFound ) |
|
84 { |
|
85 ret = new( ELeave ) CHnSimpleConditionHasNot(); |
|
86 } |
|
87 else |
|
88 { |
|
89 User::Leave( KErrGeneral ); |
|
90 } |
|
91 return ret; |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 CHnSimpleCondition::CHnSimpleCondition() |
|
99 { |
|
100 } |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 CHnSimpleCondition::~CHnSimpleCondition() |
|
107 { |
|
108 iReferenceRight.Close(); |
|
109 iReferenceLeft.Close(); |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 void CHnSimpleCondition::RemoveQuotes( RBuf8 & aValue ) |
|
117 { |
|
118 TInt quoPos = aValue.Locate('\''); |
|
119 if( quoPos == 0 ) |
|
120 { |
|
121 aValue.Delete( 0 , 1 ); |
|
122 aValue.Delete( aValue.Length() - 1, 1 ); |
|
123 } |
|
124 } |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 void CHnSimpleCondition::ConstructL( TDesC8 & aElement ) |
|
130 { |
|
131 TPtrC8 buffer = aElement; |
|
132 TInt pos = GetPositionL( buffer ); |
|
133 ASSERT( pos ); |
|
134 |
|
135 RBuf8 tempbuf; |
|
136 CleanupClosePushL( tempbuf ); |
|
137 tempbuf.CreateL( buffer.Right( buffer.Length() - pos - SignLength() ) ); |
|
138 iReferenceRight.Close(); |
|
139 iReferenceRight.CreateL( tempbuf ); |
|
140 iReferenceRight.Trim(); |
|
141 CHnSimpleCondition::RemoveQuotes( iReferenceRight ); |
|
142 |
|
143 tempbuf.Close(); |
|
144 tempbuf.CreateL( buffer.Left( pos ) ); |
|
145 |
|
146 iReferenceLeft.Close(); |
|
147 iReferenceLeft.CreateL( tempbuf ); |
|
148 iReferenceLeft.Trim(); |
|
149 CHnSimpleCondition::RemoveQuotes( iReferenceLeft ); |
|
150 |
|
151 CleanupStack::PopAndDestroy( &tempbuf ); |
|
152 } |
|
153 |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 void CHnSimpleCondition::NormalizeVariantTypeDesL( TLiwVariant* aVar ) |
|
160 { |
|
161 if( aVar->TypeId() == LIW::EVariantTypeDesC8 ) |
|
162 { |
|
163 TPtrC8 left; |
|
164 aVar->Get( left ); |
|
165 HBufC * data = HnConvUtils::Str8ToStrFastLC( left ); |
|
166 aVar->SetL( TLiwVariant( data ) ); |
|
167 CleanupStack::PopAndDestroy( data ); |
|
168 } |
|
169 } |
|
170 |
|
171 // --------------------------------------------------------------------------- |
|
172 // |
|
173 // --------------------------------------------------------------------------- |
|
174 // |
|
175 TLiwVariant* CHnSimpleCondition::CheckTypes( TLiwVariant* aVarLeft, |
|
176 TLiwVariant* aVarRight, LIW::TVariantTypeId aType1, |
|
177 LIW::TVariantTypeId aType2 ) |
|
178 { |
|
179 LIW::TVariantTypeId varLeftId = aVarLeft->TypeId(); |
|
180 LIW::TVariantTypeId varRightId = aVarRight->TypeId(); |
|
181 |
|
182 if (varLeftId == aType1 && varRightId == aType2) |
|
183 { |
|
184 return aVarLeft; |
|
185 } |
|
186 else if (varLeftId == aType2 && varRightId == aType1) |
|
187 { |
|
188 return aVarRight; |
|
189 } |
|
190 |
|
191 return NULL; |
|
192 } |
|
193 |
|
194 // --------------------------------------------------------------------------- |
|
195 // |
|
196 // --------------------------------------------------------------------------- |
|
197 // |
|
198 void CHnSimpleCondition::NegotiateListL( TLiwVariant & aVar ) |
|
199 { |
|
200 ASSERT( aVar.TypeId() == LIW::EVariantTypeList ); |
|
201 |
|
202 CLiwList* temp = CLiwDefaultList::NewL(); |
|
203 temp->PushL(); |
|
204 aVar.Get( *temp ); |
|
205 aVar.SetL( TLiwVariant( TInt32(temp->Count()) ) ); |
|
206 CleanupStack::PopAndDestroy( temp ); |
|
207 } |
|
208 |
|
209 // --------------------------------------------------------------------------- |
|
210 // |
|
211 // --------------------------------------------------------------------------- |
|
212 // |
|
213 void CHnSimpleCondition::NegotiateMapL( TLiwVariant & aVar ) |
|
214 { |
|
215 ASSERT( aVar.TypeId() == LIW::EVariantTypeMap ); |
|
216 |
|
217 CLiwDefaultMap* temp = CLiwDefaultMap::NewL(); |
|
218 temp->PushL(); |
|
219 aVar.Get( *temp ); |
|
220 aVar.SetL( TLiwVariant( TInt32(temp->Count()) ) ); |
|
221 CleanupStack::PopAndDestroy( temp ); |
|
222 } |
|
223 |
|
224 // --------------------------------------------------------------------------- |
|
225 // |
|
226 // --------------------------------------------------------------------------- |
|
227 // |
|
228 void CHnSimpleCondition::NegotiateTUintL( TLiwVariant & aVar ) |
|
229 { |
|
230 ASSERT ( aVar.TypeId() == LIW::EVariantTypeDesC ); |
|
231 |
|
232 TPtrC temp; |
|
233 TUint integer; |
|
234 |
|
235 aVar.Get(temp); |
|
236 TLex val( temp ); |
|
237 val.Val(integer); |
|
238 aVar.Set( integer ); |
|
239 |
|
240 } |
|
241 |
|
242 // --------------------------------------------------------------------------- |
|
243 // |
|
244 // --------------------------------------------------------------------------- |
|
245 // |
|
246 void CHnSimpleCondition::NegotiateTBoolL( TLiwVariant & aVar ) |
|
247 { |
|
248 ASSERT( aVar.TypeId() == LIW::EVariantTypeDesC ); |
|
249 |
|
250 TPtrC ptr; |
|
251 aVar.Get( ptr ); |
|
252 |
|
253 if ( !HnStringHandler::CompareIgnoreCaseL( ptr, KStringTrue ) ) |
|
254 { |
|
255 aVar.Set( ETrue ); |
|
256 } |
|
257 else |
|
258 { |
|
259 aVar.Set( EFalse ); |
|
260 } |
|
261 } |
|
262 |
|
263 // --------------------------------------------------------------------------- |
|
264 // |
|
265 // --------------------------------------------------------------------------- |
|
266 // |
|
267 void CHnSimpleCondition::NegotiateTInt32L( TLiwVariant & aVar ) |
|
268 { |
|
269 ASSERT( aVar.TypeId() == LIW::EVariantTypeDesC |
|
270 || aVar.TypeId() == LIW::EVariantTypeTUint ); |
|
271 |
|
272 if ( aVar.TypeId() == LIW::EVariantTypeDesC ) |
|
273 { |
|
274 TPtrC temp; |
|
275 TInt32 integer; |
|
276 |
|
277 aVar.Get(temp); |
|
278 TLex val( temp ); |
|
279 val.Val(integer); |
|
280 aVar.Set( integer ); |
|
281 } |
|
282 else if ( aVar.TypeId() == LIW::EVariantTypeTUint ) |
|
283 { |
|
284 TUint unsignedValue( 0U ); |
|
285 aVar.Get( unsignedValue ); |
|
286 if( unsignedValue <= static_cast<TUint>( KMaxTInt32 ) ) |
|
287 { |
|
288 aVar.Set( static_cast<TInt32>( unsignedValue ) ); |
|
289 } |
|
290 } |
|
291 } |
|
292 |
|
293 // --------------------------------------------------------------------------- |
|
294 // |
|
295 // --------------------------------------------------------------------------- |
|
296 // |
|
297 void CHnSimpleCondition::NegotiateTInt64L( TLiwVariant & aVar ) |
|
298 { |
|
299 ASSERT(aVar.TypeId() == LIW::EVariantTypeDesC ); |
|
300 |
|
301 TPtrC temp; |
|
302 TInt64 integer; |
|
303 |
|
304 aVar.Get(temp); |
|
305 TLex val( temp ); |
|
306 val.Val(integer); |
|
307 aVar.Set( integer ); |
|
308 } |
|
309 |
|
310 // --------------------------------------------------------------------------- |
|
311 // |
|
312 // --------------------------------------------------------------------------- |
|
313 // |
|
314 void CHnSimpleCondition::NegotiateTypesL( TLiwVariant* aVarLeft, |
|
315 TLiwVariant* aVarRight ) |
|
316 { |
|
317 NormalizeVariantTypeDesL( aVarLeft ); |
|
318 NormalizeVariantTypeDesL( aVarRight ); |
|
319 |
|
320 if (aVarLeft->TypeId() != aVarRight->TypeId()) |
|
321 { |
|
322 TLiwVariant* chosen( NULL ); |
|
323 |
|
324 chosen = CheckTypes( aVarLeft, aVarRight, LIW::EVariantTypeList, LIW::EVariantTypeDesC ); |
|
325 if ( chosen ) |
|
326 { |
|
327 NegotiateListL( *chosen ); |
|
328 return; |
|
329 } |
|
330 chosen = CheckTypes( aVarLeft, aVarRight, LIW::EVariantTypeMap, LIW::EVariantTypeDesC ); |
|
331 if ( chosen ) |
|
332 { |
|
333 NegotiateMapL( *chosen ); |
|
334 return; |
|
335 } |
|
336 chosen = CheckTypes( aVarLeft, aVarRight, LIW::EVariantTypeDesC, LIW::EVariantTypeTInt32 ); |
|
337 if ( chosen ) |
|
338 { |
|
339 NegotiateTInt32L( *chosen ); |
|
340 return; |
|
341 } |
|
342 chosen = CheckTypes( aVarLeft, aVarRight, LIW::EVariantTypeDesC, LIW::EVariantTypeTUint ); |
|
343 if ( chosen ) |
|
344 { |
|
345 NegotiateTUintL( *chosen ); |
|
346 return; |
|
347 } |
|
348 chosen = CheckTypes( aVarLeft, aVarRight, LIW::EVariantTypeDesC, LIW::EVariantTypeTInt64 ); |
|
349 if ( chosen ) |
|
350 { |
|
351 NegotiateTInt64L( *chosen ); |
|
352 return; |
|
353 } |
|
354 chosen = CheckTypes( aVarLeft, aVarRight, LIW::EVariantTypeDesC, LIW::EVariantTypeTBool ); |
|
355 if ( chosen ) |
|
356 { |
|
357 NegotiateTBoolL( *chosen ); |
|
358 return; |
|
359 } |
|
360 chosen = CheckTypes( aVarLeft, aVarRight, LIW::EVariantTypeTUint, LIW::EVariantTypeTInt32 ); |
|
361 if ( chosen ) |
|
362 { |
|
363 NegotiateTInt32L( *chosen ); |
|
364 return; |
|
365 } |
|
366 } |
|
367 } |
|
368 |
|
369 // --------------------------------------------------------------------------- |
|
370 // |
|
371 // --------------------------------------------------------------------------- |
|
372 // |
|
373 TBool CHnSimpleCondition::ResultL( const CLiwGenericParamList& aQueryResults, |
|
374 TInt aPos ) |
|
375 { |
|
376 TBool ret( EFalse ); |
|
377 |
|
378 TLiwVariant varLeft; |
|
379 varLeft.PushL(); |
|
380 TInt err1 = HnLiwUtils::GetVariantL( aQueryResults, iReferenceLeft, aPos, varLeft ); |
|
381 |
|
382 TLiwVariant varRight; |
|
383 varRight.PushL(); |
|
384 TInt err2 = HnLiwUtils::GetVariantL( aQueryResults, iReferenceRight, aPos , varRight ); |
|
385 |
|
386 if ( err1 == KErrNone && err2 == KErrNone ) |
|
387 { |
|
388 NegotiateTypesL( &varLeft, &varRight); |
|
389 ret = CheckCondition( varLeft, varRight ); |
|
390 } |
|
391 |
|
392 CleanupStack::PopAndDestroy( &varRight ); |
|
393 CleanupStack::PopAndDestroy( &varLeft ); |
|
394 |
|
395 return ret; |
|
396 } |
|
397 |