metadataengine/client/src/mdesessionimpl.cpp
branchRCL_3
changeset 15 3cebc1a84278
parent 14 646a02f170b9
child 19 82c0024438c8
child 23 33ae025ac1e8
equal deleted inserted replaced
14:646a02f170b9 15:3cebc1a84278
  2676     }
  2676     }
  2677 
  2677 
  2678 TInt CMdESessionImpl::FindNotifier( TUint32 aNotifyType, TAny* aObserver, 
  2678 TInt CMdESessionImpl::FindNotifier( TUint32 aNotifyType, TAny* aObserver, 
  2679 									CMdENamespaceDef& aNamespaceDef )
  2679 									CMdENamespaceDef& aNamespaceDef )
  2680     {
  2680     {
  2681     const TInt notifiersCount = iNotifiers.Count();
  2681     for( TInt i = iNotifiers.Count() - 1; i >=0; i-- )
  2682     for( TInt i = 0; i < notifiersCount; ++i )
       
  2683         {
  2682         {
  2684         if ( iNotifiers[i]->Match( aNotifyType, aObserver, aNamespaceDef ) )
  2683         if ( iNotifiers[i]->Match( aNotifyType, aObserver, aNamespaceDef ) )
  2685         	{
  2684         	{
  2686         	return i;
  2685         	return i;
  2687         	}
  2686         	}
  2942     else
  2941     else
  2943     	{
  2942     	{
  2944     	return &GetDefaultNamespaceDefL();
  2943     	return &GetDefaultNamespaceDefL();
  2945     	}
  2944     	}
  2946 	}
  2945 	}
       
  2946 	
       
  2947 void CMdESessionImpl::AddObjectObserverWithUriL( MMdEObjectObserverWithUri& aObserver,
       
  2948                                           CMdELogicCondition* aCondition, 
       
  2949                                           TUint32 aNotificationType,
       
  2950                                           CMdENamespaceDef* aNamespaceDef )
       
  2951     {
       
  2952     CleanupStack::PushL( aCondition );
       
  2953     
       
  2954     // if condition is given, check that it is correct type
       
  2955     if( aCondition && ( EConditionTypeLogic != aCondition->Type() ) )
       
  2956         {
       
  2957         User::Leave( KErrArgument );
       
  2958         }
       
  2959 
       
  2960     // if namespace is not given get default namespace definition
       
  2961     CMdENamespaceDef* namespaceDef = NULL;
       
  2962     if ( !aNamespaceDef )
       
  2963         {
       
  2964         namespaceDef = &GetDefaultNamespaceDefL();
       
  2965         }
       
  2966     else
       
  2967         {
       
  2968         namespaceDef = aNamespaceDef;
       
  2969         }
       
  2970 
       
  2971     TUint32 type = 0;
       
  2972     if ( aNotificationType & ENotifyAdd )
       
  2973         {
       
  2974         type |= EObjectNotifyAddWithUri;
       
  2975         }
       
  2976     if ( aNotificationType & ENotifyModify )
       
  2977         {
       
  2978         type |= EObjectNotifyModifyWithUri;
       
  2979         }
       
  2980     if ( aNotificationType & ENotifyRemove )
       
  2981         {
       
  2982         type |= EObjectNotifyRemoveWithUri;
       
  2983         }
       
  2984         
       
  2985     TInt err = FindNotifier( type, &aObserver, *namespaceDef );
       
  2986     
       
  2987     if ( err != KErrNotFound )
       
  2988         {
       
  2989         if ( err >= 0 )
       
  2990             {
       
  2991             err = KErrAlreadyExists;
       
  2992             }
       
  2993         User::LeaveIfError( err );
       
  2994         }
       
  2995 
       
  2996     CMdENotifierAO* notifier = CMdENotifierAO::NewLC( *this, iSession );
       
  2997     notifier->RegisterL( type, &aObserver, aCondition, *namespaceDef );
       
  2998 
       
  2999     CleanupStack::Pop( notifier );
       
  3000     iNotifiers.Append( notifier );
       
  3001     
       
  3002     CleanupStack::PopAndDestroy( aCondition );
       
  3003     }
       
  3004 
       
  3005 void CMdESessionImpl::RemoveObjectObserverWithUriL( 
       
  3006         MMdEObjectObserverWithUri& aObserver, CMdENamespaceDef* aNamespaceDef )
       
  3007     {
       
  3008     // if namespace is not given get default namespace definition
       
  3009     CMdENamespaceDef* namespaceDef = NULL;
       
  3010     if ( !aNamespaceDef )
       
  3011         {
       
  3012         namespaceDef = &GetDefaultNamespaceDefL();
       
  3013         }
       
  3014     else
       
  3015         {
       
  3016         namespaceDef = aNamespaceDef;
       
  3017         }
       
  3018 
       
  3019     const TInt index = FindNotifier( 
       
  3020             EObjectNotifyAddWithUri | EObjectNotifyModifyWithUri | EObjectNotifyRemoveWithUri,
       
  3021             &aObserver, *namespaceDef );
       
  3022     if ( index != KErrNotFound )
       
  3023         {
       
  3024         iNotifiers[index]->Cancel();
       
  3025         delete iNotifiers[index];
       
  3026         iNotifiers[index] = NULL;
       
  3027         iNotifiers.Remove( index );
       
  3028         iNotifiers.Compress();
       
  3029         }
       
  3030     else
       
  3031         {
       
  3032         User::Leave( KErrNotFound );
       
  3033         }
       
  3034     }
       
  3035