userlibandfileserver/fileserver/sfile/sf_cache_client.h
changeset 0 a41df078684a
child 176 af6ec97d9189
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 2006-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 the License "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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // f32\sfile\sf_cache_client.h
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalTechnology
       
    21  @released
       
    22 */
       
    23 
       
    24 #if !defined(__SF_CACHE_CLIENT_H__)
       
    25 #define __SF_CACHE_CLIENT_H__
       
    26 
       
    27 #include "sf_cache_man.h"
       
    28 
       
    29 // fwd refs
       
    30 class CCacheManager;	
       
    31 
       
    32 NONSHARABLE_CLASS(CCacheClient) : public CBase
       
    33 	{
       
    34 public:
       
    35 	~CCacheClient();
       
    36 	void Purge(TBool aPurgeDirty = EFalse);
       
    37 
       
    38 	TUint8* AllocateAndLockSegments(TInt64 aPos, TInt& aSegmentCount, TBool aMakeDirty, TBool aExtendExisting);
       
    39 
       
    40 	TUint8* FindAndLockSegments(TInt64 aPos, TInt& aSegmentCount, TInt& aFilledSegmentCount, TInt& aLockError, TBool aMakeDirty);
       
    41 	TUint8* FindSegment(TInt64 aPos);
       
    42 	
       
    43 
       
    44 	void UnlockSegments(TInt64 aPos);
       
    45 
       
    46 
       
    47 	void MarkSegmentsAsFilled(TInt64 aPos, TInt aSegmentCount);
       
    48 	void MarkSegmentsAsDirty(TInt64 aPos, TInt aSegmentCount);
       
    49 
       
    50 	TInt FindFirstDirtySegment(TInt64& aPos, TUint8*& aAddr);
       
    51 
       
    52 	void MarkSegmentsAsClean(TInt64 aPos);
       
    53 
       
    54 	
       
    55 	void SetMaxSegments(TInt aMaxSegments);
       
    56 
       
    57 	TBool SegmentEmpty(TInt64 aPos);
       
    58 	TBool SegmentDirty(TInt64 aPos);
       
    59 	TBool TooManyLockedSegments();
       
    60 
       
    61 	inline TInt CacheOffset(TInt64 aLinAddr) const \
       
    62 		{return(I64LOW(aLinAddr)& ((1 << iManager.SegmentSizeLog2())-1));}
       
    63 
       
    64 	TInt SegmentSize();
       
    65 	TInt SegmentSizeLog2();
       
    66 	TInt64 SegmentSizeMask();
       
    67 	TInt CacheLineSize();
       
    68 	TInt CacheLineSizeInSegments();
       
    69 
       
    70 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
       
    71 	void DumpCache();
       
    72 #endif
       
    73 
       
    74 private:
       
    75 	// class can only be instantiated from friend class CCacheManager
       
    76 	static CCacheClient* NewL(CCacheManager& aManager);
       
    77 	void ConstructL();
       
    78 	CCacheClient(CCacheManager& aManager);
       
    79 	
       
    80 
       
    81 	TInt LockSegments(TInt64 aPos, TInt aSegmentCount, TBool aMakeDirty);
       
    82 
       
    83 	const CCacheManager::TCacheLine* FindCacheLine(TInt64 aPos);
       
    84 	TInt FindCacheLineIndex(TInt64 aPos);
       
    85 
       
    86 	TBool FreeCacheLine(const CCacheManager::TCacheLine* aCacheLine);
       
    87 
       
    88 	void RemoveCacheLine(const CCacheManager::TCacheLine* aCacheLine);
       
    89 	void RemoveEmptySegments(const CCacheManager::TCacheLine* aCacheLine);
       
    90 
       
    91 	void RemoveLru(const CCacheManager::TCacheLine* aCacheLineToExclude);
       
    92 
       
    93 	inline TInt StartSegment(const CCacheManager::TCacheLine* aCacheLine, TInt64 aPos);
       
    94 	inline TInt CacheLineLen(const CCacheManager::TCacheLine* aCacheLine);
       
    95 
       
    96 	TInt CachedBytes();
       
    97 	TInt LockedBytes();
       
    98 private:
       
    99 	CCacheManager& iManager;
       
   100 
       
   101 	// segment array for segments that contain valid data
       
   102 	RPointerArray<CCacheManager::TCacheLine>* iCacheLines;
       
   103 	TInt iMaxBytesCached;
       
   104 
       
   105 	TInt iLastCacheLineIndex;
       
   106 
       
   107 	friend class CCacheManager;
       
   108 	};
       
   109 
       
   110 
       
   111 
       
   112 #endif