First public contribution.
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // This file holds the class declarations for the CFbTopMBMCache
15 // The cache is used to store the stream ids of bitmaps in a MBM file
25 #include "ShiftedFileStore.h"
28 //This class holds the TStreamIds of the bitmaps stored in an MBM file
29 //and the filestore of the last loaded bitmap file. The idea of the cache
30 //is to speed up loading of bitmaps from a mbm file by skipping the file
31 //opening process and mapping the MBM id directly to the Stream ids stored
34 NONSHARABLE_CLASS(CFbTopStreamIdCache): public CBase
37 CFbTopStreamIdCache(TInt aForwardSize, TInt aBackwardSize, TInt aMaxFilestores);
38 ~CFbTopStreamIdCache();
39 TStreamId GetStreamIdL(RFile& aFile,const TDesC& aFilename,TInt32 aId,TUint aFileOffset, TInt aSessionHandle);
40 TStreamId GetStreamIdL(RFs& aFs,const TDesC& aFilename,TInt32 aId,TUint aFileOffset, TInt aSessionHandle);
41 CShiftedFileStore* MruFileStore();
43 void CloseFileStores(TInt aSessionHandle=0); // If aSessionHandle is not passed, all file stores will be closed
47 RCacheEntry* AddCacheEntryL(const TDesC& aFilename, TUint aFileOffset);
48 RCacheEntry* FindCacheEntry(const TDesC& aFilename, TUint aFileOffset);
51 RPointerArray<RCacheEntry> iEntries; // Array of pointers to the cache entries in least-recently-used order
52 TUint8* iBuffer; // Buffer for storage of the cache entries
53 const TInt iForwardCacheSize; // Max number of cached bitmap ids after the last requested bitmap id
54 const TInt iBackwardCacheSize; // Max number of cached bitmap ids before the last requested bitmap id
55 const TInt iMaxCacheFilestores; // Max number of filestores in the cache
57 friend class CTStreamIdCache; // This is used for testing purposes
61 class CFbTopStreamIdCache::RCacheEntry
64 RCacheEntry(const TDesC& aFilename, TUint aFileOffset);
65 TBool SameFile(const TDesC& aFilename, TUint aFileOffset);
66 TStreamId GetStreamIdL(TInt32 aId, TInt aForwardSize, TInt aBackwardSize);
67 CShiftedFileStore* FileStore();
68 void CloseFileStore();
69 TInt SessionHandle() const;
70 void CreateFileStoreL(RFile& aFile, TInt aSessionHandle);
71 void CreateFileStoreL(RFs& aFs, const TDesC& aFilename, TInt aSessionHandle);
73 static const TInt KBaseSize; // Size of the class excluding array iStreamIdCache
76 TBufC<KMaxFileName> iFilename; // Name of the mbm file
77 TUint iFileOffset; // Offset into the mbm file
78 CShiftedFileStore *iFilestore; // File store for the mbm file
79 TInt iLastId; // Last requested bitmap id from the mbm file
80 TInt iStreamIdCount; // Number of stream ids from the mbm file
81 TInt iSessionHandle; // Handle to the associated client session
83 // Keep always iStreamIdCache as the last data member
84 // Memory for it is allocated in CFbTopStreamIdCache::AddCacheEntryL()
85 TStreamId iStreamIdCache[1]; // Array of stream ids from the mbm file
87 friend class CTStreamIdCache; // This is used for testing purposes