|
1 /* |
|
2 * Copyright (c) 2002-2006 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: CCFContextObjectImpl class description. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <s32strm.h> |
|
20 |
|
21 #include "CFContextObjectImpl.h" |
|
22 #include "cfserviceutils.h" |
|
23 #include "cftrace.h" |
|
24 |
|
25 static const TInt KTimesSame = 0; |
|
26 static const TInt KTimeFirstGreater = -1; |
|
27 static const TInt KTimeSecondGreater = 1; |
|
28 |
|
29 static const TUint KFullConfidence = 100; |
|
30 |
|
31 // MEMBER FUNCTIONS |
|
32 |
|
33 EXPORT_C CCFContextObjectImpl* CCFContextObjectImpl::NewL() |
|
34 { |
|
35 FUNC_LOG; |
|
36 |
|
37 CCFContextObjectImpl* self = CCFContextObjectImpl::NewLC(); |
|
38 CleanupStack::Pop( self ); |
|
39 |
|
40 return self; |
|
41 } |
|
42 |
|
43 EXPORT_C CCFContextObjectImpl* CCFContextObjectImpl::NewLC() |
|
44 { |
|
45 FUNC_LOG; |
|
46 |
|
47 CCFContextObjectImpl* self = new( ELeave ) CCFContextObjectImpl; |
|
48 CleanupStack::PushL( self ); |
|
49 self->ConstructL( KNullDesC, KNullDesC, KNullDesC ); |
|
50 |
|
51 return self; |
|
52 } |
|
53 |
|
54 EXPORT_C CCFContextObjectImpl* CCFContextObjectImpl::NewL( const TDesC& aSource, |
|
55 const TDesC& aType, |
|
56 const TDesC& aValue ) |
|
57 { |
|
58 FUNC_LOG; |
|
59 |
|
60 CCFContextObjectImpl* self = |
|
61 CCFContextObjectImpl::NewLC( aSource, aType, aValue ); |
|
62 CleanupStack::Pop( self ); |
|
63 |
|
64 return self; |
|
65 } |
|
66 |
|
67 EXPORT_C CCFContextObjectImpl* CCFContextObjectImpl::NewLC( const TDesC& aSource, |
|
68 const TDesC& aType, |
|
69 const TDesC& aValue ) |
|
70 { |
|
71 FUNC_LOG; |
|
72 |
|
73 CCFContextObjectImpl* self = new( ELeave ) CCFContextObjectImpl; |
|
74 CleanupStack::PushL( self ); |
|
75 self->ConstructL( aSource, aType, aValue ); |
|
76 |
|
77 return self; |
|
78 } |
|
79 |
|
80 CCFContextObjectImpl::~CCFContextObjectImpl() |
|
81 { |
|
82 FUNC_LOG; |
|
83 |
|
84 delete iSource; |
|
85 delete iType; |
|
86 delete iValue; |
|
87 } |
|
88 |
|
89 CCFContextObjectImpl::CCFContextObjectImpl(): |
|
90 iConfidence( KFullConfidence ) |
|
91 { |
|
92 FUNC_LOG; |
|
93 |
|
94 // Nothing to do |
|
95 } |
|
96 |
|
97 void CCFContextObjectImpl::ConstructL( const TDesC& aSource, |
|
98 const TDesC& aType, |
|
99 const TDesC& aValue ) |
|
100 { |
|
101 FUNC_LOG; |
|
102 |
|
103 // Initialize pointers |
|
104 iSource = aSource.AllocL(); |
|
105 iType = aType.AllocL(); |
|
106 iValue = aValue.AllocL(); |
|
107 } |
|
108 |
|
109 // METHODS |
|
110 |
|
111 //----------------------------------------------------------------------------- |
|
112 // CCFContextObjectImpl::SetTypeL |
|
113 //----------------------------------------------------------------------------- |
|
114 // |
|
115 void CCFContextObjectImpl::SetTypeL( const TDesC& aType ) |
|
116 { |
|
117 FUNC_LOG; |
|
118 |
|
119 CFServiceUtils::UpdateBufferL( iType, aType ); |
|
120 } |
|
121 |
|
122 //----------------------------------------------------------------------------- |
|
123 // CCFContextObjectImpl::Type |
|
124 //----------------------------------------------------------------------------- |
|
125 // |
|
126 const TDesC& CCFContextObjectImpl::Type() const |
|
127 { |
|
128 FUNC_LOG; |
|
129 |
|
130 if( iType ) |
|
131 { |
|
132 return *iType; |
|
133 } |
|
134 else |
|
135 { |
|
136 return KNullDesC; |
|
137 } |
|
138 } |
|
139 |
|
140 //----------------------------------------------------------------------------- |
|
141 // CCFContextObjectImpl::SetValueL |
|
142 //----------------------------------------------------------------------------- |
|
143 // |
|
144 void CCFContextObjectImpl::SetValueL( const TDesC& aValue ) |
|
145 { |
|
146 FUNC_LOG; |
|
147 |
|
148 CFServiceUtils::UpdateBufferL( iValue, aValue ); |
|
149 } |
|
150 |
|
151 //----------------------------------------------------------------------------- |
|
152 // CCFContextObjectImpl::Value |
|
153 //----------------------------------------------------------------------------- |
|
154 // |
|
155 const TDesC& CCFContextObjectImpl::Value() const |
|
156 { |
|
157 FUNC_LOG; |
|
158 |
|
159 if( iValue ) |
|
160 { |
|
161 return *iValue; |
|
162 } |
|
163 else |
|
164 { |
|
165 return KNullDesC; |
|
166 } |
|
167 } |
|
168 |
|
169 //----------------------------------------------------------------------------- |
|
170 // CCFContextObjectImpl::SetSourceL |
|
171 //----------------------------------------------------------------------------- |
|
172 // |
|
173 void CCFContextObjectImpl::SetSourceL( const TDesC& aSource ) |
|
174 { |
|
175 FUNC_LOG; |
|
176 |
|
177 CFServiceUtils::UpdateBufferL( iSource, aSource ); |
|
178 } |
|
179 |
|
180 //----------------------------------------------------------------------------- |
|
181 // CCFContextObjectImpl::Source |
|
182 //----------------------------------------------------------------------------- |
|
183 // |
|
184 const TDesC& CCFContextObjectImpl::Source() const |
|
185 { |
|
186 FUNC_LOG; |
|
187 |
|
188 if( iSource ) |
|
189 { |
|
190 return *iSource; |
|
191 } |
|
192 else |
|
193 { |
|
194 return KNullDesC; |
|
195 } |
|
196 } |
|
197 |
|
198 //----------------------------------------------------------------------------- |
|
199 // CCFContextObjectImpl::SetConfidence |
|
200 //----------------------------------------------------------------------------- |
|
201 // |
|
202 void CCFContextObjectImpl::SetConfidence( const TUint8& aConfidence ) |
|
203 { |
|
204 FUNC_LOG; |
|
205 |
|
206 iConfidence = aConfidence; |
|
207 } |
|
208 |
|
209 //----------------------------------------------------------------------------- |
|
210 // CCFContextObjectImpl::Confidence |
|
211 //----------------------------------------------------------------------------- |
|
212 // |
|
213 TUint8 CCFContextObjectImpl::Confidence() const |
|
214 { |
|
215 FUNC_LOG; |
|
216 |
|
217 return iConfidence; |
|
218 } |
|
219 |
|
220 //----------------------------------------------------------------------------- |
|
221 // CCFContextObjectImpl::SetTimestampToHomeTime |
|
222 //----------------------------------------------------------------------------- |
|
223 // |
|
224 void CCFContextObjectImpl::SetTimestampToHomeTime() |
|
225 { |
|
226 FUNC_LOG; |
|
227 |
|
228 iTimestamp.HomeTime(); |
|
229 } |
|
230 |
|
231 //----------------------------------------------------------------------------- |
|
232 // CCFContextObjectImpl::SetTimestamp |
|
233 //----------------------------------------------------------------------------- |
|
234 // |
|
235 void CCFContextObjectImpl::SetTimestamp( const TTime& aTimestamp ) |
|
236 { |
|
237 FUNC_LOG; |
|
238 |
|
239 iTimestamp = aTimestamp; |
|
240 } |
|
241 |
|
242 //----------------------------------------------------------------------------- |
|
243 // CCFContextObjectImpl::SetTimestamp |
|
244 //----------------------------------------------------------------------------- |
|
245 // |
|
246 void CCFContextObjectImpl::SetTimestamp( const TInt64& aTimestamp ) |
|
247 { |
|
248 FUNC_LOG; |
|
249 |
|
250 iTimestamp = aTimestamp; |
|
251 } |
|
252 |
|
253 //----------------------------------------------------------------------------- |
|
254 // CCFContextObjectImpl::Timestamp |
|
255 //----------------------------------------------------------------------------- |
|
256 // |
|
257 const TTime& CCFContextObjectImpl::Timestamp() const |
|
258 { |
|
259 FUNC_LOG; |
|
260 |
|
261 return iTimestamp; |
|
262 } |
|
263 |
|
264 //----------------------------------------------------------------------------- |
|
265 // CCFContextObjectImpl::CopyL |
|
266 //----------------------------------------------------------------------------- |
|
267 // |
|
268 void CCFContextObjectImpl::CopyL( const CCFContextObject& aContext ) |
|
269 { |
|
270 FUNC_LOG; |
|
271 |
|
272 SetSourceL( aContext.Source() ); |
|
273 SetTypeL( aContext.Type() ); |
|
274 SetValueL( aContext.Value() ); |
|
275 SetTimestamp( aContext.Timestamp() ); |
|
276 SetConfidence( aContext.Confidence() ); |
|
277 } |
|
278 |
|
279 //----------------------------------------------------------------------------- |
|
280 // CCFContextObjectImpl::InternalizeL |
|
281 //----------------------------------------------------------------------------- |
|
282 // |
|
283 EXPORT_C void CCFContextObjectImpl::InternalizeL( RReadStream& aStream ) |
|
284 { |
|
285 FUNC_LOG; |
|
286 |
|
287 // Source |
|
288 CFServiceUtils::ReadFromStreamL( iSource, aStream ); |
|
289 |
|
290 // Type |
|
291 CFServiceUtils::ReadFromStreamL( iType, aStream ); |
|
292 |
|
293 // Value |
|
294 CFServiceUtils::ReadFromStreamL( iValue, aStream ); |
|
295 |
|
296 // Timestamp |
|
297 TPckg<TTime> timeStamp( iTimestamp ); |
|
298 aStream.ReadL( timeStamp, sizeof( TTime ) ); |
|
299 |
|
300 // Confidence |
|
301 iConfidence = aStream.ReadUint16L(); |
|
302 } |
|
303 |
|
304 //----------------------------------------------------------------------------- |
|
305 // CCFContextObjectImpl::ExternalizeL |
|
306 //----------------------------------------------------------------------------- |
|
307 // |
|
308 EXPORT_C void CCFContextObjectImpl::ExternalizeL( RWriteStream& aStream ) |
|
309 { |
|
310 FUNC_LOG; |
|
311 |
|
312 // Source |
|
313 CFServiceUtils::WriteIntoStreamL( iSource, aStream ); |
|
314 |
|
315 // Type |
|
316 CFServiceUtils::WriteIntoStreamL( iType, aStream ); |
|
317 |
|
318 // Value |
|
319 CFServiceUtils::WriteIntoStreamL( iValue, aStream ); |
|
320 |
|
321 // Timestamp |
|
322 TPckg<TTime> timestamp( iTimestamp ); |
|
323 aStream.WriteL( timestamp, sizeof( TTime ) ); |
|
324 |
|
325 // Confidence |
|
326 aStream.WriteUint16L( iConfidence ); |
|
327 |
|
328 // Commit stream |
|
329 aStream.CommitL(); |
|
330 } |
|
331 |
|
332 //----------------------------------------------------------------------------- |
|
333 // CCFContextObjectImpl::Size |
|
334 //----------------------------------------------------------------------------- |
|
335 // |
|
336 EXPORT_C TInt CCFContextObjectImpl::Size() const |
|
337 { |
|
338 FUNC_LOG; |
|
339 |
|
340 TInt size = 0; |
|
341 |
|
342 // Source |
|
343 size += sizeof( TInt ); |
|
344 if( iSource ) |
|
345 { |
|
346 size += ( *iSource ).Size(); |
|
347 } |
|
348 |
|
349 // Type |
|
350 size += sizeof( TInt ); |
|
351 if( iType ) |
|
352 { |
|
353 size += ( *iType ).Size(); |
|
354 } |
|
355 |
|
356 // Value |
|
357 size += sizeof( TInt ); |
|
358 if( iValue ) |
|
359 { |
|
360 size += ( *iValue ).Size(); |
|
361 } |
|
362 |
|
363 // Timestamp |
|
364 size += sizeof( TTime ); |
|
365 |
|
366 // Confidence |
|
367 size += sizeof( TUint ); |
|
368 |
|
369 return size; |
|
370 } |
|
371 |
|
372 //----------------------------------------------------------------------------- |
|
373 // CCFContextObjectImpl::CompareValue |
|
374 //----------------------------------------------------------------------------- |
|
375 // |
|
376 EXPORT_C TInt CCFContextObjectImpl::CompareValue( |
|
377 const CCFContextObject& aContext ) const |
|
378 { |
|
379 FUNC_LOG; |
|
380 |
|
381 return Value().Compare( aContext.Value() ); |
|
382 } |
|
383 |
|
384 //----------------------------------------------------------------------------- |
|
385 // CCFContextObjectImpl::CompareByType |
|
386 //----------------------------------------------------------------------------- |
|
387 // |
|
388 EXPORT_C TInt CCFContextObjectImpl::CompareByType( |
|
389 const CCFContextObject& aFirst, |
|
390 const CCFContextObject& aSecond ) |
|
391 { |
|
392 FUNC_LOG; |
|
393 |
|
394 return aFirst.Type().Compare( aSecond.Type() ); |
|
395 } |
|
396 |
|
397 //----------------------------------------------------------------------------- |
|
398 // CCFContextObjectImpl::CompareByTypeAndSource |
|
399 //----------------------------------------------------------------------------- |
|
400 // |
|
401 EXPORT_C TInt CCFContextObjectImpl::CompareByTypeAndSource( |
|
402 const CCFContextObject& aFirst, |
|
403 const CCFContextObject& aSecond ) |
|
404 { |
|
405 FUNC_LOG; |
|
406 |
|
407 TInt typeCompareResult = aFirst.Type().Compare( aSecond.Type() ); |
|
408 if( typeCompareResult != 0 ) |
|
409 { |
|
410 return typeCompareResult; |
|
411 } |
|
412 else |
|
413 { |
|
414 return aFirst.Source().Compare( aSecond.Source() ); |
|
415 } |
|
416 } |
|
417 |
|
418 //----------------------------------------------------------------------------- |
|
419 // CCFContextObjectImpl::CompareByTimeDescending |
|
420 //----------------------------------------------------------------------------- |
|
421 // |
|
422 EXPORT_C TInt CCFContextObjectImpl::CompareByTimeDescending( |
|
423 const CCFContextObject& aFirst, |
|
424 const CCFContextObject& aSecond ) |
|
425 { |
|
426 FUNC_LOG; |
|
427 |
|
428 TInt retVal = KTimeSecondGreater; |
|
429 |
|
430 // Both same |
|
431 if( aFirst.Timestamp() == aSecond.Timestamp() ) |
|
432 { |
|
433 retVal = KTimesSame; |
|
434 } |
|
435 // First greater than second |
|
436 else if( aFirst.Timestamp() > aSecond.Timestamp() ) |
|
437 { |
|
438 retVal = KTimeFirstGreater; |
|
439 } |
|
440 |
|
441 return retVal; |
|
442 } |
|
443 |
|
444 //----------------------------------------------------------------------------- |
|
445 // CCFContextObjectImpl::IsSame |
|
446 //----------------------------------------------------------------------------- |
|
447 // |
|
448 EXPORT_C TBool CCFContextObjectImpl::IsSame( |
|
449 const CCFContextObject& aFirst, |
|
450 const CCFContextObject& aSecond ) |
|
451 { |
|
452 FUNC_LOG; |
|
453 |
|
454 if( aFirst.Timestamp() == aSecond.Timestamp() ) |
|
455 { |
|
456 if( aFirst.Type().Compare( aSecond.Type() ) == KErrNone ) |
|
457 { |
|
458 if( aFirst.Value().Compare( aSecond.Value() ) == KErrNone ) |
|
459 { |
|
460 if( aFirst.Source().Compare( aSecond.Source() ) == KErrNone ) |
|
461 { |
|
462 if( aFirst.Confidence() == aSecond.Confidence() ) |
|
463 { |
|
464 return ETrue; |
|
465 } |
|
466 } |
|
467 } |
|
468 } |
|
469 } |
|
470 return EFalse; |
|
471 } |