installationservices/swtransactionservices/inc_private/integritytree.h
branchRCL_3
changeset 26 8b7f4e561641
parent 25 7333d7932ef7
child 27 e8965914fac7
equal deleted inserted replaced
25:7333d7932ef7 26:8b7f4e561641
     1 /*
       
     2 * Copyright (c) 2006-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 the License "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 /**
       
    20  @file 
       
    21  @released
       
    22  @internalTechnology
       
    23 */
       
    24 
       
    25 #ifndef __INTEGRITYTREE_H__
       
    26 #define __INTEGRITYTREE_H__
       
    27 
       
    28 #include <e32base.h>
       
    29 #include <f32file.h>
       
    30 #include "integrityservicesevent.h"
       
    31 #include "integrityservices.h"
       
    32 
       
    33 namespace Usif
       
    34 {
       
    35 
       
    36 class CIntegrityTreeNode;
       
    37 class CIntegrityTreeLeaf;
       
    38 
       
    39 typedef void(* TTreeWalkFunctionL)(const TDesC& aPath, CIntegrityTreeLeaf* aLeaf, RFs& aFs, RLoader& aLoader, CFileMan& aFileMan);
       
    40 
       
    41 class CIntegrityTreeLeaf : public CBase
       
    42 	{
       
    43 public:
       
    44 	/**
       
    45 	 * Constructs a file tree leaf, and places it on the cleanup stack
       
    46 	 *
       
    47 	 * @param aFileName The filename for this leaf node
       
    48 	 * @param aType The type of this leaf
       
    49 	 * @param aOwningJournal A reference to the filename of the owning journal
       
    50 	 * @return A fully constructed tree leaf
       
    51 	 */
       
    52 	static CIntegrityTreeLeaf* NewLC(const TDesC& aFileName, TIntegrityServicesEvent aType,
       
    53 		const TDesC& aOwningJournal);
       
    54 	
       
    55 	/**
       
    56 	 * Sets the peer node if applicable. This is used for leaves that
       
    57 	 * naturally form pairs, for example a removed file and its backup.
       
    58 	 * 
       
    59 	 * @param aPeer The leaf's peer.
       
    60 	 *
       
    61 	 */
       
    62 	
       
    63 	void SetPeer(CIntegrityTreeLeaf* aPeer);
       
    64 	
       
    65 	/**
       
    66 	 * Returns the leaf's peer, or null if none was set
       
    67 	 *
       
    68 	 * @return The leaf's peer node if available
       
    69 	 *
       
    70 	 */
       
    71 	
       
    72 	CIntegrityTreeLeaf* Peer();
       
    73 	
       
    74 	/**
       
    75 	 * Returns the type of this leaf. 
       
    76 	 *
       
    77 	 * @return This leaf's type
       
    78 	 */
       
    79 	 
       
    80 	TIntegrityServicesEvent Type();
       
    81 	
       
    82 	/**
       
    83 	 * Returns the file name for this leaf
       
    84 	 *
       
    85 	 * @return The file name for this leaf
       
    86 	 */
       
    87 	
       
    88 	const TDesC& Name();
       
    89 	
       
    90 	/**
       
    91 	 * Returns the name of the journal file that owns this leaf
       
    92 	 *
       
    93 	 * @return The associated journal file name
       
    94 	 */
       
    95 	
       
    96 	const TDesC& Journal();
       
    97 	
       
    98 	~CIntegrityTreeLeaf();
       
    99 private:
       
   100 	CIntegrityTreeLeaf(TIntegrityServicesEvent aType, const TDesC& aOwningJournal);
       
   101 	void ConstructL(const TDesC& aFileName);
       
   102 	
       
   103 private:
       
   104 	HBufC* iFileName;
       
   105 	TIntegrityServicesEvent iType;
       
   106 	CIntegrityTreeLeaf* iPeer;
       
   107 	
       
   108 	const TDesC& iOwningJournal;
       
   109 	
       
   110 	};
       
   111 	
       
   112 class CIntegrityTreeNode : public CBase
       
   113 	{
       
   114 public:
       
   115 	/**
       
   116 	 * Constructs a file tree node, and places it on the cleanup stack
       
   117 	 *
       
   118 	 * @param aDirectoryName The name of the directory this node represents
       
   119 	 * @return A fully constructed tree node
       
   120 	 */
       
   121 	
       
   122 	static CIntegrityTreeNode* NewL(const TDesC& aDirectoryName);
       
   123 	
       
   124 	/**
       
   125 	 * Constructs a file tree node
       
   126 	 *
       
   127 	 * @param aDirectoryName The name of the directory this node represents
       
   128 	 * @return A fully constructed tree node
       
   129 	 */
       
   130 	
       
   131 	static CIntegrityTreeNode* NewLC(const TDesC& aDirectoryName);
       
   132 	
       
   133 	/**
       
   134 	 * Returns the name of the directory this node represents
       
   135 	 * 
       
   136 	 * @return The name of this directory
       
   137 	 */
       
   138 	
       
   139 	const TDesC& Name();
       
   140 	
       
   141 	/**
       
   142 	 * Adds a leaf node to this tree structure, adding intermediate (directory) nodes along
       
   143 	 * the way as appropriate.
       
   144 	 * 
       
   145 	 * @param aFileName The fully qualified file name of the node to add
       
   146 	 * @param aType The type of the node to add
       
   147 	 * @param aOwningJournal The file name of the journal that owns this node
       
   148 	 * @return The leaf node added.
       
   149 	 *
       
   150 	 */
       
   151 	
       
   152 	CIntegrityTreeLeaf* AddNodeL(const TDesC& aFileName, TIntegrityServicesEvent aType, const TDesC& aOwningJournal);
       
   153 	
       
   154 	/**
       
   155 	 * Finds a node in the tree if it exists.
       
   156 	 *
       
   157 	 * @param aFileName The file name to find
       
   158 	 * @param aType The type of node to find
       
   159 	 * @return KErrNone if found, otherwise one of the system wide error codes
       
   160 	 */
       
   161 	
       
   162 	TInt FindNode(const TDesC& aFileName, TIntegrityServicesEvent aType);
       
   163 	
       
   164 	/**
       
   165 	 * Applies a function to every applicable node in the tree
       
   166 	 *
       
   167 	 * @param aFunc The function to apply
       
   168 	 * @param aTypeFilter The type of node to apply the function to
       
   169 	 * @param aFs A connected file server session
       
   170 	 * @param aLoader reference to the RLoader server session
       
   171 	 * @param aFileMan A constructed CFileMan object
       
   172 	 * @param aFailType The type of failure to induce if required. Used exclusively in testing.
       
   173 	 *
       
   174 	 */
       
   175 	
       
   176 	void WalkTreeL(TTreeWalkFunctionL aFunc, TIntegrityServicesEvent aTypeFilter,
       
   177 		RFs& aFs, RLoader& aLoader, CFileMan& aFileMan, 
       
   178 		CIntegrityServices::TFailType aFailType);
       
   179 		
       
   180 	~CIntegrityTreeNode();
       
   181 protected:
       
   182 	CIntegrityTreeLeaf* DoAddNodeL(TDes& aFileName, TIntegrityServicesEvent aType, const TDesC& aOwningJournal);
       
   183 	TInt DoFindNode(TDes& aFileName, TIntegrityServicesEvent aType);
       
   184 	void DoWalkTreeL(TDes& aPath, TTreeWalkFunctionL aFunc, TIntegrityServicesEvent aTypeFilter, 
       
   185 		RFs& aFs, RLoader& aLoader, CFileMan& aFileMan,
       
   186 		CIntegrityServices::TFailType aFailType);
       
   187 	
       
   188 private:
       
   189 	CIntegrityTreeNode();
       
   190 	void ConstructL(const TDesC& aDirectoryName);
       
   191 	
       
   192 private:
       
   193 	HBufC* iDirName;
       
   194 	RPointerArray<CIntegrityTreeNode> iDirectories;
       
   195 	RPointerArray<CIntegrityTreeLeaf> iFiles;
       
   196 	
       
   197 	friend class Usif::CIntegrityServices;
       
   198 	};
       
   199 
       
   200 } // namespace Usif
       
   201 
       
   202 #endif /* __INTEGRITYTREE_H__ */