userlibandfileserver/fileserver/sfile/sf_memory_man.h
changeset 0 a41df078684a
child 36 538db54a451d
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 2008-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_memory_man.h
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalTechnology
       
    21 */
       
    22 
       
    23 #if !defined(__SF_MEMORY_MAN_H__)
       
    24 #define __SF_MEMORY_MAN_H__
       
    25 
       
    26 #include <e32def.h>
       
    27 
       
    28 const TUint KSegmentSizeLog2 = 12;
       
    29 /**	Kernel's memory page size in bytes */
       
    30 const TUint KSegmentSize = 1 << KSegmentSizeLog2;
       
    31 
       
    32 /**	Forward declaration */
       
    33 class CCacheMemoryClient;
       
    34 
       
    35 /**	Cache memory manager class */
       
    36 class CCacheMemoryManager : public CBase
       
    37 	{
       
    38 public:
       
    39 	static CCacheMemoryManager* NewL(TInt aSizeInBytes);
       
    40 	IMPORT_C CCacheMemoryClient* ConnectClientL(const TDesC& aClientName, TUint32 aMinSizeInSegs, TUint32 aMaxSizeInSegs);
       
    41 	IMPORT_C TUint SegmentSizeInBytesLog2() const;
       
    42 	TInt	RegisterClient(CCacheMemoryClient* aClient);
       
    43 	TInt 	AllocateAndLockSegments(TUint8* aStartRamAddr, TInt aSegmentCount);
       
    44 	TInt 	LockSegments(TUint8* aStartRamAddr, TUint32 aSegmentCount);
       
    45 	TInt 	UnlockSegments(TUint8* aStartRamAddr, TUint32 aSegmentCount);
       
    46 	TInt 	DecommitSegments(TUint8* aStartRamAddr, TUint32 aSegmentCount);
       
    47 	TUint8* Base();
       
    48 	void 	FreeMemoryChanged(TBool aIsMemoryLow);
       
    49 
       
    50 private:
       
    51 	~CCacheMemoryManager();
       
    52 	CCacheMemoryManager(TUint32 aMaxSize);
       
    53 	void 	ConstructL();
       
    54 	TInt 	Lock(TUint8* aStartRamAddr, TInt aSegmentCount);
       
    55 	TInt 	Unlock(TUint8* aStartRamAddr, TInt aSegmentCount);
       
    56 	TInt	Commit(TUint8* aStartRamAddr, TInt aSegmentCountt);
       
    57 	TInt 	Decommit(TUint8* aStartRamAddr, TInt aSegmentCount);
       
    58 
       
    59 private:
       
    60 	RChunk 	iChunk;					///< the RChunk interface to interact with demand paging sub-system
       
    61 	TUint8* iBase;					///< the base ram address of the manager
       
    62 	TUint32 iSizeInBytes;			///< virtual ram address size in bytes
       
    63 	TUint32 iCurrentOffsetMark;		///< a flag in bytes to record current used virtual address space 
       
    64 	TInt	iLowMemoryThreshold;	///< a threshold in bytes to flag the low memory condition, data type is aligned with TMemoryInfoV1::iTotalRamInBytes
       
    65 	TBool	isMemoryLow;			///< the flag indicates low memory condition
       
    66 
       
    67 	/**	an array holds all the registered clients */
       
    68 	RPointerArray<CCacheMemoryClient> iRegisteredClients;
       
    69 
       
    70 	friend class CCacheMemoryManagerFactory;
       
    71 	};
       
    72 
       
    73 /**
       
    74 The factory class for CCacheMemoryManager
       
    75 */
       
    76 class CCacheMemoryManagerFactory
       
    77 	{
       
    78 public:
       
    79 	static void CreateL();
       
    80 	static void Destroy();
       
    81 	IMPORT_C static CCacheMemoryManager* CacheMemoryManager();
       
    82 private:
       
    83 	static CCacheMemoryManager* iCacheMemoryManager;
       
    84 	};
       
    85 
       
    86 /**
       
    87 A static class to read cache memory manager settings
       
    88 */
       
    89 NONSHARABLE_CLASS(TGlobalCacheMemorySettings)
       
    90 	{
       
    91 public:
       
    92 	static void ReadPropertiesFile();
       
    93 
       
    94 	static TInt CacheSize();
       
    95 	static TInt LowMemoryThreshold();
       
    96 private:
       
    97 	static TInt32 iCacheSizeInBytes;
       
    98 	static TInt32 iLowMemoryThreshold;
       
    99 	};
       
   100 
       
   101 /** Default cache memory size in KBytes (32768 KBytes)*/
       
   102 const TInt 	KDefaultGlobalCacheMemorySize = (32 << 10);
       
   103 /** 
       
   104 Low memory threshold as a percentage of total RAM (10 %)
       
   105 If the amount of RAM drops below this value, attempts to allocate memory will fail
       
   106 */
       
   107 const TInt 	KDefaultLowMemoryThreshold = 10;
       
   108 
       
   109 #endif	// !defined(__SF_MEMORY_MAN_H__)