predictivesearch/PcsAlgorithm/Algorithm1/src/CPcsAlgorithm1.cpp
branchRCL_3
changeset 58 d4f567ce2e7c
parent 39 a6539d1e8e43
child 64 c1e8ba0c2b16
equal deleted inserted replaced
57:2666d9724c76 58:d4f567ce2e7c
   906 // CPcsAlgorithm1::UpdateCachingStatus
   906 // CPcsAlgorithm1::UpdateCachingStatus
   907 // Update caching status
   907 // Update caching status
   908 // ----------------------------------------------------------------------------
   908 // ----------------------------------------------------------------------------
   909 void CPcsAlgorithm1::UpdateCachingStatus(TDesC& aDataStore, TInt aStatus)
   909 void CPcsAlgorithm1::UpdateCachingStatus(TDesC& aDataStore, TInt aStatus)
   910 {
   910 {
   911 	PRINT ( _L("Enter CPcsAlgorithm1::UpdateCachingStatus") );
   911     PRINT ( _L("Enter CPcsAlgorithm1::UpdateCachingStatus") );
   912 	
   912     PRINT2 ( _L("CPcsAlgorithm1::UpdateCachingStatus: Request received for URI=%S with status=%d"),
   913 	// Handle data store update events
   913              &aDataStore, aStatus );
   914 	if ( aStatus == ECacheUpdateContactRemoved ||
   914 
   915 	     aStatus == ECacheUpdateContactModified ||
   915     // Handle data store update events
   916 	     aStatus == ECacheUpdateContactAdded )
   916     if ( aStatus == ECacheUpdateContactRemoved ||
   917 	    {
   917          aStatus == ECacheUpdateContactModified ||
       
   918          aStatus == ECacheUpdateContactAdded )
       
   919         {
   918         HandleCacheUpdated( static_cast<TCachingStatus>(aStatus) );
   920         HandleCacheUpdated( static_cast<TCachingStatus>(aStatus) );
   919         return;
   921         return;
   920 	    }
   922         }
   921 	
   923 
   922 	// If not a cache update event, then this event is related to the initial
   924     // If not a cache update event, then this event is related to the initial
   923 	// cache construction.
   925     // cache construction.
   924 	TInt index = FindStoreUri(aDataStore);
   926 
   925 	
   927     // Check if any error occurred and update the cache error
   926 	iPcsCache[index]->UpdateCacheStatus(aStatus);
   928     if ( aStatus < 0 )
   927 	
   929     {
   928 	// Check if any error occurred
   930         SetCachingError(aDataStore, aStatus);
   929 	// If so, update the cache status, Set the property and return
   931     }
   930 	if ( aStatus < 0 )
   932     else
   931 	{
   933     {
   932 		SetCachingError(aDataStore, aStatus);
   934         TInt index = FindStoreUri(aDataStore);
   933 		//return;
   935         iPcsCache[index]->UpdateCacheStatus(aStatus);
   934 	}
   936     }
   935 	
   937 
   936 	// No error occurred
   938     TCachingStatus status = ECachingNotStarted;
   937 	TCachingStatus status = ECachingComplete;
   939     TUint countNotStarted = 0;
   938 	TBool atLeastOneStoreCachingCompleteWithErrors(EFalse);
   940     TUint countInProgress = 0;
   939 	for ( TInt i = 0; i < iPcsCache.Count(); i++ )
   941     TUint countCompleted = 0;
   940 	{
   942     TUint countCompletedWithErrors = 0;
   941 		if ( iPcsCache[i]->GetCacheStatus() == ECachingComplete )
   943     TInt cacheCount = iPcsCache.Count();
   942 		{
   944     for ( TInt i = 0; i < cacheCount; i++ )
   943 	        continue;
   945     {
   944 	    }
   946         PRINT3 ( _L("CPcsAlgorithm1::UpdateCachingStatus: URI[%d]=%S, cache status=%d"),
   945 		else if ( iPcsCache[i]->GetCacheStatus() == ECachingCompleteWithErrors )
   947                  i, &iPcsCache[i]->GetURI(), iPcsCache[i]->GetCacheStatus() );
   946 		{
   948 
   947             atLeastOneStoreCachingCompleteWithErrors = ETrue;
   949         switch ( iPcsCache[i]->GetCacheStatus() )
   948             continue;
   950         {
   949 		}
   951             case ECachingNotStarted:         
   950 		else
   952             {
   951 		{
   953                 countNotStarted++;          
   952 			status = ECachingInProgress;
   954                 break;
   953 			break;
   955             }
   954 		}
   956             case ECachingInProgress:         
   955 	}
   957             {
   956 	
   958                 countInProgress++;         
   957 	if ( status == ECachingComplete )
   959                 break;
   958 	{
   960             }
   959 		// See if any error occurred while caching
   961             case ECachingComplete:           
   960 		// If so, change the status to ECachingCompleteWithErrors
   962             {
   961 		if (( iCacheError != KErrNone ) || (atLeastOneStoreCachingCompleteWithErrors))
   963                 countCompleted++;           
   962 			status = ECachingCompleteWithErrors;
   964                 break;
   963 	}
   965             }
   964 	
   966             case ECachingCompleteWithErrors: 
   965 	// Check if status changed
   967             {
   966 	if ( status != iCacheStatus )
   968                 countCompletedWithErrors++; 
   967 	{
   969                 break;
   968 		iCacheStatus = status;
   970             }
   969 		RProperty::Set(KPcsInternalUidCacheStatus, EPsKeyCacheStatus, iCacheStatus );
   971             default:                         
   970 	}
   972             { 
   971 	
   973                 // Default completed state
   972 	PRINT ( _L("End CPcsAlgorithm1::UpdateCachingStatus") );
   974                 countCompleted++;           
       
   975                 break;
       
   976             }
       
   977         }
       
   978     }
       
   979 
       
   980     // Calculate cumulative status according to single caches statuses
       
   981     if ( countCompleted > 0 && ( countCompleted + countNotStarted ) == cacheCount )
       
   982     {
       
   983         // If at least one caching is finished
       
   984         // set status to ECachingComplete or ECachingCompleteWithErrors
       
   985         // according to iCacheError
       
   986         status = ( iCacheError == KErrNone ) ? ECachingComplete : ECachingCompleteWithErrors;
       
   987     }
       
   988     else if ( countInProgress > 0 )
       
   989     {
       
   990         // Else if at least one caching is in progress,
       
   991         // set status to ECachingInProgress
       
   992         status = ECachingInProgress;
       
   993     }
       
   994     else if ( countCompletedWithErrors > 0 )
       
   995     {
       
   996         // Else if at least one caching is completed with errors, 
       
   997         //set status to ECachingCompleteWithErrors
       
   998         status = ECachingCompleteWithErrors;
       
   999     }
       
  1000     else
       
  1001     {
       
  1002         // countNotStarted == cacheCount
       
  1003         // status is set to default ECachingNotStarted
       
  1004     }
       
  1005 
       
  1006     PRINT1 ( _L("CPcsAlgorithm1::UpdateCachingStatus: Cumulative caching status is %d"),
       
  1007              status );
       
  1008 
       
  1009     // Check if status changed
       
  1010     if ( status != iCacheStatus )
       
  1011     {
       
  1012         PRINT2 ( _L("CPcsAlgorithm1::UpdateCachingStatus: Cumulative caching changed: %d -> %d"),
       
  1013                  iCacheStatus, status );
       
  1014 
       
  1015         iCacheStatus = status;
       
  1016         RProperty::Set(KPcsInternalUidCacheStatus, EPsKeyCacheStatus, iCacheStatus );
       
  1017     }
       
  1018 
       
  1019     PRINT( _L("End CPcsAlgorithm1::UpdateCachingStatus") );
   973 }
  1020 }
   974 
  1021 
   975 // ----------------------------------------------------------------------------
  1022 // ----------------------------------------------------------------------------
   976 // CPcsAlgorithm1::SetCachingError
  1023 // CPcsAlgorithm1::SetCachingError
   977 // Updates cachinge error
  1024 // Updates cachinge error
   978 // ----------------------------------------------------------------------------
  1025 // ----------------------------------------------------------------------------
   979 void CPcsAlgorithm1::SetCachingError(const TDesC& aDataStore, TInt aError)
  1026 void CPcsAlgorithm1::SetCachingError(const TDesC& aDataStore, TInt aError)
   980 {
  1027 {
   981     PRINT2 ( _L("SetCachingError::URI %S ERROR %d"), &aDataStore, aError );
  1028     PRINT2 ( _L("CPcsAlgorithm1::SetCachingError: URI=%S, ERROR=%d"), &aDataStore, aError );
   982 
  1029 
   983     iCacheError = aError;
  1030     iCacheError = aError;
   984     RProperty::Set( KPcsInternalUidCacheStatus, EPsKeyCacheError, iCacheError );
  1031     RProperty::Set( KPcsInternalUidCacheStatus, EPsKeyCacheError, iCacheError );
   985 }
  1032 }
   986 
  1033 
  1324     PRINT ( _L("Enter CPcsAlgorithm1::GetAdaptiveGridL") );
  1371     PRINT ( _L("Enter CPcsAlgorithm1::GetAdaptiveGridL") );
  1325 
  1372 
  1326     PRINT1 ( _L("CPcsAlgorithm1::GetAdaptiveGridL. Request of Adaptive Grid for %d URI(s)"),
  1373     PRINT1 ( _L("CPcsAlgorithm1::GetAdaptiveGridL. Request of Adaptive Grid for %d URI(s)"),
  1327              aURIs.MdcaCount() );
  1374              aURIs.MdcaCount() );
  1328 
  1375 
       
  1376     if ( iCacheStatus != ECachingComplete )
       
  1377         {
       
  1378         PRINT ( _L("CPcsAlgorithm1::GetAdaptiveGridL: PCS Caching is not ready, returning empty Adaptive Grid") );
       
  1379         aAdaptiveGrid.Zero();
       
  1380         }
       
  1381     else
       
  1382         {
       
  1383         GetAdaptiveGridFromCacheL( aURIs, aCompanyName, aAdaptiveGrid );
       
  1384         }
       
  1385 
       
  1386     PRINT ( _L("End CPcsAlgorithm1::GetAdaptiveGridL") );
       
  1387 }
       
  1388 
       
  1389 // ----------------------------------------------------------------------------
       
  1390 // CPcsAlgorithm1::GetAdaptiveGridFromCacheL
       
  1391 // 
       
  1392 // ----------------------------------------------------------------------------
       
  1393 void CPcsAlgorithm1::GetAdaptiveGridFromCacheL( const MDesCArray& aURIs,
       
  1394                                                 const TBool aCompanyName,
       
  1395                                                 TDes& aAdaptiveGrid )
       
  1396 {
       
  1397     PRINT ( _L("Enter CPcsAlgorithm1::GetAdaptiveGridFromCacheL") );
       
  1398 
       
  1399     PRINT1 ( _L("CPcsAlgorithm1::GetAdaptiveGridFromCacheL. Request of Adaptive Grid for %d URI(s)"),
       
  1400              aURIs.MdcaCount() );
       
  1401 
  1329     RArray<TInt> cacheIds;
  1402     RArray<TInt> cacheIds;
  1330     CleanupClosePushL( cacheIds );
  1403     CleanupClosePushL( cacheIds );
  1331 
  1404     
  1332     // Create the list of the cache indexes that will form the Adaptive Grid
  1405     // Create the list of the cache indexes that will form the Adaptive Grid
  1333     for ( TInt i=0; i < aURIs.MdcaCount(); i++ )
  1406     for ( TInt i=0; i < aURIs.MdcaCount(); i++ )
  1334     {
  1407     {
  1335         TPtrC16 uri = aURIs.MdcaPoint(i);
  1408         TPtrC16 uri = aURIs.MdcaPoint(i);
  1336 
  1409 
  1337         // If URI is a group URI skip it
  1410         // If URI is a group URI skip it
  1338         if ( CPcsAlgorithm1Utils::IsGroupUri( uri ) )
  1411         if ( CPcsAlgorithm1Utils::IsGroupUri( uri ) )
  1339         {
  1412         {
  1340             PRINT1 ( _L("CPcsAlgorithm1::GetAdaptiveGridL. Adaptive Grid for URI \"%S\" is not supported. Skipping"),
  1413             PRINT1 ( _L("CPcsAlgorithm1::GetAdaptiveGridFromCacheL. Adaptive Grid for URI \"%S\" is not supported. Skipping"),
  1341                      &uri );
  1414                      &uri );
  1342             continue;
  1415             continue;
  1343         }
  1416         }
  1344 
  1417 
  1345         TInt cacheIndex = GetCacheIndex( uri );
  1418         TInt cacheIndex = GetCacheIndex( uri );
  1346         if ( cacheIndex == KErrNotFound )
  1419         if ( cacheIndex == KErrNotFound )
  1347         {
  1420         {
  1348             PRINT1 ( _L("CPcsAlgorithm1::GetAdaptiveGridL. Cache for URI \"%S\" doesn't exist"),
  1421             PRINT1 ( _L("CPcsAlgorithm1::GetAdaptiveGridFromCacheL. Cache for URI \"%S\" doesn't exist"),
  1349                      &uri );
  1422                      &uri );
  1350             continue;
  1423             continue;
  1351         }
  1424         }
  1352 
  1425 
  1353         PRINT1 ( _L("CPcsAlgorithm1::GetAdaptiveGridL. Cache for URI \"%S\" will be used to form the Adaptive Grid"),
  1426         PRINT1 ( _L("CPcsAlgorithm1::GetAdaptiveGridFromCacheL. Cache for URI \"%S\" will be used to form the Adaptive Grid"),
  1354                  &uri );
  1427                  &uri );
  1355 
  1428 
  1356         cacheIds.AppendL( cacheIndex );
  1429         cacheIds.AppendL( cacheIndex );
  1357     }
  1430     }
  1358 
  1431 
  1359     PRINT1 ( _L("CPcsAlgorithm1::GetAdaptiveGridL. Number of caches that will be used to form the grid is %d"),
  1432     PRINT1 ( _L("CPcsAlgorithm1::GetAdaptiveGridFromCacheL. Number of caches that will be used to form the grid is %d"),
  1360              cacheIds.Count( ) );
  1433              cacheIds.Count( ) );
  1361 
  1434 
  1362     // Create the Adaptive Grid from the cache(s)
  1435     // Create the Adaptive Grid from the cache(s)
  1363     if ( cacheIds.Count() == 1 ) // No merge if we have only one cache
  1436     if ( cacheIds.Count() == 1 ) // No merge if we have only one cache
  1364         {
  1437         {
  1366         CPcsCache* cache = iPcsCache[cacheIds[0]];
  1439         CPcsCache* cache = iPcsCache[cacheIds[0]];
  1367 
  1440 
  1368         // Get the Adaptive Grid    
  1441         // Get the Adaptive Grid    
  1369         cache->GetAdaptiveGridL( aCompanyName, aAdaptiveGrid );
  1442         cache->GetAdaptiveGridL( aCompanyName, aAdaptiveGrid );
  1370 
  1443 
  1371         PRINT1 ( _L("CPcsAlgorithm1::GetAdaptiveGridL. Adaptive Grid: \"%S\" (No merge was needed)"),
  1444         PRINT1 ( _L("CPcsAlgorithm1::GetAdaptiveGridFromCacheL. Adaptive Grid: \"%S\" (No merge was needed)"),
  1372                  &aAdaptiveGrid );
  1445                  &aAdaptiveGrid );
  1373         }
  1446         }
  1374     else if ( cacheIds.Count() > 1 ) // Merge if we have more than one cache
  1447     else if ( cacheIds.Count() > 1 ) // Merge if we have more than one cache
  1375         {
  1448         {
  1376         RArray<TChar> gridAll;
  1449         RArray<TChar> gridAll;
  1392 
  1465 
  1393             // Get the Adaptive Grid    
  1466             // Get the Adaptive Grid    
  1394             gridOnePtr.Zero();
  1467             gridOnePtr.Zero();
  1395             cache->GetAdaptiveGridL( aCompanyName, gridOnePtr );
  1468             cache->GetAdaptiveGridL( aCompanyName, gridOnePtr );
  1396 
  1469 
  1397             PRINT2 ( _L("CPcsAlgorithm1::GetAdaptiveGridL. Adaptive Grid for cache \"%S\" is \"%S\""),
  1470             PRINT2 ( _L("CPcsAlgorithm1::GetAdaptiveGridFromCacheL. Adaptive Grid for cache \"%S\" is \"%S\""),
  1398                      &cache->GetURI(), &gridOnePtr );
  1471                      &cache->GetURI(), &gridOnePtr );
  1399 
  1472 
  1400             // Loop through the characters of the Adaptive Grid for the cache
  1473             // Loop through the characters of the Adaptive Grid for the cache
  1401             for ( TUint j=0;
  1474             for ( TUint j=0;
  1402                   gridSize < KPsAdaptiveGridStringMaxLen && j < gridOnePtr.Length();
  1475                   gridSize < KPsAdaptiveGridStringMaxLen && j < gridOnePtr.Length();
  1419         for ( TUint i=0; i < gridAll.Count(); i++ )
  1492         for ( TUint i=0; i < gridAll.Count(); i++ )
  1420             {
  1493             {
  1421             aAdaptiveGrid.Append( gridAll[i] );
  1494             aAdaptiveGrid.Append( gridAll[i] );
  1422             }
  1495             }
  1423 
  1496 
  1424         PRINT1 ( _L("CPcsAlgorithm1::GetAdaptiveGridL. Adaptive Grid: \"%S\" (Merge was done)"),
  1497         PRINT1 ( _L("CPcsAlgorithm1::GetAdaptiveGridFromCacheL. Adaptive Grid: \"%S\" (Merge was done)"),
  1425                  &aAdaptiveGrid );
  1498                  &aAdaptiveGrid );
  1426         
  1499         
  1427         CleanupStack::PopAndDestroy( gridOne );
  1500         CleanupStack::PopAndDestroy( gridOne );
  1428         CleanupStack::PopAndDestroy( &gridAll ); // Close
  1501         CleanupStack::PopAndDestroy( &gridAll ); // Close
  1429         }
  1502         }
  1430 
  1503 
  1431     CleanupStack::PopAndDestroy( &cacheIds ); // Close
  1504     CleanupStack::PopAndDestroy( &cacheIds ); // Close
  1432     
  1505     
  1433     PRINT ( _L("End CPcsAlgorithm1::GetAdaptiveGridL") );
  1506     PRINT ( _L("End CPcsAlgorithm1::GetAdaptiveGridFromCacheL") );
  1434 }
  1507 }
  1435 
  1508 
  1436 // ---------------------------------------------------------------------------------
  1509 // ---------------------------------------------------------------------------------
  1437 // Read the persisted sort order from the central repository
  1510 // Read the persisted sort order from the central repository
  1438 // Persisted sort order is of form URI Field1 Field2 Field3 .. FieldN (space delimited)
  1511 // Persisted sort order is of form URI Field1 Field2 Field3 .. FieldN (space delimited)