clfwrapper/ClientSrc/CCLFServerProxy.cpp
changeset 0 c53acadfccc6
child 1 acef663c1218
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2002-2009 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <PathInfo.h>
       
    21 #include <driveinfo.h>
       
    22 #include <s32mem.h>
       
    23 #include <bautils.h>
       
    24 #include <mdeobjectquery.h>
       
    25 #include <mdeconstants.h>
       
    26 #include <collate.h>
       
    27 #include "CLFConsts.h"
       
    28 #include "CLFPanics.h"
       
    29 #include "CCLFServerProxy.h"
       
    30 #include "mdsutils.h"
       
    31 
       
    32 // CONSTANTS
       
    33 const TInt KCLFDefaultBufferLength( 64 );
       
    34 const TInt KCLFDefaultArrayGranularity( 4 );
       
    35 const TInt KCLFExtensionArrayGranularity( 49 );
       
    36 
       
    37 _LIT( KCLFDriveLetterFormatString, ":\\" );
       
    38 const TInt KCLFDriveC( 'C' );
       
    39 
       
    40 const TInt KDelayNotityCLFGetUpdateEventMaxTimes = 30;
       
    41 const TInt KCLFWrapperHarvesterEventInterval = 60;
       
    42 
       
    43 _LIT( KExtensionMp3,    "mp3" );
       
    44 _LIT( KExtensionAac,    "aac" );
       
    45 _LIT( KExtensionAmr,    "amr" );
       
    46 _LIT( KExtensionAwb,    "awb" );
       
    47 _LIT( KExtensionMid,    "mid" );
       
    48 _LIT( KExtensionMidi,   "midi" );
       
    49 _LIT( KExtensionSpMid,  "spmid" );
       
    50 _LIT( KExtensionRng,    "rng" );
       
    51 _LIT( KExtensionMxmf,   "mxmf" );
       
    52 _LIT( KExtensionWav,    "wav" );
       
    53 _LIT( KExtensionAu,     "au" );
       
    54 _LIT( KExtensionWma,    "wma" );
       
    55 _LIT( KExtensionNrt,    "nrt" );
       
    56 _LIT( KExtensionRa,    "ra" );
       
    57 
       
    58 _LIT( KExtJpg, "JPG" );
       
    59 _LIT( KExtJpeg, "JPEG" );
       
    60 _LIT( KExtJp2, "JP2" );
       
    61 _LIT( KExtJ2k, "J2K" ); 
       
    62 _LIT( KExtJpx, "JPX" ); 
       
    63 _LIT( KExtJpf, "JPF" );
       
    64 _LIT( KExtMbm, "MBM" ); 
       
    65 _LIT( KExtPng, "PNG" );
       
    66 _LIT( KExtGif, "GIF" );
       
    67 _LIT( KExtBmp, "BMP" );
       
    68 _LIT( KExtTif, "TIF" );
       
    69 _LIT( KExtTiff, "TIFF" );
       
    70 _LIT( KExtOta, "OTA" );
       
    71 _LIT( KExtWbmp, "WBMP" );
       
    72 _LIT( KExtWmf, "WMF" ); 
       
    73 _LIT( KExtOtb, "OTB" ); 
       
    74 
       
    75 _LIT(KExtOma1, "dcf");
       
    76 _LIT(KExtOma2, "odf");
       
    77 _LIT(KExtOma3, "dm");
       
    78 _LIT(KExtOma4, "o4a");
       
    79 _LIT(KExtOma5, "o4v");
       
    80 
       
    81 _LIT( KExtensionMp4,   "mp4" );
       
    82 _LIT( KExtensionMpg4,  "mpg4" );
       
    83 _LIT( KExtensionMpeg4, "mpeg4" );
       
    84 _LIT( KExtensionM4v,   "m4v" );
       
    85 _LIT( KExtensionM4a,   "m4a" );
       
    86 _LIT( KExtension3gp,   "3gp" );
       
    87 _LIT( KExtension3gpp,  "3gpp" );
       
    88 _LIT( KExtension3g2,   "3g2" );
       
    89 _LIT( KExtensionRm,    "rm" );
       
    90 _LIT( KExtensionRmvb,  "rmvb" );
       
    91 _LIT( KExtensionRam,   "ram" );
       
    92 _LIT( KExtensionRv,    "rv" );
       
    93 _LIT( KExtensionWmv,    "wmv" );
       
    94 _LIT( KExtensionAvi,    "avi" );
       
    95 
       
    96 // ======== MEMBER FUNCTIONS ========
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CItemsDeletedHandler::CUpdateItemsHandler
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 inline CUpdateItemsHandler::CUpdateItemsHandler()
       
   103     : iWasNotificationHandled( EFalse ), iParentObserver( NULL ),
       
   104       iParentPresentObserver( NULL ), iRemoveObserver( EFalse )
       
   105     {
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CUpdateIDsHandler::Start
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 void CUpdateItemsHandler::StartScheduler()
       
   113     {
       
   114     if( !iScheduler.IsStarted() )
       
   115         {
       
   116         iScheduler.Start();
       
   117         }
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CUpdateIDsHandler::AsyncStop
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 void CUpdateItemsHandler::AsyncStopScheduler()
       
   125     {
       
   126     iScheduler.AsyncStop();
       
   127     }
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // CUpdateIDsHandler::WasNotificationHandled
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 TBool CUpdateItemsHandler::WasNotificationHandled() const
       
   134     {
       
   135     return iWasNotificationHandled;
       
   136     }
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // CUpdateIDsHandler::WasNotificationHandled
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 void CUpdateItemsHandler::SetRemoveObserverFlag( TBool aRemove )
       
   143     {
       
   144     iRemoveObserver = aRemove;
       
   145     }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CUpdateIDsHandler::NewL
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 CUpdateIDsHandler* CUpdateIDsHandler::NewL( const TArray< TCLFItemId >& aItemIDArray )
       
   152     {
       
   153     CUpdateIDsHandler* self = new( ELeave ) CUpdateIDsHandler( aItemIDArray );
       
   154 
       
   155     return self;
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // CUpdateIDsHandler::~CUpdateIDsHandler
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 CUpdateIDsHandler::~CUpdateIDsHandler()
       
   163     {
       
   164     iIdsPendingUpdate.Reset();
       
   165 
       
   166     if ( iScheduler.IsStarted() )
       
   167         {
       
   168         iScheduler.AsyncStop();
       
   169         }
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CUpdateFoldersHandler::~CUpdateFoldersHandler
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 void CUpdateIDsHandler::StartHandlingL()
       
   177     {
       
   178     // Pass through.
       
   179     }
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // CUpdateIDsHandler::HandleObjectNotification
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 void CUpdateIDsHandler::HandleObjectNotification( const TItemId aId, TObserverNotificationType /* aType */ )
       
   186     {
       
   187     iWasNotificationHandled = EFalse;
       
   188 
       
   189     TInt index = iIdsPendingUpdate.Find( aId );
       
   190     if ( index != KErrNotFound )
       
   191         {
       
   192         iWasNotificationHandled = ETrue;
       
   193         iIdsPendingUpdate.Remove( index );
       
   194         }
       
   195     }
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CUpdateIDsHandler::AllDone
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 TBool CUpdateIDsHandler::AllDone() const
       
   202     {
       
   203     return iIdsPendingUpdate.Count() == 0 ? ETrue : EFalse;
       
   204     }
       
   205 
       
   206 // -----------------------------------------------------------------------------
       
   207 // CUpdateIDsHandler::CUpdateIDsHandler
       
   208 // -----------------------------------------------------------------------------
       
   209 //
       
   210 inline CUpdateIDsHandler::CUpdateIDsHandler( const TArray< TCLFItemId >& aItemIDArray )
       
   211     {
       
   212     const TInt idCount( aItemIDArray.Count() );
       
   213     for ( TInt i = 0; i < idCount; ++i )
       
   214         {
       
   215         if ( iIdsPendingUpdate.Find( aItemIDArray[ i ] ) == KErrNotFound )
       
   216             {
       
   217             iIdsPendingUpdate.Append( aItemIDArray[ i ] );
       
   218             }
       
   219         }
       
   220     }
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // CItemsDeletedHandler::NewL
       
   224 // -----------------------------------------------------------------------------
       
   225 //
       
   226 CItemsDeletedHandler* CItemsDeletedHandler::NewL( CMdESession& aMdESession, 
       
   227                                                                                     const CDesCArray& aUriArray,
       
   228                                                                                     MMdEObjectObserver* aParentObserver,
       
   229                                                                                     MMdEObjectPresentObserver* aParentPresentObserver )
       
   230     {
       
   231     CItemsDeletedHandler* self = new( ELeave ) CItemsDeletedHandler( aMdESession );
       
   232     CleanupStack::PushL( self );
       
   233     self->ConstructL( aUriArray, aParentObserver, aParentPresentObserver );
       
   234     CleanupStack::Pop( self );
       
   235     return self;
       
   236     }
       
   237 
       
   238 // -----------------------------------------------------------------------------
       
   239 // CItemsDeletedHandler::~CUpdateItemsHandlerWithIDs
       
   240 // -----------------------------------------------------------------------------
       
   241 //
       
   242 CItemsDeletedHandler::~CItemsDeletedHandler()
       
   243     {
       
   244     if( iRemoveObserver )
       
   245         {
       
   246         TRAP_IGNORE( iMdESession.RemoveObjectObserverL( *iParentObserver ) );
       
   247         TRAP_IGNORE( iMdESession.RemoveObjectPresentObserverL( *iParentPresentObserver ) );
       
   248         }
       
   249     iIdsPendingRemoval.Reset();
       
   250     iObjectsPendingRemoval.ResetAndDestroy();
       
   251     
       
   252     if ( iScheduler.IsStarted() )
       
   253         {
       
   254         iScheduler.AsyncStop();
       
   255         }
       
   256     }
       
   257 
       
   258 // -----------------------------------------------------------------------------
       
   259 // CUpdateFoldersHandler::StartHandlingL
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 void CItemsDeletedHandler::StartHandlingL()
       
   263     {
       
   264     const TInt count( iObjectsPendingRemoval.Count() );
       
   265     for ( TInt i = 0; i < count; ++i )
       
   266         {
       
   267         // If object for URI to be removed is in MDS, then remove it from MDS. Obviates
       
   268         // the need to rely on unreliable filemonitorplugin.
       
   269         const TItemId id = iMdESession.RemoveObjectL( iObjectsPendingRemoval[ i ]->Id() );
       
   270         
       
   271         if ( id != KNoId )
       
   272             {
       
   273             iIdsPendingRemoval.Append( id );
       
   274             }
       
   275         }
       
   276     iObjectsPendingRemoval.ResetAndDestroy();
       
   277     }
       
   278 
       
   279 // -----------------------------------------------------------------------------
       
   280 // CItemsDeletedHandler::HandleObjectNotification
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 void CItemsDeletedHandler::HandleObjectNotification( const TItemId aId, TObserverNotificationType aType )
       
   284     {
       
   285     iWasNotificationHandled = EFalse;
       
   286 
       
   287     if ( aType == ENotifyRemove )
       
   288         {
       
   289         TInt index = iIdsPendingRemoval.Find( aId );
       
   290         if ( index != KErrNotFound )
       
   291             {
       
   292             iWasNotificationHandled = ETrue;
       
   293             iIdsPendingRemoval.Remove( index );
       
   294             }
       
   295         }
       
   296     }
       
   297 
       
   298 // -----------------------------------------------------------------------------
       
   299 // CUpdateIDsHandler::AllDone
       
   300 // -----------------------------------------------------------------------------
       
   301 //
       
   302 TBool CItemsDeletedHandler::AllDone() const
       
   303     {
       
   304     return iIdsPendingRemoval.Count() == 0 ? ETrue : EFalse;
       
   305     }
       
   306 
       
   307 // -----------------------------------------------------------------------------
       
   308 // CItemsDeletedHandler::CItemsDeletedHandler
       
   309 // -----------------------------------------------------------------------------
       
   310 //
       
   311 inline CItemsDeletedHandler::CItemsDeletedHandler( CMdESession& aMdESession )
       
   312       : iMdESession( aMdESession )
       
   313     {
       
   314     }
       
   315 
       
   316 // -----------------------------------------------------------------------------
       
   317 // CItemsDeletedHandler::ConstructL
       
   318 // -----------------------------------------------------------------------------
       
   319 //
       
   320 inline void CItemsDeletedHandler::ConstructL( const CDesCArray& aUriArray,
       
   321                                                                             MMdEObjectObserver* aParentObserver,
       
   322                                                                             MMdEObjectPresentObserver* aParentPresentObserver)
       
   323     {
       
   324     iParentObserver = aParentObserver;
       
   325     iParentPresentObserver = aParentPresentObserver;
       
   326     // This leave is needed, if the handler was deleted earlier and the parent observer was removed 
       
   327     TRAP_IGNORE( iMdESession.AddObjectObserverL( *iParentObserver ) );
       
   328     TRAP_IGNORE( iMdESession.AddObjectPresentObserverL( *iParentPresentObserver ) );
       
   329     const TInt uriCount( aUriArray.Count() );
       
   330     for ( TInt i = 0; i < uriCount; ++i )
       
   331         {
       
   332         CMdEObject* object = NULL;
       
   333 
       
   334         object = iMdESession.GetObjectL( aUriArray.MdcaPoint( i ));
       
   335         CleanupStack::PushL( object );
       
   336         if ( object )
       
   337             {
       
   338             iObjectsPendingRemoval.AppendL( object );
       
   339             }
       
   340         CleanupStack::Pop( object );
       
   341         }
       
   342     iRemoveObserver = ETrue;
       
   343     }
       
   344 
       
   345 // -----------------------------------------------------------------------------
       
   346 // CUpdateFoldersHandler::NewL
       
   347 // -----------------------------------------------------------------------------
       
   348 //
       
   349 CUpdateFoldersHandler* CUpdateFoldersHandler::NewL( CMdESession& aMdESession, const CDesCArray& aUriArray,
       
   350                                                                                        MMdEObjectObserver* aParentObserver, 
       
   351                                                                                        MMdEObjectPresentObserver* aParentPresentObserver, 
       
   352 																					   RFs& aFs,
       
   353 																					   RHarvesterClient& aHarvester,
       
   354 																					   CDesCArray* aSupportedTypes )
       
   355     {
       
   356     CUpdateFoldersHandler* self = new( ELeave ) CUpdateFoldersHandler( aMdESession, 
       
   357                                                                             aFs, aHarvester, aSupportedTypes );
       
   358     CleanupStack::PushL( self );
       
   359     self->ConstructL( aUriArray, aParentObserver, aParentPresentObserver );
       
   360     CleanupStack::Pop( self );
       
   361     return self;
       
   362     }
       
   363 
       
   364 // -----------------------------------------------------------------------------
       
   365 // CUpdateFoldersHandler::~CUpdateFoldersHandler
       
   366 // -----------------------------------------------------------------------------
       
   367 //
       
   368 CUpdateFoldersHandler::~CUpdateFoldersHandler()
       
   369     {
       
   370     if( iRemoveObserver )
       
   371         {
       
   372         TRAP_IGNORE( iMdESession.RemoveObjectObserverL( *iParentObserver ) );
       
   373         TRAP_IGNORE( iMdESession.RemoveObjectPresentObserverL( *iParentPresentObserver ) );
       
   374         }
       
   375     iUrisFound.Reset();
       
   376     iFoldersFound.Reset();
       
   377     iIdsPendingRemoval.Reset();
       
   378     iIdsPendingUpdate.Reset();
       
   379     iIdsHandled.Reset();
       
   380     
       
   381     if ( iScheduler.IsStarted() )
       
   382         {
       
   383         iScheduler.AsyncStop();
       
   384         }
       
   385     }
       
   386 
       
   387 // -----------------------------------------------------------------------------
       
   388 // CUpdateFoldersHandler::StartHandlingL
       
   389 // -----------------------------------------------------------------------------
       
   390 //
       
   391 void CUpdateFoldersHandler::StartHandlingL()
       
   392     {
       
   393     CMdEObjectQuery* query = NULL;
       
   394 
       
   395     iIdsPendingRemoval.Reset();
       
   396     iIdsPendingUpdate.Reset();
       
   397     iIdsHandled.Reset();
       
   398     
       
   399     iStartingHandling = ETrue;
       
   400     DoQueryL( query, iFoldersFound );
       
   401     CleanupStack::PushL( query );
       
   402     if( !iScheduler.IsStarted() )
       
   403         {
       
   404         iScheduler.Start();
       
   405         }
       
   406     TRAP_IGNORE( DetermineIdsToRemoveL( *query ) );
       
   407     TRAP_IGNORE( DetermineIdsToUpdateL( iUrisFound ) );
       
   408     CleanupStack::PopAndDestroy( query );
       
   409     iStartingHandling = EFalse;
       
   410     }
       
   411 
       
   412 // -----------------------------------------------------------------------------
       
   413 // CUpdateFoldersHandler::HandleObjectNotification
       
   414 // -----------------------------------------------------------------------------
       
   415 //
       
   416 void CUpdateFoldersHandler::HandleObjectNotification( const TItemId aId, TObserverNotificationType aType )
       
   417     {
       
   418     iWasNotificationHandled = EFalse;
       
   419 
       
   420     if ( aType == ENotifyRemove )
       
   421         {
       
   422         const TInt index = iIdsPendingRemoval.Find( aId );
       
   423         
       
   424         if ( index != KErrNotFound )
       
   425             {
       
   426             iIdsPendingRemoval.Remove( index );
       
   427             iWasNotificationHandled = ETrue;
       
   428             }
       
   429         }
       
   430     else if ( aType == ENotifyAdd || aType == ENotifyModify )
       
   431         {
       
   432         const TInt index = iIdsPendingUpdate.Find( aId );
       
   433         
       
   434         if ( index != KErrNotFound )
       
   435             {
       
   436             iIdsPendingUpdate.Remove( index );
       
   437             const TInt handledIndex = iIdsHandled.Find( aId );
       
   438             if( handledIndex != KErrNotFound )
       
   439                 {
       
   440                 iIdsHandled.Remove( handledIndex );
       
   441                 }
       
   442             iWasNotificationHandled = ETrue;
       
   443             }
       
   444         else if( iHarvestingOngoing )
       
   445             { 
       
   446             iIdsHandled.Append( aId );
       
   447             iWasNotificationHandled = ETrue;
       
   448             }
       
   449         }
       
   450     }
       
   451 
       
   452 // -----------------------------------------------------------------------------
       
   453 // CUpdateFoldersHandler::AllDone
       
   454 // -----------------------------------------------------------------------------
       
   455 //
       
   456 TBool CUpdateFoldersHandler::AllDone() const
       
   457     {
       
   458     return ( iIdsPendingRemoval.Count() == 0 &&
       
   459              iIdsPendingUpdate.Count() == 0 &&
       
   460              !iStartingHandling ) ? ETrue : EFalse;
       
   461     }
       
   462 
       
   463 // -----------------------------------------------------------------------------
       
   464 // CUpdateFoldersHandler::HandleQueryNewResults
       
   465 // -----------------------------------------------------------------------------
       
   466 //
       
   467 void CUpdateFoldersHandler::HandleQueryNewResults( CMdEQuery& /* aQuery */, TInt /* aFirstNewItemIndex */, TInt /* aNewItemCount */ )
       
   468     {
       
   469     // Pass through.
       
   470     }
       
   471 
       
   472 // -----------------------------------------------------------------------------
       
   473 // CUpdateFoldersHandler::HandleQueryCompleted
       
   474 // -----------------------------------------------------------------------------
       
   475 //
       
   476 void CUpdateFoldersHandler::HandleQueryCompleted( CMdEQuery& /* aQuery */, TInt /* aError */ )
       
   477     {
       
   478     iScheduler.AsyncStop();
       
   479     }
       
   480 
       
   481 // -----------------------------------------------------------------------------
       
   482 // CUpdateFoldersHandler::CUpdateFoldersHandler
       
   483 // -----------------------------------------------------------------------------
       
   484 //
       
   485 inline CUpdateFoldersHandler::CUpdateFoldersHandler( CMdESession& aMdESession, 
       
   486                                                                                          RFs& aFs,
       
   487                                                                                          RHarvesterClient& aHarvester,
       
   488                                                                                          CDesCArray* aSupportedTypes )
       
   489     : iFs( aFs ),
       
   490       iUrisFound( KCLFDefaultArrayGranularity ),
       
   491       iFoldersFound( KCLFDefaultArrayGranularity ),
       
   492       iMdESession( aMdESession ),
       
   493       iHarvester( aHarvester ),
       
   494       iHarvestError( KErrNone ),
       
   495       iStartingHandling( EFalse ),
       
   496       iExtensionArray( aSupportedTypes ),
       
   497       iHarvestingOngoing( EFalse )
       
   498     {
       
   499     }
       
   500 
       
   501 // -----------------------------------------------------------------------------
       
   502 // CUpdateFoldersHandler::ConstructL
       
   503 // -----------------------------------------------------------------------------
       
   504 //
       
   505 inline void CUpdateFoldersHandler::ConstructL( const CDesCArray& aUriArray,
       
   506                                                                              MMdEObjectObserver* aParentObserver,
       
   507                                                                              MMdEObjectPresentObserver* aParentPresentObserver )
       
   508     {
       
   509     iParentObserver = aParentObserver;
       
   510     iParentPresentObserver = aParentPresentObserver;
       
   511     // This leave is needed, if the handler was deleted earlier and the parent observer was removed 
       
   512     TRAP_IGNORE( iMdESession.AddObjectObserverL( *iParentObserver ) );
       
   513     TRAP_IGNORE( iMdESession.AddObjectPresentObserverL( *iParentPresentObserver ) );
       
   514 
       
   515     for ( TInt i = 0; i < aUriArray.MdcaCount(); ++i )
       
   516         {
       
   517         ScanNodeForUrisL( aUriArray.MdcaPoint( i ), iUrisFound, iFoldersFound );
       
   518         }
       
   519  
       
   520     iRemoveObserver = ETrue ;
       
   521     }
       
   522 
       
   523 // -----------------------------------------------------------------------------
       
   524 // CUpdateFoldersHandler::ScanNodeForUrisL
       
   525 // -----------------------------------------------------------------------------
       
   526 //
       
   527 void CUpdateFoldersHandler::ScanNodeForUrisL( const TDesC16& aNodeName, CDesCArray& aUriArray, CDesCArray& aFolderArray )
       
   528     {
       
   529     TBool isFolder = EFalse;
       
   530 
       
   531     BaflUtils::IsFolder( iFs, aNodeName, isFolder );
       
   532     if ( isFolder )
       
   533         {
       
   534         if ( !BaflUtils::FolderExists( iFs, aNodeName ) )
       
   535             {
       
   536             return;
       
   537             }
       
   538         CDirScan* dirscan = CDirScan::NewL( iFs );
       
   539         CDir* dir = NULL;
       
   540 
       
   541         CleanupStack::PushL( dirscan );
       
   542         dirscan->SetScanDataL( aNodeName, KEntryAttNormal, EDirsAnyOrder );
       
   543 
       
   544         for ( dirscan->NextL( dir ); dir; dirscan->NextL( dir ) )
       
   545             {
       
   546             CleanupStack::PushL( dir );
       
   547 
       
   548             for ( TInt i = 0 ; i < dir->Count() ; ++i )
       
   549                 {
       
   550                 const TEntry& entry = ( *dir )[ i ];
       
   551                 const TInt totalLength = entry.iName.Length() + dirscan->FullPath().Length() + 1;
       
   552 
       
   553                 if (( !entry.IsDir() ) && ( totalLength <= KMaxFileName ))
       
   554                     {
       
   555                     TFileName currentPath( dirscan->FullPath() );
       
   556                     currentPath.Append( ( *dir )[ i ].iName );
       
   557                     aUriArray.AppendL( currentPath );
       
   558                     }
       
   559                 }
       
   560             CleanupStack::PopAndDestroy( dir );
       
   561 
       
   562             }
       
   563         aFolderArray.AppendL( aNodeName );
       
   564 
       
   565         CleanupStack::PopAndDestroy( dirscan );
       
   566         }
       
   567     else
       
   568         {
       
   569         aUriArray.AppendL( aNodeName );
       
   570         }
       
   571     }
       
   572 
       
   573 // -----------------------------------------------------------------------------
       
   574 // CUpdateFoldersHandler::DetermineIdsToRemove
       
   575 // -----------------------------------------------------------------------------
       
   576 //
       
   577 void CUpdateFoldersHandler::DetermineIdsToRemoveL ( const CMdEObjectQuery& aQuery )
       
   578     {
       
   579     RProcess process( KCurrentProcessHandle );
       
   580     process.Id().Id(); 
       
   581     if( process.HasCapability( ECapabilityWriteDeviceData ) )
       
   582         {
       
   583         const TInt queryCount( aQuery.Count() );
       
   584         for ( TInt i = 0; i < queryCount; ++i )
       
   585             {
       
   586             CMdEObject& object = aQuery.Result( i );
       
   587             TEntry entry;
       
   588             const TInt err = iFs.Entry( object.Uri(), entry );
       
   589 
       
   590             if ( err == KErrNotFound )
       
   591                 {
       
   592                 // Queried metadata object has a URI that does not match a filesystem URI.
       
   593                 // It must therefore be removed.
       
   594                 TItemId id( KNoId ); 
       
   595                 id = iMdESession.RemoveObjectL( object.Id() );
       
   596                 if ( id != KNoId )
       
   597                     {
       
   598                     iIdsPendingRemoval.Append( id );
       
   599                     }
       
   600                 }
       
   601             }
       
   602         }
       
   603     process.Close();
       
   604     }
       
   605 
       
   606 // -----------------------------------------------------------------------------
       
   607 // CUpdateFoldersHandler::DetermineIdsToRemove
       
   608 // -----------------------------------------------------------------------------
       
   609 //
       
   610 void CUpdateFoldersHandler::DetermineIdsToUpdateL ( const CDesCArray& aUriArray )
       
   611     {
       
   612     const TInt uriCount( aUriArray.Count() );
       
   613     for ( TInt i = 0; i < uriCount; ++i )
       
   614         {
       
   615         CMdEObject* object = NULL;
       
   616         const TDesC& uri = aUriArray.MdcaPoint( i );
       
   617         TPtrC ext;
       
   618         const TBool exists( MdsUtils::GetExt( uri, ext ) );
       
   619         if( !exists || !IsSupportedType( ext ) )
       
   620             {
       
   621             return;
       
   622             }
       
   623 
       
   624         object = iMdESession.GetObjectL( uri ); 
       
   625         CleanupStack::PushL( object );
       
   626 
       
   627         if ( !object )
       
   628             {
       
   629             // If object for given URI is not in MDS, then determine if an ENotifyAdd
       
   630             // or ENotifyModify  is pending by attempting to harvest the file associated
       
   631             // with the URI.
       
   632             DoHarvestL( uri );
       
   633             }
       
   634         CleanupStack::PopAndDestroy( object );
       
   635         }
       
   636     }
       
   637 
       
   638 // -----------------------------------------------------------------------------
       
   639 // CUpdateFoldersHandler::DoQueryL
       
   640 // -----------------------------------------------------------------------------
       
   641 //
       
   642 void CUpdateFoldersHandler::DoQueryL( CMdEObjectQuery*& aQuery, const CDesCArray& aFolderArray )
       
   643     {
       
   644     CMdENamespaceDef& defaultNamespaceDef = iMdESession.GetDefaultNamespaceDefL();
       
   645     CMdEObjectDef& objDef = defaultNamespaceDef.GetObjectDefL( MdeConstants::Object::KBaseObject );
       
   646     aQuery = iMdESession.NewObjectQueryL( iMdESession.GetDefaultNamespaceDefL(), objDef, this );
       
   647     CleanupStack::PushL( aQuery );
       
   648     CMdELogicCondition& uriLogicCond = aQuery->Conditions().AddLogicConditionL( ELogicConditionOperatorOr );
       
   649 
       
   650     const TInt folderCount( aFolderArray.Count() );
       
   651     for ( TInt i = 0; i < folderCount; ++i )
       
   652         {
       
   653         uriLogicCond.AddObjectConditionL( EObjectConditionCompareUriBeginsWith, aFolderArray.MdcaPoint( i ) );
       
   654         }
       
   655     aQuery->FindL();
       
   656 
       
   657     CleanupStack::Pop( aQuery ); // Caller takes ownership.
       
   658     }
       
   659 
       
   660 // -----------------------------------------------------------------------------
       
   661 // CUpdateFoldersHandler::DoHarvest
       
   662 // -----------------------------------------------------------------------------
       
   663 //
       
   664 void CUpdateFoldersHandler::DoHarvestL( const TDesC& aUri )
       
   665     {
       
   666     RArray< TItemId > albumIds;
       
   667 
       
   668     TUid uid( KNullUid );
       
   669     iHarvester.SetObserver( this );
       
   670     iHarvestingFile = TFileName( aUri );
       
   671     iHarvestingOngoing = ETrue;
       
   672     iHarvester.HarvestFileWithUID( aUri, albumIds, EFalse, uid );
       
   673     if( !iScheduler.IsStarted() )
       
   674         {
       
   675         iScheduler.Start();
       
   676         }
       
   677 
       
   678     albumIds.Close();
       
   679     
       
   680     // Wait until harvest complete before trying again.
       
   681     iHarvester.RemoveObserver( this );
       
   682     if ( iHarvestError == KErrNone )
       
   683         {
       
   684         CMdEObject* object = NULL;
       
   685 
       
   686         object = iMdESession.GetObjectL( aUri );
       
   687         if( object )
       
   688             {
       
   689             const TInt index = iIdsHandled.Find( object->Id() );
       
   690             if( index != KErrNotFound )
       
   691                 {
       
   692                 iIdsHandled.Remove( index );
       
   693                 }
       
   694             else
       
   695                 {
       
   696                 iIdsPendingUpdate.Append( object->Id() ); 
       
   697                 }
       
   698             }
       
   699         }
       
   700 
       
   701     iHarvestError = KErrNone;
       
   702     }
       
   703 
       
   704 // -----------------------------------------------------------------------------
       
   705 // CUpdateFoldersHandler::HarvestingComplete
       
   706 // Callback from harvester client after harvesting
       
   707 // -----------------------------------------------------------------------------
       
   708 //
       
   709 void CUpdateFoldersHandler::HarvestingComplete( TDesC& aURI, const TInt aError )
       
   710     {
       
   711     const TFileName uri( aURI );
       
   712     TBool match( EFalse );
       
   713     TCollationMethod m = *Mem::CollationMethodByIndex( 0 );
       
   714 
       
   715     iHarvestError = aError;
       
   716     m.iFlags = ( TCollationMethod::EIgnoreNone | TCollationMethod::EFoldCase );   
       
   717 
       
   718     if ( uri.CompareC( iHarvestingFile, 3, &m ) == 0 )
       
   719         {
       
   720         match = ETrue;
       
   721         iHarvestingOngoing = EFalse;
       
   722         }
       
   723     if ( iScheduler.IsStarted() && match )
       
   724         {
       
   725         iScheduler.AsyncStop();
       
   726         }
       
   727     }
       
   728 
       
   729 // -----------------------------------------------------------------------------
       
   730 // CUpdateFoldersHandler::IsSupportedType
       
   731 // -----------------------------------------------------------------------------
       
   732 //
       
   733 TBool CUpdateFoldersHandler::IsSupportedType( const TDesC& aExtension )
       
   734     {
       
   735     TCollationMethod m = *Mem::CollationMethodByIndex( 0 );
       
   736     m.iFlags = ( TCollationMethod::EIgnoreNone | TCollationMethod::EFoldCase );   
       
   737     
       
   738     for( TInt i( 0 ); i < iExtensionArray->Count(); i++ )
       
   739         {
       
   740         const TDesC& ext = iExtensionArray->MdcaPoint( i );
       
   741         if ( ext.CompareC( aExtension, 3, &m ) == 0 )
       
   742             {
       
   743             return ETrue;
       
   744             }
       
   745         }
       
   746     return EFalse;
       
   747     }
       
   748 
       
   749 // -----------------------------------------------------------------------------
       
   750 // CCLFServerProxy::~CCLFServerProxy
       
   751 // Destructor.
       
   752 // -----------------------------------------------------------------------------
       
   753 //
       
   754 CCLFServerProxy::~CCLFServerProxy()
       
   755     {
       
   756     // Reset the arrays this class owns.
       
   757     iStatusArray.Reset();
       
   758     iOpCodeArray.Reset();
       
   759     iUpdatedIds.Reset();
       
   760     TRAP_IGNORE( iMdESession.RemoveObjectObserverL( *this ));
       
   761     TRAP_IGNORE( iMdESession.RemoveObjectPresentObserverL( *this ));
       
   762     iUpdateItemsHandlerArray.ResetAndDestroy();
       
   763     delete iUriArray;
       
   764     delete iExtensionArray;
       
   765     iFs.Close();
       
   766 
       
   767     iHC.RemoveHarvesterEventObserver( *this );
       
   768     iHC.Close();
       
   769     }
       
   770 
       
   771 // -----------------------------------------------------------------------------
       
   772 // CCLFDbItemProvider::NewL
       
   773 // -----------------------------------------------------------------------------
       
   774 //
       
   775 CCLFServerProxy* CCLFServerProxy::NewL( CMdESession& aMdESession )
       
   776     {
       
   777     CCLFServerProxy* self = new( ELeave ) CCLFServerProxy( aMdESession );
       
   778     CleanupStack::PushL( self );
       
   779     self->ConstructL();
       
   780     CleanupStack::Pop( self );
       
   781     return self;
       
   782     }
       
   783 
       
   784 // -----------------------------------------------------------------------------
       
   785 // CCLFServerProxy::GetUpdateEndEvent
       
   786 // -----------------------------------------------------------------------------
       
   787 //
       
   788 void CCLFServerProxy::GetUpdateEndEvent( TRequestStatus& aRequestStatus )
       
   789     {
       
   790     GetEvent( aRequestStatus, ECLFGetUpdateEvent );
       
   791     }
       
   792 
       
   793 // -----------------------------------------------------------------------------
       
   794 // CCLFServerProxy::CancelEventGets
       
   795 // -----------------------------------------------------------------------------
       
   796 //
       
   797 TInt CCLFServerProxy::CancelGetEvent()
       
   798     {
       
   799     CancelGetEvent( ECLFGetUpdateEvent );
       
   800 
       
   801     return KErrNone;
       
   802     }
       
   803 
       
   804 // -----------------------------------------------------------------------------
       
   805 // CCLFServerProxy::GetUpdateStartEvent
       
   806 // -----------------------------------------------------------------------------
       
   807 //
       
   808 void CCLFServerProxy::GetUpdateStartEvent( TRequestStatus& aRequestStatus )
       
   809     {
       
   810     GetEvent( aRequestStatus, ECLFProcessStartEvent );
       
   811     }
       
   812 
       
   813 // -----------------------------------------------------------------------------
       
   814 // CCLFServerProxy::CancelGetUpdateStartEvent
       
   815 // -----------------------------------------------------------------------------
       
   816 //
       
   817 TInt CCLFServerProxy::CancelGetUpdateStartEvent()
       
   818     {
       
   819     CancelGetEvent( ECLFProcessStartEvent );
       
   820 
       
   821     return KErrNone;
       
   822     }
       
   823 
       
   824 // -----------------------------------------------------------------------------
       
   825 // CCLFServerProxy::FetchItemListData
       
   826 // -----------------------------------------------------------------------------
       
   827 //
       
   828 TInt CCLFServerProxy::FetchItemListData( RArray< TCLFItemId >& aItemIDArray )
       
   829     {
       
   830     const TInt count( iUpdatedIds.Count() );
       
   831     for ( TInt i = 0; i < count; ++i )
       
   832         {
       
   833         aItemIDArray.Append( iUpdatedIds[ i ] );
       
   834         }
       
   835 
       
   836     iUpdatedIds.Reset();
       
   837 
       
   838     return KErrNone;
       
   839     }
       
   840 
       
   841 // -----------------------------------------------------------------------------
       
   842 // CCLFServerProxy::UpdateItems
       
   843 // -----------------------------------------------------------------------------
       
   844 //
       
   845 TInt CCLFServerProxy::UpdateItemsL( const TArray< TCLFItemId >& aItemIDArray )
       
   846     {
       
   847     CUpdateItemsHandler* handler = CUpdateIDsHandler::NewL( aItemIDArray );
       
   848 
       
   849     CleanupStack::PushL( handler );
       
   850     StartHandlingL( handler );
       
   851     CleanupStack::Pop( handler );
       
   852 
       
   853     return KErrNone;
       
   854     }
       
   855 
       
   856 // -----------------------------------------------------------------------------
       
   857 // CCLFServerProxy::UpdateItems
       
   858 // -----------------------------------------------------------------------------
       
   859 //
       
   860 TInt CCLFServerProxy::UpdateItemsL( const TInt aSemanticId, const TDesC8& aOpaqueData )
       
   861     {
       
   862     CDesCArray* uriArray = new ( ELeave ) CDesCArraySeg( KCLFDefaultArrayGranularity );
       
   863     CleanupStack::PushL( uriArray );
       
   864     DeSerializeL( aOpaqueData, *uriArray );
       
   865 
       
   866     if ( uriArray->Count() )
       
   867         {
       
   868         CUpdateItemsHandler* handler = NULL;
       
   869         
       
   870         if ( aSemanticId == KCLFItemsDeletedSemanticId )
       
   871             {
       
   872             handler = CItemsDeletedHandler::NewL( iMdESession, *uriArray, this, this );
       
   873             }
       
   874         else if ( aSemanticId == KCLFUpdateFoldersSemanticId )
       
   875             {
       
   876             handler = CUpdateFoldersHandler::NewL( iMdESession, *uriArray, this, this, 
       
   877                               iFs, iHC, iExtensionArray );
       
   878             }
       
   879         else if ( aSemanticId == KCLFUpdateCollectionsSemanticId )
       
   880             {
       
   881             // Pass through; collections are not supported.
       
   882             CleanupStack::PopAndDestroy( uriArray );
       
   883             return KErrNone;
       
   884             }
       
   885 
       
   886         CleanupStack::PushL( handler );
       
   887         StartHandlingL( handler );
       
   888         CleanupStack::Pop( handler );
       
   889         }
       
   890     CleanupStack::PopAndDestroy( uriArray );
       
   891 
       
   892     return KErrNone;
       
   893     }
       
   894 
       
   895 // -----------------------------------------------------------------------------
       
   896 // CCLFServerProxy::UpdateAllItems
       
   897 // -----------------------------------------------------------------------------
       
   898 //
       
   899 TInt CCLFServerProxy::UpdateAllItemsL()
       
   900     {
       
   901     CUpdateItemsHandler* handler = CUpdateFoldersHandler::NewL( iMdESession, 
       
   902                                                          *iUriArray, this, this, iFs, iHC, iExtensionArray );
       
   903     CleanupStack::PushL( handler );
       
   904     StartHandlingL( handler );
       
   905     CleanupStack::Pop( handler );
       
   906     
       
   907     return KErrNone;
       
   908     }
       
   909 
       
   910 // ---------------------------------------------------------------------------
       
   911 // Default constructor
       
   912 // ---------------------------------------------------------------------------
       
   913 //
       
   914 inline CCLFServerProxy::CCLFServerProxy( CMdESession& aMdESession )
       
   915     : iMdESession( aMdESession ),
       
   916     iUriArray( NULL ),
       
   917     iExtensionArray( NULL ),
       
   918     iHEStateFinished( ETrue ),
       
   919     iNeedNotifyCLFGetUpdateEvent( EFalse ),
       
   920     iDelayNotifyCLFGetUpdateEventCount( 0 )
       
   921     {
       
   922     }
       
   923 
       
   924 // -----------------------------------------------------------------------------
       
   925 // CCLFServerProxy::ConstructL
       
   926 // -----------------------------------------------------------------------------
       
   927 //
       
   928 inline void CCLFServerProxy::ConstructL()
       
   929     {
       
   930     iUriArray = new ( ELeave ) CDesCArraySeg( KCLFDefaultArrayGranularity );
       
   931     User::LeaveIfError( iFs.Connect() );
       
   932     
       
   933     TDriveList driveList;
       
   934     TChar driveLetter; 
       
   935     TInt numOfElements( 0 );
       
   936     User::LeaveIfError( DriveInfo::GetUserVisibleDrives( iFs, 
       
   937                                                          driveList, 
       
   938                                                          numOfElements, 
       
   939                                                          KDriveAttExclude | KDriveAttRemote | KDriveAttRom ) );
       
   940     
       
   941     for( TInt driveNumber = EDriveA ; driveNumber <= EDriveZ ; driveNumber++ ) 
       
   942         { 
       
   943         if ( driveList[driveNumber] ) 
       
   944             {
       
   945             User::LeaveIfError( iFs.DriveToChar( driveNumber, driveLetter ) );
       
   946             HBufC* letter = HBufC::NewLC( KMaxPath );
       
   947             TPtr letterPtr( letter->Des() );
       
   948 
       
   949             if( driveLetter == KCLFDriveC )
       
   950                 {
       
   951                 letterPtr = PathInfo::PhoneMemoryRootPath();
       
   952                 }
       
   953             else
       
   954                 {
       
   955                 letterPtr.Append( driveLetter );
       
   956                 letterPtr.Append( KCLFDriveLetterFormatString ); 
       
   957                 }   
       
   958                         
       
   959             if( BaflUtils::PathExists( iFs, letterPtr ) )
       
   960                 {
       
   961                 iUriArray->AppendL( letterPtr );
       
   962                 }
       
   963             CleanupStack::PopAndDestroy( letter );
       
   964             }
       
   965         }
       
   966     
       
   967     PopulateSupportedExtensionL();
       
   968     
       
   969     iMdESession.AddObjectObserverL( *this );
       
   970     iMdESession.AddObjectPresentObserverL( *this );
       
   971 
       
   972     User::LeaveIfError( iHC.Connect() );
       
   973     iHC.AddHarvesterEventObserver( *this, EHEObserverTypeOverall, KCLFWrapperHarvesterEventInterval );
       
   974 
       
   975     }
       
   976 
       
   977 // -----------------------------------------------------------------------------
       
   978 // CCLFServerProxy::HarvestingUpdated
       
   979 // -----------------------------------------------------------------------------
       
   980 //
       
   981 void CCLFServerProxy::HarvestingUpdated( 
       
   982 			HarvesterEventObserverType /*aHEObserverType*/, 
       
   983 			HarvesterEventState aHarvesterEventState,
       
   984 			TInt /*aItemsLeft*/ )
       
   985     {
       
   986     if( aHarvesterEventState == EHEStateFinished ||
       
   987         aHarvesterEventState == EHEStatePaused )
       
   988         {
       
   989         iHEStateFinished = ETrue;
       
   990         if ( iNeedNotifyCLFGetUpdateEvent )
       
   991             {
       
   992             NotifyUpdateEvent( ECLFGetUpdateEvent );
       
   993             }
       
   994         }
       
   995     else
       
   996         {
       
   997         iHEStateFinished = EFalse;
       
   998         }
       
   999     }
       
  1000 
       
  1001 // -----------------------------------------------------------------------------
       
  1002 // CCLFServerProxy::StartHandlingL
       
  1003 // -----------------------------------------------------------------------------
       
  1004 //
       
  1005 void CCLFServerProxy::StartHandlingL( CUpdateItemsHandler* aHandler )
       
  1006     {
       
  1007     if ( aHandler )
       
  1008         {
       
  1009         // Notify pending active objects about the event.
       
  1010         NotifyUpdateEvent( ECLFProcessStartEvent );
       
  1011 
       
  1012         // Now wait until the update is over, then return.
       
  1013         iUpdateItemsHandlerArray.Append( aHandler );
       
  1014         TRAPD( err, aHandler->StartHandlingL(); );
       
  1015         if( err != KErrNone )
       
  1016             {
       
  1017             // Remove aHandler, because it is in clean up stack.
       
  1018             iUpdateItemsHandlerArray.Remove( iUpdateItemsHandlerArray.Count() - 1 );
       
  1019             User::LeaveIfError( err );
       
  1020             }
       
  1021         if ( aHandler->AllDone() )
       
  1022             {
       
  1023             delete aHandler;
       
  1024             iUpdateItemsHandlerArray.Remove( iUpdateItemsHandlerArray.Count() - 1 );
       
  1025             }
       
  1026         else
       
  1027             {
       
  1028             aHandler->StartScheduler();
       
  1029             }
       
  1030         }
       
  1031     }
       
  1032 
       
  1033 // -----------------------------------------------------------------------------
       
  1034 // CCLFServerProxy::HandleObjectNotification
       
  1035 // -----------------------------------------------------------------------------
       
  1036 //
       
  1037 void CCLFServerProxy::HandleObjectNotification( CMdESession& /*aSession*/,
       
  1038                                                 TObserverNotificationType aType,
       
  1039                                                 const RArray< TItemId >& aObjectIdArray )
       
  1040     {
       
  1041     TBool unhandledIds = EFalse;
       
  1042 
       
  1043     const TInt objectCount( aObjectIdArray.Count() );
       
  1044     for ( TInt i = 0; i < objectCount; ++i )
       
  1045         {
       
  1046         TBool handled = EFalse;
       
  1047 
       
  1048         iUpdatedIds.Append( aObjectIdArray[ i ] );
       
  1049         for ( TInt j = 0; j < iUpdateItemsHandlerArray.Count(); ++j )
       
  1050             {
       
  1051             iUpdateItemsHandlerArray[ j ]->HandleObjectNotification( aObjectIdArray[ i ], aType );
       
  1052             handled = handled ? ETrue : iUpdateItemsHandlerArray[ j ]->WasNotificationHandled();
       
  1053 
       
  1054             if ( iUpdateItemsHandlerArray[ j ]->AllDone() )
       
  1055                 {
       
  1056                 // If we have a pending update, we can now let it continue.
       
  1057                 iDelayNotifyCLFGetUpdateEventCount = KDelayNotityCLFGetUpdateEventMaxTimes;
       
  1058                 NotifyUpdateEvent( ECLFGetUpdateEvent );
       
  1059                 iUpdateItemsHandlerArray[ j ]->AsyncStopScheduler();
       
  1060                 iUpdateItemsHandlerArray[j]->SetRemoveObserverFlag( EFalse );
       
  1061                 delete iUpdateItemsHandlerArray[ j ]; 
       
  1062                 iUpdateItemsHandlerArray.Remove( j );
       
  1063                 j--; // Compensate for the removed handler
       
  1064                 }
       
  1065             }
       
  1066         unhandledIds = ( unhandledIds || !handled ) ? ETrue : EFalse;
       
  1067         }
       
  1068 
       
  1069     if ( unhandledIds )
       
  1070         {
       
  1071         // If we have an ID that doesn't match a pending update, we assume
       
  1072         // that the object notification was generated from outside the current
       
  1073         // application, and we therefore must simulate a process end event.
       
  1074         if( aType == ENotifyRemove )
       
  1075             {
       
  1076             // Increase the update triggering value more rapidly to provide remove events faster
       
  1077             iDelayNotifyCLFGetUpdateEventCount += 12;
       
  1078             }
       
  1079         NotifyUpdateEvent( ECLFGetUpdateEvent );
       
  1080         }
       
  1081     }
       
  1082 
       
  1083 // -----------------------------------------------------------------------------
       
  1084 // CCLFServerProxy::MMdEObjectPresentObserver
       
  1085 // -----------------------------------------------------------------------------
       
  1086 //
       
  1087 void CCLFServerProxy::HandleObjectPresentNotification( CMdESession& /*aSession*/,
       
  1088                                                 TBool /*aPresent*/,
       
  1089                                                 const RArray< TItemId >& aObjectIdArray )
       
  1090     {
       
  1091     TBool unhandledIds = EFalse;
       
  1092 
       
  1093     const TInt objectCount( aObjectIdArray.Count() );
       
  1094     for ( TInt i = 0; i < objectCount; ++i )
       
  1095         {
       
  1096         TBool handled = EFalse;
       
  1097 
       
  1098         iUpdatedIds.Append( aObjectIdArray[ i ] );
       
  1099         for ( TInt j = 0; j < iUpdateItemsHandlerArray.Count(); ++j )
       
  1100             {
       
  1101             iUpdateItemsHandlerArray[ j ]->HandleObjectNotification( aObjectIdArray[ i ], ENotifyModify );
       
  1102             handled = handled ? ETrue : iUpdateItemsHandlerArray[ j ]->WasNotificationHandled();
       
  1103 
       
  1104             if ( iUpdateItemsHandlerArray[ j ]->AllDone() )
       
  1105                 {
       
  1106                 // If we have a pending update, we can now let it continue.
       
  1107                 NotifyUpdateEvent( ECLFGetUpdateEvent );
       
  1108                 iUpdateItemsHandlerArray[ j ]->AsyncStopScheduler();
       
  1109                 iUpdateItemsHandlerArray[j]->SetRemoveObserverFlag( EFalse );
       
  1110                 delete iUpdateItemsHandlerArray[ j ]; 
       
  1111                 iUpdateItemsHandlerArray.Remove( j );
       
  1112                 j--; // Compensate for the removed handler
       
  1113                 }
       
  1114             }
       
  1115         unhandledIds = ( unhandledIds || !handled ) ? ETrue : EFalse;
       
  1116         }
       
  1117 
       
  1118     if ( unhandledIds )
       
  1119         {
       
  1120         // If we have an ID that doesn't match a pending update, we assume
       
  1121         // that the object notification was generated from outside the current
       
  1122         // application, and we therefore must simulate a process end event.
       
  1123         NotifyUpdateEvent( ECLFGetUpdateEvent );
       
  1124         }
       
  1125     }
       
  1126 
       
  1127 // -----------------------------------------------------------------------------
       
  1128 // CCLFServerProxy::NotifyUpdateEvent
       
  1129 // -----------------------------------------------------------------------------
       
  1130 //
       
  1131 void CCLFServerProxy::NotifyUpdateEvent( const TCLFServerOpCodes aOpCode )
       
  1132     {
       
  1133 
       
  1134     if ( ECLFGetUpdateEvent == aOpCode
       
  1135             && !iHEStateFinished
       
  1136             && iDelayNotifyCLFGetUpdateEventCount < KDelayNotityCLFGetUpdateEventMaxTimes )
       
  1137         {
       
  1138         iNeedNotifyCLFGetUpdateEvent = ETrue;
       
  1139         iDelayNotifyCLFGetUpdateEventCount++;
       
  1140         return;
       
  1141         }
       
  1142 
       
  1143     for ( TInt i = 0; i < iOpCodeArray.Count(); ++i )
       
  1144         {
       
  1145         if ( iOpCodeArray[ i ] == aOpCode )
       
  1146             {
       
  1147             User::RequestComplete( iStatusArray[ i ], KErrNone );
       
  1148             iStatusArray.Remove( i );
       
  1149             iOpCodeArray.Remove( i );
       
  1150             }
       
  1151         }
       
  1152     
       
  1153     if ( ECLFGetUpdateEvent == aOpCode )
       
  1154         {
       
  1155         iNeedNotifyCLFGetUpdateEvent = EFalse;
       
  1156         iDelayNotifyCLFGetUpdateEventCount = 0;
       
  1157         }
       
  1158     }
       
  1159 
       
  1160 // -----------------------------------------------------------------------------
       
  1161 // CCLFServerProxy::DeSerializeL
       
  1162 // -----------------------------------------------------------------------------
       
  1163 //
       
  1164 void CCLFServerProxy::DeSerializeL( const TDesC8& aData, CDesCArray& aDataArray )
       
  1165     {
       
  1166     // Check if KNullDesC
       
  1167     if ( aData.Length() > 0 )
       
  1168         {
       
  1169         RDesReadStream readStream( aData );
       
  1170         CleanupClosePushL( readStream );
       
  1171         const TInt count( readStream.ReadInt32L() );
       
  1172 
       
  1173         HBufC* buffer = HBufC::NewLC( KCLFDefaultBufferLength );
       
  1174         TPtr ptr( buffer->Des() );
       
  1175         for ( TInt i = 0 ; i < count ; ++i )
       
  1176             {
       
  1177             const TInt length( readStream.ReadInt32L() );
       
  1178             const TUint uintLength( length );
       
  1179             const TInt maxLength( KMaxTInt / 2 );
       
  1180             if (( length < 0 ) || ( uintLength > maxLength ))
       
  1181                 {
       
  1182                 User::Leave( KErrNotSupported );
       
  1183                 }
       
  1184             else if ( length > ptr.MaxLength() )
       
  1185                 {
       
  1186                 // create new buffer
       
  1187                 CleanupStack::PopAndDestroy( buffer );
       
  1188                 buffer = HBufC::NewLC( length );
       
  1189                 ptr.Set( buffer->Des() );
       
  1190                 }
       
  1191             else
       
  1192                 {
       
  1193                 ptr.Zero();
       
  1194                 }
       
  1195             readStream.ReadL( ptr, length );
       
  1196             aDataArray.AppendL( ptr );
       
  1197             }
       
  1198         CleanupStack::PopAndDestroy( 2, &readStream );
       
  1199         }
       
  1200     }
       
  1201 
       
  1202 // -----------------------------------------------------------------------------
       
  1203 // CCLFServerProxy::GetEvent
       
  1204 // -----------------------------------------------------------------------------
       
  1205 //
       
  1206 void CCLFServerProxy::GetEvent( TRequestStatus& aRequestStatus, TCLFServerOpCodes aOpcode )
       
  1207     {
       
  1208     iStatusArray.Append( &aRequestStatus );
       
  1209     iOpCodeArray.Append( aOpcode );
       
  1210     aRequestStatus = KRequestPending;
       
  1211     }
       
  1212 
       
  1213 // -----------------------------------------------------------------------------
       
  1214 // CCLFServerProxy::CancelGetEvent
       
  1215 // -----------------------------------------------------------------------------
       
  1216 //
       
  1217 void CCLFServerProxy::CancelGetEvent( TCLFServerOpCodes aOpcode )
       
  1218     {
       
  1219     for ( TInt i = 0; i < iStatusArray.Count(); ++i )
       
  1220         {
       
  1221         if ( iOpCodeArray[ i ] == aOpcode )
       
  1222             {
       
  1223             User::RequestComplete( iStatusArray[ i ], KErrCancel );
       
  1224             iStatusArray.Remove( i );
       
  1225             iOpCodeArray.Remove( i );
       
  1226             }
       
  1227         }
       
  1228     }
       
  1229 
       
  1230 // -----------------------------------------------------------------------------
       
  1231 // CCLFServerProxy::PopulateSupportedExtensionL
       
  1232 // -----------------------------------------------------------------------------
       
  1233 //
       
  1234 void CCLFServerProxy::PopulateSupportedExtensionL()
       
  1235     {
       
  1236     iExtensionArray = new ( ELeave ) CDesCArraySeg( KCLFExtensionArrayGranularity );
       
  1237     iExtensionArray->AppendL( KExtensionMp3 );
       
  1238     iExtensionArray->AppendL( KExtensionAac );
       
  1239     iExtensionArray->AppendL( KExtensionAmr );
       
  1240     iExtensionArray->AppendL( KExtensionAwb );
       
  1241     iExtensionArray->AppendL( KExtensionMid );
       
  1242     iExtensionArray->AppendL( KExtensionMidi );
       
  1243     iExtensionArray->AppendL( KExtensionSpMid );
       
  1244     iExtensionArray->AppendL( KExtensionRng );
       
  1245     iExtensionArray->AppendL( KExtensionMxmf );
       
  1246     iExtensionArray->AppendL( KExtensionWav );
       
  1247     iExtensionArray->AppendL( KExtensionAu );
       
  1248     iExtensionArray->AppendL( KExtensionNrt );
       
  1249     iExtensionArray->AppendL( KExtensionWma );
       
  1250     iExtensionArray->AppendL( KExtensionRa );
       
  1251     
       
  1252     iExtensionArray->AppendL( KExtJpg );
       
  1253     iExtensionArray->AppendL( KExtJpeg );
       
  1254     iExtensionArray->AppendL( KExtJp2 );
       
  1255     iExtensionArray->AppendL( KExtJ2k );
       
  1256     iExtensionArray->AppendL( KExtJpx );
       
  1257     iExtensionArray->AppendL( KExtJpf );
       
  1258     iExtensionArray->AppendL( KExtMbm );
       
  1259     iExtensionArray->AppendL( KExtPng );
       
  1260     iExtensionArray->AppendL( KExtGif );
       
  1261     iExtensionArray->AppendL( KExtBmp );
       
  1262     iExtensionArray->AppendL( KExtTif );
       
  1263     iExtensionArray->AppendL( KExtTiff );
       
  1264     iExtensionArray->AppendL( KExtOta );
       
  1265     iExtensionArray->AppendL( KExtWbmp );
       
  1266     iExtensionArray->AppendL( KExtWmf );
       
  1267     iExtensionArray->AppendL( KExtOtb );
       
  1268     
       
  1269     iExtensionArray->AppendL( KExtOma1 );
       
  1270     iExtensionArray->AppendL( KExtOma2 );
       
  1271     iExtensionArray->AppendL( KExtOma3 );
       
  1272     iExtensionArray->AppendL( KExtOma4 );
       
  1273     iExtensionArray->AppendL( KExtOma5 );
       
  1274     
       
  1275     iExtensionArray->AppendL( KExtensionMp4 );
       
  1276     iExtensionArray->AppendL( KExtensionMpg4 );
       
  1277     iExtensionArray->AppendL( KExtensionMpeg4 );
       
  1278     iExtensionArray->AppendL( KExtensionM4v );
       
  1279     iExtensionArray->AppendL( KExtensionM4a );
       
  1280     iExtensionArray->AppendL( KExtension3gp );
       
  1281     iExtensionArray->AppendL( KExtension3gpp );
       
  1282     iExtensionArray->AppendL( KExtension3g2 );
       
  1283     iExtensionArray->AppendL( KExtensionRm );
       
  1284     iExtensionArray->AppendL( KExtensionRmvb );
       
  1285     iExtensionArray->AppendL( KExtensionRam );
       
  1286     iExtensionArray->AppendL( KExtensionRv );
       
  1287     iExtensionArray->AppendL( KExtensionWmv );
       
  1288     iExtensionArray->AppendL( KExtensionAvi );
       
  1289     }
       
  1290 
       
  1291 //  End of File