epoc32/include/s32page.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 2 2fe1408b6811
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@2
     1
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
williamr@2
     2
// All rights reserved.
williamr@2
     3
// This component and the accompanying materials are made available
williamr@4
     4
// under the terms of "Eclipse Public License v1.0"
williamr@2
     5
// which accompanies this distribution, and is available
williamr@4
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
williamr@2
     7
//
williamr@2
     8
// Initial Contributors:
williamr@2
     9
// Nokia Corporation - initial contribution.
williamr@2
    10
//
williamr@2
    11
// Contributors:
williamr@2
    12
//
williamr@2
    13
// Description:
williamr@2
    14
//
williamr@2
    15
williamr@2
    16
#if !defined(__S32PAGE_H__)
williamr@2
    17
#define __S32PAGE_H__
williamr@2
    18
#if !defined(__S32STRM_H__)
williamr@2
    19
#include <s32strm.h>
williamr@2
    20
#endif
williamr@2
    21
williamr@2
    22
/** Size of the pages in the page pool. */
williamr@2
    23
const TInt KPoolPageSize=512;
williamr@2
    24
//
williamr@2
    25
const TUint32 KNullPageRefValue=0;
williamr@2
    26
williamr@2
    27
/**
williamr@2
    28
 * @publishedAll 
williamr@2
    29
 * @released
williamr@2
    30
 * Encapsulates a page reference.
williamr@2
    31
williamr@2
    32
A page reference is an integer value that can be used to identify a page. 
williamr@2
    33
 */
williamr@2
    34
class TPageRef
williamr@2
    35
	{
williamr@2
    36
public:
williamr@2
    37
	/** Default constructor. */
williamr@2
    38
	inline TPageRef() {}
williamr@2
    39
	inline TPageRef(TUint32 aValue);
williamr@2
    40
//
williamr@2
    41
	inline TBool operator==(TPageRef aRef) const;
williamr@2
    42
	inline TBool operator!=(TPageRef aRef) const;
williamr@2
    43
//
williamr@2
    44
	inline void ExternalizeL(RWriteStream& aStream) const;
williamr@2
    45
	inline void InternalizeL(RReadStream& aStream);
williamr@2
    46
//
williamr@2
    47
	inline TUint32 Value() const;
williamr@2
    48
private:
williamr@2
    49
	TUint32 iVal;
williamr@2
    50
	};
williamr@2
    51
#if defined(__NO_CLASS_CONSTS__)
williamr@2
    52
#define KNullPageRef TPageRef(KNullPageRefValue)
williamr@2
    53
#else
williamr@2
    54
/** Defines a null page reference. */
williamr@2
    55
const TPageRef KNullPageRef=TPageRef(KNullPageRefValue);
williamr@2
    56
#endif
williamr@2
    57
williamr@2
    58
class MPagePool;
williamr@2
    59
/** Typedef to define a function that abandons pages in page pool. It is used by 
williamr@2
    60
MPagePool::AcquireL().
williamr@2
    61
williamr@2
    62
@see MPagePool::AcquireL() */
williamr@2
    63
typedef void (*TPageAbandonFunction)(MPagePool& aPool);
williamr@2
    64
williamr@2
    65
/** Flags that define how allocated pages can be reclaimed.
williamr@2
    66
williamr@2
    67
A BTree can locate some pages even when the tree is broken, but not all. The 
williamr@2
    68
ones it cannot track must be tracked by the page pool in order to reclaim 
williamr@2
    69
the storage if the tree breaks. */
williamr@2
    70
enum TPageReclamation 
williamr@2
    71
	/** The page can be deleted, but its space not reclaimed.
williamr@2
    72
	
williamr@2
    73
	The page pool will not track these pages, so to retrieve the space the page 
williamr@2
    74
	must be deleted explicitly. */
williamr@2
    75
	{EPageDeleteOnly,
williamr@2
    76
	/** Page can be reclaimed.
williamr@2
    77
	
williamr@2
    78
	The page pool will track these pages, and will be able to reclaim the pages 
williamr@2
    79
	when, for example, RStorePagePool::ReclaimL() is called. */
williamr@2
    80
	EPageReclaimable};
williamr@2
    81
williamr@2
    82
/** Flags that define how a page should be treated when it is unlocked. */
williamr@2
    83
enum TPageChange 
williamr@2
    84
	/** Unlock only. */
williamr@2
    85
	{EPageNoChange,
williamr@2
    86
	/** Mark the page as dirty. */
williamr@2
    87
	EPageDirty,
williamr@2
    88
	/** Mark the page as needing a safe update. */
williamr@2
    89
	EPageUpdate,
williamr@2
    90
	/** Discard the page. */
williamr@2
    91
	EPageAbandon=-1};
williamr@2
    92
williamr@2
    93
williamr@2
    94
/**
williamr@2
    95
 * @publishedAll 
williamr@2
    96
 * @released
williamr@2
    97
 * Interface to a page pool, the storage abstraction used by the B-trees API. 
williamr@2
    98
williamr@2
    99
The interface is abstract and handles pages as TAny pointers. It is left to 
williamr@2
   100
derived classes to implement page storage in a particular storage medium, 
williamr@2
   101
such as memory or disk.  
williamr@2
   102
*/
williamr@2
   103
