463 // |
463 // |
464 CMdSNotifier::TEntry& CMdSNotifier::CreateEntryL( TInt aId, |
464 CMdSNotifier::TEntry& CMdSNotifier::CreateEntryL( TInt aId, |
465 TConditionType aType, CMdCSerializationBuffer* aSerializedBuffer, |
465 TConditionType aType, CMdCSerializationBuffer* aSerializedBuffer, |
466 TDefId aNamespaceDefId, CMdSServerSession& aSession, TBool aConfidential ) |
466 TDefId aNamespaceDefId, CMdSServerSession& aSession, TBool aConfidential ) |
467 { |
467 { |
468 |
468 TEntry entry = TEntry( aId, aType, aSerializedBuffer, aNamespaceDefId, aSession, aConfidential ); |
469 User::LeaveIfError( iEntries.Append( |
469 User::LeaveIfError( iEntries.InsertInOrder( entry, TLinearOrder<TEntry>(CMdSNotifier::Compare) ) ); |
470 TEntry( aId, aType, aSerializedBuffer, aNamespaceDefId, aSession, aConfidential ) ) ); |
470 |
471 return iEntries[ iEntries.Count() - 1 ]; |
471 return FindEntryL( aId ); |
472 } |
472 } |
473 |
473 |
474 // ------------------------------------------------ |
474 // ------------------------------------------------ |
475 // FindEntry |
475 // FindEntry |
476 // ------------------------------------------------ |
476 // ------------------------------------------------ |
477 // |
477 // |
478 CMdSNotifier::TEntry& CMdSNotifier::FindEntryL( TInt aId ) |
478 CMdSNotifier::TEntry& CMdSNotifier::FindEntryL( TInt aId ) |
479 { |
479 { |
480 CMdSNotifier::TEntry* entry = NULL; |
480 CMdSNotifier::TEntry* entry = NULL; |
481 |
481 |
482 const TInt count = iEntries.Count(); |
482 TInt low( 0 ); |
483 |
483 TInt high( iEntries.Count() ); |
484 for ( TInt i = 0; i < count; ++i ) |
484 |
485 { |
485 while( low < high ) |
486 if ( iEntries[i].iId == aId ) |
486 { |
487 { |
487 TInt mid( (low+high)>>1 ); |
488 entry = &iEntries[i]; |
488 |
|
489 const TInt compare( aId - iEntries[mid].Id() ); |
|
490 if( compare == 0 ) |
|
491 { |
|
492 entry = &iEntries[mid]; |
489 break; |
493 break; |
490 } |
494 } |
491 } |
495 else if( compare > 0 ) |
|
496 { |
|
497 low = mid + 1; |
|
498 } |
|
499 else |
|
500 { |
|
501 high = mid; |
|
502 } |
|
503 } |
492 |
504 |
493 if( !entry ) |
505 if( !entry ) |
494 { |
506 { |
495 User::Leave( KErrNotFound ); |
507 User::Leave( KErrNotFound ); |
496 } |
508 } |
502 // RemoveEntryL |
514 // RemoveEntryL |
503 // ------------------------------------------------ |
515 // ------------------------------------------------ |
504 // |
516 // |
505 void CMdSNotifier::RemoveEntryL( TInt aId ) |
517 void CMdSNotifier::RemoveEntryL( TInt aId ) |
506 { |
518 { |
507 const TInt count = iEntries.Count(); |
519 CMdSNotifier::TEntry* e = NULL; |
508 |
520 |
509 for ( TInt i = 0; i < count; ++i ) |
521 TInt low( 0 ); |
510 { |
522 TInt mid( 0 ); |
511 TEntry& e = iEntries[i]; |
523 TInt high( iEntries.Count() ); |
512 if ( e.iId == aId ) |
524 |
513 { |
525 while( low < high ) |
514 if ( e.IsPending() ) |
526 { |
515 { |
527 mid = (low+high)>>1; |
516 e.TriggerError( KErrCancel ); |
528 |
517 } |
529 const TInt compare( aId - iEntries[mid].Id() ); |
518 |
530 if( compare == 0 ) |
519 if ( e.iSerializedCondition ) |
531 { |
520 { |
532 e = &iEntries[mid]; |
521 delete e.iSerializedCondition; |
533 break; |
522 e.iSerializedCondition = NULL; |
534 } |
523 } |
535 else if( compare > 0 ) |
524 if ( e.iDataBuffer ) |
536 { |
525 { |
537 low = mid + 1; |
526 delete e.iDataBuffer; |
538 } |
527 e.iDataBuffer = NULL; |
539 else |
528 } |
540 { |
529 iEntries.Remove( i ); |
541 high = mid; |
530 return; |
542 } |
531 } |
543 } |
532 } |
544 |
533 User::Leave( KErrNotFound ); |
545 if( e ) |
|
546 { |
|
547 if ( e->IsPending() ) |
|
548 { |
|
549 e->TriggerError( KErrCancel ); |
|
550 } |
|
551 |
|
552 if ( e->iSerializedCondition ) |
|
553 { |
|
554 delete e->iSerializedCondition; |
|
555 e->iSerializedCondition = NULL; |
|
556 } |
|
557 if ( e->iDataBuffer ) |
|
558 { |
|
559 delete e->iDataBuffer; |
|
560 e->iDataBuffer = NULL; |
|
561 } |
|
562 iEntries.Remove( mid ); |
|
563 } |
|
564 else |
|
565 { |
|
566 User::Leave( KErrNotFound ); |
|
567 } |
534 } |
568 } |
535 |
569 |
536 // ------------------------------------------------ |
570 // ------------------------------------------------ |
537 // RemoveEntriesBySession |
571 // RemoveEntriesBySession |
538 // ------------------------------------------------ |
572 // ------------------------------------------------ |
635 { |
669 { |
636 TRAP_IGNORE( e.CacheL( EObjectNotifyAdd | ERelationNotifyAdd | EEventNotifyAdd | EObjectNotifyAddWithUri, |
670 TRAP_IGNORE( e.CacheL( EObjectNotifyAdd | ERelationNotifyAdd | EEventNotifyAdd | EObjectNotifyAddWithUri, |
637 matchingItemIdArray, matchingItemUriArray ) ); |
671 matchingItemIdArray, matchingItemUriArray ) ); |
638 } |
672 } |
639 } |
673 } |
640 // Copy of each uri is made to each client, which will own the returned uri |
674 } |
641 // Thus URI ownership is transferred and original array can be destroyed |
675 |
642 matchingItemUriArray.ResetAndDestroy(); |
676 CleanupStack::PopAndDestroy( 2, &matchingItemIdArray ); // matchingItemIdArray, matchingItemUriArray |
643 } |
|
644 |
|
645 CleanupStack::PopAndDestroy( 2, &matchingItemIdArray ); |
|
646 } |
677 } |
647 CleanupStack::PopAndDestroy( 2, &allItemsIdArray ); // allItemsIdArray, allItemsUriArray |
678 CleanupStack::PopAndDestroy( 2, &allItemsIdArray ); // allItemsIdArray, allItemsUriArray |
648 } |
679 } |
649 |
680 |
650 // ------------------------------------------------ |
681 // ------------------------------------------------ |
969 { |
1000 { |
970 TRAP_IGNORE( e.CacheL( EObjectNotifyModify | ERelationNotifyModify | EObjectNotifyModifyWithUri, |
1001 TRAP_IGNORE( e.CacheL( EObjectNotifyModify | ERelationNotifyModify | EObjectNotifyModifyWithUri, |
971 matchingObjectIdArray, matchingItemUriArray ) ); |
1002 matchingObjectIdArray, matchingItemUriArray ) ); |
972 } |
1003 } |
973 } |
1004 } |
974 // Copy of each uri is made to each client, which will own the returned uri |
1005 } |
975 // Thus URI ownership is transferred and original array can be destroyed |
1006 CleanupStack::PopAndDestroy( 2, &matchingObjectIdArray ); // matchingItemIdArray, matchingItemUriArray |
976 matchingItemUriArray.ResetAndDestroy(); |
|
977 } |
|
978 CleanupStack::PopAndDestroy( 2, &matchingObjectIdArray ); |
|
979 } |
1007 } |
980 CleanupStack::PopAndDestroy( 2, &allItemsIdArray ); // allItemsIdArray, allItemsUriArray |
1008 CleanupStack::PopAndDestroy( 2, &allItemsIdArray ); // allItemsIdArray, allItemsUriArray |
981 } |
1009 } |
982 |
1010 |
983 // ------------------------------------------------ |
1011 // ------------------------------------------------ |