|
1 /* |
|
2 * Copyright (c) 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: MPresenceDocument API object implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "presenceinfofilterimp.h" |
|
20 #include "ximprbufhelpers.h" |
|
21 #include "ximpobjecthelpers.h" |
|
22 #include "presenceinfo.h" |
|
23 #include "badesca.h" |
|
24 |
|
25 const TInt KFilterGranularity = 3; |
|
26 const TInt KFieldGranularity = 3; |
|
27 |
|
28 using namespace NPresenceInfo; |
|
29 |
|
30 // ============================ LOCAL FUNCTIONS ============================== |
|
31 |
|
32 // ============================ HELPER CLASS ================================= |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // CFilterField::NewL |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 CPresenceInfoFilterImp::CFilterField* |
|
39 CPresenceInfoFilterImp::CFilterField::NewL( |
|
40 const TDesC8& aInfoName ) |
|
41 { |
|
42 CFilterField* self = new ( ELeave ) CFilterField(); |
|
43 CleanupStack::PushL( self ); |
|
44 self->ConstructL( aInfoName ); |
|
45 CleanupStack::Pop( self ); |
|
46 return self; |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // CFilterField::NewLC |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 CPresenceInfoFilterImp::CFilterField* |
|
54 CPresenceInfoFilterImp::CFilterField::NewLC() |
|
55 { |
|
56 CFilterField* self = new ( ELeave ) CFilterField(); |
|
57 CleanupStack::PushL( self ); |
|
58 self->ConstructL(); |
|
59 return self; |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // CFilterField::ConstructL |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 void CPresenceInfoFilterImp::CFilterField::ConstructL( |
|
67 const TDesC8& aInfoName ) |
|
68 { |
|
69 HBufC8* tmp = aInfoName.AllocL(); |
|
70 iInfoName.Assign( tmp ); |
|
71 |
|
72 iFieldNames = new ( ELeave ) CDesC8ArraySeg( KFieldGranularity ); |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // CFilterField::ConstructL |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 void CPresenceInfoFilterImp::CFilterField::ConstructL() |
|
80 { |
|
81 iInfoName.CreateL( 0 ); |
|
82 iFieldNames = new ( ELeave ) CDesC8ArraySeg( KFieldGranularity ); |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // CFilterField::CFilterField |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 CPresenceInfoFilterImp::CFilterField::CFilterField() |
|
90 { |
|
91 } |
|
92 |
|
93 // --------------------------------------------------------------------------- |
|
94 // CFilterField::~CFilterField |
|
95 // --------------------------------------------------------------------------- |
|
96 // |
|
97 CPresenceInfoFilterImp::CFilterField::~CFilterField() |
|
98 { |
|
99 iInfoName.Close(); |
|
100 delete iFieldNames; |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------------------------- |
|
104 // CFilterField::InfoName |
|
105 // --------------------------------------------------------------------------- |
|
106 // |
|
107 const TDesC8& CPresenceInfoFilterImp::CFilterField::InfoName() |
|
108 { |
|
109 return iInfoName; |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // CFilterField::AddFieldNameL |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 void CPresenceInfoFilterImp::CFilterField::AddFieldNameL( |
|
117 const TDesC8& aFieldName ) |
|
118 { |
|
119 iFieldNames->InsertIsqL( aFieldName ); |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // CFilterField::OrderOfFields() |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 TInt CPresenceInfoFilterImp::CFilterField::OrderOfFields( |
|
127 const CFilterField& aFirst, |
|
128 const CFilterField& aSecond ) |
|
129 { |
|
130 // order is based on the info name |
|
131 return aFirst.iInfoName.Compare( aSecond.iInfoName ); |
|
132 } |
|
133 |
|
134 // --------------------------------------------------------------------------- |
|
135 // CFilterField::OrderOfFieldsByName() |
|
136 // --------------------------------------------------------------------------- |
|
137 // |
|
138 TInt CPresenceInfoFilterImp::CFilterField::OrderOfFieldsByName( |
|
139 const TDesC8* aName, |
|
140 const CFilterField& aSecond ) |
|
141 { |
|
142 return aName->Compare( aSecond.iInfoName ); |
|
143 } |
|
144 |
|
145 // --------------------------------------------------------------------------- |
|
146 // CFilterField::ExternalizeL |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 void CPresenceInfoFilterImp::CFilterField::ExternalizeL( |
|
150 RWriteStream& aStream ) const |
|
151 { |
|
152 XIMPRBuf8Helper::ExternalizeL( iInfoName, aStream ); |
|
153 |
|
154 aStream.WriteInt32L( iFieldNames->Count() ); |
|
155 |
|
156 for ( TInt i = 0; i < iFieldNames->Count(); i++ ) |
|
157 { |
|
158 TPtrC8 p = iFieldNames->MdcaPoint( i ); |
|
159 aStream.WriteInt32L( p.Length() ); |
|
160 aStream.WriteL( p ); |
|
161 } |
|
162 } |
|
163 |
|
164 // --------------------------------------------------------------------------- |
|
165 // CFilterField::InternalizeL |
|
166 // --------------------------------------------------------------------------- |
|
167 // |
|
168 void CPresenceInfoFilterImp::CFilterField::InternalizeL( |
|
169 RReadStream& aStream ) |
|
170 { |
|
171 XIMPRBuf8Helper::InternalizeL( iInfoName, aStream ); |
|
172 |
|
173 TInt count = aStream.ReadInt32L(); |
|
174 for ( TInt i = 0; i < count; i++ ) |
|
175 { |
|
176 TInt length = aStream.ReadInt32L(); |
|
177 HBufC8* buf = HBufC8::NewLC( length ); |
|
178 |
|
179 TPtr8 des = TPtr8( buf->Des() ); |
|
180 aStream.ReadL( des, length ); |
|
181 iFieldNames->InsertIsqL( *buf ); |
|
182 |
|
183 CleanupStack::PopAndDestroy( buf ); |
|
184 } |
|
185 } |
|
186 |
|
187 // --------------------------------------------------------------------------- |
|
188 // CFilterField::MergeL |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 void CPresenceInfoFilterImp::CFilterField::MergeL( CFilterField& aOtherField ) |
|
192 { |
|
193 // merge algorithm: |
|
194 // add all field names from given filter field, ignoring duplicates |
|
195 |
|
196 for ( TInt i = 0; i < iFieldNames->Count(); i++ ) |
|
197 { |
|
198 TInt pos = 0; |
|
199 TInt ret = iFieldNames->FindIsq( aOtherField.iFieldNames->MdcaPoint( i ), pos ); |
|
200 |
|
201 if ( 0 != ret ) |
|
202 { |
|
203 iFieldNames->InsertIsqL( aOtherField.iFieldNames->MdcaPoint( i ) ); |
|
204 } |
|
205 } |
|
206 } |
|
207 |
|
208 // --------------------------------------------------------------------------- |
|
209 // CFilterField::operator== |
|
210 // --------------------------------------------------------------------------- |
|
211 // |
|
212 TBool CPresenceInfoFilterImp::CFilterField::operator==( const CFilterField& aSource ) |
|
213 { |
|
214 if( iInfoName.Compare( aSource.iInfoName ) != 0 ) |
|
215 { |
|
216 return EFalse; |
|
217 } |
|
218 TInt count = iFieldNames->Count(); |
|
219 if( count != aSource.iFieldNames->Count() ) |
|
220 { |
|
221 return EFalse; |
|
222 } |
|
223 |
|
224 for ( TInt i = 0; i < count; i++ ) |
|
225 { |
|
226 if( iFieldNames->MdcaPoint( i ).Compare( aSource.iFieldNames->MdcaPoint( i ) ) != 0 ) |
|
227 { |
|
228 return EFalse; |
|
229 } |
|
230 } |
|
231 return ETrue; |
|
232 } |
|
233 |
|
234 // --------------------------------------------------------------------------- |
|
235 // CFilterField::operator!= |
|
236 // --------------------------------------------------------------------------- |
|
237 // |
|
238 TBool CPresenceInfoFilterImp::CFilterField::operator!=( const CFilterField& aSource ) |
|
239 { |
|
240 return !( *this == aSource ); |
|
241 } |
|
242 |
|
243 // ============================ MEMBER FUNCTIONS ============================= |
|
244 |
|
245 // --------------------------------------------------------------------------- |
|
246 // CPresenceInfoFilterImp::NewLC() |
|
247 // --------------------------------------------------------------------------- |
|
248 // |
|
249 EXPORT_C CPresenceInfoFilterImp* CPresenceInfoFilterImp::NewLC() |
|
250 { |
|
251 CPresenceInfoFilterImp* self = new( ELeave ) CPresenceInfoFilterImp; |
|
252 CleanupStack::PushL( self ); |
|
253 self->ConstructL(); |
|
254 return self; |
|
255 } |
|
256 |
|
257 // --------------------------------------------------------------------------- |
|
258 // CPresenceInfoFilterImp::NewL() |
|
259 // --------------------------------------------------------------------------- |
|
260 // |
|
261 EXPORT_C CPresenceInfoFilterImp* CPresenceInfoFilterImp::NewL() |
|
262 { |
|
263 CPresenceInfoFilterImp* self = NewLC(); |
|
264 CleanupStack::Pop( self ); |
|
265 return self; |
|
266 } |
|
267 // --------------------------------------------------------------------------- |
|
268 // CPresenceInfoImp::NewFromStreamLC() |
|
269 // --------------------------------------------------------------------------- |
|
270 // |
|
271 XIMPIMP_IMPLEMENT_DATAOBJ_NEWFROMSTREAM( CPresenceInfoFilterImp ) |
|
272 |
|
273 // --------------------------------------------------------------------------- |
|
274 // Implement supported interface access. |
|
275 // --------------------------------------------------------------------------- |
|
276 // |
|
277 XIMPIMP_IF_BASE_GET_INTERFACE_BEGIN( CPresenceInfoFilterImp, |
|
278 MPresenceInfoFilter ) |
|
279 XIMPIMP_IF_BASE_GET_INTERFACE_END() |
|
280 |
|
281 |
|
282 XIMPIMP_IF_BASE_GET_CONST_INTERFACE_BEGIN( CPresenceInfoFilterImp, |
|
283 MPresenceInfoFilter ) |
|
284 XIMPIMP_IF_BASE_GET_INTERFACE_END() |
|
285 |
|
286 // --------------------------------------------------------------------------- |
|
287 // CPresenceInfoFilterImp::EqualsContent() |
|
288 // --------------------------------------------------------------------------- |
|
289 // |
|
290 TBool CPresenceInfoFilterImp::EqualsContent( |
|
291 const CXIMPApiDataObjBase& aOtherInstance ) const |
|
292 { |
|
293 const CPresenceInfoFilterImp* tmp = |
|
294 TXIMPGetImpClassOrPanic< const CPresenceInfoFilterImp >::From( aOtherInstance.Base() ); |
|
295 |
|
296 TInt count = iPersonFilter->Count(); |
|
297 if( count != tmp->iPersonFilter->Count() ) |
|
298 { |
|
299 return EFalse; |
|
300 } |
|
301 |
|
302 for ( TInt i = 0; i < count; i++ ) |
|
303 { |
|
304 if( iPersonFilter->MdcaPoint( i ).Compare( tmp->iPersonFilter->MdcaPoint( i ) ) != 0 ) |
|
305 { |
|
306 return EFalse; |
|
307 } |
|
308 } |
|
309 |
|
310 count = iServiceFilter.Count(); |
|
311 if( count != tmp->iServiceFilter.Count() ) |
|
312 { |
|
313 return EFalse; |
|
314 } |
|
315 |
|
316 for( TInt a = 0; a < count; ++a ) |
|
317 { |
|
318 if( iServiceFilter[ a ] != tmp->iServiceFilter[ a ] ) |
|
319 { |
|
320 return EFalse; |
|
321 } |
|
322 } |
|
323 |
|
324 count = iDeviceFilter.Count(); |
|
325 if( count != tmp->iDeviceFilter.Count() ) |
|
326 { |
|
327 return EFalse; |
|
328 } |
|
329 |
|
330 for( TInt a = 0; a < count; ++a ) |
|
331 { |
|
332 if( iDeviceFilter[ a ] != tmp->iDeviceFilter[ a ] ) |
|
333 { |
|
334 return EFalse; |
|
335 } |
|
336 } |
|
337 return ETrue; |
|
338 } |
|
339 |
|
340 // --------------------------------------------------------------------------- |
|
341 // CPresenceInfoFilterImp::CPresenceInfoFilterImp() |
|
342 // --------------------------------------------------------------------------- |
|
343 // |
|
344 CPresenceInfoFilterImp::CPresenceInfoFilterImp() |
|
345 { |
|
346 } |
|
347 |
|
348 |
|
349 // --------------------------------------------------------------------------- |
|
350 // CPresenceInfoFilterImp::~CPresenceInfoFilterImp() |
|
351 // --------------------------------------------------------------------------- |
|
352 // |
|
353 CPresenceInfoFilterImp::~CPresenceInfoFilterImp() |
|
354 { |
|
355 delete iPersonFilter; |
|
356 iServiceFilter.ResetAndDestroy(); |
|
357 iDeviceFilter.ResetAndDestroy(); |
|
358 } |
|
359 |
|
360 |
|
361 |
|
362 // --------------------------------------------------------------------------- |
|
363 // CPresenceInfoFilterImp::ConstructL() |
|
364 // --------------------------------------------------------------------------- |
|
365 // |
|
366 void CPresenceInfoFilterImp::ConstructL() |
|
367 { |
|
368 iPersonFilter = new ( ELeave ) CDesC8ArraySeg( KFilterGranularity ); |
|
369 } |
|
370 |
|
371 // --------------------------------------------------------------------------- |
|
372 // CPresenceInfoFilterImp::ExternalizeArrayL() |
|
373 // --------------------------------------------------------------------------- |
|
374 // |
|
375 void CPresenceInfoFilterImp::ExternalizeArrayL( |
|
376 const CDesC8ArraySeg* aArray, RWriteStream& aStream ) const |
|
377 { |
|
378 aStream.WriteInt32L( aArray->Count() ); |
|
379 |
|
380 for ( TInt i = 0; i < aArray->Count(); i++ ) |
|
381 { |
|
382 TPtrC8 p = aArray->MdcaPoint( i ); |
|
383 aStream.WriteInt32L( p.Length() ); |
|
384 aStream.WriteL( p ); |
|
385 } |
|
386 } |
|
387 |
|
388 // --------------------------------------------------------------------------- |
|
389 // CPresenceInfoFilterImp::ExternalizeFieldSetL |
|
390 // --------------------------------------------------------------------------- |
|
391 // |
|
392 void CPresenceInfoFilterImp::ExternalizeFieldSetL( |
|
393 const RXIMPObjOwningPtrArray<CFilterField>& aFieldSet, |
|
394 RWriteStream& aStream |
|
395 ) const |
|
396 { |
|
397 TInt count = aFieldSet.Count(); |
|
398 |
|
399 aStream.WriteInt32L( count ); |
|
400 for ( TInt i = 0; i < count; i++ ) |
|
401 { |
|
402 CFilterField* field = aFieldSet[ i ]; |
|
403 field->ExternalizeL( aStream ); |
|
404 } |
|
405 } |
|
406 |
|
407 // --------------------------------------------------------------------------- |
|
408 // CPresenceInfoFilterImp::InternalizeFieldSetL |
|
409 // --------------------------------------------------------------------------- |
|
410 // |
|
411 void CPresenceInfoFilterImp::InternalizeFieldSetL( |
|
412 RXIMPObjOwningPtrArray<CFilterField>& aFieldSet, |
|
413 RReadStream& aStream |
|
414 ) |
|
415 { |
|
416 TInt count = aStream.ReadInt32L(); |
|
417 |
|
418 for ( TInt i = 0; i < count; i++ ) |
|
419 { |
|
420 CFilterField* field = CFilterField::NewLC(); |
|
421 field->InternalizeL( aStream ); |
|
422 aFieldSet.AppendL( field ); |
|
423 CleanupStack::Pop( field ); |
|
424 } |
|
425 } |
|
426 |
|
427 // --------------------------------------------------------------------------- |
|
428 // CPresenceInfoFilterImp::ExternalizeL() |
|
429 // --------------------------------------------------------------------------- |
|
430 // |
|
431 EXPORT_C void CPresenceInfoFilterImp::ExternalizeL( RWriteStream& aStream ) const |
|
432 { |
|
433 ExternalizeArrayL( iPersonFilter, aStream ); |
|
434 ExternalizeFieldSetL( iServiceFilter, aStream ); |
|
435 ExternalizeFieldSetL( iDeviceFilter, aStream ); |
|
436 } |
|
437 |
|
438 // --------------------------------------------------------------------------- |
|
439 // CPresenceInfoFilterImp::InternalizeArrayL() |
|
440 // --------------------------------------------------------------------------- |
|
441 // |
|
442 void CPresenceInfoFilterImp::InternalizeArrayL( |
|
443 CDesC8ArraySeg* aArray, RReadStream& aStream ) |
|
444 { |
|
445 TInt count = aStream.ReadInt32L(); |
|
446 for ( TInt i = 0; i < count; i++ ) |
|
447 { |
|
448 TInt length = aStream.ReadInt32L(); |
|
449 |
|
450 HBufC8* buf = HBufC8::NewLC( length ); |
|
451 |
|
452 TPtr8 des = TPtr8( buf->Des() ); |
|
453 aStream.ReadL( des, length ); |
|
454 aArray->InsertIsqL( des ); |
|
455 |
|
456 CleanupStack::PopAndDestroy( buf ); |
|
457 } |
|
458 } |
|
459 |
|
460 |
|
461 // --------------------------------------------------------------------------- |
|
462 // CPresenceInfoFilterImp::InternalizeL() |
|
463 // --------------------------------------------------------------------------- |
|
464 // |
|
465 EXPORT_C void CPresenceInfoFilterImp::InternalizeL( RReadStream& aStream ) |
|
466 { |
|
467 InternalizeArrayL( iPersonFilter, aStream ); |
|
468 InternalizeFieldSetL( iServiceFilter, aStream ); |
|
469 InternalizeFieldSetL( iDeviceFilter, aStream ); |
|
470 } |
|
471 |
|
472 // --------------------------------------------------------------------------- |
|
473 // CPresenceInfoFilterImp::ContainsPersonFilter |
|
474 // --------------------------------------------------------------------------- |
|
475 // |
|
476 TBool CPresenceInfoFilterImp::ContainsPersonFilter( |
|
477 CDesC8ArraySeg* aA, |
|
478 CDesC8ArraySeg* aCompare |
|
479 ) |
|
480 { |
|
481 TInt count = aCompare->Count(); |
|
482 if ( count >= aA->Count() ) |
|
483 { |
|
484 // impossible to be contained |
|
485 return EFalse; |
|
486 } |
|
487 |
|
488 for ( TInt i = 0; i < count; i++ ) |
|
489 { |
|
490 // all person filter strings in aCompare MUST be found in this class |
|
491 TInt pos = 0; |
|
492 if( 0 != aA->FindIsq( aCompare->MdcaPoint( i ), pos ) ) |
|
493 { |
|
494 // element not contained within "this", so whole filter not contained |
|
495 return EFalse; |
|
496 } |
|
497 } |
|
498 |
|
499 return ETrue; |
|
500 } |
|
501 |
|
502 // --------------------------------------------------------------------------- |
|
503 // CPresenceInfoFilterImp::ContainsFilterFields |
|
504 // --------------------------------------------------------------------------- |
|
505 // |
|
506 TBool CPresenceInfoFilterImp::ContainsFilterFields( |
|
507 RXIMPObjOwningPtrArray<CFilterField>& aA, |
|
508 RXIMPObjOwningPtrArray<CFilterField>& aCompare |
|
509 ) |
|
510 { |
|
511 // check all filter fields |
|
512 TInt count = aCompare.Count(); |
|
513 if ( count >= aA.Count() ) |
|
514 { |
|
515 // impossible for "aCompare" to be contained, has more fields |
|
516 return EFalse; |
|
517 } |
|
518 |
|
519 for( TInt i = 0; i < count; i++ ) |
|
520 { |
|
521 // all filters in aCompare MUST be found in this class. |
|
522 // first check for the named filter field class |
|
523 TInt pos = 0; |
|
524 pos = aA.FindInOrder( |
|
525 aCompare[ i ]->InfoName(), |
|
526 CFilterField::OrderOfFieldsByName ); |
|
527 |
|
528 if ( KErrNotFound == pos ) |
|
529 { |
|
530 // element not contained within "aA", so whole filter not contained |
|
531 return EFalse; |
|
532 } |
|
533 |
|
534 // now the subfields in the filter field class |
|
535 TInt countFields = aCompare[ i ]->iFieldNames->MdcaCount(); |
|
536 if ( countFields >= aA[ pos ]->iFieldNames->MdcaCount() ) |
|
537 { |
|
538 // impossible to be contained |
|
539 return EFalse; |
|
540 } |
|
541 |
|
542 for ( TInt j = 0; j < countFields; j++ ) |
|
543 { |
|
544 TInt dummyPos = 0; |
|
545 if ( aA[ pos ]->iFieldNames->FindIsq( aCompare[ i ]->iFieldNames->MdcaPoint( j ), dummyPos ) ) |
|
546 { |
|
547 // field not contained within "aA", so whole |
|
548 // filter not contained |
|
549 return EFalse; |
|
550 } |
|
551 } |
|
552 } |
|
553 |
|
554 return ETrue; |
|
555 } |
|
556 |
|
557 // --------------------------------------------------------------------------- |
|
558 // CPresenceInfoFilterImp::Contains |
|
559 // --------------------------------------------------------------------------- |
|
560 // |
|
561 EXPORT_C TBool CPresenceInfoFilterImp::Contains( CPresenceInfoFilterImp& aCompare ) |
|
562 { |
|
563 // walk through all filters in aCompare, |
|
564 // if a filter is NOT found in this class --> not contained |
|
565 // if all filters are found in this class --> contained |
|
566 |
|
567 // person filter |
|
568 if ( ! ContainsPersonFilter( iPersonFilter, aCompare.iPersonFilter ) ) |
|
569 { |
|
570 return EFalse; |
|
571 } |
|
572 |
|
573 // service filter |
|
574 if ( ! ContainsFilterFields( iServiceFilter, aCompare.iServiceFilter ) ) |
|
575 { |
|
576 return EFalse; |
|
577 } |
|
578 |
|
579 // device filter |
|
580 if ( ! ContainsFilterFields( iDeviceFilter, aCompare.iDeviceFilter ) ) |
|
581 { |
|
582 return EFalse; |
|
583 } |
|
584 |
|
585 return ETrue; |
|
586 } |
|
587 |
|
588 // --------------------------------------------------------------------------- |
|
589 // CPresenceInfoFilterImp::operator== |
|
590 // --------------------------------------------------------------------------- |
|
591 // |
|
592 EXPORT_C TBool CPresenceInfoFilterImp::operator==( CPresenceInfoFilterImp& aSource ) |
|
593 { |
|
594 return EqualsContent( aSource ); |
|
595 } |
|
596 |
|
597 // --------------------------------------------------------------------------- |
|
598 // CPresenceInfoFilterImp::operator!= |
|
599 // --------------------------------------------------------------------------- |
|
600 // |
|
601 EXPORT_C TBool CPresenceInfoFilterImp::operator!=( CPresenceInfoFilterImp& aSource ) |
|
602 { |
|
603 return !EqualsContent( aSource ); |
|
604 } |
|
605 |
|
606 |
|
607 // --------------------------------------------------------------------------- |
|
608 // CPresenceInfoFilterImp::AcceptPersonFilterL |
|
609 // --------------------------------------------------------------------------- |
|
610 // |
|
611 void CPresenceInfoFilterImp::AcceptPersonFilterL( const TDesC8& aFieldName ) |
|
612 { |
|
613 if ( !aFieldName.Compare( NPresenceInfo::NFieldType::KAcceptAll ) ) |
|
614 { |
|
615 iPersonFilter->InsertIsqL( NPresenceInfo::NFieldType::KStatusMessage ); |
|
616 iPersonFilter->InsertIsqL( NPresenceInfo::NFieldType::KAvatar ); |
|
617 iPersonFilter->InsertIsqL( NPresenceInfo::NFieldType::KAvailability ); |
|
618 } |
|
619 else |
|
620 { |
|
621 iPersonFilter->InsertIsqL( aFieldName ); |
|
622 } |
|
623 } |
|
624 |
|
625 // --------------------------------------------------------------------------- |
|
626 // CPresenceInfoFilterImp::AcceptFilterL |
|
627 // --------------------------------------------------------------------------- |
|
628 // |
|
629 void CPresenceInfoFilterImp::AcceptFilterL( |
|
630 RXIMPObjOwningPtrArray< CFilterField >& aFieldSet, |
|
631 const TDesC8& aInfoName, |
|
632 const TDesC8& aFieldName ) |
|
633 { |
|
634 TLinearOrder< CPresenceInfoFilterImp::CFilterField > order( |
|
635 CPresenceInfoFilterImp::CFilterField::OrderOfFields ); |
|
636 |
|
637 CFilterField* field = CFilterField::NewL( aInfoName ); |
|
638 CleanupStack::PushL( field ); |
|
639 field->iFieldNames->InsertIsqL( aFieldName ); |
|
640 aFieldSet.InsertInOrderL( field, order ); |
|
641 CleanupStack::Pop( field ); |
|
642 } |
|
643 |
|
644 // --------------------------------------------------------------------------- |
|
645 // CPresenceInfoFilterImp::AcceptServiceFilterL |
|
646 // --------------------------------------------------------------------------- |
|
647 // |
|
648 void CPresenceInfoFilterImp::AcceptServiceFilterL( |
|
649 const TDesC8& aServiceName, |
|
650 const TDesC8& aFieldName ) |
|
651 { |
|
652 AcceptFilterL( iServiceFilter, aServiceName, aFieldName ); |
|
653 } |
|
654 |
|
655 // --------------------------------------------------------------------------- |
|
656 // CPresenceInfoFilterImp::AcceptDeviceFilterL |
|
657 // --------------------------------------------------------------------------- |
|
658 // |
|
659 void CPresenceInfoFilterImp::AcceptDeviceFilterL( |
|
660 const TDesC8& aDeviceName, |
|
661 const TDesC8& aFieldName ) |
|
662 { |
|
663 AcceptFilterL( iDeviceFilter, aDeviceName, aFieldName ); |
|
664 } |
|
665 |
|
666 // --------------------------------------------------------------------------- |
|
667 // CPresenceInfoFilterImp::MatchPersonFilter |
|
668 // --------------------------------------------------------------------------- |
|
669 // |
|
670 TBool CPresenceInfoFilterImp::MatchPersonFilter( |
|
671 const TDesC8& aFieldName ) const |
|
672 { |
|
673 TBool found = EFalse; |
|
674 for ( TInt i = 0; i < iPersonFilter->Count() && ! found; i++ ) |
|
675 { |
|
676 if ( KErrNotFound != ( iPersonFilter->MdcaPoint( i ).Match( aFieldName ) ) ) |
|
677 { |
|
678 // found it |
|
679 return ETrue; |
|
680 } |
|
681 } |
|
682 |
|
683 return EFalse; |
|
684 } |
|
685 |
|
686 // --------------------------------------------------------------------------- |
|
687 // CPresenceInfoFilterImp::MatchFilterL |
|
688 // --------------------------------------------------------------------------- |
|
689 // |
|
690 TBool CPresenceInfoFilterImp::MatchFilterL( |
|
691 const RXIMPObjOwningPtrArray< CFilterField >& aFieldSet, |
|
692 const TDesC8& aInfoName, |
|
693 const TDesC8& aFieldName ) const |
|
694 { |
|
695 CFilterField* candidate = CFilterField::NewL( aInfoName ); |
|
696 CleanupStack::PushL( candidate ); |
|
697 |
|
698 TBool foundMatch = EFalse; |
|
699 |
|
700 // walk through all fields. slow algo! use a hash to index the field set. |
|
701 for ( TInt j = 0; j < aFieldSet.Count(); j++ ) |
|
702 { |
|
703 // now, go through all fields in service filter which match |
|
704 // the candidate |
|
705 CFilterField* field = aFieldSet[ j ]; |
|
706 |
|
707 if ( KErrNotFound != aInfoName.Match( field->iInfoName ) ) |
|
708 { |
|
709 // field name matches, so try to find the types |
|
710 |
|
711 for ( TInt i = 0; i < field->iFieldNames->Count(); i++ ) |
|
712 { |
|
713 TBool found = ( KErrNotFound != aFieldName.Match( field->iFieldNames->MdcaPoint( i ) ) ) |
|
714 ? ETrue : EFalse; |
|
715 foundMatch |= found; |
|
716 } |
|
717 } |
|
718 } |
|
719 CleanupStack::PopAndDestroy( candidate ); |
|
720 |
|
721 return foundMatch; |
|
722 } |
|
723 |
|
724 // --------------------------------------------------------------------------- |
|
725 // CPresenceInfoFilterImp::MatchServiceFilter |
|
726 // --------------------------------------------------------------------------- |
|
727 // |
|
728 TBool CPresenceInfoFilterImp::MatchServiceFilterL( |
|
729 const TDesC8& aServiceName, |
|
730 const TDesC8& aFieldName ) const |
|
731 { |
|
732 return MatchFilterL( iServiceFilter, aServiceName, aFieldName ); |
|
733 } |
|
734 |
|
735 // --------------------------------------------------------------------------- |
|
736 // CPresenceInfoFilterImp::MatchDeviceFilterL |
|
737 // --------------------------------------------------------------------------- |
|
738 // |
|
739 TBool CPresenceInfoFilterImp::MatchDeviceFilterL( |
|
740 const TDesC8& aDeviceName, |
|
741 const TDesC8& aFieldName ) const |
|
742 { |
|
743 return MatchFilterL( iDeviceFilter, aDeviceName, aFieldName ); |
|
744 } |
|
745 |
|
746 // --------------------------------------------------------------------------- |
|
747 // CPresenceInfoFilterImp::UnionL |
|
748 // --------------------------------------------------------------------------- |
|
749 // |
|
750 EXPORT_C CPresenceInfoFilterImp* CPresenceInfoFilterImp::UnionL( |
|
751 CPresenceInfoFilterImp& aFirst, |
|
752 CPresenceInfoFilterImp& aSecond ) |
|
753 { |
|
754 CPresenceInfoFilterImp* cloned = TXIMPObjectCloner< CPresenceInfoFilterImp >::CloneLC( aFirst ); |
|
755 |
|
756 // union of the person filters - must not add duplicates |
|
757 for ( TInt i = 0; i < aSecond.iPersonFilter->Count(); i++ ) |
|
758 { |
|
759 TInt pos = 0; |
|
760 TInt ret = cloned->iPersonFilter->FindIsq( aSecond.iPersonFilter->MdcaPoint( i ), pos ); |
|
761 |
|
762 if ( 0 != ret ) |
|
763 { |
|
764 cloned->iPersonFilter->InsertIsqL( aSecond.iPersonFilter->MdcaPoint( i ) ); |
|
765 } |
|
766 } |
|
767 |
|
768 // union of service fields |
|
769 aFirst.UnionOfFieldsL( aSecond.iServiceFilter, cloned->iServiceFilter ); |
|
770 |
|
771 // union of device fields |
|
772 aFirst.UnionOfFieldsL( aSecond.iDeviceFilter, cloned->iDeviceFilter ); |
|
773 |
|
774 CleanupStack::Pop( cloned ); |
|
775 return cloned; |
|
776 } |
|
777 |
|
778 // --------------------------------------------------------------------------- |
|
779 // CPresenceInfoFilterImp::UnionOfFieldsL |
|
780 // --------------------------------------------------------------------------- |
|
781 // |
|
782 void CPresenceInfoFilterImp::UnionOfFieldsL( |
|
783 RXIMPObjOwningPtrArray< CFilterField>& aSource, |
|
784 RXIMPObjOwningPtrArray< CFilterField>& aTarget ) |
|
785 { |
|
786 TLinearOrder< CPresenceInfoFilterImp::CFilterField > order( |
|
787 CPresenceInfoFilterImp::CFilterField::OrderOfFields ); |
|
788 |
|
789 for ( TInt i = 0; i < aSource.Count(); i++ ) |
|
790 { |
|
791 CFilterField* field = aSource[ i ]; |
|
792 |
|
793 // if the field name exists in the target, merge the fields |
|
794 TInt pos = aTarget.FindInOrder( field, order ); |
|
795 if ( pos == KErrNotFound ) |
|
796 { |
|
797 // not found, insert the non-found one as a copy |
|
798 CFilterField* newField = TXIMPObjectCloner< CFilterField >::CloneLC( *field ); |
|
799 aTarget.InsertInOrder( newField, order ); |
|
800 CleanupStack::Pop( newField ); |
|
801 } |
|
802 else |
|
803 { |
|
804 // found one, merge them to the cloned one |
|
805 aTarget[ pos ]->MergeL( *field ); |
|
806 } |
|
807 } |
|
808 } |
|
809 |
|
810 // End of file |