os/kernelhwsrv/userlibandfileserver/fileserver/sfile/sf_memory_man.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/userlibandfileserver/fileserver/sfile/sf_memory_man.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,109 @@
     1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// f32\sfile\sf_memory_man.h
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +/**
    1.22 + @file
    1.23 + @internalTechnology
    1.24 +*/
    1.25 +
    1.26 +#if !defined(__SF_MEMORY_MAN_H__)
    1.27 +#define __SF_MEMORY_MAN_H__
    1.28 +
    1.29 +#include <e32def.h>
    1.30 +
    1.31 +const TUint KSegmentSizeLog2 = 12;
    1.32 +/**	Kernel's memory page size in bytes */
    1.33 +const TUint KSegmentSize = 1 << KSegmentSizeLog2;
    1.34 +
    1.35 +/**	Forward declaration */
    1.36 +class CCacheMemoryClient;
    1.37 +
    1.38 +/**	Cache memory manager class */
    1.39 +class CCacheMemoryManager : public CBase
    1.40 +	{
    1.41 +public:
    1.42 +	static CCacheMemoryManager* NewL(TInt aSizeInBytes);
    1.43 +	IMPORT_C CCacheMemoryClient* ConnectClientL(const TDesC& aClientName, TUint32 aMinSizeInSegs, TUint32 aMaxSizeInSegs);
    1.44 +	IMPORT_C TUint SegmentSizeInBytesLog2() const;
    1.45 +	TInt	RegisterClient(CCacheMemoryClient* aClient);
    1.46 +	TInt 	AllocateAndLockSegments(TUint8* aStartRamAddr, TInt aSegmentCount);
    1.47 +	TInt 	LockSegments(TUint8* aStartRamAddr, TUint32 aSegmentCount);
    1.48 +	TInt 	UnlockSegments(TUint8* aStartRamAddr, TUint32 aSegmentCount);
    1.49 +	TInt 	DecommitSegments(TUint8* aStartRamAddr, TUint32 aSegmentCount);
    1.50 +	TUint8* Base();
    1.51 +	void 	FreeMemoryChanged(TBool aIsMemoryLow);
    1.52 +
    1.53 +private:
    1.54 +	~CCacheMemoryManager();
    1.55 +	CCacheMemoryManager(TUint32 aMaxSize);
    1.56 +	void 	ConstructL();
    1.57 +	TInt 	Lock(TUint8* aStartRamAddr, TInt aSegmentCount);
    1.58 +	TInt 	Unlock(TUint8* aStartRamAddr, TInt aSegmentCount);
    1.59 +	TInt	Commit(TUint8* aStartRamAddr, TInt aSegmentCountt);
    1.60 +	TInt 	Decommit(TUint8* aStartRamAddr, TInt aSegmentCount);
    1.61 +
    1.62 +private:
    1.63 +	RChunk 	iChunk;					///< the RChunk interface to interact with demand paging sub-system
    1.64 +	TUint8* iBase;					///< the base ram address of the manager
    1.65 +	TUint32 iSizeInBytes;			///< virtual ram address size in bytes
    1.66 +	TUint32 iCurrentOffsetMark;		///< a flag in bytes to record current used virtual address space 
    1.67 +	TInt	iLowMemoryThreshold;	///< a threshold in bytes to flag the low memory condition, data type is aligned with TMemoryInfoV1::iTotalRamInBytes
    1.68 +	TBool	isMemoryLow;			///< the flag indicates low memory condition
    1.69 +
    1.70 +	/**	an array holds all the registered clients */
    1.71 +	RPointerArray<CCacheMemoryClient> iRegisteredClients;
    1.72 +
    1.73 +	friend class CCacheMemoryManagerFactory;
    1.74 +	};
    1.75 +
    1.76 +/**
    1.77 +The factory class for CCacheMemoryManager
    1.78 +*/
    1.79 +class CCacheMemoryManagerFactory
    1.80 +	{
    1.81 +public:
    1.82 +	static void CreateL();
    1.83 +	static void Destroy();
    1.84 +	IMPORT_C static CCacheMemoryManager* CacheMemoryManager();
    1.85 +private:
    1.86 +	static CCacheMemoryManager* iCacheMemoryManager;
    1.87 +	};
    1.88 +
    1.89 +/**
    1.90 +A static class to read cache memory manager settings
    1.91 +*/
    1.92 +NONSHARABLE_CLASS(TGlobalCacheMemorySettings)
    1.93 +	{
    1.94 +public:
    1.95 +	static void ReadPropertiesFile();
    1.96 +
    1.97 +	static TInt CacheSize();
    1.98 +	static TInt LowMemoryThreshold();
    1.99 +private:
   1.100 +	static TInt32 iCacheSizeInBytes;
   1.101 +	static TInt32 iLowMemoryThreshold;
   1.102 +	};
   1.103 +
   1.104 +/** Default cache memory size in KBytes (8192 KBytes)*/
   1.105 +const TInt 	KDefaultGlobalCacheMemorySize = (8 << 10);
   1.106 +/** 
   1.107 +Low memory threshold as a percentage of total RAM (10 %)
   1.108 +If the amount of RAM drops below this value, attempts to allocate memory will fail
   1.109 +*/
   1.110 +const TInt 	KDefaultLowMemoryThreshold = 10;
   1.111 +
   1.112 +#endif	// !defined(__SF_MEMORY_MAN_H__)