class MPagePool
williamr@2
   104
	{
williamr@2
   105
public:
williamr@2
   106
	IMPORT_C void PushL();
williamr@2
   107
	inline void Pop();
williamr@2
   108
williamr@2
   109
	/** Returns a function that abandons all locked pages for this page pool. 
williamr@2
   110
	
williamr@2
   111
	@return A function that abandons all locked pages for this page pool. */
williamr@2
   112
	virtual TPageAbandonFunction AcquireL()=0;
williamr@2
   113
//
williamr@2
   114
	virtual TAny* AllocL()=0;
williamr@2
   115
williamr@2
   116
	/** Locks a page and returns a pointer to it.
williamr@2
   117
	
williamr@2
   118
	@param aRef Reference to the page to lock
williamr@2
   119
	@return Locked page */
williamr@2
   120
	virtual TAny* LockL(TPageRef aRef)=0;
williamr@2
   121
//
williamr@2
   122
	virtual TPageRef AssignL(const TAny* aPage,TPageReclamation aReclamation=EPageDeleteOnly)=0;
williamr@2
   123
williamr@2
   124
	/** Updates a page. 
williamr@2
   125
	
williamr@2
   126
	This can be used for cached pages that may have become outdated.
williamr@2
   127
	
williamr@2
   128
	@param aPage Page to update */
williamr@2
   129
	virtual void UpdateL(const TAny* aPage)=0;
williamr@2
   130
williamr@2
   131
	/** Unlocks a page.
williamr@2
   132
	
williamr@2
   133
	@param aPage Page to unlock
williamr@2
   134
	@param aChange How the page should be treated once it is unlocked */
williamr@2
   135
	virtual void Unlock(const TAny* aPage,TPageChange aChange=EPageNoChange)=0;
williamr@2
   136
//
williamr@2
   137
	IMPORT_C void Delete(TPageRef aRef);
williamr@2
   138
	IMPORT_C void DeleteL(TPageRef aRef);
williamr@2
   139
protected:
williamr@2
   140
	virtual void DoDeleteL(TPageRef aRef)=0;
williamr@2
   141
	};
williamr@2
   142
williamr@2
   143
/**
williamr@2
   144
 * @publishedAll 
williamr@2
   145
 * @released
williamr@2
   146
 * Uses memory to implement the MPagePool page pool interface.
williamr@2
   147
williamr@2
   148
The class allocates pages from the default heap, storing them in an array. 
williamr@2
   149
This pool is not persistent.
williamr@2
   150
 */
williamr@2
   151
class CMemPagePool : public CBase,public MPagePool
williamr@2
   152
	{
williamr@2
   153
public:
williamr@2
   154
	IMPORT_C static CMemPagePool* NewL();
williamr@2
   155
	IMPORT_C static CMemPagePool* NewLC();
williamr@2
   156
	IMPORT_C CMemPagePool();
williamr@2
   157
	IMPORT_C ~CMemPagePool();
williamr@2
   158
//
williamr@2
   159
	IMPORT_C TPageAbandonFunction AcquireL();
williamr@2
   160
	IMPORT_C TAny* AllocL();
williamr@2
   161
	IMPORT_C TAny* LockL(TPageRef aRef);
williamr@2
   162
	IMPORT_C TPageRef AssignL(const TAny* aPage,TPageReclamation aReclamation=EPageDeleteOnly);
williamr@2
   163
	IMPORT_C void UpdateL(const TAny* aPage);
williamr@2
   164
	IMPORT_C void Unlock(const TAny* aPage,TPageChange aChange=EPageNoChange);
williamr@2
   165
protected:
williamr@2
   166
	IMPORT_C void DoDeleteL(TPageRef aRef);
williamr@2
   167
private:
williamr@2
   168
	TAny*& PageL(TPageRef aRef);
williamr@2
   169
	static void DoAbandon(MPagePool& aPool);
williamr@2
   170
private:
williamr@2
   171
	CArrayFixSeg<TAny*> iPages;
williamr@2
   172
	};
williamr@2
   173
//
williamr@2
   174
#if defined(_DEBUG)&&!defined(__PAGE_CACHE_STATS)
williamr@2
   175
//#define __PAGE_CACHE_STATS
williamr@2
   176
#endif
williamr@2
   177
//
williamr@2
   178
class TCachePage;
williamr@2
   179
struct SCachePage;
williamr@2
   180
class TCachePagePool;
williamr@2
   181
williamr@2
   182
/**
williamr@2
   183
 * @publishedAll 
williamr@2
   184
 * @released
williamr@2
   185
 * Provides a cache for page pools. 
williamr@2
   186
williamr@2
   187
Persistent page pools rely on a cache to provide in-memory space for their 
williamr@2
   188
pages and to cache frequently accessed pages.  
williamr@2
   189
*/
williamr@2
   190
