metadataengine/server/src/mdsnotifier.cpp
changeset 23 33ae025ac1e8
parent 21 50bf9db68373
child 40 910a23996aa0
equal deleted inserted replaced
21:50bf9db68373 23:33ae025ac1e8
   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.InsertInOrderAllowRepeats( 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         if ( e->iSerializedCondition )
       
   552             {
       
   553             delete e->iSerializedCondition;
       
   554             e->iSerializedCondition = NULL;
       
   555             }
       
   556         if ( e->iDataBuffer )
       
   557             {
       
   558             delete e->iDataBuffer;
       
   559             e->iDataBuffer = NULL;
       
   560             }
       
   561         iEntries.Remove( mid );
       
   562         }
       
   563     else
       
   564         {
       
   565         User::Leave( KErrNotFound );
       
   566         }
   534     }
   567     }
   535 
   568 
   536 // ------------------------------------------------
   569 // ------------------------------------------------
   537 // RemoveEntriesBySession
   570 // RemoveEntriesBySession
   538 // ------------------------------------------------
   571 // ------------------------------------------------
  1333 	        		}
  1366 	        		}
  1334             	CleanupStack::PopAndDestroy( &matchedRelations );
  1367             	CleanupStack::PopAndDestroy( &matchedRelations );
  1335             	}
  1368             	}
  1336 	        }
  1369 	        }
  1337 		}
  1370 		}
  1338 
       
  1339 	}
  1371 	}
  1340 
  1372 
       
  1373 TInt CMdSNotifier::Compare( const TEntry& aFirst, const TEntry& aSecond )
       
  1374     {
       
  1375     return aFirst.Id() - aSecond.Id();
       
  1376     }
       
  1377