ncdengine/provider/server/inc/ncdnodecachecleaner.h
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2006 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:   Contains CNcdNodeCacheCleaner class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef NCD_NODE_CACHE_CLEANER_H
       
    20 #define NCD_NODE_CACHE_CLEANER_H
       
    21 
       
    22 
       
    23 // For array and uid
       
    24 #include <e32cmn.h>
       
    25 #include <badesca.h>
       
    26 
       
    27 // For active object
       
    28 #include <e32base.h>
       
    29 
       
    30 // For TTime
       
    31 #include <e32std.h>
       
    32 
       
    33 #include "ncdnodeclassids.h"
       
    34 #include "catalogspair.h"
       
    35 
       
    36 class CNcdNodeManager;
       
    37 class CNcdNodeDbManager;
       
    38 class CNcdNodeFactory;
       
    39 class CNcdNodeIdentifier;
       
    40 class CNcdGeneralManager;
       
    41 
       
    42 
       
    43 /**
       
    44  * This class object provides active object functionality for cleanup
       
    45  * of database.
       
    46  *
       
    47  * The state of this class object is not saved into db.
       
    48  * So, in some cases nodes that have been marked for deletion
       
    49  * may be left into the database if this class object is deleted
       
    50  * before cleaning has been finished (this is a rare case though).
       
    51  * If the node data is left hanging to the db, this cleaner can
       
    52  * clean them at latest when they expire.
       
    53  *
       
    54  *  @lib ?library
       
    55  *  @since S60 ?S60_version *** for example, S60 v3.0
       
    56  */
       
    57 class CNcdNodeCacheCleaner : public CActive
       
    58     {
       
    59 
       
    60 public:
       
    61 
       
    62     enum TCleanupState
       
    63         {
       
    64         /**
       
    65          * Cleanup has not been started.
       
    66          * Or, it has been stopped.
       
    67          */
       
    68         ENotStarted,
       
    69 
       
    70         /**
       
    71          * Special cases are given by the user of this class.
       
    72          * These objects are removed first.
       
    73          */
       
    74         ECleaningSpecialCases,
       
    75                 
       
    76         /**
       
    77          * Cleans the temporary nodes that are not used anymore.
       
    78          */
       
    79         ECleaningTemporaryNodes,
       
    80 
       
    81         /**
       
    82          * Makes sure that there are no items just hanging in the db.
       
    83          * If this is case then something has gone wrong somewhere.
       
    84          * Clean these wonder items.
       
    85          */
       
    86         ECleaningHangingCases,
       
    87 
       
    88         /** 
       
    89          * Sets the information for the next cleaning.
       
    90          */
       
    91         EStartCleaningHangingSpecialCases,
       
    92         
       
    93         /**
       
    94          * This will clean special items that can not be identified
       
    95          * by using the nodeidentifiers. For these items metadata has
       
    96          * to be created from the stream and ids have to be checked
       
    97          * separately. For example icons need to be cleaned this way.
       
    98          */
       
    99         ECleaningHangingSpecialCases,
       
   100 
       
   101         /**
       
   102          * Finishes the cleaning of special cases.
       
   103          */
       
   104         EFinishCleaningHangingSpecialCases,
       
   105 
       
   106         /**
       
   107          * Start cleaning excess data if db size has been exceeded.
       
   108          */
       
   109         EStartCleaningExcess,
       
   110 
       
   111         /**
       
   112          * This state will remove the root and its direct children
       
   113          * from the database node array which will contain the node
       
   114          * identifiers of the nodes that may be removed from db during
       
   115          * the cleaning process.
       
   116          * The identifiers are moved to separate array that is used
       
   117          * to check if children are transparent or bundle folders that
       
   118          * require special handling.
       
   119          */
       
   120         EStartRootChildrenCheck,
       
   121 
       
   122         /** 
       
   123          * During this state the cleaner will check if the root children 
       
   124          * are transparent or bundle nodes and handles them accordingly.
       
   125          */        
       
   126         ECheckRootChildren,
       
   127 
       
   128         /**
       
   129          * This state is used when the root children have been bundle 
       
   130          * folders. The transparency of the bundle children is checked
       
   131          * and transparent folder identifiers are removed from the db
       
   132          * node identifier list. So, transparent children will not be
       
   133          * removed from the database.
       
   134          *
       
   135          */
       
   136         EHandleBundleChildren,
       
   137 
       
   138         /**
       
   139          * When all the expired items of certain branch have been found,
       
   140          * the cleaning process is started and items are removed from the db.
       
   141          * Expireds are only removed if database is full.
       
   142          */
       
   143         ECleaningExpireds,
       
   144                 
       
   145         /**
       
   146          * Cleaning excess data because db size has been exceeded.
       
   147          * The cleaning is done by removing the deepest nodes first.
       
   148          * They are still checked to be sure that they can be removed.
       
   149          * This will loop back to ECleaningTemporaryNodes until enough
       
   150          * space is freed.
       
   151          */
       
   152         ECleaningExcess,
       
   153                                 
       
   154         /**
       
   155          * Cleanup operation should be stopped and
       
   156          * when the latest operation is finished the
       
   157          * state should be set as ENotStarted.
       
   158          */
       
   159         EStopping
       
   160         };
       
   161 
       
   162 
       
   163     /**
       
   164      * NewL
       
   165      *
       
   166      * @param aNodeManager
       
   167      * @param aNodeDbManager
       
   168      * @param aDbDefaultMaxSize The default value for the maximum size of 
       
   169      * the database in bytes. If this size is exceeded, then the db should 
       
   170      * be cleaned.
       
   171      * @param aNodeFactory
       
   172      * @param aClientUid
       
   173      * @return CNcdNodeCacheCleaner* Pointer to the created object 
       
   174      * of this class.
       
   175      */
       
   176     static CNcdNodeCacheCleaner* NewL( CNcdGeneralManager& aGeneralManager,
       
   177                                        CNcdNodeDbManager& aNodeDbManager,
       
   178                                        TInt aDbDefaultMaxSize,
       
   179                                        CNcdNodeFactory& aNodeFactory );
       
   180 
       
   181     /**
       
   182      * @see CNcdNodeCacheCleaner::NewL
       
   183      */
       
   184     static CNcdNodeCacheCleaner* NewLC( CNcdGeneralManager& aGeneralManager,
       
   185                                         CNcdNodeDbManager& aNodeDbManager,
       
   186                                         TInt aDbDefaultMaxSize,
       
   187                                         CNcdNodeFactory& aNodeFactory );
       
   188 
       
   189 
       
   190     /**
       
   191      * Destructor
       
   192      */
       
   193     virtual ~CNcdNodeCacheCleaner();
       
   194 
       
   195 
       
   196     /** 
       
   197      * This function is used when the identifier arrays are sorted for other
       
   198      * functionalities in this class object.
       
   199      * The sorting is done only by comparing the length of the node id value.
       
   200      * The shorter will be first in the array.
       
   201      *
       
   202      * @see RPointerArray::Sort
       
   203      */
       
   204     static TInt NodeIdentifierArraySortById( const CNcdNodeIdentifier& aNodeId1,
       
   205                                              const CNcdNodeIdentifier& aNodeId2 );
       
   206 
       
   207 
       
   208     /**
       
   209      * @return const TUid& Uid of the client
       
   210      * that this cleaner is for.
       
   211      */
       
   212     const TUid& ClientUid() const;
       
   213 
       
   214     
       
   215     /**
       
   216      * @return TCleanupState The state of the asynchronous cleanup.
       
   217      */
       
   218     TCleanupState CleanupState() const;   
       
   219 
       
   220 
       
   221     /**
       
   222      * This function sets the flag that informs if the cache cleaner
       
   223      * is allowed to do cleaning. If EFlase is set, then possible
       
   224      * ongoing operation is cancelled and new operations are
       
   225      * prevented. If ETrue is set, then cleaning is allowed.
       
   226      * ETrue is a default value when cleaner is created.
       
   227      *
       
   228      * @param aAllow Informs if the cleaning is allowed.
       
   229      */
       
   230     void SetAllowCleaning( TBool aAllow );
       
   231     
       
   232     
       
   233     /**
       
   234      * @see CNcdNodeCacheCleaner::SetAllowCleaning
       
   235      *
       
   236      * @param aAllow Informs if the cleaning is allowed.
       
   237      */
       
   238     TBool AllowCleaning() const;
       
   239 
       
   240 
       
   241     /**
       
   242      * Starts the asynchronous cleanup process for the client that this cleaner
       
   243      * is created for.
       
   244      */
       
   245     void StartCleanupL();
       
   246 
       
   247     /**
       
   248      * Stops the asynchronous cleanup.
       
   249      */
       
   250     void StopCleanup();
       
   251 
       
   252 
       
   253     /**
       
   254      * If the database size has been exceeded, then the cleaning operation
       
   255      * will be started.
       
   256      * This function may be called for example when new nodes have been added to
       
   257      * the database.
       
   258      *
       
   259      * @note If the db is full:
       
   260      * - The hierarchy will be removed from the leaves
       
   261      * towards the root node until enough data has been removed from the db.
       
   262      * - All the expired nodes will be removed. In addition to those that have
       
   263      * been registered as removable nodes. 
       
   264      */
       
   265     void CheckDbSizeL();
       
   266  
       
   267  
       
   268     /**
       
   269      * The identifiers of the given array will be used to search the nodes from 
       
   270      * the db and to remove them if they exist.
       
   271      * This function should be used if there are multiple identifiers know
       
   272      * because this temporary information is saved simultaneously then.
       
   273      *
       
   274      * @note If the given identifier already exists in the do not remove array
       
   275      * then the identifier is inserted into the waiting array. And, it will
       
   276      * be moved from the waiting array to the cleanup array when the identifier
       
   277      * is asked to be removed from the do not remove array.
       
   278      *
       
   279      * @param aIdentifiers Identifiers that inform which items should be removed
       
   280      * from the db.
       
   281      */
       
   282     void AddCleanupIdentifiersL( const RPointerArray<CNcdNodeIdentifier>& aIdentifiers );
       
   283 
       
   284     /**
       
   285      * Same as AddCleanupIdentifiers but gets only one identifier at a time.
       
   286      * If multiple identifiers are know same time, AddCleanupIdentifiers function
       
   287      * should be used.
       
   288      *
       
   289      * @see CNcdNodeCacheCleaner::AddCleanupIdentifiersL
       
   290      */
       
   291     void AddCleanupIdentifierL( const CNcdNodeIdentifier& aIdentifier );
       
   292 
       
   293 
       
   294 
       
   295     /**
       
   296      * Removes the given identifiers from the cleanup list. This can be used
       
   297      * if the given items have been updated from somewhere else, and they should not be
       
   298      * removed from the db anymore.
       
   299      *
       
   300      * @note If the identifier is located in the waiting array then it will be removed
       
   301      * from that array also.
       
   302      *
       
   303      * @param aIdentifiers Identifies data that should not be removed from the db.
       
   304      */    
       
   305     void RemoveCleanupIdentifiers( const RPointerArray<CNcdNodeIdentifier>& aIdentifiers );
       
   306 
       
   307     /**
       
   308      * Same as AddCleanupIdentifiers but gets only one identifier at a time.
       
   309      * If multiple identifiers are know same time, AddCleanupIdentifiers function
       
   310      * should be used.
       
   311      *
       
   312      * @see CNcdNodeCacheCleaner::RemoveCleanupIdentifiers
       
   313      */
       
   314     void RemoveCleanupIdentifier( const CNcdNodeIdentifier& aIdentifier );
       
   315 
       
   316 
       
   317 
       
   318     /**
       
   319      * The identifiers of the given array will be used to block the removal
       
   320      * of the given items from the db.
       
   321      * This function should be used if there are multiple identifiers
       
   322      * because this temporary information is saved simultaneously then.
       
   323      *
       
   324      * @note If the identifier exists in the cleanup array it will be moved
       
   325      * to the waiting array. This way the node can be moved back to the cleanup
       
   326      * array when the do not remove state is not required for the item anymore.
       
   327      *
       
   328      * @param aIdentifiers Identifiers that inform which items should be removed
       
   329      * from the db.
       
   330      * @param aCanRemoveParent If ETrue, node's parent may be removed from the cache
       
   331      */
       
   332     void AddDoNotRemoveIdentifiersL( 
       
   333         const RPointerArray<CNcdNodeIdentifier>& aIdentifiers,
       
   334         TBool aCanRemoveParent = EFalse );
       
   335 
       
   336     /**
       
   337      * Same as AddDoNotRemoveIdentifiers but gets only one identifier at a time.
       
   338      * If multiple identifiers are know same time, AddDoNotRemoveIdentifiers function
       
   339      * should be used.
       
   340      *
       
   341      * @see CNcdNodeCacheCleaner::AddDoNotRemoveIdentifiersL
       
   342      */
       
   343     void AddDoNotRemoveIdentifierL( 
       
   344         const CNcdNodeIdentifier& aIdentifier, 
       
   345         TBool aCanRemoveParent = EFalse );
       
   346 
       
   347 
       
   348     /**
       
   349      * Removes the given identifiers from the do not remove list. This can be used
       
   350      * if the given items are allowed to be removed from the db later on.
       
   351      *
       
   352      * @note If the identifier exists in the waiting array then it will be moved
       
   353      * back to the cleanup array also.
       
   354      *
       
   355      * @param aIdentifiers Identifies data that should not be removed from the db.
       
   356      */    
       
   357     void RemoveDoNotRemoveIdentifiersL( const RPointerArray<CNcdNodeIdentifier>& aIdentifiers );
       
   358 
       
   359     /**
       
   360      * Same as RemoveDoNotRemoveIdentifiers but gets only one identifier at a time.
       
   361      * If multiple identifiers are know same time, AddDoNotRemoveIdentifiers function
       
   362      * should be used.
       
   363      *
       
   364      * @param aForceRemove If ETrue, removes also 'floating' nodes (favorites)
       
   365      * @see CNcdNodeCacheCleaner::RemoveDoNotRemoveIdentifiers
       
   366      */
       
   367     void RemoveDoNotRemoveIdentifierL( 
       
   368         const CNcdNodeIdentifier& aIdentifier, 
       
   369         TBool aForceRemove = EFalse );
       
   370 
       
   371 
       
   372 
       
   373     /**
       
   374      * @return TInt The maximum size of the db in bytes.
       
   375      */
       
   376     TInt DbMaxSize() const;
       
   377     
       
   378     /**
       
   379      * This function can be used to set the client specific max size
       
   380      * for the db. This value replaces the default value that was set in
       
   381      * the constructor of this class.
       
   382      *
       
   383      * @param aDbMaxSize The maximum size for the db in bytes.
       
   384      * If this size is exceeded, then the cleanup should be started and
       
   385      * db cleaned until the db max size is not exceeded any more.
       
   386      */
       
   387     void SetDbMaxSize( const TInt aDbMaxSize );
       
   388 
       
   389 
       
   390     /**
       
   391      * This function moves the waiting items into cleanup array 
       
   392      * and does the cleanup for all the cleanup list items.
       
   393      * The do not clean array is not reseted. So, the nodes that are in the do not clean array
       
   394      * will not be deleted. 
       
   395      * The function does the cleaning sychronously.
       
   396      * This functions is propably mainly used, when the application is shutting down
       
   397      * and it is wanted to be sure that all the possible items are removed from
       
   398      * the db.
       
   399      *
       
   400      * @note This function also cancels the possible on going asynchronous 
       
   401      * operations before starting its own cleaning.
       
   402      *
       
   403      * @note HandleCleaningL provides gentler way of removing. It does not remove items
       
   404      * that should wait until marked free for removal. 
       
   405      *
       
   406      * @see CNcdNodeCacheCleaner::HandleCleaningL
       
   407      */
       
   408     void ForceCleanupL();
       
   409 
       
   410 
       
   411     /**
       
   412      * This function is meant for the public use and uses the HandleCleaningL below
       
   413      * with both parameters set to ETrue. Because of the ETrue parameters, the
       
   414      * asynchronous process has to be stopped.
       
   415      * 
       
   416      * @note This function also cancels the possible on going asynchronous 
       
   417      * operations before starting its own cleaning.
       
   418      *
       
   419      * @see CNcdNodeCacheCleaner::HandleCleaningL
       
   420      */ 
       
   421     void HandleCleaningL();
       
   422 
       
   423 
       
   424 protected:
       
   425 
       
   426     /** 
       
   427      * Handles the cleaning call for the db.
       
   428      * This function can be used if synchronous cleaning is wanted.
       
   429      * This function does not clean the items that are moved into
       
   430      * waiting arrays for some reasons.
       
   431      * Checks that correct identifiers and types are given for
       
   432      * dbmanager remove operation. This function cleans all the nodes
       
   433      * that are free to be removed from db.
       
   434      *
       
   435      * @note ForceCleanupL provides a hardcore way to remove everything,
       
   436      * including items that should be waiting until marked as free to remove.
       
   437      *
       
   438      * @note When ETrue values are set for the parameters, the acynhronous process
       
   439      * should be stopped before calling this function. If this not done, 
       
   440      * the cleaning process may go wrong. Thus, this function
       
   441      * is not meant for public use. 
       
   442      *
       
   443      * @see CNcdNodeCacheCleaner::ForceCleanupL
       
   444      *
       
   445      * @param aReloadNodeList If set ETrue then the node item list will be relaoded
       
   446      * from the database. Then, the parent and child comparisons will be upto date.
       
   447      * Notice, that if this is set true, the db-loading will take some time 
       
   448      * but it may be a good idea to update the list, because if the cleaning 
       
   449      * has not been done for a while the node list may have changed dramatically 
       
   450      * when other parts of the code have updated the database.
       
   451      * @param aResetNodeList If set ETrue, then the node list will be reset in the end
       
   452      * of this function. This flag is provided, so the user may save some memory if
       
   453      * the node list is not needed after this function. Be really carefull when using
       
   454      * this flag. Because in some states of this object the node list should not be cleaned.
       
   455      * Whe using this object the ETrue should most likely be used here if this object
       
   456      * is not in the middle of cleaning or when the object is about to be deleted.
       
   457      */
       
   458     void HandleCleaningL( TBool aReloadNodeList, TBool aResetNodeList );
       
   459 
       
   460 
       
   461     /**
       
   462      * Ensures that iCleanupIdentifiers does not contain any of the ids in 
       
   463      * iDoNotRemoves
       
   464      */
       
   465     void RemoveDoNotRemovesFromCleanupArray();
       
   466         
       
   467 protected: // CActive
       
   468 
       
   469     /**
       
   470      * @see CActive::DoCancel
       
   471      */
       
   472     virtual void DoCancel();
       
   473 
       
   474     /**
       
   475      * @see CActive::RunL
       
   476      */
       
   477     virtual void RunL();
       
   478 
       
   479     /**
       
   480      * @see CActive::RunError
       
   481      */
       
   482     virtual TInt RunError( TInt aError );
       
   483 
       
   484 protected:
       
   485 
       
   486     /**
       
   487      * Constructor
       
   488      *
       
   489      * @see CNcdNodeCacheCleaner::NewL
       
   490      */
       
   491     CNcdNodeCacheCleaner( CNcdGeneralManager& aGeneralManager,
       
   492                           CNcdNodeDbManager& aNodeDbManager,
       
   493                           TInt aDbDefaultMaxSize,
       
   494                           CNcdNodeFactory& aNodeFactory );
       
   495 
       
   496     /**
       
   497      * ConstructL
       
   498      */
       
   499     void ConstructL();
       
   500 
       
   501     /**
       
   502      * @return CNcdNodeManager& Manager that owns this cleaner
       
   503      */
       
   504     CNcdNodeManager& NodeManager() const;
       
   505 
       
   506     /**
       
   507      * @return CNcdNodeDbManager& Database manager that provides functions
       
   508      * to handle database content.
       
   509      */
       
   510     CNcdNodeDbManager& NodeDbManager() const;
       
   511 
       
   512     /**
       
   513      * @return CNcdNodeFactory& Factory that is used to create node
       
   514      * related class objects.
       
   515      */
       
   516     CNcdNodeFactory& NodeFactory() const;
       
   517         
       
   518 
       
   519 private:
       
   520 
       
   521     typedef CCatalogsPair<CNcdNodeIdentifier, TBool> CDoNotRemoveIdentifier;
       
   522     
       
   523 private:
       
   524 
       
   525     // Prevent these two if they are not implemented
       
   526     CNcdNodeCacheCleaner( const CNcdNodeCacheCleaner& aObject );
       
   527     CNcdNodeCacheCleaner& operator =( const CNcdNodeCacheCleaner& aObject );
       
   528 
       
   529     /**
       
   530      * This function is used to check if the given identifier exists in the target array.
       
   531      *
       
   532      * @param aIdentifier This identifier is searched from the array.
       
   533      * @param aTargetIdentifiers Array contains the identifiers that the given identifier
       
   534      * is compared against.
       
   535      * @return TBool ETrue if the identifier was found from the array. Else EFalse.
       
   536      */
       
   537     TBool ContainsIdentifier( 
       
   538         const CNcdNodeIdentifier& aIdentifier ,
       
   539         const RPointerArray<CDoNotRemoveIdentifier>& aTargetIdentifiers ) const;    
       
   540     
       
   541     
       
   542     // Adds given identifiers into the target array if they do not already
       
   543     // exist there. If the target array was changed due to the appending operation,
       
   544     // ETrue is returned. If nothing was appended, then EFalse is returned.
       
   545     TBool AddIdentifiersL( const RPointerArray<CNcdNodeIdentifier>& aIdentifiers,
       
   546                            RPointerArray<CNcdNodeIdentifier>& aTargetArray );
       
   547                                                       
       
   548     // Adds given identifier into the target array if it does not already
       
   549     // exist there. If the target array was changed due to the appending operation,
       
   550     // ETrue is returned. If nothing was appended, then EFalse is returned.
       
   551     TBool AddIdentifierL( const CNcdNodeIdentifier& aIdentifier,
       
   552                           RPointerArray<CNcdNodeIdentifier>& aTargetArray ); 
       
   553 
       
   554 
       
   555     // Removes all occurrences of the given identifiers from the target array 
       
   556     // if they are found.
       
   557     // ETrue is returned if any identifier was removed. If nothing was done to
       
   558     // the target array, then EFalse is returned.
       
   559     TBool RemoveIdentifiers( const RPointerArray<CNcdNodeIdentifier>& aIdentifiers,
       
   560                              RPointerArray<CNcdNodeIdentifier>& aTargetArray );    
       
   561 
       
   562     // Removes all occurrences of the given identifier from the target array 
       
   563     // if they are found.
       
   564     // ETrue is returned if any identifier was removed. If nothing was done to
       
   565     // the target array, then EFalse is returned.
       
   566     TBool RemoveIdentifier( const CNcdNodeIdentifier& aIdentifier,
       
   567                             RPointerArray<CNcdNodeIdentifier>& aTargetArray );
       
   568 
       
   569     // aForceRemove is used to indicate whether Favorite nodes should be
       
   570     // removed or not. Default is no
       
   571     TBool RemoveIdentifier( const CNcdNodeIdentifier& aIdentifier,
       
   572                             RPointerArray<CDoNotRemoveIdentifier>& aTargetArray,
       
   573                             TBool aForceRemove = EFalse );
       
   574                               
       
   575     // Resets the node item info from the db to the member array.
       
   576     // This will contain only node item infos.
       
   577     void SetAllDbStorageNodeItemsL();
       
   578 
       
   579     // Resets the icon item info from the db to the member array.
       
   580     // This will contain only icon item infos.
       
   581     void SetAllDbStorageIconItemsL();
       
   582 
       
   583     // Resets the screenshot item info from the db to the member array.
       
   584     // This will contain only screenshot item infos.
       
   585     void SetAllDbStorageScreenshotItemsL();
       
   586 
       
   587     // Gets the children identifiers of the cleanup array identifiers. Appends
       
   588     // the children also to the cleanup array. So, this function makes sure that
       
   589     // the hierarchies below the cleanup array identifiers are also included into
       
   590     // the array.
       
   591     void AddChildrenToCleanupArrayL();
       
   592 
       
   593     // Checks if the parents that have been inserted to parent waiting list
       
   594     // can be put back to the cleaning list.
       
   595     void ParentCleaningCheckL();
       
   596 
       
   597     // This function checks if the db contains temporary nodes and adds them to the
       
   598     // cleanup list.
       
   599     void CheckTemporaryNodesL();
       
   600     
       
   601     // Resets this object state. To be ready for the next try.
       
   602     // This function is used. If something went wrong during the
       
   603     // cleanup procedure.
       
   604     void ResetState();
       
   605 
       
   606     // This function can be used to print the given array into the log file.
       
   607     void ArrayDebugPrint( const RPointerArray<CNcdNodeIdentifier>& aIdentifiers ) const;
       
   608 
       
   609     void ArrayDebugPrint( const RPointerArray<CDoNotRemoveIdentifier>& aIdentifiers ) const;
       
   610 
       
   611     // Functions that are used during active cleaning.
       
   612     // These functions mainly correspond to the states of this cleaner.
       
   613     
       
   614     void CleanSpecialsL();
       
   615     void CleanTemporaryNodesL();
       
   616     void CleanHangingsL();
       
   617     void StartCleanSpecialHangingsL();
       
   618     void CleanSpecialHangingsL();
       
   619     void FinishCleanSpecialHangingsL();
       
   620     void StartCleanExcessL();
       
   621     void StartRootChildrenCheckL();
       
   622     void CheckRootChildrenL();
       
   623     void HandleBundleChildrenL();
       
   624     void CleanExpiredsL();
       
   625     void CleanExcessL();
       
   626     void StoppingL();      
       
   627 
       
   628                               
       
   629 private: // data
       
   630 
       
   631     CNcdGeneralManager& iGeneralManager;
       
   632     
       
   633     // Node manager handles creation of the nodes.   
       
   634     CNcdNodeManager& iNodeManager;
       
   635     
       
   636     // Data base manager is used to remove the nodes from the db.
       
   637     CNcdNodeDbManager& iNodeDbManager;
       
   638 
       
   639     // This contains the client specific max db byte size
       
   640     TInt iDbMaxSize;
       
   641     
       
   642     // The factory is used to create the correct nodes.
       
   643     CNcdNodeFactory& iNodeFactory;
       
   644 
       
   645     // This flag that informs if the cache cleaner 
       
   646     // is allowed to do cleaning.
       
   647     TBool iAllowCleaning;
       
   648         
       
   649     // This variable is used to check if the db should be cleaned with
       
   650     // higher priority.
       
   651     CActive::TPriority iIncreasePriority;
       
   652 
       
   653     // This flag is used to inform if the priority should be reseted. ´
       
   654     // This is needed because the priority can not be set
       
   655     // if the object is active. Thus, it has to be done later for example
       
   656     // next time the cleaning is started.
       
   657     TBool iResetPriority;
       
   658 
       
   659     // This time contains the last time that the cleanup has started.
       
   660     // If no cleanup has been started in required period. Then the
       
   661     // cleanup will be automatically started when the db size is asked
       
   662     // next time.
       
   663     TTime iLastCleanupTime;
       
   664 
       
   665     // Informs if the cleanup has been set to 
       
   666     TCleanupState iCleanupState;
       
   667 
       
   668     // This index can be used to infrom what identifiers are already handled
       
   669     // and which nodes should still be checked for cleanup when expired nodes
       
   670     // are cleaned.
       
   671     TInt iExpiredCleaningIndex;
       
   672     
       
   673     // This is used to inform if the excess celanup loop has already started.
       
   674     TBool iExcessCleanupStarted;
       
   675     
       
   676     // This array actually contains only the node, which will be used
       
   677     // when the node items are searched from the db.
       
   678     RArray<NcdNodeClassIds::TNcdNodeClassType> iNodeCleanupTypes;
       
   679 
       
   680     // This array contains the types that can be deleted directly by
       
   681     // using the metadata identifier.
       
   682     // This does not include node type
       
   683     // because it will always be used when cleaning.
       
   684     RArray<NcdNodeClassIds::TNcdNodeClassType> iMetaCleanupTypes;
       
   685 
       
   686     // This contains the list of the general types of the icon items
       
   687     // that should be removed. 
       
   688     // The items of these types can not be identified directly by using
       
   689     // node or metadata identifiers.
       
   690     RArray<NcdNodeClassIds::TNcdNodeClassType> iIconCleanupTypes; 
       
   691 
       
   692     // This contains the list of the general types of the screenshot items
       
   693     // that should be removed. 
       
   694     // The items of these types can not be identified directly by using
       
   695     // node or metadata identifiers.
       
   696     RArray<NcdNodeClassIds::TNcdNodeClassType> iScreenshotCleanupTypes; 
       
   697 
       
   698     // This array contains the namespaces whose data will not be cleaned.
       
   699     CPtrCArray* iDoNotCleanNameSpaces;    
       
   700         
       
   701     // The nodes that should be cleaned from the db.
       
   702     // Notice, that this array is used for every cleanup phase. So, even
       
   703     // if the user of this class object adds identifiers during
       
   704     // the cleanup process, those nodes will be removed also when next remove
       
   705     // operation is done because the same array is used when cleanup is done.
       
   706     RPointerArray<CNcdNodeIdentifier> iCleanupIdentifiers;
       
   707 
       
   708     // This array will contain all the db storage node identifiers.
       
   709     // This array can be used to create the actual node items according
       
   710     // to the id info.
       
   711     RPointerArray<CNcdNodeIdentifier> iAllDbStorageNodeItems;    
       
   712 
       
   713     // This array will contain all the icon ids that are used to check
       
   714     // if some icons should be deleted from the db.
       
   715     RPointerArray<CNcdNodeIdentifier> iAllDbIconItems;
       
   716 
       
   717     // This array will contain all the screenshot ids that are used to check
       
   718     // if some screenshots should be deleted from the db.
       
   719     RPointerArray<CNcdNodeIdentifier> iAllDbScreenshotItems;
       
   720 
       
   721     // This array will contain all the current metadata identifiers. That can 
       
   722     // be used to create metadatas and to check if some special contents
       
   723     // should be removed.
       
   724     RPointerArray<CNcdNodeIdentifier> iDbMetaIdentifiers;
       
   725 
       
   726     // This list will be used if the remove operation is started and
       
   727     // during remove operation engine infroms that some nodes should
       
   728     // not be deleted after all.    
       
   729     RPointerArray< CDoNotRemoveIdentifier > iDoNotRemoves;
       
   730 
       
   731     // This array contains identifiers that have been initially marked for
       
   732     // cleanup but after that have also been tried to move to the do not
       
   733     // remove array. Then, the identifier will be set for waiting until
       
   734     // is requested to be removed from the do not remove array. So, then
       
   735     // the identifier will be moved from the waiting array to cleanup array.
       
   736     RPointerArray<CNcdNodeIdentifier> iWaitingIdentifiers;
       
   737     
       
   738     // This list contains the parents that have been put to cleanuplist but
       
   739     // can not be deleted because their children are in waiting list or in
       
   740     // do not remove list.
       
   741     RPointerArray<CNcdNodeIdentifier> iWaitingParentIdentifiers;
       
   742 
       
   743     // This array will contain identifiers of children nodes of
       
   744     // the root. These identifiers are used, when transparency and bundle
       
   745     // check are done to these nodes.
       
   746     RPointerArray<CNcdNodeIdentifier> iRootChildren;
       
   747     
       
   748     // This array will contain the children of a certain bundle when
       
   749     // the transparency check are done to the children of the bundle.
       
   750     RPointerArray<CNcdNodeIdentifier> iBundleChildren;
       
   751     };
       
   752     
       
   753 #endif // NCD_NODE_CACHE_CLEANER_H