class CPageCache : public CBase
williamr@2
   191
	{
williamr@2
   192
public:
williamr@2
   193
	enum {EDefaultPages=20};
williamr@2
   194
#if defined(__PAGE_CACHE_STATS)
williamr@2
   195
	
williamr@2
   196
	/**
williamr@2
   197
	 * @publishedAll 
williamr@2
   198
	 * @released
williamr@2
   199
	 */
williamr@2
   200
	class TStats
williamr@2
   201
		{
williamr@2
   202
	public:
williamr@2
   203
		inline TInt Requests() const;
williamr@2
   204
		inline TInt Hits() const;
williamr@2
   205
		inline TInt Misses() const;
williamr@2
   206
		inline void Reset();
williamr@2
   207
	private:
williamr@2
   208
		inline void Hit();
williamr@2
   209
		inline void Miss();
williamr@2
   210
	private:
williamr@2
   211
		TInt iRequests;
williamr@2
   212
		TInt iMisses;
williamr@2
   213
	private:
williamr@2
   214
		friend class CPageCache;
williamr@2
   215
		};
williamr@2
   216
#endif
williamr@2
   217
public:
williamr@2
   218
	IMPORT_C static CPageCache* NewL(TInt aPages=EDefaultPages);
williamr@2
   219
	IMPORT_C static CPageCache* NewLC(TInt aPages=EDefaultPages);
williamr@2
   220
	IMPORT_C CPageCache();
williamr@2
   221
	IMPORT_C void ConstructL(TInt aPages=EDefaultPages);
williamr@2
   222
	IMPORT_C ~CPageCache();
williamr@2
   223
//
williamr@2
   224
#if defined(__PAGE_CACHE_STATS)
williamr@2
   225
	inline TStats& Stats();
williamr@2
   226
	inline const TStats& Stats() const;
williamr@2
   227
#endif
williamr@2
   228
private:
williamr@2
   229
	TCachePage* Find(TCachePagePool* aPool,TPageRef aRef);
williamr@2
   230
private:
williamr@2
   231
	SCachePage* iPages;
williamr@2
   232
	SCachePage* iEnd;
williamr@2
   233
	TDblQue<TCachePage> iFree;
williamr@2
   234
#if defined(__PAGE_CACHE_STATS)
williamr@2
   235
	TStats iStats;
williamr@2
   236
#endif
williamr@2
   237
private:
williamr@2
   238
	friend class TCachePagePool;
williamr@2
   239
	};
williamr@2
   240
williamr@2
   241
/**
williamr@2
   242
 * @publishedAll 
williamr@2
   243
 * @released
williamr@2
   244
 * Provides a page pool with cached pages.
williamr@2
   245
williamr@2
   246
It is an intermediary class, used in the definition of page pools that use 
williamr@2
   247
a cache, such as RFilePagePool and RStorePagePool.
williamr@2
   248
williamr@2
   249
@see RFilePagePool
williamr@2
   250
@see RStorePagePool  
williamr@2
   251
*/
williamr@2
   252
class TCachePagePool : public MPagePool
williamr@2
   253
	{
williamr@2
   254
public:
williamr@2
   255
	inline void Set(CPageCache& aCache);
williamr@2
   256
//
williamr@2
   257
	IMPORT_C TPageAbandonFunction AcquireL();
williamr@2
   258
	IMPORT_C TAny* AllocL();
williamr@2
   259
	IMPORT_C TAny* LockL(TPageRef aRef);
williamr@2
   260
	IMPORT_C TPageRef AssignL(const TAny* aPage,TPageReclamation aReclamation=EPageDeleteOnly);
williamr@2
   261
	IMPORT_C void UpdateL(const TAny* aPage);
williamr@2
   262
	IMPORT_C void Unlock(const TAny* aPage,TPageChange aChange=EPageNoChange);
williamr@2
   263
//
williamr@2
   264
	IMPORT_C TInt Flush();
williamr@2
   265
	IMPORT_C void FlushL();
williamr@2
   266
	IMPORT_C void Purge();
williamr@2
   267
protected:
williamr@2
   268
	inline TCachePagePool();
williamr@2
   269
	inline TCachePagePool(CPageCache& aCache);
williamr@2
   270
	IMPORT_C void DoDeleteL(TPageRef aRef);
williamr@2
   271
private:
williamr@2
   272
	virtual TPageRef ExtendL(const TAny* aPage,TPageReclamation aReclamation)=0;
williamr@2
   273
	virtual void WriteL(TPageRef aRef,const TAny* aPage,TPageChange aChange)=0;
williamr@2
   274
	virtual void ReadL(TPageRef aRef,TAny* aPage)=0;
williamr@2
   275
//
williamr@2
   276
	static void DoAbandon(MPagePool& aPool);
williamr@2
   277
	static TCachePage* DoAllocL(CPageCache& aCache);
williamr@2
   278
private:
williamr@2
   279
	CPageCache* iCache;
williamr@2
   280
	};
williamr@2
   281
williamr@2
   282
#include <s32page.inl>
williamr@2
   283
#endif