epoc32/include/e32base.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) 1994-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 the License "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
// e32\include\e32base.h
williamr@2
    15
// 
williamr@2
    16
//
williamr@2
    17
williamr@2
    18
#ifndef __E32BASE_H__
williamr@2
    19
#define __E32BASE_H__
williamr@2
    20
#include <e32std.h>
williamr@2
    21
williamr@2
    22
/**
williamr@2
    23
 * Container Base Class
williamr@2
    24
 */
williamr@2
    25
class CBase
williamr@2
    26
/**
williamr@2
    27
@publishedAll
williamr@2
    28
@released
williamr@2
    29
williamr@2
    30
Base class for all classes to be instantiated on the heap.
williamr@2
    31
williamr@2
    32
By convention, all classes derived from CBase have a name beginning with the 
williamr@2
    33
letter 'C'.
williamr@2
    34
williamr@2
    35
The class has two important features:
williamr@2
    36
williamr@2
    37
1. A virtual destructor that allows instances of derived classes to be destroyed 
williamr@2
    38
   and properly cleaned up through a CBase* pointer. All CBase derived objects 
williamr@2
    39
   can be pushed, as CBase* pointers, onto the cleanup stack, and destroyed through 
williamr@2
    40
   a call to CleanupStack::PopAndDestroy().
williamr@2
    41
williamr@2
    42
2. Initialisation of the CBase derived object to binary zeroes through a specific 
williamr@2
    43
   CBase::operator new() - this means that members, whose initial value should 
williamr@2
    44
   be zero, do not have to be initialised in the constructor. This allows safe 
williamr@2
    45
   destruction of a partially-constructed object.
williamr@2
    46
williamr@2
    47
Note that using C++ arrays of CBase-derived types is not recommended, as objects 
williamr@2
    48
in the array will not be zero-initialised (as there is no operator new[] member). 
williamr@2
    49
You should use an array class such as RPointerArray instead for arrays of 
williamr@2
    50
CBase-derived types.
williamr@2
    51
williamr@2
    52
@see CleanupStack
williamr@2
    53
*/
williamr@2
    54
	{
williamr@2
    55
public:
williamr@2
    56
	/**
williamr@2
    57
	Default constructor
williamr@2
    58
	*/
williamr@2
    59
	inline CBase()	{}
williamr@2
    60
	IMPORT_C virtual ~CBase();
williamr@2
    61
	inline TAny* operator new(TUint aSize, TAny* aBase) __NO_THROW;
williamr@2
    62
	inline TAny* operator new(TUint aSize) __NO_THROW;
williamr@2
    63
	inline TAny* operator new(TUint aSize, TLeave);
williamr@2
    64
	inline TAny* operator new(TUint aSize, TUint aExtraSize) __NO_THROW;
williamr@2
    65
	inline TAny* operator new(TUint aSize, TLeave, TUint aExtraSize);
williamr@2
    66
	IMPORT_C static void Delete(CBase* aPtr);
williamr@2
    67
protected:
williamr@2
    68
	IMPORT_C virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1);
williamr@2
    69
private:
williamr@2
    70
	CBase(const CBase&);
williamr@2
    71
	CBase& operator=(const CBase&);
williamr@2
    72
private:
williamr@2
    73
	};
williamr@2
    74
	
williamr@2
    75
	
williamr@2
    76
	
williamr@2
    77
	
williamr@2
    78
class CBufBase : public CBase
williamr@2
    79
/**
williamr@2
    80
@publishedAll
williamr@2
    81
@released
williamr@2
    82
williamr@2
    83
Defines the interface for dynamic buffers. 
williamr@2
    84
williamr@2
    85
The basic functions, InsertL(), Read(), Write(), Delete(), Reset() and Size(), 
williamr@2
    86
transfer data between the buffer and other places, and allow that data to 
williamr@2
    87
be deleted
williamr@2
    88
williamr@2
    89
The ExpandL() and Resize() functions allow some operations to be carried out 
williamr@2
    90
with greater efficiency
williamr@2
    91
williamr@2
    92
A Compress() function frees (back to the heap) any space which may have been 
williamr@2
    93
allocated, but not used
williamr@2
    94
williamr@2
    95
Ptr() and BackPtr() allow look-up of contiguous data from any given position, 
williamr@2
    96
forward or backward
williamr@2
    97
*/
williamr@2
    98
	{
williamr@2
    99
public:
williamr@2
   100
	IMPORT_C ~CBufBase();
williamr@2
   101
	inline TInt Size() const;
williamr@2
   102
	IMPORT_C void Reset();
williamr@2
   103
	IMPORT_C void Read(TInt aPos,TDes8& aDes) const;
williamr@2
   104
	IMPORT_C void Read(TInt aPos,TDes8& aDes,TInt aLength) const;
williamr@2
   105
	IMPORT_C void Read(TInt aPos,TAny* aPtr,TInt aLength) const;
williamr@2
   106
	IMPORT_C void Write(TInt aPos,const TDesC8& aDes);
williamr@2
   107
	IMPORT_C void Write(TInt aPos,const TDesC8& aDes,TInt aLength);
williamr@2
   108
	IMPORT_C void Write(TInt aPos,const TAny* aPtr,TInt aLength);
williamr@2
   109
	IMPORT_C void InsertL(TInt aPos,const TDesC8& aDes);
williamr@2
   110
	IMPORT_C void InsertL(TInt aPos,const TDesC8& aDes,TInt aLength);
williamr@2
   111
	IMPORT_C void InsertL(TInt aPos,const TAny* aPtr,TInt aLength);
williamr@2
   112
	IMPORT_C void ExpandL(TInt aPos,TInt aLength);
williamr@2
   113
	IMPORT_C void ResizeL(TInt aSize);
williamr@2
   114
// Pure virtual
williamr@2
   115
	/**
williamr@2
   116
	Compresses the buffer so as to occupy minimal space.
williamr@2
   117
	
williamr@2
   118
	Normally, you would call this when a buffer has reached its final size,
williamr@2
   119
	or when you know it will not expand again for a while, or when an
williamr@2
   120
	out-of-memory error has occurred and your program is taking measures to
williamr@2
   121
	save space. Compression in these circumstances releases memory for other
williamr@2
   122
	programs to use, but has no adverse effect on performance.
williamr@2
   123
	
williamr@2
   124
	Derived classes provide the implementation.
williamr@2
   125
	
williamr@2
   126
	@see CBufFlat::Compress
williamr@2
   127
	@see CBufSeg::Compress
williamr@2
   128
	*/
williamr@2
   129
    virtual void Compress()=0;
williamr@2
   130
	/**
williamr@2
   131
	Deletes data from the buffer.
williamr@2
   132
	
williamr@2
   133
	Derived classes provide the implementation.
williamr@2
   134
	
williamr@2
   135
	@param aPos    Buffer position where the deletion will begin; must be in the 
williamr@2
   136
                   range zero to (Size() minus the length of the data
williamr@2
   137
                   to be deleted). 
williamr@2
   138
	@param aLength The number of bytes to be deleted; must be non-negative.
williamr@2
   139
		
williamr@2
   140
	@see CBufFlat::Delete
williamr@2
   141
	@see CBufSeg::Delete
williamr@2
   142
	*/
williamr@2
   143
	virtual void Delete(TInt aPos,TInt aLength)=0;
williamr@2
   144
	/**
williamr@2
   145
	Gets a pointer descriptor to represent the data from the specified position to  
williamr@2
   146
	the end of the contiguous region containing that byte.
williamr@2
   147
	
williamr@2
   148
	Derived classes provide the implementation.
williamr@2
   149
		
williamr@2
   150
	@param aPos Buffer position: must be in range zero to Size().
williamr@2
   151
	 
williamr@2
   152
	@return Descriptor representing the data starting at aPos, and whose length
williamr@2
   153
	        indicates the number of contiguous bytes stored in the buffer, 
williamr@2
   154
            forward from that point. The length will be non-zero unless aPos==Size().
williamr@2
   155
              	
williamr@2
   156
	@see CBufFlat::Ptr
williamr@2
   157
	@see CBufSeg::Ptr
williamr@2
   158
	*/
williamr@2
   159
	virtual TPtr8 Ptr(TInt aPos)=0;
williamr@2
   160
	/**
williamr@2
   161
	Gets a pointer descriptor to represent data from just before the specified 
williamr@2
   162
	data byte backward to the beginning of the contiguous region containing 
williamr@2
   163
	that byte.
williamr@2
   164
	
williamr@2
   165
	Derived classes provide the implementation.
williamr@2
   166
	
williamr@2
   167
	@param aPos Buffer position: must be in range zero to Size().
williamr@2
   168
	 
williamr@2
   169
	@return Descriptor representing the back contiguous region. 
williamr@2
   170
	        The address in the descriptor is the pointer to the bytes at the
williamr@2
   171
	        buffer position, unless the buffer position was at the beginning of
williamr@2
   172
	        a non-first segment in the buffer: in this case, the address is a
williamr@2
   173
	        pointer just beyond the last data byte in the previous segment.
williamr@2
   174
	        The length is the number of contiguous bytes from the address
williamr@2
   175
	        backwards to the beginning of the segment.
williamr@2
   176
		
williamr@2
   177
	@see CBufFlat::BackPtr
williamr@2
   178
	@see CBufSeg::BackPtr
williamr@2
   179
	*/
williamr@2
   180
	virtual TPtr8 BackPtr(TInt aPos)=0;
williamr@2
   181
private:
williamr@2
   182
	virtual void DoInsertL(TInt aPos,const TAny* aPtr,TInt aLength)=0;
williamr@2
   183
protected:
williamr@2
   184
	IMPORT_C CBufBase(TInt anExpandSize);
williamr@2
   185
protected:
williamr@2
   186
	TInt iSize;
williamr@2
   187
	TInt iExpandSize;
williamr@2
   188
	};
williamr@2
   189
williamr@2
   190
williamr@2
   191
williamr@2
   192
williamr@2
   193
class CBufFlat : public CBufBase
williamr@2
   194
/**
williamr@2
   195
@publishedAll
williamr@2
   196
@released
williamr@2
   197
williamr@2
   198
Provides a flat storage dynamic buffer.
williamr@2
   199
williamr@2
   200
This class should be used when high-speed pointer lookup is an important
williamr@2
   201
consideration, and you are reasonably confident that the insertion of
williamr@2
   202
data will not fail. 
williamr@2
   203
williamr@2
   204
This class is an implementation of the abstract buffer interface provided 
williamr@2
   205
by CBufBase and uses a single heap cell to contain the data.
williamr@2
   206
*/
williamr@2
   207
	{
williamr@2
   208
public:
williamr@2
   209
	IMPORT_C ~CBufFlat();
williamr@2
   210
	IMPORT_C static CBufFlat* NewL(TInt anExpandSize);
williamr@2
   211
	inline TInt Capacity() const;
williamr@2
   212
	IMPORT_C void SetReserveL(TInt aSize);
williamr@2
   213
	IMPORT_C void Compress();
williamr@2
   214
	IMPORT_C void Delete(TInt aPos,TInt aLength);
williamr@2
   215
	IMPORT_C TPtr8 Ptr(TInt aPos);
williamr@2
   216
	IMPORT_C TPtr8 BackPtr(TInt aPos);
williamr@2
   217
protected:
williamr@2
   218
	IMPORT_C CBufFlat(TInt anExpandSize);
williamr@2
   219
private:
williamr@2
   220
	IMPORT_C void DoInsertL(TInt aPos,const TAny* aPtr,TInt aLength);
williamr@2
   221
private:
williamr@2
   222
	TInt iMaxSize;
williamr@2
   223
	TUint8* iPtr;
williamr@2
   224
	};
williamr@2
   225
williamr@2
   226
williamr@2
   227
williamr@2
   228
williamr@2
   229
class TBufSegLink;
williamr@2
   230
class CBufSeg : public CBufBase
williamr@2
   231
/**
williamr@2
   232
@publishedAll
williamr@2
   233
@released
williamr@2
   234
williamr@2
   235
Provides a segmented dynamic buffer.
williamr@2
   236
williamr@2
   237
This class should be used when the object has a long life-time and an
williamr@2
   238
unpredictable number of insertions, or there is concern about the performance
williamr@2
   239
of insertion and deletion operations into large buffers.
williamr@2
   240
williamr@2
   241
This class is an implementation of the abstract buffer interface provided 
williamr@2
   242
by CBufBase and uses doubly-linked list of heap cells to contain the data; 
williamr@2
   243
each cell containing a segment of the buffer.
williamr@2
   244
williamr@2
   245
Its (private) data members include an anchor for the doubly-linked list, and also a 
williamr@2
   246
reference to the buffer position used by the last operation. This reference 
williamr@2
   247
acts as a cache; if the next operation uses a similar buffer position, then 
williamr@2
   248
calculation of the pointer corresponding to its buffer position is much faster.
williamr@2
   249
*/
williamr@2
   250
	{
williamr@2
   251
public:
williamr@2
   252
	IMPORT_C ~CBufSeg();
williamr@2
   253
	IMPORT_C static CBufSeg* NewL(TInt anExpandSize);
williamr@2
   254
    IMPORT_C void Compress();
williamr@2
   255
	IMPORT_C void Delete(TInt aPos,TInt aLength);
williamr@2
   256
	IMPORT_C TPtr8 Ptr(TInt aPos);
williamr@2
   257
	IMPORT_C TPtr8 BackPtr(TInt aPos);
williamr@2
   258
protected:
williamr@2
   259
	IMPORT_C CBufSeg(TInt anExpandSize);
williamr@2
   260
	void InsertIntoSegment(TBufSegLink* aSeg,TInt anOffset,const TAny* aPtr,TInt aLength);
williamr@2
   261
	void DeleteFromSegment(TBufSegLink* aSeg,TInt anOffset,TInt aLength);
williamr@2
   262
	void FreeSegment(TBufSegLink* aSeg);
williamr@2
   263
    void SetSBO(TInt aPos);
williamr@2
   264
	void AllocSegL(TBufSegLink* aSeg,TInt aNumber);
williamr@2
   265
private:
williamr@2
   266
	IMPORT_C void DoInsertL(TInt aPos,const TAny* aPtr,TInt aLength);
williamr@2
   267
private:
williamr@2
   268
    TDblQue<TBufSegLink> iQue;
williamr@2
   269
	TBufSegLink* iSeg;
williamr@2
   270
	TInt iBase;
williamr@2
   271
	TInt iOffset;
williamr@2
   272
	};
williamr@2
   273
williamr@2
   274
williamr@2
   275
williamr@2
   276
williamr@2
   277
class TKeyArrayFix : public TKey
williamr@2
   278
/**
williamr@2
   279
@publishedAll
williamr@2
   280
@released
williamr@2
   281
williamr@2
   282
Defines the characteristics of a key used to access the elements of arrays 
williamr@2
   283
of fixed length objects.
williamr@2
   284
williamr@2
   285
An object of this type can represent three categories of key, depending on 
williamr@2
   286
the constructor used:
williamr@2
   287
williamr@2
   288
1. a descriptor key 
williamr@2
   289
williamr@2
   290
2. a text key
williamr@2
   291
williamr@2
   292
3. a numeric key.
williamr@2
   293
williamr@2
   294
The Sort(), InsertIsqL(), Find() and FindIsqL() member functions of the CArrayFixFlat 
williamr@2
   295
and CArrayFixSeg class hierarchies need a TKeyArrayFix object as an argument 
williamr@2
   296
to define the location and type of key within an array element.
williamr@2
   297
williamr@2
   298
@see CArrayFixFlat
williamr@2
   299
@see CArrayFixSeg
williamr@2
   300
*/
williamr@2
   301
	{
williamr@2
   302
public:
williamr@2
   303
	IMPORT_C TKeyArrayFix(TInt anOffset,TKeyCmpText aType);
williamr@2
   304
	IMPORT_C TKeyArrayFix(TInt anOffset,TKeyCmpText aType,TInt aLength);
williamr@2
   305
	IMPORT_C TKeyArrayFix(TInt anOffset,TKeyCmpNumeric aType);
williamr@2
   306
protected:
williamr@2
   307
	IMPORT_C virtual void Set(CBufBase* aBase,TInt aRecordLength);
williamr@2
   308
	IMPORT_C TAny* At(TInt anIndex) const;
williamr@2
   309
protected:
williamr@2
   310
	TInt iRecordLength;
williamr@2
   311
	CBufBase* iBase;
williamr@2
   312
	friend class CArrayFixBase;
williamr@2
   313
	};
williamr@2
   314
williamr@2
   315
williamr@2
   316
williamr@2
   317
williamr@2
   318
typedef CBufBase*(*TBufRep)(TInt anExpandSize);
williamr@2
   319
class CArrayFixBase : public CBase
williamr@2
   320
/**
williamr@2
   321
@publishedAll
williamr@2
   322
@released
williamr@2
   323
williamr@2
   324
Base class for arrays of fixed length objects.
williamr@2
   325
williamr@2
   326
It provides implementation and public functions which are common to all arrays
williamr@2
   327
of this type.
williamr@2
   328
williamr@2
   329
The class is always derived from and is never instantiated explicitly.
williamr@2
   330
*/
williamr@2
   331
	{
williamr@2
   332
public:
williamr@2
   333
	IMPORT_C ~CArrayFixBase();
williamr@2
   334
	inline TInt Count() const;
williamr@2
   335
	inline TInt Length() const;
williamr@2
   336
	IMPORT_C void Compress();
williamr@2
   337
	IMPORT_C void Reset();
williamr@2
   338
	IMPORT_C TInt Sort(TKeyArrayFix& aKey);
williamr@2
   339
	IMPORT_C TAny* At(TInt anIndex) const;
williamr@2
   340
	IMPORT_C TAny* End(TInt anIndex) const;
williamr@2
   341
	IMPORT_C TAny* Back(TInt anIndex) const;
williamr@2
   342
	IMPORT_C void Delete(TInt anIndex);
williamr@2
   343
	IMPORT_C void Delete(TInt anIndex,TInt aCount);
williamr@2
   344
	IMPORT_C TAny* ExpandL(TInt anIndex);
williamr@2
   345
	IMPORT_C TInt Find(const TAny* aPtr,TKeyArrayFix& aKey,TInt& anIndex) const;
williamr@2
   346
	IMPORT_C TInt FindIsq(const TAny* aPtr,TKeyArrayFix& aKey,TInt& anIndex) const;
williamr@2
   347
	IMPORT_C void InsertL(TInt anIndex,const TAny* aPtr);
williamr@2
   348
	IMPORT_C void InsertL(TInt anIndex,const TAny* aPtr,TInt aCount);
williamr@2
   349
	IMPORT_C TInt InsertIsqL(const TAny* aPtr,TKeyArrayFix& aKey);
williamr@2
   350
	IMPORT_C TInt InsertIsqAllowDuplicatesL(const TAny* aPtr,TKeyArrayFix& aKey);
williamr@2
   351
	IMPORT_C void ResizeL(TInt aCount,const TAny* aPtr);
williamr@2
   352
protected:
williamr@2
   353
	IMPORT_C CArrayFixBase(TBufRep aRep,TInt aRecordLength,TInt aGranularity);
williamr@2
   354
	IMPORT_C void InsertRepL(TInt anIndex,const TAny* aPtr,TInt aReplicas);
williamr@2
   355
	IMPORT_C void SetKey(TKeyArrayFix& aKey) const;
williamr@2
   356
	IMPORT_C void SetReserveFlatL(TInt aCount);
williamr@2
   357
	IMPORT_C static TInt CountR(const CBase* aPtr);
williamr@2
   358
	IMPORT_C static const TAny* AtR(const CBase* aPtr,TInt anIndex);
williamr@2
   359
private:
williamr@2
   360
	TInt iCount;
williamr@2
   361
	TInt iGranularity;
williamr@2
   362
	TInt iLength;
williamr@2
   363
	TBufRep iCreateRep;
williamr@2
   364
	CBufBase* iBase;
williamr@2
   365
	};
williamr@2
   366
williamr@2
   367
williamr@2
   368
williamr@2
   369
williamr@2
   370
template <class T>
williamr@2
   371
class CArrayFix : public CArrayFixBase
williamr@2
   372
/**
williamr@2
   373
@publishedAll
williamr@2
   374
@released
williamr@2
   375
williamr@2
   376
A thin templated base class for arrays of fixed length objects. 
williamr@2
   377
williamr@2
   378
The public functions provide standard array behaviour.
williamr@2
   379
williamr@2
   380
The class is always derived from and is never instantiated explicitly.
williamr@2
   381
*/
williamr@2
   382
	{
williamr@2
   383
public:
williamr@2
   384
	inline CArrayFix(TBufRep aRep,TInt aGranularity);
williamr@2
   385
	inline const T& operator[](TInt anIndex) const;
williamr@2
   386
	inline T& operator[](TInt anIndex);
williamr@2
   387
	inline const T& At(TInt anIndex) const;
williamr@2
   388
	inline const T* End(TInt anIndex) const;
williamr@2
   389
	inline const T* Back(TInt anIndex) const;
williamr@2
   390
	inline T& At(TInt anIndex);
williamr@2
   391
	inline T* End(TInt anIndex);
williamr@2
   392
	inline T* Back(TInt anIndex);
williamr@2
   393
	inline void AppendL(const T& aRef);
williamr@2
   394
	inline void AppendL(const T* aPtr,TInt aCount);
williamr@2
   395
	inline void AppendL(const T& aRef,TInt aReplicas);
williamr@2
   396
	inline T& ExpandL(TInt anIndex);
williamr@2
   397
	inline T& ExtendL();
williamr@2
   398
	inline TInt Find(const T& aRef,TKeyArrayFix& aKey,TInt& anIndex) const;
williamr@2
   399
	inline TInt FindIsq(const T& aRef,TKeyArrayFix& aKey,TInt& anIndex) const;
williamr@2
   400
	inline void InsertL(TInt anIndex,const T& aRef);
williamr@2
   401
	inline void InsertL(TInt anIndex,const T* aPtr,TInt aCount);
williamr@2
   402
	inline void InsertL(TInt anIndex,const T& aRef,TInt aReplicas);
williamr@2
   403
	inline TInt InsertIsqL(const T& aRef,TKeyArrayFix& aKey);
williamr@2
   404
	inline TInt InsertIsqAllowDuplicatesL(const T& aRef,TKeyArrayFix& aKey);
williamr@2
   405
	inline void ResizeL(TInt aCount);
williamr@2
   406
	inline void ResizeL(TInt aCount,const T& aRef);
williamr@2
   407
	inline const TArray<T> Array() const;
williamr@2
   408
	};
williamr@2
   409
williamr@2
   410
williamr@2
   411
williamr@2
   412
williamr@2
   413
TEMPLATE_SPECIALIZATION class CArrayFix<TAny> : public CArrayFixBase
williamr@2
   414
/**
williamr@2
   415
@publishedAll
williamr@2
   416
@released
williamr@2
   417
williamr@2
   418
A template specialisation base class for arrays of fixed length
williamr@2
   419
untyped objects.
williamr@2
   420
williamr@2
   421
The public functions provide standard array behaviour.
williamr@2
   422
williamr@2
   423
The class is always derived from and is never instantiated explicitly.
williamr@2
   424
*/
williamr@2
   425
	{
williamr@2
   426
public:
williamr@2
   427
	inline CArrayFix(TBufRep aRep,TInt aRecordLength,TInt aGranularity);
williamr@2
   428
	inline const TAny* At(TInt anIndex) const;
williamr@2
   429
	inline const TAny* End(TInt anIndex) const;
williamr@2
   430
	inline const TAny* Back(TInt anIndex) const;
williamr@2
   431
	inline TAny* At(TInt anIndex);
williamr@2
   432
	inline TAny* End(TInt anIndex);
williamr@2
   433
	inline TAny* Back(TInt anIndex);
williamr@2
   434
	inline void AppendL(const TAny* aPtr);
williamr@2
   435
	inline void AppendL(const TAny* aPtr,TInt aCount);
williamr@2
   436
	inline TAny* ExtendL();
williamr@2
   437
	};
williamr@2
   438
williamr@2
   439
williamr@2
   440
williamr@2
   441
williamr@2
   442
williamr@2
   443
template <class T>
williamr@2
   444
class CArrayFixFlat : public CArrayFix<T>
williamr@2
   445
/**
williamr@2
   446
@publishedAll
williamr@2
   447
@released
williamr@2
   448
williamr@2
   449
Array of fixed length objects contained within a flat dynamic buffer.
williamr@2
   450
williamr@2
   451
The elements of the array are instances of the template class T.
williamr@2
   452
williamr@2
   453
The flat dynamic buffer is an instance of a CBufFlat.
williamr@2
   454
williamr@2
   455
The elements can be T or R type objects and must have an accessible default 
williamr@2
   456
constructor.
williamr@2
   457
williamr@2
   458
Note that, where possible, use the RArray<class T> class as this is more
williamr@2
   459
efficient.
williamr@2
   460
williamr@2
   461
@see CBufFlat
williamr@2
   462
@see RArray
williamr@2
   463
*/
williamr@2
   464
	{
williamr@2
   465
public:
williamr@2
   466
	inline explicit CArrayFixFlat(TInt aGranularity);
williamr@2
   467
	inline void SetReserveL(TInt aCount);
williamr@2
   468
	};
williamr@2
   469
williamr@2
   470
williamr@2
   471
williamr@2
   472
williamr@2
   473
TEMPLATE_SPECIALIZATION class CArrayFixFlat<TAny> : public CArrayFix<TAny>
williamr@2
   474
/**
williamr@2
   475
@publishedAll
williamr@2
   476
@released
williamr@2
   477
williamr@2
   478
An array of fixed length untyped objects using a flat dynamic buffer.
williamr@2
   479
williamr@2
   480
The array elements are contained within a CBufFlat.
williamr@2
   481
williamr@2
   482
The class is useful for constructing an array of fixed length buffers, where 
williamr@2
   483
the length is decided at run time.
williamr@2
   484
williamr@2
   485
This class is also useful as a data member of a base class in a thin template 
williamr@2
   486
class/base class pair where the type of the array element is not known until 
williamr@2
   487
the owning thin template class is instantiated.
williamr@2
   488
williamr@2
   489
@see CBufFlat
williamr@2
   490
*/
williamr@2
   491
	{
williamr@2
   492
public:
williamr@2
   493
	inline CArrayFixFlat(TInt aRecordLength,TInt aGranularity);
williamr@2
   494
	inline void SetReserveL(TInt aCount);
williamr@2
   495
	};
williamr@2
   496
williamr@2
   497
williamr@2
   498
williamr@2
   499
williamr@2
   500
TEMPLATE_SPECIALIZATION class CArrayFixFlat<TInt> : public CArrayFix<TInt>
williamr@2
   501
/**
williamr@2
   502
@publishedAll
williamr@2
   503
@released
williamr@2
   504
williamr@2
   505
Template specialisation base class for arrays of TInt types implemented in a 
williamr@2
   506
flat dynamic buffer.
williamr@2
   507
williamr@2
   508
@see TInt 
williamr@2
   509
*/
williamr@2
   510
	{
williamr@2
   511
public:
williamr@2
   512
	IMPORT_C explicit CArrayFixFlat(TInt aGranularity);
williamr@2
   513
	IMPORT_C ~CArrayFixFlat();
williamr@2
   514
	inline void SetReserveL(TInt aCount);
williamr@2
   515
	};
williamr@2
   516
williamr@2
   517
williamr@2
   518
williamr@2
   519
williamr@2
   520
TEMPLATE_SPECIALIZATION class CArrayFixFlat<TUid> : public CArrayFix<TUid>
williamr@2
   521
/**
williamr@2
   522
@publishedAll
williamr@2
   523
@released
williamr@2
   524
williamr@2
   525
Template specialisation base class for arrays of TUid types implemented in a 
williamr@2
   526
flat dynamic buffer.
williamr@2
   527
williamr@2
   528
@see TUid 
williamr@2
   529
*/
williamr@2
   530
	{
williamr@2
   531
public:
williamr@2
   532
	IMPORT_C explicit CArrayFixFlat(TInt aGranularity);
williamr@2
   533
	IMPORT_C ~CArrayFixFlat();
williamr@2
   534
	inline void SetReserveL(TInt aCount);
williamr@2
   535
	};
williamr@2
   536
williamr@2
   537
williamr@2
   538
williamr@2
   539
williamr@2
   540
template <class T>
williamr@2
   541
class CArrayFixSeg : public CArrayFix<T>
williamr@2
   542
/**
williamr@2
   543
@publishedAll
williamr@2
   544
@released
williamr@2
   545
williamr@2
   546
Array of fixed length objects contained within a segmented buffer.
williamr@2
   547
williamr@2
   548
The elements of the array are instances of the template class T.
williamr@2
   549
williamr@2
   550
The segmented buffer is an instance of a CBufSeg.
williamr@2
   551
williamr@2
   552
The elements can be T or R type objects and must have an accessible default 
williamr@2
   553
constructor.
williamr@2
   554
williamr@2
   555
@see CBufSeg
williamr@2
   556
*/
williamr@2
   557
	{
williamr@2
   558
public:
williamr@2
   559
	inline explicit CArrayFixSeg(TInt aGranularity);
williamr@2
   560
	};
williamr@2
   561
williamr@2
   562
williamr@2
   563
williamr@2
   564
williamr@2
   565
TEMPLATE_SPECIALIZATION class CArrayFixSeg<TAny> : public CArrayFix<TAny>
williamr@2
   566
/**
williamr@2
   567
@publishedAll
williamr@2
   568
@released
williamr@2
   569
williamr@2
   570
An array of fixed length untyped objects using a segmented dynamic buffer.
williamr@2
   571
 
williamr@2
   572
The array elements are contained within a CBufSeg.
williamr@2
   573
williamr@2
   574
The class is useful for constructing an array of fixed length buffers, where 
williamr@2
   575
the length is decided at run time.
williamr@2
   576
williamr@2
   577
This class is also useful as a data member of a base class in a thin template 
williamr@2
   578
class/base class pair where the type of the array element is not known until 
williamr@2
   579
the owning thin template class is instantiated.
williamr@2
   580
williamr@2
   581
@see CBufSeg
williamr@2
   582
*/
williamr@2
   583
	{
williamr@2
   584
public:
williamr@2
   585
	inline CArrayFixSeg(TInt aRecordLength,TInt aGranularity);
williamr@2
   586
	};
williamr@2
   587
williamr@2
   588
williamr@2
   589
williamr@2
   590
williamr@2
   591
template <class T>
williamr@2
   592
class CArrayPtr : public CArrayFix<T*>
williamr@2
   593
/**
williamr@2
   594
@publishedAll
williamr@2
   595
@released
williamr@2
   596
williamr@2
   597
A thin templated base class for arrays of pointers to objects.
williamr@2
   598
williamr@2
   599
The public functions contribute to standard array behaviour.
williamr@2
   600
williamr@2
   601
The class is always derived from and is never instantiated explicitly.
williamr@2
   602
*/
williamr@2
   603
	{
williamr@2
   604
public:
williamr@2
   605
	inline CArrayPtr(TBufRep aRep,TInt aGranularity);
williamr@2
   606
    void ResetAndDestroy();
williamr@2
   607
	};
williamr@2
   608
williamr@2
   609
williamr@2
   610
williamr@2
   611
williamr@2
   612
williamr@2
   613
template <class T>
williamr@2
   614
class CArrayPtrFlat : public CArrayPtr<T>
williamr@2
   615
/**
williamr@2
   616
@publishedAll
williamr@2
   617
@released
williamr@2
   618
williamr@2
   619
Array of pointers to objects implemented using a flat dynamic buffer.
williamr@2
   620
williamr@2
   621
The elements of the array are pointers to instances of the template class T
williamr@2
   622
and are contained within a CBufFlat.
williamr@2
   623
williamr@2
   624
This type of array has the full behaviour of flat arrays but, in addition, 
williamr@2
   625
the CArrayPtr<class T>::ResetAndDestroy() function offers a way of destroying 
williamr@2
   626
all of the objects whose pointers form the elements of the array, before
williamr@2
   627
resetting the array.
williamr@2
   628
williamr@2
   629
Note that where possible, use the RPointerArray<class T> class as this is
williamr@2
   630
more efficient.
williamr@2
   631
williamr@2
   632
@see CBufFlat
williamr@2
   633
@see CArrayPtr::ResetAndDestroy
williamr@2
   634
@see RPointerArray
williamr@2
   635
*/
williamr@2
   636
	{
williamr@2
   637
public:
williamr@2
   638
	inline explicit CArrayPtrFlat(TInt aGranularity);
williamr@2
   639
	inline void SetReserveL(TInt aCount);
williamr@2
   640
	};
williamr@2
   641
williamr@2
   642
williamr@2
   643
williamr@2
   644
williamr@2
   645
template <class T>
williamr@2
   646
class CArrayPtrSeg : public CArrayPtr<T>
williamr@2
   647
/**
williamr@2
   648
@publishedAll
williamr@2
   649
@released
williamr@2
   650
williamr@2
   651
Array of pointers to objects implemented using a segmented dynamic buffer. 
williamr@2
   652
williamr@2
   653
The elements of the array are pointers to instances of the template class T
williamr@2
   654
and are contained within a CBufSeg.
williamr@2
   655
williamr@2
   656
This type of array has the full behaviour of segmented arrays but, in addition, 
williamr@2
   657
the CArrayPtr<class T>::ResetAndDestroy() function offers a way of destroying 
williamr@2
   658
all of the objects whose pointers form the elements of the array before
williamr@2
   659
resetting the array.
williamr@2
   660
williamr@2
   661
@see CBufSeg
williamr@2
   662
@see CArrayPtr::ResetAndDestroy
williamr@2
   663
*/
williamr@2
   664
	{
williamr@2
   665
public:
williamr@2
   666
	inline explicit CArrayPtrSeg(TInt aGranularity);
williamr@2
   667
	};
williamr@2
   668
williamr@2
   669
williamr@2
   670
williamr@2
   671
williamr@2
   672
class TKeyArrayVar : public TKey
williamr@2
   673
/**
williamr@2
   674
@publishedAll
williamr@2
   675
@released
williamr@2
   676
williamr@2
   677
Defines the characteristics of a key used to access the elements of arrays 
williamr@2
   678
of variable length objects.
williamr@2
   679
williamr@2
   680
An object of this type can represent three categories of key, depending on 
williamr@2
   681
the constructor used:
williamr@2
   682
williamr@2
   683
1. a descriptor key 
williamr@2
   684
williamr@2
   685
2. a text key
williamr@2
   686
williamr@2
   687
3. a numeric key.
williamr@2
   688
williamr@2
   689
The Sort(), InsertIsqL(), Find() and FindIsqL() member functions of the CArrayVarFlat 
williamr@2
   690
and CArrayVarSeg class hierarchies need a TKeyArrayVar object as an argument 
williamr@2
   691
to define the location and type of key within an array element.
williamr@2
   692
williamr@2
   693
A TKeyArrayVar object is also required for sorting a packed array. The implementation 
williamr@2
   694
of the SortL() member function of the CArrayPakFlat class constructs a temporary 
williamr@2
   695
CArrayVarFlat object which requires the TKeyArrayVar object.
williamr@2
   696
williamr@2
   697
@see CArrayVarFlat
williamr@2
   698
@see CArrayVarSeg
williamr@2
   699
@see CArrayPakFlat
williamr@2
   700
*/
williamr@2
   701
	{
williamr@2
   702
public:
williamr@2
   703
	IMPORT_C TKeyArrayVar(TInt anOffset,TKeyCmpText aType);
williamr@2
   704
	IMPORT_C TKeyArrayVar(TInt anOffset,TKeyCmpText aType,TInt aLength);
williamr@2
   705
	IMPORT_C TKeyArrayVar(TInt anOffset,TKeyCmpNumeric aType);
williamr@2
   706
protected:
williamr@2
   707
	IMPORT_C virtual void Set(CBufBase* aBase);
williamr@2
   708
	IMPORT_C TAny* At(TInt anIndex) const;
williamr@2
   709
protected:
williamr@2
   710
	CBufBase* iBase;
williamr@2
   711
	friend class CArrayVarBase;
williamr@2
   712
	};
williamr@2
   713
williamr@2
   714
williamr@2
   715
williamr@2
   716
williamr@2
   717
williamr@2
   718
class CArrayVarBase : public CBase
williamr@2
   719
/**
williamr@2
   720
@publishedAll
williamr@2
   721
@released
williamr@2
   722
williamr@2
   723
An implementation base class for variable length arrays. 
williamr@2
   724
williamr@2
   725
It provides implementation and public functions which are common to all
williamr@2
   726
variable length type arrays.
williamr@2
   727
williamr@2
   728
The class is always derived from and is never instantiated explicitly.
williamr@2
   729
*/
williamr@2
   730
	{
williamr@2
   731
public:
williamr@2
   732
	IMPORT_C ~CArrayVarBase();
williamr@2
   733
	inline TInt Count() const;
williamr@2
   734
	IMPORT_C TInt Length(TInt anIndex) const;
williamr@2
   735
	IMPORT_C void Compress();
williamr@2
   736
	IMPORT_C void Reset();
williamr@2
   737
	IMPORT_C TInt Sort(TKeyArrayVar& aKey);
williamr@2
   738
	IMPORT_C TAny* At(TInt anIndex) const;
williamr@2
   739
	IMPORT_C void Delete(TInt anIndex);
williamr@2
   740
	IMPORT_C void Delete(TInt anIndex,TInt aCount);
williamr@2
   741
	IMPORT_C TAny* ExpandL(TInt anIndex,TInt aLength);
williamr@2
   742
	IMPORT_C TInt Find(const TAny* aPtr,TKeyArrayVar& aKey,TInt& anIndex) const;
williamr@2
   743
	IMPORT_C TInt FindIsq(const TAny* aPtr,TKeyArrayVar& aKey,TInt& anIndex) const;
williamr@2
   744
	IMPORT_C void InsertL(TInt anIndex,const TAny* aPtr,TInt aLength);
williamr@2
   745
	IMPORT_C TInt InsertIsqL(const TAny* aPtr,TInt aLength,TKeyArrayVar& aKey);
williamr@2
   746
	IMPORT_C TInt InsertIsqAllowDuplicatesL(const TAny* aPtr,TInt aLength,TKeyArrayVar& aKey);
williamr@2
   747
protected:
williamr@2
   748
	IMPORT_C CArrayVarBase(TBufRep aRep,TInt aGranularity);
williamr@2
   749
	IMPORT_C void SetKey(TKeyArrayVar& aKey) const;
williamr@2
   750
	IMPORT_C static TInt CountR(const CBase* aPtr);
williamr@2
   751
	IMPORT_C static const TAny* AtR(const CBase* aPtr,TInt anIndex);
williamr@2
   752
private:
williamr@2
   753
	TInt iCount;
williamr@2
   754
	TInt iGranularity;
williamr@2
   755
	TBufRep iCreateRep;
williamr@2
   756
	CBufBase* iBase;
williamr@2
   757
	};
williamr@2
   758
williamr@2
   759
williamr@2
   760
williamr@2
   761
williamr@2
   762
template <class T>
williamr@2
   763
class CArrayVar : public CArrayVarBase
williamr@2
   764
/**
williamr@2
   765
@publishedAll
williamr@2
   766
@released
williamr@2
   767
williamr@2
   768
A thin templated base class for variable length arrays.
williamr@2
   769
williamr@2
   770
The public functions provide standard array behaviour.
williamr@2
   771
williamr@2
   772
The class is always derived from and is never instantiated explicitly.
williamr@2
   773
*/
williamr@2
   774
	{
williamr@2
   775
public:
williamr@2
   776
	inline CArrayVar(TBufRep aRep,TInt aGranularity);
williamr@2
   777
	inline const T& operator[](TInt anIndex) const;
williamr@2
   778
	inline T& operator[](TInt anIndex);
williamr@2
   779
	inline const T& At(TInt anIndex) const;
williamr@2
   780
	inline T& At(TInt anIndex);
williamr@2
   781
	inline void AppendL(const T& aRef,TInt aLength);
williamr@2
   782
	inline T& ExpandL(TInt anIndex,TInt aLength);
williamr@2
   783
	inline T& ExtendL(TInt aLength);
williamr@2
   784
	inline TInt Find(const T& aRef,TKeyArrayVar& aKey,TInt& anIndex) const;
williamr@2
   785
	inline TInt FindIsq(const T& aRef,TKeyArrayVar& aKey,TInt& anIndex) const;
williamr@2
   786
	inline void InsertL(TInt anIndex,const T& aRef,TInt aLength);
williamr@2
   787
	inline TInt InsertIsqL(const T& aRef,TInt aLength,TKeyArrayVar& aKey);
williamr@2
   788
 	inline TInt InsertIsqAllowDuplicatesL(const T& aRef,TInt aLength,TKeyArrayVar& aKey);
williamr@2
   789
	inline const TArray<T> Array() const;
williamr@2
   790
	};
williamr@2
   791
williamr@2
   792
williamr@2
   793
williamr@2
   794
williamr@2
   795
TEMPLATE_SPECIALIZATION class CArrayVar<TAny> : public CArrayVarBase
williamr@2
   796
/**
williamr@2
   797
@publishedAll
williamr@2
   798
@released
williamr@2
   799
williamr@2
   800
A template specialisation base class for variable length arrays.
williamr@2
   801
williamr@2
   802
The array buffer organisation is defined at construction.
williamr@2
   803
williamr@2
   804
The class is useful for constructing an array of variable length buffers, 
williamr@2
   805
where the length is decided at run time.
williamr@2
   806
williamr@2
   807
This class is also useful as a data member of a base class in a thin template 
williamr@2
   808
class/base class pair, where the type of the array element is not known until 
williamr@2
   809
the owning thin template class is instantiated.
williamr@2
   810
*/
williamr@2
   811
	{
williamr@2
   812
public:
williamr@2
   813
	inline CArrayVar(TBufRep aRep,TInt aGranularity);
williamr@2
   814
	inline const TAny* At(TInt anIndex) const;
williamr@2
   815
	inline TAny* At(TInt anIndex);
williamr@2
   816
	inline void AppendL(const TAny* aPtr,TInt aLength);
williamr@2
   817
	inline TAny* ExtendL(TInt aLength);
williamr@2
   818
	};
williamr@2
   819
williamr@2
   820
williamr@2
   821
williamr@2
   822
williamr@2
   823
template <class T>
williamr@2
   824
class CArrayVarFlat : public CArrayVar<T>
williamr@2
   825
/**
williamr@2
   826
@publishedAll
williamr@2
   827
@released
williamr@2
   828
williamr@2
   829
Array of variable length objects implemented using a flat dynamic buffer.
williamr@2
   830
williamr@2
   831
The elements of the array are instances of the template class T and are
williamr@2
   832
contained within their own heap cells. Pointers to the elements are maintained
williamr@2
   833
within the flat dynamic buffer, a CBufFlat.
williamr@2
   834
williamr@2
   835
The elements can be T or R type objects and must have an accessible default 
williamr@2
   836
constructor. 
williamr@2
   837
williamr@2
   838
@see CBufFlat
williamr@2
   839
*/
williamr@2
   840
	{
williamr@2
   841
public:
williamr@2
   842
	inline explicit CArrayVarFlat(TInt aGranularity);
williamr@2
   843
	};
williamr@2
   844
williamr@2
   845
williamr@2
   846
williamr@2
   847
williamr@2
   848
template <class T>
williamr@2
   849
class CArrayVarSeg : public CArrayVar<T>
williamr@2
   850
/**
williamr@2
   851
@publishedAll
williamr@2
   852
@released
williamr@2
   853
williamr@2
   854
Array of variable length objects implemented using a segmented dynamic buffer. 
williamr@2
   855
williamr@2
   856
The elements of the array are instances of the template class T and are
williamr@2
   857
contained within their own heap cells. Pointers to the elements are maintained
williamr@2
   858
within a segmented dynamic buffer, a CBufSeg.
williamr@2
   859
williamr@2
   860
The elements can be T or R type objects and must have an accessible default 
williamr@2
   861
constructor.
williamr@2
   862
williamr@2
   863
@see CBufSeg
williamr@2
   864
*/
williamr@2
   865
	{
williamr@2
   866
public:
williamr@2
   867
	inline explicit CArrayVarSeg(TInt aGranularity);
williamr@2
   868
	};
williamr@2
   869
williamr@2
   870
williamr@2
   871
williamr@2
   872
williamr@2
   873
class TKeyArrayPak : public TKeyArrayVar
williamr@2
   874
/**
williamr@2
   875
@publishedAll
williamr@2
   876
@released
williamr@2
   877
williamr@2
   878
Defines the characteristics of a key used to access the elements of packed 
williamr@2
   879
arrays.
williamr@2
   880
williamr@2
   881
An object of this type can represent three categories of key, depending on 
williamr@2
   882
the constructor used:
williamr@2
   883
williamr@2
   884
1. a descriptor key 
williamr@2
   885
williamr@2
   886
2. a text key
williamr@2
   887
williamr@2
   888
3. a numeric key.
williamr@2
   889
williamr@2
   890
The InsertIsqL(), Find() and FindIsqL() member functions of the CArrayPakFlat 
williamr@2
   891
class hierarchy need a TKeyArrayPak object as an argument to define the location 
williamr@2
   892
and type of key within an array element.
williamr@2
   893
williamr@2
   894
Note that a TKeyArrayVar object is required for sorting a packed array. The 
williamr@2
   895
implementation of the SortL() member function of the CArrayPakFlat class constructs 
williamr@2
   896
a temporary CArrayVarFlat object which requires the TKeyArrayVar object.
williamr@2
   897
williamr@2
   898
@see CArrayVarSeg
williamr@2
   899
@see CArrayPakFlat
williamr@2
   900
@see TKeyArrayVar
williamr@2
   901
*/
williamr@2
   902
	{
williamr@2
   903
public:
williamr@2
   904
	IMPORT_C TKeyArrayPak(TInt anOffset,TKeyCmpText aType);
williamr@2
   905
	IMPORT_C TKeyArrayPak(TInt anOffset,TKeyCmpText aType,TInt aLength);
williamr@2
   906
	IMPORT_C TKeyArrayPak(TInt anOffset,TKeyCmpNumeric aType);
williamr@2
   907
protected:
williamr@2
   908
	IMPORT_C virtual void Set(CBufBase* aBase);
williamr@2
   909
	IMPORT_C TAny* At(TInt anIndex) const;
williamr@2
   910
private:
williamr@2
   911
	TInt iCacheIndex;
williamr@2
   912
	TInt iCacheOffset;
williamr@2
   913
	friend class CArrayPakBase;
williamr@2
   914
	};
williamr@2
   915
williamr@2
   916
williamr@2
   917
williamr@2
   918
williamr@2
   919
class CArrayPakBase : public CBase
williamr@2
   920
/**
williamr@2
   921
@publishedAll
williamr@2
   922
@released
williamr@2
   923
williamr@2
   924
An implementation base class for all variable length, packed arrays.
williamr@2
   925
williamr@2
   926
The class is always derived from and is never instantiated explicitly.
williamr@2
   927
*/
williamr@2
   928
	{
williamr@2
   929
public:
williamr@2
   930
	IMPORT_C ~CArrayPakBase();
williamr@2
   931
	inline TInt Count() const;
williamr@2
   932
	IMPORT_C TInt Length(TInt anIndex) const;
williamr@2
   933
	IMPORT_C void Compress();
williamr@2
   934
	IMPORT_C void Reset();
williamr@2
   935
	IMPORT_C void SortL(TKeyArrayVar& aKey);
williamr@2
   936
	IMPORT_C TAny* At(TInt anIndex) const;
williamr@2
   937
	IMPORT_C void Delete(TInt anIndex);
williamr@2
   938
	IMPORT_C void Delete(TInt anIndex,TInt aCount);
williamr@2
   939
	IMPORT_C TAny* ExpandL(TInt anIndex,TInt aLength);
williamr@2
   940
	IMPORT_C TInt Find(const TAny* aPtr,TKeyArrayPak& aKey,TInt& anIndex) const;
williamr@2
   941
	IMPORT_C TInt FindIsq(const TAny* aPtr,TKeyArrayPak& aKey,TInt& anIndex) const;
williamr@2
   942
	IMPORT_C void InsertL(TInt anIndex,const TAny* aPtr,TInt aLength);
williamr@2
   943
	IMPORT_C TInt InsertIsqL(const TAny* aPtr,TInt aLength,TKeyArrayPak& aKey);
williamr@2
   944
	IMPORT_C TInt InsertIsqAllowDuplicatesL(const TAny* aPtr,TInt aLength,TKeyArrayPak& aKey);
williamr@2
   945
protected:
williamr@2
   946
	IMPORT_C CArrayPakBase(TBufRep aRep,TInt aGranularity);
williamr@2
   947
	IMPORT_C void SetKey(TKeyArrayPak& aKey) const;
williamr@2
   948
	IMPORT_C TInt GetOffset(TInt anIndex) const;
williamr@2
   949
	IMPORT_C void BuildVarArrayL(CArrayVarFlat<TAny>*& aVarFlat);
williamr@2
   950
	IMPORT_C static TInt CountR(const CBase* aPtr);
williamr@2
   951
	IMPORT_C static const TAny* AtR(const CBase* aPtr,TInt anIndex);
williamr@2
   952
private:
williamr@2
   953
	TInt iCount;
williamr@2
   954
	TInt iGranularity;
williamr@2
   955
	TBufRep iCreateRep;
williamr@2
   956
	CBufBase* iBase;
williamr@2
   957
	TInt iCacheIndex;
williamr@2
   958
	TInt iCacheOffset;
williamr@2
   959
	};
williamr@2
   960
williamr@2
   961
williamr@2
   962
williamr@2
   963
williamr@2
   964
template <class T>
williamr@2
   965
class CArrayPak : public CArrayPakBase
williamr@2
   966
/**
williamr@2
   967
@publishedAll
williamr@2
   968
@released
williamr@2
   969
williamr@2
   970
A thin templated base class for variable length, packed, arrays.
williamr@2
   971
williamr@2
   972
The public functions provide standard array behaviour.
williamr@2
   973
williamr@2
   974
The class is always derived from and is never instantiated explicitly.
williamr@2
   975
*/
williamr@2
   976
	{
williamr@2
   977
public:
williamr@2
   978
	inline CArrayPak(TBufRep aRep,TInt aGranularity);
williamr@2
   979
	inline const T& operator[](TInt anIndex) const;
williamr@2
   980
	inline T& operator[](TInt anIndex);
williamr@2
   981
	inline const T& At(TInt anIndex) const;
williamr@2
   982
	inline T& At(TInt anIndex);
williamr@2
   983
	inline void AppendL(const T& aRef,TInt aLength);
williamr@2
   984
	inline T& ExpandL(TInt anIndex,TInt aLength);
williamr@2
   985
	inline T& ExtendL(TInt aLength);
williamr@2
   986
	inline TInt Find(const T& aRef,TKeyArrayPak& aKey,TInt& anIndex) const;
williamr@2
   987
	inline TInt FindIsq(const T& aRef,TKeyArrayPak& aKey,TInt& anIndex) const;
williamr@2
   988
	inline void InsertL(TInt anIndex,const T& aRef,TInt aLength);
williamr@2
   989
	inline TInt InsertIsqL(const T& aRef,TInt aLength,TKeyArrayPak& aKey);
williamr@2
   990
	inline TInt InsertIsqAllowDuplicatesL(const T& aRef,TInt aLength,TKeyArrayPak& aKey);
williamr@2
   991
	inline const TArray<T> Array() const;
williamr@2
   992
	};
williamr@2
   993
williamr@2
   994
williamr@2
   995
williamr@2
   996
williamr@2
   997
TEMPLATE_SPECIALIZATION class CArrayPak<TAny> : public CArrayPakBase
williamr@2
   998
/**
williamr@2
   999
@publishedAll
williamr@2
  1000
@released
williamr@2
  1001
williamr@2
  1002
A template specialisation base class for variable length, packed, arrays.
williamr@2
  1003
williamr@2
  1004
The array buffer organisation is defined at construction.
williamr@2
  1005
williamr@2
  1006
The class is useful for constructing an array of variable length buffers, 
williamr@2
  1007
where the length is decided at run time.
williamr@2
  1008
williamr@2
  1009
This class is also useful as a data member of a base class in a thin template 
williamr@2
  1010
class/base class pair where the type of the array element is not known until 
williamr@2
  1011
the owning thin template class is instantiated.
williamr@2
  1012
*/
williamr@2
  1013
	{
williamr@2
  1014
public:
williamr@2
  1015
	inline CArrayPak(TBufRep aRep,TInt aGranularity);
williamr@2
  1016
	inline const TAny* At(TInt anIndex) const;
williamr@2
  1017
	inline TAny* At(TInt anIndex);
williamr@2
  1018
	inline void AppendL(const TAny* aPtr,TInt aLength);
williamr@2
  1019
	inline TAny* ExtendL(TInt aLength);
williamr@2
  1020
	};
williamr@2
  1021
williamr@2
  1022
williamr@2
  1023
williamr@2
  1024
williamr@2
  1025
template <class T>
williamr@2
  1026
class CArrayPakFlat : public CArrayPak<T>
williamr@2
  1027
/**
williamr@2
  1028
@publishedAll
williamr@2
  1029
@released
williamr@2
  1030
williamr@2
  1031
Array of variable length objects packed into a flat buffer. 
williamr@2
  1032
williamr@2
  1033
The elements of the array are instances of the template class T and are
williamr@2
  1034
contained within a flat dynamic buffer, a CBufFlat.
williamr@2
  1035
williamr@2
  1036
The elements can be T or R type objects and must have an accessible default 
williamr@2
  1037
constructor.
williamr@2
  1038
williamr@2
  1039
@see CBufFlat
williamr@2
  1040
*/
williamr@2
  1041
	{
williamr@2
  1042
public:
williamr@2
  1043
	inline explicit CArrayPakFlat(TInt aGranularity);
williamr@2
  1044
	};
williamr@2
  1045
williamr@2
  1046
williamr@2
  1047
williamr@2
  1048
williamr@2
  1049
class CObjectCon;
williamr@2
  1050
class CObject : public CBase
williamr@2
  1051
/**
williamr@2
  1052
@publishedAll
williamr@2
  1053
@released
williamr@2
  1054
williamr@2
  1055
Implements reference counting to track concurrent references to itself.
williamr@2
  1056
williamr@2
  1057
An object of this type arranges automatic destruction of itself when the final 
williamr@2
  1058
reference is removed.
williamr@2
  1059
williamr@2
  1060
A reference counting object is any object which has CObject as its base class. 
williamr@2
  1061
Constructing a CObject derived type or calling its Open() member function 
williamr@2
  1062
adds a reference to that object by adding one to the reference count; calling 
williamr@2
  1063
its Close() member function removes a reference by subtracting one from the 
williamr@2
  1064
reference count; when the last user of the object calls Close(), the reference 
williamr@2
  1065
count becomes zero and the object is automatically destroyed.
williamr@2
  1066
*/
williamr@2
  1067
	{
williamr@2
  1068
public:
williamr@2
  1069
	IMPORT_C CObject();
williamr@2
  1070
	IMPORT_C ~CObject();
williamr@2
  1071
	IMPORT_C virtual TInt Open();
williamr@2
  1072
	IMPORT_C virtual void Close();
williamr@2
  1073
	IMPORT_C virtual TName Name() const;
williamr@2
  1074
	IMPORT_C virtual TFullName FullName() const;
williamr@2
  1075
	IMPORT_C TInt SetName(const TDesC* aName);
williamr@2
  1076
	IMPORT_C void SetNameL(const TDesC* aName);
williamr@2
  1077
	inline CObject* Owner() const;
williamr@2
  1078
	inline void SetOwner(CObject* anOwner);
williamr@2
  1079
	inline TInt AccessCount() const;
williamr@2
  1080
protected:
williamr@2
  1081
	IMPORT_C virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1);
williamr@2
  1082
protected:
williamr@2
  1083
	inline TInt UniqueID() const;
williamr@2
  1084
	inline void Inc();
williamr@2
  1085
	inline void Dec();
williamr@2
  1086
private:
williamr@2
  1087
	TInt iAccessCount;
williamr@2
  1088
	CObject* iOwner;
williamr@2
  1089
	CObjectCon* iContainer;
williamr@2
  1090
	HBufC* iName;
williamr@2
  1091
	TAny* iSpare1;
williamr@2
  1092
	TAny* iSpare2;
williamr@2
  1093
	friend class CObjectCon;
williamr@2
  1094
	friend class CObjectIx;
williamr@2
  1095
	__DECLARE_TEST;
williamr@2
  1096
	};
williamr@2
  1097
williamr@4
  1098
//Forward declaration of SObjectIxRec
williamr@4
  1099
struct SObjectIxRec;
williamr@2
  1100
	
williamr@2
  1101
class CObjectIx : public CBase
williamr@2
  1102
/**
williamr@2
  1103
@publishedAll
williamr@2
  1104
@released
williamr@2
  1105
williamr@2
  1106
Generates handle numbers for reference counting objects.
williamr@2
  1107
williamr@2
  1108
This is referred to as an object index.
williamr@2
  1109
williamr@2
  1110
Adding a reference counting object to an object index is the way in which 
williamr@2
  1111
a unique handle number can be generated for that object. A handle number is 
williamr@2
  1112
the way in which an object, which is owned or managed by another thread or 
williamr@2
  1113
process can be identified.
williamr@2
  1114
williamr@2
  1115
@see CObject
williamr@2
  1116
*/
williamr@2
  1117
	{
williamr@2
  1118
public:
williamr@2
  1119
	enum {
williamr@2
  1120
	     /**
williamr@2
  1121
	     When ORd into the handle number, indicates that the reference
williamr@2
  1122
	     counting object cannot be closed.
williamr@2
  1123
	     */
williamr@2
  1124
         ENoClose=KHandleNoClose,
williamr@2
  1125
         
williamr@2
  1126
         
williamr@2
  1127
         /**
williamr@2
  1128
         When ORed into the handle number, indicates that the handle
williamr@2
  1129
         is a local handle.
williamr@2
  1130
         */
williamr@2
  1131
         ELocalHandle=KHandleFlagLocal
williamr@2
  1132
         };
williamr@2
  1133
public:
williamr@2
  1134
	IMPORT_C static CObjectIx* NewL();
williamr@2
  1135
	IMPORT_C ~CObjectIx();
williamr@2
  1136
	IMPORT_C TInt AddL(CObject* anObj);
williamr@2
  1137
	IMPORT_C void Remove(TInt aHandle);
williamr@2
  1138
	IMPORT_C CObject* At(TInt aHandle,TInt aUniqueID);
williamr@2
  1139
	IMPORT_C CObject* At(TInt aHandle);
williamr@2
  1140
	IMPORT_C CObject* AtL(TInt aHandle,TInt aUniqueID);
williamr@2
  1141
	IMPORT_C CObject* AtL(TInt aHandle);
williamr@2
  1142
	IMPORT_C TInt At(const CObject* anObject) const;
williamr@2
  1143
	IMPORT_C TInt Count(CObject* anObject) const;
williamr@2
  1144
	IMPORT_C CObject* operator[](TInt anIndex);
williamr@2
  1145
	inline TInt Count() const;
williamr@2
  1146
	inline TInt ActiveCount() const;
williamr@2
  1147
protected:
williamr@2
  1148
	IMPORT_C CObjectIx();
williamr@2
  1149
private:
williamr@2
  1150
	void UpdateState();
williamr@2
  1151
private:
williamr@2
  1152
	TInt iNumEntries;		// Number of actual entries in the index
williamr@2
  1153
	TInt iHighWaterMark;	// points to at least 1 above the highest active index
williamr@2
  1154
	TInt iAllocated;		// Max entries before realloc needed
williamr@2
  1155
	TInt iNextInstance;
williamr@2
  1156
	SObjectIxRec *iObjects;
williamr@2
  1157
	TInt iFree;				// The index of the first free slot or -1.
williamr@2
  1158
	TInt iUpdateDisabled;   // If >0, disables HWM update, reorder of the free list and memory shrinking.
williamr@2
  1159
	TAny* iSpare1;
williamr@2
  1160
	TAny* iSpare2;
williamr@2
  1161
	};
williamr@2
  1162
//
williamr@2
  1163
inline TBool IsLocalHandle(TInt aHandle)
williamr@2
  1164
	{return(aHandle&CObjectIx::ELocalHandle);}
williamr@2
  1165
inline void SetLocalHandle(TInt &aHandle)
williamr@2
  1166
	{aHandle|=CObjectIx::ELocalHandle;}
williamr@2
  1167
inline void UnSetLocalHandle(TInt &aHandle)
williamr@2
  1168
	{aHandle&=(~CObjectIx::ELocalHandle);}
williamr@2
  1169
williamr@2
  1170
williamr@2
  1171
williamr@2
  1172
williamr@2
  1173
class CObjectCon : public CBase
williamr@2
  1174
/**
williamr@2
  1175
@publishedAll
williamr@2
  1176
@released
williamr@2
  1177
williamr@2
  1178
An object container.
williamr@2
  1179
williamr@2
  1180
An object container acts as a home for a set of related reference counting 
williamr@2
  1181
objects.
williamr@2
  1182
williamr@2
  1183
A reference counting object, a CObject type, must be added to an object
williamr@2
  1184
container. Only one instance of a given reference counting object can be
williamr@2
  1185
held by an object container, i.e. each object within an object container
williamr@2
  1186
must be distinct.
williamr@2
  1187
williamr@2
  1188
Object containers are constructed by an object container index, a CObjectConIx 
williamr@2
  1189
type. 
williamr@2
  1190
williamr@2
  1191
Note that this class is not intended for user derivation.
williamr@2
  1192
williamr@2
  1193
@see CObject
williamr@2
  1194
@see CObjectConIx
williamr@2
  1195
*/
williamr@2
  1196
	{
williamr@2
  1197
public:
williamr@2
  1198
	IMPORT_C static CObjectCon* NewL();
williamr@2
  1199
	IMPORT_C ~CObjectCon();
williamr@2
  1200
	IMPORT_C void Remove(CObject* anObj);
williamr@2
  1201
	IMPORT_C void AddL(CObject* anObj);
williamr@2
  1202
	IMPORT_C CObject* operator[](TInt anIndex);
williamr@2
  1203
	IMPORT_C CObject* At(TInt aFindHandle) const;
williamr@2
  1204
	IMPORT_C CObject* AtL(TInt aFindHandle) const;
williamr@2
  1205
	IMPORT_C TInt CheckUniqueFullName(const CObject* anOwner,const TDesC& aName) const;
williamr@2
  1206
	IMPORT_C TInt CheckUniqueFullName(const CObject* anObject) const;
williamr@2
  1207
	IMPORT_C TInt FindByName(TInt& aFindHandle,const TDesC& aMatch,TName& aName) const;
williamr@2
  1208
	IMPORT_C TInt FindByFullName(TInt& aFindHandle,const TDesC& aMatch,TFullName& aFullName) const;
williamr@2
  1209
	inline TInt UniqueID() const;
williamr@2
  1210
	inline TInt Count() const;
williamr@2
  1211
protected:
williamr@2
  1212
	IMPORT_C CObjectCon(TInt aUniqueID);
williamr@2
  1213
	TBool NamesMatch(const CObject* anObject, const CObject* aCurrentObject) const;
williamr@2
  1214
	TBool NamesMatch(const CObject* anObject, const TName& anObjectName, const CObject* aCurrentObject) const;
williamr@2
  1215
public:
williamr@2
  1216
    /**
williamr@2
  1217
    The object container's unique Id value.
williamr@2
  1218
    */
williamr@2
  1219
	TInt iUniqueID;
williamr@2
  1220
private:
williamr@2
  1221
	TInt iCount;
williamr@2
  1222
	TInt iAllocated;
williamr@2
  1223
	CObject** iObjects;
williamr@2
  1224
	TAny* iSpare1;
williamr@2
  1225
	TAny* iSpare2;
williamr@2
  1226
	friend class CObjectConIx;
williamr@2
  1227
	};
williamr@2
  1228
williamr@2
  1229
williamr@2
  1230
williamr@2
  1231
williamr@2
  1232
class CObjectConIx : public CBase
williamr@2
  1233
/**
williamr@2
  1234
@publishedAll
williamr@2
  1235
@released
williamr@2
  1236
williamr@2
  1237
A container for object containers
williamr@2
  1238
williamr@2
  1239
This is referred to as a container index.
williamr@2
  1240
williamr@2
  1241
The class provides the mechanism through which object containers, CObjectCon 
williamr@2
  1242
types, are created.
williamr@2
  1243
williamr@2
  1244
@see CObjectCon
williamr@2
  1245
@see CObject
williamr@2
  1246
*/
williamr@2
  1247
	{
williamr@4
  1248
#ifndef	SYMBIAN_ENABLE_SPLIT_HEADERS
williamr@4
  1249
protected:
williamr@4
  1250
    /**
williamr@4
  1251
    @internalComponent
williamr@4
  1252
    */
williamr@4
  1253
	enum {ENotOwnerID};
williamr@4
  1254
#endif
williamr@4
  1255
	
williamr@2
  1256
public:
williamr@2
  1257
	IMPORT_C static CObjectConIx* NewL();
williamr@2
  1258
	IMPORT_C ~CObjectConIx();
williamr@2
  1259
	IMPORT_C CObjectCon* Lookup(TInt aFindHandle) const;
williamr@2
  1260
	IMPORT_C CObjectCon* CreateL();
williamr@2
  1261
	IMPORT_C void Remove(CObjectCon* aCon);
williamr@2
  1262
protected:
williamr@2
  1263
	IMPORT_C CObjectConIx();
williamr@2
  1264
	IMPORT_C void CreateContainerL(CObjectCon*& anObject);
williamr@2
  1265
private:
williamr@2
  1266
	CObjectCon* LookupByUniqueId(TInt aUniqueId) const;
williamr@2
  1267
private:
williamr@2
  1268
	TInt iCount;
williamr@2
  1269
	TInt iAllocated;
williamr@2
  1270
	TUint16 iNextUniqueID;
williamr@2
  1271
	TUint16 iUniqueIDHasWrapped;
williamr@2
  1272
	CObjectCon** iContainers;
williamr@2
  1273
	TAny* iSpare1;
williamr@2
  1274
	TAny* iSpare2;
williamr@2
  1275
	};
williamr@2
  1276
williamr@2
  1277
// Forward Declaration of TCleanupStackItem
williamr@2
  1278
class TCleanupStackItem;
williamr@2
  1279
williamr@2
  1280
williamr@2
  1281
williamr@2
  1282
williamr@2
  1283
/**
williamr@2
  1284
@publishedAll
williamr@2
  1285
@released
williamr@2
  1286
williamr@2
  1287
Defines a function which takes a single argument of type TAny* and returns 
williamr@2
  1288
void.
williamr@2
  1289
williamr@2
  1290
An argument of this type is required by the constructors of a TCleanupItem 
williamr@2
  1291
object.
williamr@2
  1292
*/
williamr@2
  1293
typedef void (*TCleanupOperation)(TAny*);
williamr@2
  1294
williamr@2
  1295
williamr@2
  1296
williamr@2
  1297
williamr@2
  1298
class TCleanupItem
williamr@2
  1299
/**
williamr@2
  1300
@publishedAll
williamr@2
  1301
@released
williamr@2
  1302
williamr@2
  1303
Encapsulates a cleanup operation and an object on which the operation
williamr@2
  1304
is to be performed.
williamr@2
  1305
williamr@2
  1306
The class allows cleanup to be more sophisticated than simply deleting objects,
williamr@2
  1307
for example, releasing access to some shared resource.
williamr@2
  1308
*/
williamr@2
  1309
	{
williamr@2
  1310
public:
williamr@2
  1311
	inline TCleanupItem(TCleanupOperation anOperation);
williamr@2
  1312
	inline TCleanupItem(TCleanupOperation anOperation,TAny* aPtr);
williamr@2
  1313
private:
williamr@2
  1314
	TCleanupOperation iOperation;
williamr@2
  1315
	TAny* iPtr;
williamr@2
  1316
	friend class TCleanupStackItem;
williamr@2
  1317
	};
williamr@2
  1318
williamr@2
  1319
williamr@2
  1320
williamr@2
  1321
williamr@2
  1322
class CCleanup : public CBase
williamr@2
  1323
/**
williamr@2
  1324
@publishedAll
williamr@2
  1325
@released
williamr@2
  1326
williamr@2
  1327
Implements the cleanup stack.
williamr@2
  1328
williamr@2
  1329
An object of this type is created and used by the cleanup stack
williamr@2
  1330
interface, CTrapCleanup.
williamr@2
  1331
*/
williamr@2
  1332
	{
williamr@2
  1333
public:
williamr@2
  1334
	IMPORT_C static CCleanup* New();
williamr@2
  1335
	IMPORT_C static CCleanup* NewL();
williamr@2
  1336
	IMPORT_C ~CCleanup();
williamr@2
  1337
	IMPORT_C void NextLevel();
williamr@2
  1338
	IMPORT_C void PreviousLevel();
williamr@2
  1339
	IMPORT_C void PushL(TAny* aPtr);
williamr@2
  1340
	IMPORT_C void PushL(CBase* anObject);
williamr@2
  1341
	IMPORT_C void PushL(TCleanupItem anItem);
williamr@2
  1342
	IMPORT_C void Pop();
williamr@2
  1343
	IMPORT_C void Pop(TInt aCount);
williamr@2
  1344
	IMPORT_C void PopAll();
williamr@2
  1345
	IMPORT_C void PopAndDestroy();
williamr@2
  1346
	IMPORT_C void PopAndDestroy(TInt aCount);
williamr@2
  1347
	IMPORT_C void PopAndDestroyAll();
williamr@2
  1348
	IMPORT_C void Check(TAny* aExpectedItem);
williamr@2
  1349
protected:
williamr@2
  1350
	IMPORT_C void DoPop(TInt aCount,TBool aDestroy);
williamr@2
  1351
	IMPORT_C void DoPopAll(TBool aDestroy);
williamr@2
  1352
protected:
williamr@2
  1353
	IMPORT_C CCleanup();
williamr@2
  1354
protected:
williamr@2
  1355
	/**
williamr@2
  1356
	Pointer to the bottom of the cleanup stack.
williamr@2
  1357
	*/
williamr@2
  1358
	TCleanupStackItem* iBase;
williamr@2
  1359
	
williamr@2
  1360
	
williamr@2
  1361
	/**
williamr@2
  1362
	Pointer to the top of the cleanup stack.
williamr@2
  1363
	*/
williamr@2
  1364
	TCleanupStackItem* iTop;
williamr@2
  1365
	
williamr@2
  1366
	
williamr@2
  1367
	/**
williamr@2
  1368
	Pointer to the next availaible slot in the cleanup stack.
williamr@2
  1369
	*/
williamr@2
  1370
	TCleanupStackItem* iNext;
williamr@2
  1371
	};
williamr@2
  1372
williamr@2
  1373
williamr@2
  1374
williamr@2
  1375
williamr@2
  1376
NONSHARABLE_CLASS(TCleanupTrapHandler) : public TTrapHandler
williamr@2
  1377
/**
williamr@2
  1378
@publishedAll
williamr@2
  1379
@released
williamr@2
  1380
williamr@2
  1381
Implementation for a handler to work with the TRAP mechanism.
williamr@2
  1382
williamr@2
  1383
This class does not normally need to be used or accessed directly by applications 
williamr@2
  1384
and third party code.
williamr@2
  1385
*/
williamr@2
  1386
	{
williamr@2
  1387
public:
williamr@2
  1388
	TCleanupTrapHandler();
williamr@2
  1389
	virtual void Trap();
williamr@2
  1390
	virtual void UnTrap();
williamr@2
  1391
	
williamr@2
  1392
	virtual void Leave(TInt aValue);
williamr@2
  1393
	inline CCleanup& Cleanup();
williamr@2
  1394
private:
williamr@2
  1395
	CCleanup* iCleanup;
williamr@2
  1396
	friend class CTrapCleanup;
williamr@2
  1397
	};
williamr@2
  1398
williamr@2
  1399
williamr@2
  1400
williamr@2
  1401
williamr@2
  1402
template <class T>
williamr@2
  1403
class TAutoClose
williamr@2
  1404
/**
williamr@2
  1405
@publishedAll
williamr@2
  1406
@released
williamr@2
  1407
williamr@2
  1408
Automatically calls Close() on an object when that object goes out of scope.
williamr@2
  1409
williamr@2
  1410
The behaviour takes advantage of the fact that the compiler automatically 
williamr@2
  1411
destroys objects that go out of scope.
williamr@2
  1412
*/
williamr@2
  1413
	{
williamr@2
  1414
public:
williamr@2
  1415
	inline ~TAutoClose();
williamr@2
  1416
	inline void PushL();
williamr@2
  1417
	inline void Pop();
williamr@2
  1418
private:
williamr@2
  1419
	static void Close(TAny *aObj);
williamr@2
  1420
public:
williamr@2
  1421
	/**
williamr@2
  1422
	An instance of the template class.
williamr@2
  1423
	*/
williamr@2
  1424
	T iObj;
williamr@2
  1425
	};
williamr@2
  1426
williamr@2
  1427
williamr@2
  1428
williamr@2
  1429
williamr@2
  1430
class CTrapCleanup : public CBase
williamr@2
  1431
/**
williamr@2
  1432
@publishedAll
williamr@2
  1433
@released
williamr@2
  1434
williamr@2
  1435
Cleanup stack interface. 
williamr@2
  1436
williamr@2
  1437
The creation and destruction of a cleanup stack is done automatically by GUI 
williamr@2
  1438
applications and servers.
williamr@2
  1439
*/
williamr@2
  1440
	{
williamr@2
  1441
public:
williamr@2
  1442
	IMPORT_C static CTrapCleanup* New();
williamr@2
  1443
	IMPORT_C ~CTrapCleanup();
williamr@2
  1444
protected:
williamr@2
  1445
	IMPORT_C CTrapCleanup();
williamr@2
  1446
private:
williamr@2
  1447
	TCleanupTrapHandler iHandler;
williamr@2
  1448
	TTrapHandler* iOldHandler;
williamr@2
  1449
	};
williamr@2
  1450
williamr@2
  1451
williamr@2
  1452
williamr@2
  1453
williamr@2
  1454
class CCirBufBase : public CBase
williamr@2
  1455
/**
williamr@2
  1456
@publishedAll
williamr@2
  1457
@released
williamr@2
  1458
williamr@2
  1459
Base class for circular buffers.
williamr@2
  1460
williamr@2
  1461
The class is part of the implementation of circular buffers and is never
williamr@2
  1462
instantiated. 
williamr@2
  1463
williamr@2
  1464
The class provides member functions that form part of the interface.
williamr@2
  1465
*/
williamr@2
  1466
	{
williamr@2
  1467
public:
williamr@2
  1468
	IMPORT_C ~CCirBufBase();
williamr@2
  1469
	inline TInt Count() const;
williamr@2
  1470
	inline TInt Length() const;
williamr@2
  1471
	IMPORT_C void SetLengthL(TInt aLength);
williamr@2
  1472
	IMPORT_C void Reset();
williamr@2
  1473
protected:
williamr@2
  1474
	IMPORT_C CCirBufBase(TInt aSize);
williamr@2
  1475
	IMPORT_C TInt DoAdd(const TUint8* aPtr);
williamr@2
  1476
	IMPORT_C TInt DoAdd(const TUint8* aPtr,TInt aCount);
williamr@2
  1477
	IMPORT_C TInt DoRemove(TUint8* aPtr);
williamr@2
  1478
	IMPORT_C TInt DoRemove(TUint8* aPtr,TInt aCount);
williamr@2
  1479
protected:
williamr@2
  1480
	TInt iCount;
williamr@2
  1481
	TInt iSize;
williamr@2
  1482
	TInt iLength;
williamr@2
  1483
	TUint8* iPtr;
williamr@2
  1484
	TUint8* iPtrE;
williamr@2
  1485
	TUint8* iHead;
williamr@2
  1486
	TUint8* iTail;
williamr@2
  1487
	};
williamr@2
  1488
williamr@2
  1489
williamr@2
  1490
williamr@2
  1491
williamr@2
  1492
template <class T>
williamr@2
  1493
class CCirBuf : public CCirBufBase
williamr@2
  1494
/**
williamr@2
  1495
@publishedAll
williamr@2
  1496
@released
williamr@2
  1497
williamr@2
  1498
A circular buffer containing objects of a type defined by the
williamr@2
  1499
template parameter.
williamr@2
  1500
*/
williamr@2
  1501
	{
williamr@2
  1502
public:
williamr@2
  1503
	inline CCirBuf();
williamr@2
  1504
#if defined(__VC32__)
williamr@2
  1505
	inline ~CCirBuf() {}
williamr@2
  1506
#endif
williamr@2
  1507
	inline TInt Add(const T* aPtr);
williamr@2
  1508
	inline TInt Add(const T* aPtr,TInt aCount);
williamr@2
  1509
	inline TInt Remove(T* aPtr);
williamr@2
  1510
	inline TInt Remove(T* aPtr,TInt aCount);
williamr@2
  1511
	};
williamr@2
  1512
williamr@2
  1513
williamr@2
  1514
williamr@2
  1515
williamr@2
  1516
class CCirBuffer : public CCirBuf<TUint8>
williamr@2
  1517
/**
williamr@2
  1518
@publishedAll
williamr@2
  1519
@released
williamr@2
  1520
williamr@4
  1521
Circular buffer of unsigned 8-bit integers. 
williamr@4
  1522
williamr@4
  1523
The integer values range from 0 to 255.
williamr@2
  1524
*/
williamr@2
  1525
	{
williamr@2
  1526
public:
williamr@2
  1527
	IMPORT_C CCirBuffer();
williamr@2
  1528
	IMPORT_C ~CCirBuffer();
williamr@2
  1529
	IMPORT_C TInt Get();
williamr@2
  1530
	IMPORT_C TInt Put(TInt aVal);
williamr@2
  1531
	};
williamr@2
  1532
//
williamr@2
  1533
williamr@2
  1534
williamr@2
  1535
williamr@2
  1536
class CActive : public CBase
williamr@2
  1537
/**
williamr@2
  1538
@publishedAll
williamr@2
  1539
@released
williamr@2
  1540
williamr@2
  1541
The core class of the active object abstraction.
williamr@2
  1542
williamr@2
  1543
It encapsulates both the issuing of a request to an asynchronous service provider 
williamr@2
  1544
and the handling of completed requests. An application can have one or more 
williamr@2
  1545
active objects whose processing is controlled by an active scheduler.
williamr@2
  1546
*/
williamr@2
  1547
	{
williamr@2
  1548
public:
williamr@2
  1549
williamr@2
  1550
/**
williamr@2
  1551
Defines standard priorities for active objects.
williamr@2
  1552
*/
williamr@2
  1553
enum TPriority
williamr@2
  1554
	{
williamr@2
  1555
	/**
williamr@2
  1556
	A low priority, useful for active objects representing
williamr@2
  1557
	background processing.
williamr@2
  1558
	*/
williamr@2
  1559
	EPriorityIdle=-100,
williamr@2
  1560
	
williamr@2
  1561
	
williamr@2
  1562
	/**
williamr@2
  1563
	A priority higher than EPriorityIdle but lower than EPriorityStandard.
williamr@2
  1564
	*/
williamr@2
  1565
	EPriorityLow=-20,
williamr@2
  1566
	
williamr@2
  1567
	
williamr@2
  1568
	/**
williamr@2
  1569
	Most active objects will have this priority.
williamr@2
  1570
	*/
williamr@2
  1571
	EPriorityStandard=0,
williamr@2
  1572
williamr@2
  1573
williamr@2
  1574
	/**
williamr@2
  1575
	A priority higher than EPriorityStandard; useful for active objects
williamr@2
  1576
	handling user input.
williamr@2
  1577
	*/
williamr@2
  1578
	EPriorityUserInput=10,
williamr@2
  1579
	
williamr@2
  1580
	
williamr@2
  1581
	/**
williamr@2
  1582
	A priority higher than EPriorityUserInput.
williamr@2
  1583
	*/
williamr@2
  1584
	EPriorityHigh=20,
williamr@2
  1585
	};
williamr@2
  1586
public:
williamr@2
  1587
	IMPORT_C ~CActive();
williamr@2
  1588
	IMPORT_C void Cancel();
williamr@2
  1589
	IMPORT_C void Deque();
williamr@2
  1590
	IMPORT_C void SetPriority(TInt aPriority);
williamr@2
  1591
	inline TBool IsActive() const;
williamr@2
  1592
	inline TBool IsAdded() const;
williamr@2
  1593
	inline TInt Priority() const;
williamr@2
  1594
protected:
williamr@2
  1595
	IMPORT_C CActive(TInt aPriority);
williamr@2
  1596
	IMPORT_C void SetActive();
williamr@2
  1597
williamr@2
  1598
williamr@2
  1599
    /**
williamr@2
  1600
    Implements cancellation of an outstanding request.
williamr@2
  1601
	
williamr@2
  1602
	This function is called as part of the active object's Cancel().
williamr@2
  1603
	
williamr@2
  1604
	It must call the appropriate cancel function offered by the active object's 
williamr@2
  1605
	asynchronous service provider. The asynchronous service provider's cancel 
williamr@2
  1606
	is expected to act immediately.
williamr@2
  1607
	
williamr@2
  1608
	DoCancel() must not wait for event completion; this is handled by Cancel().
williamr@2
  1609
	
williamr@2
  1610
	@see CActive::Cancel
williamr@2
  1611
	*/
williamr@2
  1612
	virtual void DoCancel() =0;
williamr@2
  1613
williamr@2
  1614
williamr@2
  1615
	/**
williamr@2
  1616
	Handles an active object's request completion event.
williamr@2
  1617
	
williamr@2
  1618
	A derived class must provide an implementation to handle the
williamr@2
  1619
	completed request. If appropriate, it may issue another request.
williamr@2
  1620
	
williamr@2
  1621
	The function is called by the active scheduler when a request
williamr@2
  1622
	completion event occurs, i.e. after the active scheduler's
williamr@2
  1623
	WaitForAnyRequest() function completes.
williamr@2
  1624
	
williamr@2
  1625
	Before calling this active object's RunL() function, the active scheduler 
williamr@2
  1626
	has:
williamr@2
  1627
	
williamr@2
  1628
	1. decided that this is the highest priority active object with
williamr@2
  1629
	   a completed request
williamr@2
  1630
	
williamr@2
  1631
    2. marked this active object's request as complete (i.e. the request is no 
williamr@2
  1632
	   longer outstanding)
williamr@2
  1633
	
williamr@2
  1634
	RunL() runs under a trap harness in the active scheduler. If it leaves,
williamr@2
  1635
	then the active scheduler calls RunError() to handle the leave.
williamr@2
  1636
	
williamr@2
  1637
	Note that once the active scheduler's Start() function has been called, 
williamr@2
  1638
	all user code is run under one of the program's active object's RunL() or 
williamr@2
  1639
	RunError() functions.
williamr@2
  1640
	
williamr@2
  1641
	@see CActiveScheduler::Start
williamr@2
  1642
	@see CActiveScheduler::Error
williamr@2
  1643
	@see CActiveScheduler::WaitForAnyRequest
williamr@2
  1644
	@see TRAPD
williamr@2
  1645
	*/
williamr@2
  1646
	virtual void RunL() =0;
williamr@2
  1647
	IMPORT_C virtual TInt RunError(TInt aError);
williamr@2
  1648
protected:
williamr@2
  1649
	IMPORT_C virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1);
williamr@2
  1650
public:
williamr@2
  1651
	
williamr@2
  1652
	/**
williamr@2
  1653
	The request status associated with an asynchronous request.
williamr@2
  1654
	
williamr@2
  1655
	This is passed as a parameter to all asynchronous service providers.
williamr@2
  1656
	
williamr@2
  1657
	The active scheduler uses this to check whether the active object's request 
williamr@2
  1658
	has completed.
williamr@2
  1659
	
williamr@2
  1660
	The function can use the completion code to judge the success or otherwise 
williamr@2
  1661
	of the request.
williamr@2
  1662
	*/
williamr@2
  1663
	TRequestStatus iStatus;
williamr@2
  1664
private:
williamr@2
  1665
//	TBool iActive;
williamr@2
  1666
	TPriQueLink iLink;
williamr@2
  1667
	TAny* iSpare;
williamr@2
  1668
	friend class CActiveScheduler;
williamr@2
  1669
	friend class CServer;
williamr@2
  1670
	friend class CServer2;
williamr@2
  1671
	};
williamr@2
  1672
williamr@2
  1673
williamr@2
  1674
williamr@2
  1675
williamr@2
  1676
class CIdle : public CActive
williamr@2
  1677
/**
williamr@2
  1678
@publishedAll
williamr@2
  1679
@released
williamr@2
  1680
williamr@2
  1681
An active object that performs low-priority processing when no higher-priority 
williamr@2
  1682
active objects are ready to run.
williamr@2
  1683
williamr@2
  1684
An idle time active object together with its associated callback function 
williamr@2
  1685
may be used to implement potentially long running background tasks, such as 
williamr@2
  1686
spreadsheet recalculation and word processor repagination.
williamr@2
  1687
*/
williamr@2
  1688
	{
williamr@2
  1689
public:
williamr@2
  1690
	IMPORT_C static CIdle* New(TInt aPriority);
williamr@2
  1691
	IMPORT_C static CIdle* NewL(TInt aPriority);
williamr@2
  1692
	IMPORT_C ~CIdle();
williamr@2
  1693
	IMPORT_C void Start(TCallBack aCallBack);
williamr@2
  1694
protected:
williamr@2
  1695
	IMPORT_C CIdle(TInt aPriority);
williamr@2
  1696
	IMPORT_C void RunL();
williamr@2
  1697
	IMPORT_C void DoCancel();
williamr@2
  1698
protected:
williamr@2
  1699
	
williamr@2
  1700
	/**
williamr@2
  1701
	The callback object that encapsulates the background task.
williamr@2
  1702
	
williamr@2
  1703
	@see Start
williamr@2
  1704
	*/
williamr@2
  1705
	TCallBack iCallBack;
williamr@2
  1706
	};
williamr@2
  1707
williamr@2
  1708
williamr@2
  1709
williamr@2
  1710
williamr@2
  1711
class CAsyncOneShot : public CActive
williamr@2
  1712
/**
williamr@2
  1713
@publishedAll
williamr@2
  1714
@released
williamr@2
  1715
williamr@2
  1716
An active object that performs processing that is only performed once.
williamr@2
  1717
williamr@2
  1718
The active object is intended to be given a low priority, so that it runs 
williamr@2
  1719
only when no higher-priority active objects are ready to run. In addition, 
williamr@2
  1720
the class ensures that the current thread cannot be closed until the active 
williamr@2
  1721
object is destroyed.
williamr@2
  1722
williamr@2
  1723
The class needs to be derived from to make use of its behaviour, in particular, 
williamr@2
  1724
it needs to define and implement a RunL() function.
williamr@2
  1725
williamr@2
  1726
NB: the constructor creates a process-relative handle to the current thread 
williamr@2
  1727
and this is stored within this object. If the thread subsequently dies abnormally, 
williamr@2
  1728
then this handle will not be closed, and the thread will not be destroyed 
williamr@2
  1729
until the process terminates.
williamr@2
  1730
williamr@2
  1731
NB: if Call() is called from a different thread (for example, to implement 
williamr@2
  1732
a kind of inter-thread communication), a client-specific mechanism must be 
williamr@2
  1733
used to ensure that the thread that created this object is still alive.
williamr@2
  1734
williamr@2
  1735
NB: if the thread that created this object has its own heap and terminates 
williamr@2
  1736
abnormally, then the handle stored within this object is lost.
williamr@2
  1737
williamr@2
  1738
@see CActive::RunL
williamr@2
  1739
@see CAsyncOneShot::Call
williamr@2
  1740
*/
williamr@2
  1741
	{
williamr@2
  1742
public:
williamr@2
  1743
	IMPORT_C CAsyncOneShot(TInt aPriority);
williamr@2
  1744
	IMPORT_C virtual void DoCancel();
williamr@2
  1745
	IMPORT_C virtual void Call();
williamr@2
  1746
	IMPORT_C virtual ~CAsyncOneShot();
williamr@2
  1747
	inline RThread& Thread();
williamr@2
  1748
private:
williamr@2
  1749
	void Setup();
williamr@2
  1750
	RThread iThread;
williamr@2
  1751
	};
williamr@2
  1752
williamr@2
  1753
williamr@2
  1754
williamr@2
  1755
williamr@2
  1756
class CAsyncCallBack : public CAsyncOneShot
williamr@2
  1757
/**
williamr@2
  1758
@publishedAll
williamr@2
  1759
@released
williamr@2
  1760
williamr@2
  1761
An active object that performs its processing through an associated call back 
williamr@2
  1762
function, and which is only performed once.
williamr@2
  1763
*/
williamr@2
  1764
	{
williamr@2
  1765
public:
williamr@2
  1766
	IMPORT_C CAsyncCallBack(TInt aPriority);
williamr@2
  1767
	IMPORT_C CAsyncCallBack(const TCallBack& aCallBack, TInt aPriority);
williamr@2
  1768
	IMPORT_C void Set(const TCallBack& aCallBack);
williamr@2
  1769
	IMPORT_C void CallBack();
williamr@2
  1770
	IMPORT_C virtual ~CAsyncCallBack();
williamr@2
  1771
protected:
williamr@2
  1772
	virtual void RunL();
williamr@2
  1773
//
williamr@2
  1774
protected:
williamr@2
  1775
	/**
williamr@2
  1776
	The callback object that encapsulates the callback function.
williamr@2
  1777
	*/
williamr@2
  1778
	TCallBack iCallBack;
williamr@2
  1779
	};
williamr@2
  1780
williamr@2
  1781
williamr@2
  1782
williamr@2
  1783
williamr@2
  1784
class TDeltaTimerEntry
williamr@2
  1785
/**
williamr@2
  1786
@publishedAll
williamr@2
  1787
@released
williamr@2
  1788
williamr@2
  1789
A timed event entry.
williamr@2
  1790
williamr@2
  1791
An object of this type is added to a queue of timed events, as represented 
williamr@2
  1792
by a CDeltaTimer object. It represents a call back function that is called 
williamr@2
  1793
when the associated timed event expires.
williamr@2
  1794
williamr@2
  1795
@see CDeltaTimer
williamr@2
  1796
*/
williamr@2
  1797
	{
williamr@2
  1798
	friend class CDeltaTimer;
williamr@2
  1799
public:
williamr@4
  1800
	inline TDeltaTimerEntry(const TCallBack& aCallback);
williamr@2
  1801
	inline TDeltaTimerEntry();
williamr@2
  1802
	inline void Set(TCallBack& aCallback);
williamr@2
  1803
private:
williamr@2
  1804
	TCallBack iCallBack; 
williamr@2
  1805
	TTickCountQueLink iLink;
williamr@2
  1806
	};
williamr@2
  1807
	
williamr@2
  1808
	
williamr@2
  1809
	
williamr@2
  1810
williamr@2
  1811
class CDeltaTimer : public CActive
williamr@2
  1812
/**
williamr@2
  1813
@publishedAll
williamr@2
  1814
@released
williamr@2
  1815
williamr@2
  1816
A queue of timed events.
williamr@2
  1817
williamr@2
  1818
A timed event is a callback function encapsulated by a TDeltaTimerEntry object, 
williamr@2
  1819
and is intended to be called when the time interval represented by the event 
williamr@2
  1820
expires.
williamr@2
  1821
williamr@2
  1822
The queue itself is a TDeltaQue list. A timed event entry is added into a 
williamr@2
  1823
position in the queue that is determined by the time interval specified for 
williamr@2
  1824
that event. Although the time interval for a timed event is specified as an 
williamr@2
  1825
interval from the present moment, when added to the queue the implementation 
williamr@2
  1826
treats each event as having an interval from the previous timed event (or now).
williamr@2
  1827
williamr@2
  1828
CDeltaTimer is an active object, driven by an RTimer which is usually set to
williamr@2
  1829
expire upon completion of the event at the head of the queue.  If the time to
williamr@2
  1830
the next event is too great or an event at the head of the queue has been
williamr@2
  1831
removed, the timer may be set to expire prior to the event at the head of the
williamr@2
  1832
queue (if any).
williamr@2
  1833
williamr@2
  1834
When the timer completes, the head of the queue is inspected to see whether
williamr@2
  1835
the timed event at the head of the queue has expired.  On expiry, the callback
williamr@2
  1836
function represented by that timed event is called, and the timed event entry
williamr@2
  1837
is removed from the queue.  The queue then inspects further events for expiry,
williamr@2
  1838
calling and removing them as necessary until either the queue is empty or there
williamr@2
  1839
is an event in the future to wait for.
williamr@2
  1840
williamr@2
  1841
Note that the tick period is the minimum time interval for an event and the
williamr@2
  1842
granularity of all timings using the queue.  Note that in general, any event
williamr@2
  1843
may be called back some time after it has expired and that specifically the
williamr@2
  1844
duration of all events will at least be rounded up to a muliple of the tick
williamr@2
  1845
period.
williamr@2
  1846
williamr@2
  1847
williamr@2
  1848
@see TDeltaTimerEntry
williamr@2
  1849
@see TDeltaQue
williamr@2
  1850
@see RTimer
williamr@2
  1851
*/
williamr@2
  1852
	{
williamr@2
  1853
public:
williamr@2
  1854
	// Queue management
williamr@2
  1855
	IMPORT_C virtual void Queue(TTimeIntervalMicroSeconds32 aTimeInMicroSeconds, TDeltaTimerEntry& aEntry);
williamr@2
  1856
	IMPORT_C virtual void Remove(TDeltaTimerEntry& aEntry);
williamr@2
  1857
	IMPORT_C TInt QueueLong(TTimeIntervalMicroSeconds aTimeInMicroSeconds, TDeltaTimerEntry& aEntry);
williamr@2
  1858
williamr@2
  1859
	// Factory functions
williamr@2
  1860
	IMPORT_C static CDeltaTimer* NewL(TInt aPriority);
williamr@2
  1861
	IMPORT_C static CDeltaTimer* NewL(TInt aPriority, TTimeIntervalMicroSeconds32 aGranularity);
williamr@2
  1862
williamr@2
  1863
	// Destructor
williamr@2
  1864
	~CDeltaTimer();
williamr@2
  1865
williamr@2
  1866
private:
williamr@2
  1867
	// Construction
williamr@2
  1868
	CDeltaTimer(TInt aPriority, TInt aTickPeriod);
williamr@2
  1869
williamr@2
  1870
	// From CActive	
williamr@2
  1871
	void DoCancel();
williamr@2
  1872
	void RunL();
williamr@2
  1873
williamr@2
  1874
	// Utility
williamr@2
  1875
	void Activate(TBool aRequeueTimer = EFalse);
williamr@2
  1876
williamr@2
  1877
private:	
williamr@2
  1878
	/**
williamr@2
  1879
	The asynchronous timer.
williamr@2
  1880
	*/
williamr@2
  1881
	RTimer iTimer;
williamr@2
  1882
	
williamr@2
  1883
	/**
williamr@2
  1884
	The list of timed event entries.
williamr@2
  1885
	*/
williamr@2
  1886
	TTickCountQue iQueue;
williamr@2
  1887
	
williamr@2
  1888
	/**
williamr@2
  1889
	The period of a tick count.
williamr@2
  1890
	*/
williamr@2
  1891
	const TInt iTickPeriod;
williamr@2
  1892
	
williamr@2
  1893
	/**
williamr@2
  1894
	Pseudo-lock on the the queue to avoid reentrancy problems
williamr@2
  1895
	*/
williamr@2
  1896
	TBool iQueueBusy;
williamr@2
  1897
	};
williamr@2
  1898
williamr@2
  1899
williamr@2
  1900
williamr@2
  1901
williamr@2
  1902
class CTimer : public CActive
williamr@2
  1903
/**
williamr@2
  1904
@publishedAll
williamr@2
  1905
@released
williamr@2
  1906
williamr@2
  1907
Base class for a timer active object.
williamr@2
  1908
williamr@2
  1909
This is an active object that uses the asynchronous services provided by RTimer, 
williamr@2
  1910
to generate events. These events occur either at a specific time specified 
williamr@2
  1911
as a TTime, or after an interval specified in microseconds.
williamr@2
  1912
williamr@2
  1913
The RunL() virtual member function is called by the active scheduler after 
williamr@2
  1914
this event occurs.
williamr@2
  1915
williamr@2
  1916
To write a class derived from CTimer, first define and implement a constructor 
williamr@2
  1917
through which the priority of the CTimer active object can be specified. Then 
williamr@2
  1918
define and implement a suitable RunL() function to handle the completion of 
williamr@2
  1919
a timer request. This function is not defined by CTimer itself and must, therefore, 
williamr@2
  1920
be provided by the derived class.
williamr@2
  1921
williamr@2
  1922
This class is ultimately implemented in terms of the nanokernel tick, and
williamr@2
  1923
therefore the granularity of the generated events is limited to the period of
williamr@2
  1924
this timer.  This is variant specific, but is usually 1 millisecond.
williamr@2
  1925
williamr@2
  1926
Note that the CPeriodic and CHeartbeat classes are derived from CTimer, and 
williamr@2
  1927
answer most timing needs.
williamr@2
  1928
williamr@2
  1929
@see CHeartbeat
williamr@2
  1930
@see CPeriodic
williamr@2
  1931
@see CHeartbeat
williamr@2
  1932
*/
williamr@2
  1933
	{
williamr@2
  1934
public:
williamr@2
  1935
	IMPORT_C ~CTimer();
williamr@2
  1936
	IMPORT_C void At(const TTime& aTime);
williamr@2
  1937
	IMPORT_C void AtUTC(const TTime& aTimeInUTC);
williamr@2
  1938
	IMPORT_C void After(TTimeIntervalMicroSeconds32 anInterval);
williamr@2
  1939
	IMPORT_C void Lock(TTimerLockSpec aLock);
williamr@2
  1940
	IMPORT_C void Inactivity(TTimeIntervalSeconds aSeconds);
williamr@2
  1941
	IMPORT_C void HighRes(TTimeIntervalMicroSeconds32 aInterval);
williamr@2
  1942
protected:
williamr@2
  1943
	IMPORT_C CTimer(TInt aPriority);
williamr@2
  1944
	IMPORT_C void ConstructL();
williamr@2
  1945
	IMPORT_C void DoCancel();
williamr@2
  1946
private:
williamr@2
  1947
	RTimer iTimer;
williamr@2
  1948
	};
williamr@2
  1949
williamr@2
  1950
williamr@2
  1951
williamr@2
  1952
williamr@2
  1953
class CPeriodic : public CTimer
williamr@2
  1954
/**
williamr@2
  1955
@publishedAll
williamr@2
  1956
@released
williamr@2
  1957
williamr@2
  1958
Periodic timer active object. 
williamr@2
  1959
williamr@2
  1960
This class generates regular timer events and handles them with a callback 
williamr@2
  1961
function. The callback is specified as a parameter to Start().
williamr@2
  1962
williamr@2
  1963
The callback may not be called immediately after the signal from the timer 
williamr@2
  1964
request has been generated, for the following reasons:
williamr@2
  1965
williamr@2
  1966
1. the RunL() of another active object may be running at the time of the signal
williamr@2
  1967
williamr@2
  1968
2. other active objects may have a higher priority than the CPeriodic
williamr@2
  1969
williamr@2
  1970
If timing accuracy is important to your application, you can minimise the 
williamr@2
  1971
first problem by ensuring all RunL()s complete quickly, and can eliminate 
williamr@2
  1972
the second by giving the CPeriodic a higher priority than any other active 
williamr@2
  1973
object. Although it is generally recommended that timer-related active objects 
williamr@2
  1974
have a high priority, this will not address the problem of CPeriodic timers 
williamr@2
  1975
running behind, because active object scheduling is not pre-emptive.
williamr@2
  1976
williamr@2
  1977
After a timer signal generated by a CPeriodic, the next signal is requested 
williamr@2
  1978
just before running the callback, and this request can be delayed for the 
williamr@2
  1979
same reasons that running the callback can be delayed. Therefore, a large 
williamr@2
  1980
number N of periods may add up to somewhat more than N times the requested 
williamr@2
  1981
period time. If absolute precision is required in tracking time, do not rely 
williamr@2
  1982
on counting the number of times the callback is called: read the value of 
williamr@2
  1983
the system clock every time you need it.
williamr@2
  1984
williamr@2
  1985
For many applications, such precision is not required, for example, tick 
williamr@2
  1986
counting is sufficiently accurate for controlling time-outs in a communications 
williamr@2
  1987
program.
williamr@2
  1988
williamr@2
  1989
Note that you should be familiar with CActive in order to understand
williamr@2
  1990
CPeriodic behaviour, but not necessarily with CTimer.
williamr@2
  1991
williamr@2
  1992
@see CHeartbeat
williamr@2
  1993
*/
williamr@2
  1994
	{
williamr@2
  1995
public:
williamr@2
  1996
	IMPORT_C static CPeriodic* New(TInt aPriority);
williamr@2
  1997
	IMPORT_C static CPeriodic* NewL(TInt aPriority);
williamr@2
  1998
	IMPORT_C ~CPeriodic();
williamr@2
  1999
	IMPORT_C void Start(TTimeIntervalMicroSeconds32 aDelay,TTimeIntervalMicroSeconds32 anInterval,TCallBack aCallBack);
williamr@2
  2000
protected:
williamr@2
  2001
	IMPORT_C CPeriodic(TInt aPriority);
williamr@2
  2002
	IMPORT_C void RunL();
williamr@2
  2003
private:
williamr@2
  2004
	TTimeIntervalMicroSeconds32 iInterval;
williamr@2
  2005
	TCallBack iCallBack;
williamr@2
  2006
	};
williamr@2
  2007
williamr@2
  2008
williamr@2
  2009
williamr@2
  2010
williamr@2
  2011
class MBeating
williamr@2
  2012
/**
williamr@2
  2013
@publishedAll
williamr@2
  2014
@released
williamr@2
  2015
williamr@2
  2016
Heartbeat timer call-back handling interface.
williamr@2
  2017
williamr@2
  2018
The interface provides a pair of functions to handle the beating and
williamr@2
  2019
synchronisation of heartbeat timers.
williamr@2
  2020
williamr@2
  2021
The CHeartbeat active object class uses an object implementing the MBeating 
williamr@2
  2022
interface.
williamr@2
  2023
williamr@2
  2024
@see CHeartbeat::Start
williamr@2
  2025
*/
williamr@2
  2026
	{
williamr@2
  2027
public:
williamr@2
  2028
	/**
williamr@2
  2029
	Handles a regular heartbeat timer event.
williamr@2
  2030
	
williamr@2
  2031
	This type of event is one where the timer completes in synchronisation
williamr@2
  2032
	with the system clock.
williamr@2
  2033
	*/
williamr@2
  2034
	virtual void Beat() =0;
williamr@2
  2035
	
williamr@2
  2036
	/**
williamr@2
  2037
	Synchronises the heartbeat timer with system clock. 
williamr@2
  2038
	
williamr@2
  2039
	This function handles a heartbeat timer event where the timer completes out 
williamr@2
  2040
	of synchronisation with the system clock, (i.e. one or more heartbeats have 
williamr@2
  2041
	been missed).
williamr@2
  2042
	*/
williamr@2
  2043
	virtual void Synchronize() =0;
williamr@2
  2044
	};
williamr@2
  2045
williamr@2
  2046
williamr@2
  2047
williamr@2
  2048
williamr@2
  2049
class CHeartbeat : public CTimer
williamr@2
  2050
/**
williamr@2
  2051
@publishedAll
williamr@2
  2052
@released
williamr@2
  2053
williamr@2
  2054
Heatbeat timer.
williamr@2
  2055
williamr@2
  2056
This class generates regular heartbeat events on a fixed fraction of a second. 
williamr@2
  2057
It is more accurate than a CPeriodic timer, because it provides a function 
williamr@2
  2058
to restore timer accuracy if it gets out of synchronisation with the system 
williamr@2
  2059
clock.
williamr@2
  2060
williamr@2
  2061
The protected RunL() function is called when the timer completes. The RunL() 
williamr@2
  2062
function in turn calls either the MBeating::Beat() or the MBeating::Synchronize() 
williamr@2
  2063
functions; MBeating is specified as a parameter to the Start() function 
williamr@2
  2064
used to start the heartbeat timer.
williamr@2
  2065
williamr@2
  2066
The relevant MBeating function may not be called immediately after the signal 
williamr@2
  2067
from the timer request has been generated, for the following reasons:
williamr@2
  2068
williamr@2
  2069
1. the RunL() of another active object may be running at the time of the signal
williamr@2
  2070
williamr@2
  2071
2. other active objects may have a higher priority than the CHeartbeat
williamr@2
  2072
williamr@2
  2073
If no heartbeat is missed, then the Beat() function is called.
williamr@2
  2074
williamr@2
  2075
If one or more heartbeats are missed then the Synchronize() function is called. 
williamr@2
  2076
It is important to bear in mind that the machine might be switched off after 
williamr@2
  2077
a few beats of the heart, and then Synchronize() will be called several days 
williamr@2
  2078
later. It is therefore essential that synchronisation is achieved as quickly 
williamr@2
  2079
as possible, rather than trying to catch up a tick at a time. In the context 
williamr@2
  2080
of an analogue clock, for instance, the clock should just redraw itself with 
williamr@2
  2081
the current time - rather than moving the hands round in steps until the time 
williamr@2
  2082
is correct.
williamr@2
  2083
williamr@2
  2084
CHeartbeat is an active object, derived from CActive (via CTimer). You should 
williamr@2
  2085
be familiar with CActive in order to understand CHeartbeat behaviour, but 
williamr@2
  2086
not necessarily with CTimer.
williamr@2
  2087
williamr@2
  2088
@see MBeating
williamr@2
  2089
*/
williamr@2
  2090
	{
williamr@2
  2091
public:
williamr@2
  2092
	IMPORT_C static CHeartbeat* New(TInt aPriority);
williamr@2
  2093
	IMPORT_C static CHeartbeat* NewL(TInt aPriority);
williamr@2
  2094
	IMPORT_C ~CHeartbeat();
williamr@2
  2095
	IMPORT_C void Start(TTimerLockSpec aLock,MBeating *aBeating);
williamr@2
  2096
protected:
williamr@2
  2097
	IMPORT_C CHeartbeat(TInt aPriority);
williamr@2
  2098
	IMPORT_C void RunL();
williamr@2
  2099
private:
williamr@2
  2100
	TTimerLockSpec iLock;
williamr@2
  2101
	MBeating *iBeating;
williamr@2
  2102
	};
williamr@2
  2103
//
williamr@2
  2104
williamr@2
  2105
class CServer2;
williamr@2
  2106
williamr@2
  2107
williamr@2
  2108
williamr@2
  2109
williamr@2
  2110
/**
williamr@2
  2111
@publishedAll
williamr@2
  2112
@released
williamr@2
  2113
williamr@2
  2114
Represents a session (version 2) for a client thread on the server-side.
williamr@2
  2115
williamr@2
  2116
A session acts as a channel of communication between the client and the server.
williamr@2
  2117
A client thread can have multiple concurrent sessions with a server.
williamr@2
  2118
williamr@2
  2119
A session can be:
williamr@2
  2120
- restricted to the creating thread
williamr@2
  2121
- can be shared with other threads in the same process
williamr@2
  2122
- can be shared by all threads in the system.
williamr@2
  2123
williamr@2
  2124
A server must define and implement a derived class. In particular, 
williamr@2
  2125
it must provide an implementation for the ServiceL() virtual function.
williamr@2
  2126
williamr@2
  2127
(Note that this class should be used instead of CSession)
williamr@2
  2128
*/
williamr@2
  2129
class CSession2 : public CBase
williamr@2
  2130
	{
williamr@2
  2131
	friend class CServer2;
williamr@2
  2132
public:
williamr@2
  2133
	IMPORT_C virtual ~CSession2() =0;
williamr@2
  2134
private:
williamr@2
  2135
	IMPORT_C virtual void CreateL(); // Default method, does nothing
williamr@2
  2136
public:
williamr@2
  2137
	inline const CServer2* Server() const;
williamr@2
  2138
	IMPORT_C void ResourceCountMarkStart();
williamr@2
  2139
	IMPORT_C void ResourceCountMarkEnd(const RMessage2& aMessage);
williamr@2
  2140
	IMPORT_C virtual TInt CountResources();
williamr@2
  2141
williamr@2
  2142
    /**
williamr@2
  2143
    Handles the servicing of a client request that has been passed
williamr@2
  2144
    to the server.
williamr@2
  2145
williamr@2
  2146
    This function must be implemented in a derived class. The details of
williamr@2
  2147
    the request are contained within the message.
williamr@2
  2148
williamr@2
  2149
	@param aMessage The message containing the details of the client request.
williamr@2
  2150
    */
williamr@2
  2151
	virtual void ServiceL(const RMessage2& aMessage) =0;
williamr@2
  2152
	IMPORT_C virtual void ServiceError(const RMessage2& aMessage,TInt aError);
williamr@2
  2153
protected:
williamr@2
  2154
	IMPORT_C CSession2();
williamr@2
  2155
	IMPORT_C virtual void Disconnect(const RMessage2& aMessage);
williamr@2
  2156
	IMPORT_C virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1);
williamr@2
  2157
public:
williamr@4
  2158
	IMPORT_C void SetServer(const CServer2* aServer);
williamr@2
  2159
    /**
williamr@2
  2160
    @internalComponent
williamr@2
  2161
    */
williamr@2
  2162
	enum TPanicNo {ESesCountResourcesNotImplemented=1,ESesFoundResCountHeaven};
williamr@4
  2163
williamr@2
  2164
private:
williamr@2
  2165
	TInt iResourceCountMark;
williamr@2
  2166
	TDblQueLink iLink;
williamr@2
  2167
	const CServer2* iServer;
williamr@2
  2168
	TAny* iSpare;
williamr@2
  2169
	};
williamr@2
  2170
williamr@2
  2171
/**
williamr@2
  2172
@publishedAll
williamr@2
  2173
@released
williamr@2
  2174
williamr@2
  2175
Abstract base class for servers (version 2).
williamr@2
  2176
williamr@2
  2177
This is an active object. It accepts requests from client threads and forwards
williamr@2
  2178
them to the relevant server-side client session. It also handles the creation
williamr@2
  2179
of server-side client sessions as a result of requests from client threads.
williamr@2
  2180
williamr@2
  2181
A server must define and implement a derived class.
williamr@2
  2182
williamr@2
  2183
(Note that this class should be used instead of CServer)
williamr@2
  2184
*/
williamr@2
  2185
class CServer2 : public CActive
williamr@2
  2186
	{
williamr@2
  2187
public:
williamr@4
  2188
williamr@4
  2189
	/**
williamr@4
  2190
	This enumeration defines the maximum sharability of sessions opened
williamr@4
  2191
	with this server; for backwards compatibilty, these should be have
williamr@4
  2192
	the same values as the corresponding EIpcSessionType enumeration
williamr@4
  2193
	*/
williamr@2
  2194
	enum TServerType
williamr@2
  2195
		{
williamr@4
  2196
		EUnsharableSessions					= EIpcSession_Unsharable,
williamr@4
  2197
		ESharableSessions					= EIpcSession_Sharable,
williamr@4
  2198
		EGlobalSharableSessions				= EIpcSession_GlobalSharable,
williamr@2
  2199
		};
williamr@4
  2200
williamr@2
  2201
public:
williamr@2
  2202
	IMPORT_C virtual ~CServer2() =0;
williamr@2
  2203
	IMPORT_C TInt Start(const TDesC& aName);
williamr@2
  2204
	IMPORT_C void StartL(const TDesC& aName);
williamr@2
  2205
	IMPORT_C void ReStart();
williamr@4
  2206
	IMPORT_C void SetPinClientDescriptors(TBool aPin);
williamr@2
  2207
	
williamr@2
  2208
	/**
williamr@2
  2209
	Gets a handle to the server.
williamr@2
  2210
	
williamr@2
  2211
	Note that the RServer2 object is classified as Symbian internal, and its
williamr@2
  2212
	member functions cannot be acessed. However, the handle can be passed
williamr@2
  2213
	to the RSessionBase::CreateSession() variants that take a server handle.
williamr@2
  2214
	
williamr@2
  2215
	@return The handle to the server.
williamr@2
  2216
	*/
williamr@2
  2217
	inline RServer2 Server() const { return iServer; }
williamr@2
  2218
protected:
williamr@2
  2219
	inline const RMessage2& Message() const;
williamr@2
  2220
	IMPORT_C CServer2(TInt aPriority, TServerType aType=EUnsharableSessions);
williamr@2
  2221
	IMPORT_C void DoCancel();
williamr@2
  2222
	IMPORT_C void RunL();
williamr@2
  2223
	IMPORT_C TInt RunError(TInt aError);
williamr@2
  2224
	IMPORT_C virtual void DoConnect(const RMessage2& aMessage);
williamr@2
  2225
	IMPORT_C virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1);
williamr@2
  2226
private:
williamr@2
  2227
    
williamr@2
  2228
    /**
williamr@2
  2229
    Creates a server-side session object.
williamr@2
  2230
williamr@2
  2231
    The session represents a communication link between a client and a server,
williamr@2
  2232
    and its creation is initiated by the client through a call to one of
williamr@2
  2233
    the RSessionBase::CreateSession() variants. 
williamr@2
  2234
williamr@2
  2235
    A server must provide an implementation, which as a minimum should:
williamr@2
  2236
williamr@2
  2237
    - check that the version of the server is compatible with the client by
williamr@2
  2238
      comparing the client supplied version number against the server's version
williamr@2
  2239
      number; it should leave if there is incompatibility.
williamr@2
  2240
williamr@2
  2241
    - construct and return the server side client session object.
williamr@2
  2242
williamr@2
  2243
    @param aVersion The version information supplied by the client. 
williamr@2
  2244
    @param aMessage Represents the details of the client request that is requesting
williamr@2
  2245
                    the creation of the session.
williamr@2
  2246
    
williamr@2
  2247
    @return A pointer to the newly created server-side session object. 
williamr@2
  2248
    
williamr@2
  2249
    @see User::QueryVersionSupported()
williamr@2
  2250
    */
williamr@2
  2251
	IMPORT_C virtual CSession2* NewSessionL(const TVersion& aVersion,const RMessage2& aMessage) const =0;
williamr@2
  2252
	void Connect(const RMessage2& aMessage);
williamr@2
  2253
	void DoConnectL(const RMessage2& aMessage,CSession2* volatile& aSession);
williamr@2
  2254
public:
williamr@4
  2255
	IMPORT_C void SetMaster(const CServer2* aServer);
williamr@4
  2256
williamr@2
  2257
	/**
williamr@2
  2258
    @internalComponent
williamr@2
  2259
    */
williamr@2
  2260
	enum TPanic
williamr@2
  2261
		{
williamr@2
  2262
		EBadMessageNumber,
williamr@2
  2263
		ESessionNotConnected,
williamr@2
  2264
		ESessionAlreadyConnected,
williamr@2
  2265
		EClientDoesntHaveRequiredCaps,
williamr@2
  2266
		};
williamr@4
  2267
williamr@2
  2268
private:
williamr@4
  2269
	TUint8 iSessionType;
williamr@4
  2270
	TUint8 iServerRole;
williamr@4
  2271
	TUint16 iServerOpts;
williamr@2
  2272
	RServer2 iServer;
williamr@2
  2273
	RMessage2 iMessage;
williamr@2
  2274
	TAny* iSpare;
williamr@2
  2275
	TDblQue<CSession2> iSessionQ;
williamr@4
  2276
	
williamr@2
  2277
protected:
williamr@2
  2278
	TDblQueIter<CSession2> iSessionIter;
williamr@2
  2279
private:
williamr@2
  2280
	void Disconnect(const RMessage2& aMessage);
williamr@2
  2281
	static void BadMessage(const RMessage2& aMessage);
williamr@2
  2282
	static void NotConnected(const RMessage2& aMessage);
williamr@2
  2283
	friend class CPolicyServer;
williamr@2
  2284
	};
williamr@2
  2285
williamr@2
  2286
williamr@2
  2287
williamr@2
  2288
/**
williamr@2
  2289
A security policy framework built on top of the normal CServer2 class.
williamr@2
  2290
williamr@2
  2291
The two major functions of the Policy Server framework are to check a received
williamr@2
  2292
message against a security policy and then to perform an action depending on
williamr@2
  2293
the result of this check. The exact behaviour is defined by the contents of
williamr@2
  2294
the TPolicy structure given in the constructor for CPolicyServer. 
williamr@2
  2295
williamr@2
  2296
The processing performed when a server receives a message are describe below.
williamr@2
  2297
This should aid understanding of the interaction of the TPolicy structure and
williamr@2
  2298
virtual member functions which may be implemented by classes derived from CPolicyServer.
williamr@2
  2299
williamr@2
  2300
Checking the Security Policy
williamr@2
  2301
williamr@2
  2302
On receipt of a message, the message function number is used to search the
williamr@2
  2303
list of ranges pointed to by TPolicy::iRanges. This yields a range
williamr@2
  2304
number R, which is between 0 and TPolicy::iRangeCount-1.
williamr@2
  2305
The policy index, X, for this range is then fetched from TPolicy::iElementsIndex[R].
williamr@2
  2306
If the message is a Connect message, then X is fetched directly from TPolicy::iOnConnect
williamr@2
  2307
instead.
williamr@2
  2308
williamr@2
  2309
The further action taken is determined by the value of X.
williamr@2
  2310
-	If X==TSpecialCase::EAlwaysPass,
williamr@2
  2311
	the message is processed as normal; either by passing it to the ServiceL()
williamr@2
  2312
	method of a session, or, in the case of a connection message, a new session
williamr@2
  2313
	is created.
williamr@2
  2314
-	If X==TSpecialCase::ENotSupported,
williamr@2
  2315
	the message is completed with KErrNotSupported.
williamr@2
  2316
-	If X==TSpecialCase::ECustomCheck,
williamr@2
  2317
	a call to the virtual function CustomSecurityCheckL() is made. The implementation
williamr@2
  2318
	of this method must return one of the TCustomResult enumerations which determine
williamr@2
  2319
	what further action is to be taken:
williamr@2
  2320
	-	TCustomResult::EPass 
williamr@2
  2321
		The message is processed as normal; either by passing it to the ServiceL()
williamr@2
  2322
		method of a session, or, in the case of a connection message, a new session
williamr@2
  2323
		is created.
williamr@2
  2324
	-	TCustomResult::EFail 
williamr@2
  2325
		This causes CheckFailedL() to be called with the action specified by the
williamr@2
  2326
		aAction reference given to CustomSecurityCheckL() (This defaults to
williamr@2
  2327
		TFailureAction::EFailClient.)
williamr@2
  2328
	-	TCustomResult::EAsync 
williamr@2
  2329
		The derived class is responsible for further processing of the message,
williamr@2
  2330
		the Policy Server framework will do nothing more with it.
williamr@2
  2331
-	If X < TSpecialCase::ESpecialCaseHardLimit,
williamr@2
  2332
		X is taken as an index into the array of TPolicyElement objects pointed
williamr@2
  2333
		to by TPolicy::iElements. The platform security attributes of the process
williamr@2
  2334
		which sent the message being processed are checked against the security
williamr@2
  2335
		policy specified in this TPolicyElement. If the process possesses all of
williamr@2
  2336
		the attributes specified then the message processed as normal. Otherwise,
williamr@2
  2337
		CheckFailedL() is called with the action value specified in the TPolicyElement .
williamr@2
  2338
williamr@2
  2339
Handling Policy Check Failure
williamr@2
  2340
williamr@2
  2341
The CheckFailedL() method is called when a security check has failed. It performs
williamr@2
  2342
an action according to the aAction value given to it:
williamr@2
  2343
williamr@2
  2344
-	If aAction==TFailureAction::EFailClient, the message is completed with
williamr@2
  2345
	KErrPermissionDenied.
williamr@2
  2346
-	If aAction==TFailureAction::EPanicClient, the client thread is panicked.
williamr@2
  2347
-	If aAction < 0 a call to the virtual function CustomFailureActionL() is made.
williamr@2
  2348
	The implementation of this method must return one of the TCustomResult
williamr@2
  2349
	enumerations which determine what further action is to be taken:
williamr@2
  2350
	-	TCustomResult::EPass 
williamr@2
  2351
		The message is processed as normal; either by passing it to the ServiceL()
williamr@2
  2352
		method of a session, or, in the case of a connection message, a new session
williamr@2
  2353
		is created.
williamr@2
  2354
	-	TCustomResult::EFail 
williamr@2
  2355
		The message is completed with KErrPermissionDenied.
williamr@2
  2356
	-	TCustomResult::EAsync 
williamr@2
  2357
		The derived class is responsible for further processing of the message,
williamr@2
  2358
		the Policy Server framework will do nothing more with it.
williamr@2
  2359
williamr@2
  2360
@publishedAll
williamr@2
  2361
@released
williamr@2
  2362
*/
williamr@2
  2363
class CPolicyServer : public CServer2
williamr@2
  2364
	{
williamr@2
  2365
public:
williamr@2
  2366
	/** Enumeration specifying action to take if a security check fails.
williamr@2
  2367
	Values >= 0 are handled by CheckFailedL().  Values < 0 are specific to the
williamr@2
  2368
	derived implementation of the policy server and will result in a call to
williamr@2
  2369
	CustomFailureActionL() if a security check fails.  Attempts to use undefined
williamr@2
  2370
	values >= 0 will result in a panic in CheckFailedL().
williamr@2
  2371
	*/
williamr@2
  2372
	enum TFailureAction
williamr@2
  2373
		{
williamr@2
  2374
		EFailClient	= 0,	/**< Complete message with KErrPermissionDenied */
williamr@2
  2375
		EPanicClient= 1,	/**< Panic client */
williamr@2
  2376
		};
williamr@2
  2377
williamr@2
  2378
	/** Enumeration of acceptable return codes from both of
williamr@2
  2379
	CustomSecurityCheckL() and CustomFailureActionL().  Results of EPass or EFail
williamr@2
  2380
	are handled by the CPolicyServer framework.  No other action is required on
williamr@2
  2381
	the part of the derived implementation.  However, results of EAsync imply
williamr@2
  2382
	that the derived implementation will call the appropriate function once the
williamr@2
  2383
	result is known.  See CustomSecurityCheckL() and CustomFailureActionL for
williamr@2
  2384
	more information.
williamr@2
  2385
	*/
williamr@2
  2386
	enum TCustomResult
williamr@2
  2387
		{
williamr@2
  2388
		EPass = 0,	/**< Security check passed. */
williamr@2
  2389
		EFail = 1,	/**< Security check failed. */
williamr@2
  2390
		EAsync = 2,	/**< Security checking will be performed asynchronously. */
williamr@2
  2391
		};
williamr@2
  2392
williamr@2
  2393
	/** Class specifying a security check and the action to take
williamr@2
  2394
williamr@2
  2395
	If iAction is >=0 it must be a member of TFailureAction
williamr@2
  2396
	If iAction is <0 it is assumed to specify a custom action specific to the
williamr@2
  2397
	derived implementation.  In this case, CustomFailureActionL must be implemented
williamr@2
  2398
	by the derived class.
williamr@2
  2399
	*/
williamr@2
  2400
	class TPolicyElement
williamr@2
  2401
		{
williamr@2
  2402
	public:
williamr@2
  2403
		/** Security policy to check against the client which sent a message.
williamr@2
  2404
williamr@2
  2405
		This class can specify a security policy consisting of either:
williamr@2
  2406
williamr@2
  2407
		-#	A check for between 0 and 7 capabilities
williamr@2
  2408
		-#	A check for a given Secure ID along with 0-3 capabilities
williamr@2
  2409
		-#	A check for a given Vendor ID along with 0-3 capabilities
williamr@2
  2410
williamr@2
  2411
		This member should only be initialised by one of the following macros:
williamr@2
  2412
williamr@2
  2413
		-	_INIT_SECURITY_POLICY_PASS
williamr@2
  2414
		-	_INIT_SECURITY_POLICY_FAIL
williamr@2
  2415
		-	_INIT_SECURITY_POLICY_C1
williamr@2
  2416
		-	_INIT_SECURITY_POLICY_C2
williamr@2
  2417
		-	_INIT_SECURITY_POLICY_C3
williamr@2
  2418
		-	_INIT_SECURITY_POLICY_C4
williamr@2
  2419
		-	_INIT_SECURITY_POLICY_C5
williamr@2
  2420
		-	_INIT_SECURITY_POLICY_C6
williamr@2
  2421
		-	_INIT_SECURITY_POLICY_C7
williamr@2
  2422
		-	_INIT_SECURITY_POLICY_S0
williamr@2
  2423
		-	_INIT_SECURITY_POLICY_S1
williamr@2
  2424
		-	_INIT_SECURITY_POLICY_S2
williamr@2
  2425
		-	_INIT_SECURITY_POLICY_S3
williamr@2
  2426
		-	_INIT_SECURITY_POLICY_V0
williamr@2
  2427
		-	_INIT_SECURITY_POLICY_V1
williamr@2
  2428
		-	_INIT_SECURITY_POLICY_V2
williamr@2
  2429
		-	_INIT_SECURITY_POLICY_V3
williamr@2
  2430
williamr@2
  2431
		@see TPolicy
williamr@2
  2432
		*/
williamr@2
  2433
		TStaticSecurityPolicy	 	iPolicy;
williamr@2
  2434
williamr@2
  2435
		/** Action to take on failure. Either a value from TFailureAction
williamr@2
  2436
			or a negative value which has meaning to the CustomFailureActionL()
williamr@2
  2437
			method of a derived class.
williamr@2
  2438
		*/
williamr@2
  2439
		TInt						iAction;	
williamr@2
  2440
		};
williamr@2
  2441
williamr@2
  2442
	/** Special case values which can be used instead of a policy element index
williamr@2
  2443
		contained in the array TPolicy::iElementsIndex
williamr@2
  2444
	*/
williamr@2
  2445
	enum TSpecialCase 
williamr@2
  2446
		{
williamr@2
  2447
		/** Indicates a custom check should be made by calling CustomSecurityCheckL() */
williamr@2
  2448
		ECustomCheck 			=255u,
williamr@2
  2449
williamr@2
  2450
		/** Indicates that message is requesting an unsupported function.
williamr@2
  2451
			The message is completed with KErrNotSupported. */
williamr@2
  2452
		ENotSupported			=254u,
williamr@2
  2453
williamr@2
  2454
		/** Indicates that the message is requesting an unrestricted function
williamr@2
  2455
			and therefore should be processed without any further checks. */
williamr@2
  2456
		EAlwaysPass				=253u, 
williamr@2
  2457
williamr@2
  2458
		ESpecialCaseLimit 		=252u, 		/**< @internalTechnology */
williamr@2
  2459
		ESpecialCaseHardLimit	=250u		/**< @internalTechnology */
williamr@2
  2460
		};
williamr@2
  2461
williamr@2
  2462
	/** Object specifying which security checks to perform on each request
williamr@2
  2463
	number and what action to take if the check fails.  
williamr@2
  2464
williamr@2
  2465
	Explanations of each of the members of this class are detailed below.
williamr@2
  2466
williamr@2
  2467
	As explained in CPolicyServer::CPolicyServer, it is important that the
williamr@2
  2468
	instance of this class (CPolicyServer::TPolicy) given to the policy
williamr@2
  2469
	server constructor, exists for the lifetime of the server. For this
williamr@2
  2470
	reason, as well as code size considerations, it is recommended that
williamr@2
  2471
	the TPolicy instance is const static data.
williamr@2
  2472
	The following code segment shows the recommended way of doing this.
williamr@2
  2473
	Further detail on what each of these statements means is given below.
williamr@2
  2474
williamr@2
  2475
	@code
williamr@2
  2476
	const TUint myRangeCount = 4;
williamr@2
  2477
	const TInt myRanges[myRangeCount] = 
williamr@2
  2478
		{
williamr@2
  2479
		0, //range is 0-2 inclusive
williamr@2
  2480
		3, //range is 3-6 inclusive
williamr@2
  2481
		7, //range is 7
williamr@2
  2482
		8, //range is 8-KMaxTInt inclusive
williamr@2
  2483
		};
williamr@2
  2484
	const TUint8 myElementsIndex[myRangeCount] = 
williamr@2
  2485
		{
williamr@2
  2486
		1, 								//applies to 0th range (req num: 0-2)
williamr@2
  2487
		CPolicyServer::ECustomCheck, 	//applies to 1st range (req num: 3-6)
williamr@2
  2488
		0, 								//applies to 2nd range (req num: 7)
williamr@2
  2489
		CPolicyServer::ENotSupported,	//applies to 3rd range (req num: 8-KMaxTInt)
williamr@2
  2490
		};
williamr@2
  2491
	const CPolicyServer::TPolicyElement myElements[] = 
williamr@2
  2492
		{
williamr@2
  2493
		{_INIT_SECURITY_POLICY_C1(ECapabilityDiskAdmin), CPolicyServer::EFailClient},
williamr@2
  2494
		{_INIT_SECURITY_POLICY_C1(ECapabilityLocation), CMyPolicyServer::EQueryUser},
williamr@2
  2495
		}
williamr@2
  2496
	const CPolicySErver::TPolicy myPolicy =
williamr@2
  2497
		{
williamr@2
  2498
		CPolicyServer::EAlwaysPass, //specifies all connect attempts should pass
williamr@2
  2499
		myRangeCount,					
williamr@2
  2500
		myRanges,
williamr@2
  2501
		myElementsIndex,
williamr@2
  2502
		myElements,
williamr@2
  2503
		}
williamr@2
  2504
	@endcode
williamr@2
  2505
	*/
williamr@2
  2506
	class TPolicy
williamr@2
  2507
		{
williamr@2
  2508
	public:
williamr@2
  2509
		/** The index into iElements, or an allowed value of TSpecialCase,
williamr@2
  2510
		that is used to check a connection attempt . */
williamr@2
  2511
		TUint8 iOnConnect;
williamr@2
  2512
williamr@2
  2513
		/** Number of ranges in the iRanges array. */
williamr@2
  2514
		TUint16 iRangeCount;
williamr@2
  2515
williamr@2
  2516
		/** A pointer to an array of ordered ranges of request numbers.  Each
williamr@2
  2517
		element in this array refers to the starting request number of a range.
williamr@2
  2518
		The range of the previous element is up to and including the current
williamr@2
  2519
		element minus 1.  Thus an array like:
williamr@2
  2520
		@code
williamr@2
  2521
		const TInt myRanges[4] = {0, 3, 7, 8};
williamr@2
  2522
		@endcode
williamr@2
  2523
		means that:
williamr@2
  2524
		- the 0th range is 0-2 (inclusive).
williamr@2
  2525
		- the 1st range is 3-6 (inclusive).
williamr@2
  2526
		- the 2nd range is solely request number 7.
williamr@2
  2527
		- the 3rd range is 8-KMaxTInt (inclusive).
williamr@2
  2528
williamr@2
  2529
		Note that the all possible request numbers must be accounted for.  This
williamr@2
  2530
		implies that the first element must be 0.  It also implies that the
williamr@2
  2531
		last range goes from the that element to KMaxTint.  Finally, each
williamr@2
  2532
		element must be strictly greater than the previous element.  As the
williamr@2
  2533
		first element is 0, this clearly implies that iRanges must not contain
williamr@2
  2534
		negative elements. 
williamr@2
  2535
		*/
williamr@2
  2536
		const TInt* iRanges;
williamr@2
  2537
williamr@2
  2538
		/** A pointer to an array of TUint8 values specifying the appropriate action
williamr@2
  2539
		to take for each range in iRanges.  For example, the 0th element of
williamr@2
  2540
		iElementsIndex specifies the appropriate action to take for the 0th
williamr@2
  2541
		range in iRanges.  As such, iElementsIndex must have precisely the same
williamr@2
  2542
		number of elements as iRanges.  
williamr@2
  2543
	
williamr@2
  2544
		The following rules apply to the value of each element in iElementsIndex:
williamr@2
  2545
		-#	Each value must be a valid index into iElements (that is, less than
williamr@2
  2546
			the number of elements in iElements) OR a valid value from
williamr@2
  2547
			TSpecialCase. 
williamr@2
  2548
		-#	Elements' values need not follow any special ordering.
williamr@2
  2549
		-#	Elements may repeat values.
williamr@2
  2550
		
williamr@2
  2551
		Continuing the example from iRanges:
williamr@2
  2552
		@code
williamr@2
  2553
		const TInt myRanges[4] = {0, 3, 7, 8};
williamr@2
  2554
		const TUInt8 myElementsIndex[4] = {
williamr@2
  2555
			1, 
williamr@2
  2556
			CPolicyServer::ECustomCheck, 
williamr@2
  2557
			0, 
williamr@2
  2558
			CPolicyServer::ENotSupported
williamr@2
  2559
			};
williamr@2
  2560
		@endcode
williamr@2
  2561
		This means that:
williamr@2
  2562
		-#	Requests within the first range of myRanges (request numbers 0-2)
williamr@2
  2563
			will be checked against the policy specified by the 1st element of
williamr@2
  2564
			iElements.
williamr@2
  2565
		-#	Requests with the the second range of myRanges (request numbers
williamr@2
  2566
			3-6) require a custom check to determine if they are allowed.  This requires
williamr@2
  2567
			derived server implementations to implement CustomSecurityCheckL()
williamr@2
  2568
		-#	Requests within the third range of myRanges (request number 7) will
williamr@2
  2569
			be checked against the policy specified by the 0th element of iElements.
williamr@2
  2570
		-#	Requests within the fourth range of myRanges (request numbers
williamr@2
  2571
			8-KMaxTInt) will automatically be completed with KErrNotSupported by
williamr@2
  2572
			the policy server framework.
williamr@2
  2573
		*/
williamr@2
  2574
		const TUint8* iElementsIndex;
williamr@2
  2575
williamr@2
  2576
		/** A pointer to an array of distinct policy elements.
williamr@2
  2577
williamr@2
  2578
		Continuing with the previous examples:
williamr@2
  2579
		@code
williamr@2
  2580
		const TInt myRanges[4] = {0, 3, 7, 8};
williamr@2
  2581
		const TUInt8 myElementsIndex[4] = {
williamr@2
  2582
			1, 
williamr@2
  2583
			CPolicyServer::ECustomCheck, 
williamr@2
  2584
			0, 
williamr@2
  2585
			CPolicyServer::ENotSupported
williamr@2
  2586
			};
williamr@2
  2587
		const TPolicyElement iElements[] = {
williamr@2
  2588
			{_INIT_SECURITY_POLICY_C1(ECapabilityDiskAdmin), CPolicyServer::EFailClient},
williamr@2
  2589
			{_INIT_SECURITY_POLICY_C1(ECapabilityLocation), CMyPolicyServer::EQueryUser}
williamr@2
  2590
			}
williamr@2
  2591
		@endcode
williamr@2
  2592
williamr@2
  2593
		The instantiation of iElements specifies that:
williamr@2
  2594
		-#	Request numbers 0-2 require the Location capability.  As the
williamr@2
  2595
			iAction member of the 1st element specifies a custom action
williamr@2
  2596
			(represented by the negative number, CMyPolicyServer::EQueryUser),
williamr@2
  2597
			requests without Location will passed to the reimplementation of
williamr@2
  2598
			CustomFailureActionL.
williamr@2
  2599
		-#	Request number 7 requires the DiskAdmin capability.  Requestors
williamr@2
  2600
			without DiskAdmin will have their request completed with
williamr@2
  2601
			KErrPermissionDenied.
williamr@2
  2602
		*/
williamr@2
  2603
		const TPolicyElement* iElements;	
williamr@2
  2604
		};
williamr@2
  2605
williamr@2
  2606
public:
williamr@2
  2607
	/** Process an accepted message which has passed its policy check.
williamr@2
  2608
williamr@2
  2609
	The message is either passed to the ServiceL() method of a session,
williamr@2
  2610
	or, in the case of a connection message, a new session is created.
williamr@2
  2611
		
williamr@2
  2612
	This is called by RunL() to process a message which has passed its security
williamr@2
  2613
	check.  If the server implementation returns EAsync from either
williamr@2
  2614
	CustomSecurityCheckL() or CustomFailureActionL(), then it is the responsibility
williamr@2
  2615
	of the derived server implementation to call ProcessL at a later point if
williamr@2
  2616
	the messages passes the asynchronous check.
williamr@2
  2617
williamr@2
  2618
	This function should only ever be called by derived implementations if
williamr@2
  2619
	asynchronous security checks are in use.
williamr@2
  2620
	*/
williamr@2
  2621
	IMPORT_C void ProcessL(const RMessage2& aMsg);
williamr@2
  2622
williamr@2
  2623
	/** Called when a security check has failed.  
williamr@2
  2624
williamr@2
  2625
	The aAction parameter determines the action taken:
williamr@2
  2626
	-	If aAction==TFailureAction::EFailClient, the message is completed with
williamr@2
  2627
		KErrPermissionDenied.
williamr@2
  2628
	-	If aAction==TFailureAction::EPanicClient, the client thread is panicked.
williamr@2
  2629
	-	If aAction < 0 a call to the virtual function CustomFailureActionL() is made.
williamr@2
  2630
williamr@2
  2631
	This function should only ever be called by derived implementations if
williamr@2
  2632
	asynchronous security checks are in use. 
williamr@2
  2633
williamr@2
  2634
	@param	aMsg	 The message which failed its check.
williamr@2
  2635
	@param	aAction	 The action to take. (See description.)
williamr@2
  2636
	@param 	aMissing A list of the security attributes that were missing from
williamr@2
  2637
					 the checked process.  
williamr@2
  2638
	*/
williamr@2
  2639
	IMPORT_C void CheckFailedL(const RMessage2& aMsg, TInt aAction, const TSecurityInfo& aMissing);
williamr@2
  2640
williamr@2
  2641
	/** Called if a leave occurs during processing of a message.  The
williamr@2
  2642
	underlying framework ensures that leaves which occur during
williamr@2
  2643
	CSession2::ServiceL are passed to CSession2::ServiceError.  Leaves occuring
williamr@2
  2644
	prior to this (ie. during CustomSecurityCheckL() or CustomFailureActionL() ) are
williamr@2
  2645
	completed with the leave code.
williamr@2
  2646
williamr@2
  2647
	This function should only ever be called by derived implementations if
williamr@2
  2648
	asynchronous security checks are in use.  In this case the RunError() of
williamr@2
  2649
	that other active object must call ProcessError().
williamr@2
  2650
williamr@2
  2651
	@param	aMsg		The message being processed when the leave occurred.
williamr@2
  2652
	@param	aError		The leave code.
williamr@2
  2653
	*/
williamr@2
  2654
	IMPORT_C void ProcessError(const RMessage2& aMsg, TInt aError);
williamr@2
  2655
williamr@2
  2656
protected:
williamr@2
  2657
	/** Construct a policy server
williamr@2
  2658
williamr@2
  2659
	@param aPriority	Active object priority for this server
williamr@2
  2660
	@param aPolicy		Reference to a policy object describing the security checks
williamr@2
  2661
						required for each message type.  The server does not make a
williamr@2
  2662
						copy of policy, and therefore this object must exist for the
williamr@2
  2663
						lifetime of the server.  It is recommended that aPolicy
williamr@2
  2664
						is in const static data.
williamr@2
  2665
	@param aType		Type of session sharing supported by this server
williamr@2
  2666
	*/
williamr@2
  2667
	IMPORT_C CPolicyServer(TInt aPriority, const TPolicy& aPolicy, TServerType aType=EUnsharableSessions);
williamr@2
  2668
williamr@2
  2669
	/** Performs a custom security check.
williamr@2
  2670
	Derived server classes must implement this function if any element in
williamr@2
  2671
	iElementsIndex has the value CPolicyServer::ECustomCheck.
williamr@2
  2672
	Similarly, if CPolicyServer::ECustomCheck is not used, then this function
williamr@2
  2673
	can be safely ignored.
williamr@2
  2674
williamr@2
  2675
	If CPolicyServer::ECustomCheck is used, there are two further cases to consider:
williamr@2
  2676
	-#	The custom security check can synchronously decide if the message
williamr@2
  2677
		should pass.  In this case, the derived implementation must simply return
williamr@2
  2678
		either EPass or EFail depending on the result of the security check.
williamr@2
  2679
	-#	The custom security check needs to use asynchronous methods in order
williamr@2
  2680
		to determine whether the message should procceed.  In this case, these
williamr@2
  2681
		asysnchronous methods should be started and then the EAsync value returned.
williamr@2
  2682
		Furthermore, implmentations returning EAsync commit to the following:
williamr@2
  2683
		-	If the security check eventually passes, ProcessL() must be called with
williamr@2
  2684
			the appropriate message.
williamr@2
  2685
		-	If the security check eventually fails, CheckFailedL() must be called
williamr@2
  2686
			with that message.
williamr@2
  2687
		-	Pending messages on a given session need to be completed and discarded
williamr@2
  2688
			if the session is closed.
williamr@2
  2689
williamr@2
  2690
		IMPORTANT NOTE. When processing a message asynchronously, a copy must be
williamr@2
  2691
		made of the RMessage2 object. Saving a refernece or pointer to the original
williamr@2
  2692
		message will produce unpredictable defects. This is because the object will
williamr@2
  2693
		be reused for the next message that the server receives.
williamr@2
  2694
		
williamr@2
  2695
	In both cases, synchronous and asynchronous, the derived implementation has the
williamr@2
  2696
	option of updating the aAction and/or aMissing parameters if that is
williamr@2
  2697
	appropriate.
williamr@2
  2698
williamr@2
  2699
	@param	aMsg The message to check.
williamr@2
  2700
	@param	aAction A reference to the action to take if the security check
williamr@2
  2701
			fails. This is either a value from TFailureAction or a negative
williamr@2
  2702
			value which has meaning to the CustomFailureActionL() method of
williamr@2
  2703
			a derived class.
williamr@2
  2704
			The policy server framework gives this value a default of
williamr@2
  2705
			EFailClient.  If a derived implementation wishes a
williamr@2
  2706
			different value, then it should change this.
williamr@2
  2707
	@param 	aMissing A reference to the list of security attributes missing
williamr@2
  2708
			from the checked process.  The policy server initialises this
williamr@2
  2709
			object to zero (that is a sid of 0, a vid of 0, and no capabilities).
williamr@2
  2710
			If derived implementations wish to take advantage of a list of
williamr@2
  2711
			missing attributes in their implementation of CustomFailureActionL(),
williamr@2
  2712
			then they should set those missing attributes here in
williamr@2
  2713
			CustomSecurityCheckL().
williamr@2
  2714
	@return A value from TCustomResult.  
williamr@2
  2715
	@panic CBase 95 If the default implementation is called.
williamr@2
  2716
	*/
williamr@2
  2717
	IMPORT_C virtual TCustomResult CustomSecurityCheckL(const RMessage2& aMsg, TInt& aAction, TSecurityInfo& aMissing);
williamr@2
  2718
williamr@2
  2719
	/** Performs a custom action after the failure of a security check.
williamr@2
  2720
	Derived server classes must implement this function if the aAction value
williamr@2
  2721
	passed to CheckFailedL() is less than zero.  This can happened if the policy
williamr@2
  2722
	specified a negative number in the iAction member of any of the
williamr@2
  2723
	TPolicyElements, or, if the derived CustomSecurityCheckL() modified the
williamr@2
  2724
	value of aAction prior to returning.
williamr@2
  2725
	
williamr@2
  2726
	If negative aAction values are used, there are two further cases to consider:
williamr@2
  2727
	-#	The custom security check can synchronously decide if the message
williamr@2
  2728
		should pass.  In this case, the derived implementation must simply return
williamr@2
  2729
		either EPass or EFail depending on the result of the security check.
williamr@2
  2730
	-#	The custom security check needs to use asynchronous methods in order
williamr@2
  2731
		to determine whether the message should still proceed.  In this case, these
williamr@2
  2732
		asysnchronous methods should be started and then the EAsync value returned.
williamr@2
  2733
		Furthermore, implmentations returning EAsync commit to the following:
williamr@2
  2734
		-	If the security check eventually passes, ProcessL() must be called with
williamr@2
  2735
			the appropriate message.
williamr@2
  2736
		-	If the security check eventually fails, or if a fatal error condition occurs, 
williamr@2
  2737
			including if the previously mentioned call to ProcessL() leaves; 
williamr@2
  2738
			then CPolicyServer::ProcessError() should be called passing the message and 
williamr@2
  2739
			relevant error code.
williamr@2
  2740
		-	Pending messages on a given session need to be completed and discarded 
williamr@2
  2741
			if the session is closed.
williamr@2
  2742
williamr@2
  2743
		IMPORTANT NOTE. When processing a message asynchronously, a copy must be
williamr@2
  2744
		made of the RMessage2 object. Saving a refernece or pointer to the original
williamr@2
  2745
		message will produce unpredictable defects. This is because the object will
williamr@2
  2746
		be reused for the next message that the server receives.
williamr@2
  2747
williamr@2
  2748
	The default implementation of this function panics the server.
williamr@2
  2749
williamr@2
  2750
	@param	aMsg The message to check
williamr@2
  2751
	@param	aAction The custom failure action requested.
williamr@2
  2752
					This is either a value from TFailureAction or a negative
williamr@2
  2753
					value which has meaning to the CustomFailureActionL() method of
williamr@2
  2754
					a derived class.
williamr@2
  2755
	@param 	aMissing A const reference to the list of security attributes missing
williamr@2
  2756
			from the checked process.  There are two cases to consider:
williamr@2
  2757
			(a) If this message was checked (and failed) by a static policy
williamr@2
  2758
				applied by the policy server framework, aMissing will contain a
williamr@2
  2759
				list of the security attributes that caused the policy to fail.  An
williamr@2
  2760
				completely zeroed aMissing implies that an always fail policy was
williamr@2
  2761
				encountered.
williamr@2
  2762
			(b) If this message was failed by a custom security check, then
williamr@2
  2763
				aMissing will be zeroed unless the CustomSecurityCheckL() method
williamr@2
  2764
				filled it in.
williamr@2
  2765
	@return A value from TCustomResult.  
williamr@2
  2766
	@panic CBase 95 If the default implementation is called.
williamr@2
  2767
	*/
williamr@2
  2768
	IMPORT_C virtual TCustomResult CustomFailureActionL(const RMessage2& aMsg, TInt aAction, const TSecurityInfo& aMissing);
williamr@2
  2769
williamr@2
  2770
protected:
williamr@2
  2771
	IMPORT_C virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1);
williamr@2
  2772
private:
williamr@2
  2773
	IMPORT_C virtual void RunL();
williamr@2
  2774
	IMPORT_C virtual TInt RunError(TInt aError);
williamr@2
  2775
	const CPolicyServer::TPolicyElement* FindPolicyElement(TInt aFn, TUint& aSpecialCase) const;
williamr@2
  2776
private:
williamr@2
  2777
	const TPolicy& iPolicy;
williamr@2
  2778
williamr@2
  2779
	};
williamr@2
  2780
williamr@2
  2781
williamr@2
  2782
williamr@2
  2783
class CActiveScheduler : public CBase
williamr@2
  2784
/**
williamr@2
  2785
@publishedAll
williamr@2
  2786
@released
williamr@2
  2787
williamr@2
  2788
Controls the handling of asynchronous requests as represented by
williamr@2
  2789
active objects.
williamr@2
  2790
williamr@2
  2791
An active scheduler is used to schedule the sequence in which active object request
williamr@2
  2792
completion events are handled by a single event-handling thread.
williamr@2
  2793
williamr@2
  2794
An active scheduler can be instantiated and used directly if either:
williamr@2
  2795
williamr@2
  2796
- the RunL() function of all of its active objects is guaranteed not to leave, or
williamr@2
  2797
williamr@2
  2798
- each of its active objects implements a suitable RunError() function to provide suitable cleanup
williamr@2
  2799
williamr@2
  2800
If any of the active scheduler's active objects does not provide a RunError()
williamr@2
  2801
function, then a CActiveScheduler derived class must be defined and an implementation
williamr@2
  2802
of the Error() function provided to perform the cleanup required.
williamr@2
  2803
williamr@2
  2804
There is one active scheduler per thread and the static functions provided by the
williamr@2
  2805
class always refer to the current active scheduler.
williamr@2
  2806
williamr@2
  2807
@see CActiveScheduler::Error
williamr@2
  2808
@see CActive 
williamr@2
  2809
@see CActiveSchedulerWait
williamr@2
  2810
*/
williamr@2
  2811
	{
williamr@2
  2812
	friend class CActiveSchedulerWait;
williamr@2
  2813
public:
williamr@2
  2814
	struct TLoop;
williamr@2
  2815
	typedef TLoop* TLoopOwner;
williamr@2
  2816
public:
williamr@2
  2817
	IMPORT_C CActiveScheduler();
williamr@2
  2818
	IMPORT_C ~CActiveScheduler();
williamr@2
  2819
	IMPORT_C static void Install(CActiveScheduler* aScheduler);
williamr@2
  2820
	IMPORT_C static CActiveScheduler* Current();
williamr@2
  2821
	IMPORT_C static void Add(CActive* aActive);
williamr@2
  2822
	IMPORT_C static void Start();
williamr@2
  2823
	IMPORT_C static void Stop();
williamr@2
  2824
	IMPORT_C static TBool RunIfReady(TInt& aError, TInt aMinimumPriority);
williamr@2
  2825
	IMPORT_C static CActiveScheduler* Replace(CActiveScheduler* aNewActiveScheduler);
williamr@2
  2826
	IMPORT_C virtual void WaitForAnyRequest();
williamr@2
  2827
	IMPORT_C virtual void Error(TInt aError) const;
williamr@2
  2828
	IMPORT_C void Halt(TInt aExitCode) const;
williamr@2
  2829
	IMPORT_C TInt StackDepth() const;
williamr@2
  2830
private:
williamr@2
  2831
	class TCleanupBundle
williamr@2
  2832
	{
williamr@2
  2833
		public:
williamr@2
  2834
		CCleanup* iCleanupPtr;
williamr@2
  2835
		TInt iDummyInt;
williamr@2
  2836
	};
williamr@2
  2837
private:
williamr@2
  2838
	static void Start(TLoopOwner* aOwner);
williamr@2
  2839
	IMPORT_C virtual void OnStarting();
williamr@2
  2840
	IMPORT_C virtual void OnStopping();
williamr@2
  2841
	IMPORT_C virtual void Reserved_1();
williamr@2
  2842
	IMPORT_C virtual void Reserved_2();
williamr@2
  2843
	void Run(TLoopOwner* const volatile& aLoop);
williamr@2
  2844
	void DoRunL(TLoopOwner* const volatile& aLoop, CActive* volatile & aCurrentObj, TCleanupBundle* aCleanupBundle);
williamr@2
  2845
protected:
williamr@2
  2846
	IMPORT_C virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1);
williamr@2
  2847
protected:
williamr@2
  2848
	inline TInt Level() const;	// deprecated
williamr@2
  2849
private:
williamr@2
  2850
	TLoop* iStack;
williamr@2
  2851
	TPriQue<CActive> iActiveQ;
williamr@2
  2852
	TAny* iSpare;
williamr@2
  2853
	};
williamr@2
  2854
williamr@2
  2855
williamr@2
  2856
williamr@2
  2857
williamr@2
  2858
class CActiveSchedulerWait : public CBase
williamr@2
  2859
/**
williamr@2
  2860
@publishedAll
williamr@2
  2861
@released
williamr@2
  2862
williamr@2
  2863
Controls a single scheduling loop in the current active scheduler.
williamr@2
  2864
williamr@2
  2865
This class provides better control of nested wait loops in the active
williamr@2
  2866
scheduler.
williamr@2
  2867
williamr@2
  2868
Note that a CActiveSchedulerWait object can be used as a data member
williamr@2
  2869
inside other CBase derived classes.
williamr@2
  2870
williamr@2
  2871
@see CActiveScheduler
williamr@2
  2872
*/
williamr@2
  2873
	{
williamr@2
  2874
public:
williamr@2
  2875
	IMPORT_C CActiveSchedulerWait();
williamr@2
  2876
	IMPORT_C ~CActiveSchedulerWait();
williamr@2
  2877
	IMPORT_C void Start();
williamr@2
  2878
	IMPORT_C void AsyncStop();
williamr@2
  2879
	IMPORT_C void AsyncStop(const TCallBack& aCallMeWhenStopped);
williamr@2
  2880
	inline TBool IsStarted() const;
williamr@2
  2881
	IMPORT_C TBool CanStopNow() const;
williamr@2
  2882
private:
williamr@2
  2883
	CActiveScheduler::TLoopOwner iLoop;
williamr@2
  2884
	};
williamr@2
  2885
williamr@2
  2886
williamr@2
  2887
williamr@2
  2888
williamr@2
  2889
class CleanupStack
williamr@2
  2890
/**
williamr@2
  2891
@publishedAll
williamr@2
  2892
@released
williamr@2
  2893
williamr@2
  2894
A collection of static functions that are used to add resources to and remove 
williamr@2
  2895
resources from the cleanup stack.
williamr@2
  2896
*/
williamr@2
  2897
	{
williamr@2
  2898
public:
williamr@2
  2899
	IMPORT_C static void PushL(TAny* aPtr);
williamr@2
  2900
	IMPORT_C static void PushL(CBase* aPtr);
williamr@2
  2901
	IMPORT_C static void PushL(TCleanupItem anItem);
williamr@2
  2902
	IMPORT_C static void Pop();
williamr@2
  2903
	IMPORT_C static void Pop(TInt aCount);
williamr@2
  2904
	IMPORT_C static void PopAndDestroy();
williamr@2
  2905
	IMPORT_C static void PopAndDestroy(TInt aCount);
williamr@2
  2906
	IMPORT_C static void Check(TAny* aExpectedItem);
williamr@2
  2907
	inline static void Pop(TAny* aExpectedItem);
williamr@2
  2908
	inline static void Pop(TInt aCount, TAny* aLastExpectedItem);
williamr@2
  2909
	inline static void PopAndDestroy(TAny* aExpectedItem);
williamr@2
  2910
	inline static void PopAndDestroy(TInt aCount, TAny* aLastExpectedItem);
williamr@2
  2911
	};
williamr@2
  2912
williamr@2
  2913
williamr@2
  2914
williamr@2
  2915
williamr@2
  2916
/**
williamr@2
  2917
@publishedAll
williamr@2
  2918
@released
williamr@2
  2919
williamr@2
  2920
A utility class used by the templated function CleanupDeletePushL() to create 
williamr@2
  2921
a TCleanupItem item that will perform a delete type operation on
williamr@2
  2922
the class T type object.
williamr@2
  2923
williamr@2
  2924
@see CleanupDeletePushL()
williamr@2
  2925
*/
williamr@2
  2926
template <class T>
williamr@2
  2927
class CleanupDelete
williamr@2
  2928
	{
williamr@2
  2929
public:
williamr@2
  2930
	inline static void PushL(T* aPtr);
williamr@2
  2931
private:
williamr@2
  2932
	static void Delete(TAny *aPtr);
williamr@2
  2933
	};
williamr@2
  2934
	
williamr@2
  2935
	
williamr@2
  2936
williamr@2
  2937
	
williamr@2
  2938
/**
williamr@2
  2939
@publishedAll
williamr@2
  2940
@released
williamr@2
  2941
williamr@2
  2942
Constructs and pushes a TCleanupItem object onto the cleanup stack.
williamr@2
  2943
williamr@2
  2944
The TCleanupItem encapsulates:
williamr@2
  2945
williamr@2
  2946
- the pointer aPtr to the object of type class T which is to be cleaned up
williamr@2
  2947
williamr@2
  2948
- an associated cleanup operation.
williamr@2
  2949
williamr@2
  2950
The cleanup operation is the private static function Delete() of the templated
williamr@2
  2951
class CleanupDelete, and is called as a result of a subsequent call
williamr@2
  2952
to CleanupStack::PopAndDestroy().
williamr@2
  2953
williamr@2
  2954
CleanupDelete::Delete() is passed a pointer to the class T object to be cleaned
williamr@2
  2955
up, and the function implements cleanup by deleting the passed object.
williamr@2
  2956
williamr@2
  2957
An example of its use:
williamr@2
  2958
williamr@2
  2959
@code
williamr@2
  2960
...
williamr@2
  2961
CTestOne* one = new (ELeave) CTestOne;
williamr@2
  2962
CleanupDeletePushL(one);
williamr@2
  2963
...
williamr@2
  2964
CleanupStack::PopAndDestroy(); // <--- results in "one" being deleted.
williamr@2
  2965
...
williamr@2
  2966
@endcode
williamr@2
  2967
williamr@2
  2968
@param aPtr A pointer to a templated class T type object for which the cleanup item is being created. 
williamr@2
  2969
williamr@2
  2970
@see TCleanupItem
williamr@2
  2971
@see CleanupDelete
williamr@2
  2972
@see CleanupStack::PopAndDestroy()
williamr@2
  2973
*/
williamr@2
  2974
template <class T>
williamr@2
  2975
inline void CleanupDeletePushL(T* aPtr);
williamr@2
  2976
williamr@2
  2977
williamr@2
  2978
williamr@2
  2979
williamr@2
  2980
/**
williamr@2
  2981
@publishedAll
williamr@2
  2982
@released
williamr@2
  2983
williamr@2
  2984
A utility class used by the templated function CleanupArrayDeletePushL() to 
williamr@2
  2985
create a TCleanupItem item that will perform a delete type operation on an 
williamr@2
  2986
array of class T type objects.
williamr@2
  2987
williamr@2
  2988
@see CleanupArrayDeletePushL()
williamr@2
  2989
*/
williamr@2
  2990
template <class T>
williamr@2
  2991
class CleanupArrayDelete
williamr@2
  2992
	{
williamr@2
  2993
public:
williamr@2
  2994
	inline static void PushL(T* aPtr);
williamr@2
  2995
private:
williamr@2
  2996
	static void ArrayDelete(TAny *aPtr);
williamr@2
  2997
	};
williamr@2
  2998
williamr@2
  2999
williamr@2
  3000
williamr@2
  3001
williamr@2
  3002
/**
williamr@2
  3003
@publishedAll
williamr@2
  3004
@released
williamr@2
  3005
williamr@2
  3006
Constructs and pushes a TCleanupItem object onto the cleanup stack.
williamr@2
  3007
williamr@2
  3008
The TCleanupItem encapsulates:
williamr@2
  3009
williamr@2
  3010
- the pointer aPtr to an array of type class T objects to be cleaned up
williamr@2
  3011
williamr@2
  3012
- an associated cleanup operation.
williamr@2
  3013
williamr@2
  3014
The cleanup operation is the private static function ArrayDelete() of the
williamr@2
  3015
templated class CleanupArrayDelete, and is called as a result of
williamr@2
  3016
a subsequent call to CleanupStack::PopAndDestroy().
williamr@2
  3017
williamr@2
  3018
CleanupArrayDelete::ArrayDelete() is passed a pointer to the array of class T
williamr@2
  3019
objects to be cleaned up, and the function implements cleanup by deleting
williamr@2
  3020
the passed array using the delete [] operator.
williamr@2
  3021
williamr@2
  3022
An example of its use:
williamr@2
  3023
williamr@2
  3024
@code
williamr@2
  3025
...
williamr@2
  3026
RTestOne* one = new (ELeave) RTestOne [KSomeArraySize];
williamr@2
  3027
CleanupArrayDeletePushL(one);
williamr@2
  3028
... // Do something with the object.........
williamr@2
  3029
CleanupStack::PopAndDestroy(); // <--- results in the array "one" being deleted.
williamr@2
  3030
...
williamr@2
  3031
@endcode
williamr@2
  3032
williamr@2
  3033
@param aPtr A pointer to an array of class T type objects for which
williamr@2
  3034
            the cleanup item is being created.
williamr@2
  3035
williamr@2
  3036
@see TCleanupItem
williamr@2
  3037
@see CleanupArrayDelete
williamr@2
  3038
@see CleanupStack::PopAndDestroy()
williamr@2
  3039
*/
williamr@2
  3040
template <class T>
williamr@2
  3041
inline void CleanupArrayDeletePushL(T* aPtr);
williamr@2
  3042
williamr@2
  3043
williamr@2
  3044
williamr@2
  3045
williamr@2
  3046
/**
williamr@2
  3047
@publishedAll
williamr@2
  3048
@released
williamr@2
  3049
williamr@2
  3050
A utility class used by the templated function CleanupClosePushL() to create 
williamr@2
  3051
a TCleanupItem item that will perform a close type operation on
williamr@2
  3052
the class T type object.
williamr@2
  3053
williamr@2
  3054
@see CleanupClosePushL()
williamr@2
  3055
*/
williamr@2
  3056
template <class T>
williamr@2
  3057
class CleanupClose
williamr@2
  3058
	{
williamr@2
  3059
public:
williamr@2
  3060
	inline static void PushL(T& aRef);
williamr@2
  3061
private:
williamr@2
  3062
	static void Close(TAny *aPtr);
williamr@2
  3063
	};
williamr@2
  3064
	
williamr@2
  3065
	
williamr@2
  3066
williamr@2
  3067
	
williamr@2
  3068
/**
williamr@2
  3069
@publishedAll
williamr@2
  3070
@released
williamr@2
  3071
williamr@2
  3072
Constructs and pushes a TCleanupItem object onto the cleanup stack.
williamr@2
  3073
williamr@2
  3074
The TCleanupItem encapsulates:
williamr@2
  3075
williamr@2
  3076
1. a reference aRef to the object of type class T which is to be cleaned up
williamr@2
  3077
williamr@2
  3078
2. an associated cleanup operation.
williamr@2
  3079
williamr@2
  3080
The cleanup operation is the private static function Close() of the templated
williamr@2
  3081
class CleanupClose and is invoked as a result of a subsequent call to
williamr@2
  3082
CleanupStack::PopAndDestroy().
williamr@2
  3083
williamr@2
  3084
CleanupClose::Close() is passed a pointer to the class T object to be cleaned
williamr@2
  3085
up, and the function implements cleanup by calling Close() on the passed object.
williamr@2
  3086
The class T object must, therefore, define and implement (or inherit)  a Close()
williamr@2
  3087
member function.
williamr@2
  3088
williamr@2
  3089
An example of its use:
williamr@2
  3090
williamr@2
  3091
@code
williamr@2
  3092
class RTestTwo;
williamr@2
  3093
	{
williamr@2
  3094
public :
williamr@2
  3095
    ...
williamr@2
  3096
	IMPORT_C void Close();
williamr@2
  3097
	...
williamr@2
  3098
	}
williamr@2
  3099
...
williamr@2
  3100
RTestTwo two;
williamr@2
  3101
CleanupClosePushL(two);
williamr@2
  3102
...
williamr@2
  3103
CleanupStack::PopAndDestroy(); // <--- results in Close() being called on "two".
williamr@2
  3104
......
williamr@2
  3105
@endcode
williamr@2
  3106
williamr@2
  3107
In practice, this type of cleanup operation is commonly applied to handles
williamr@2
  3108
to resources; if such handles are constructed on the program stack, then it is
williamr@2
  3109
important that such handles are closed.
williamr@2
  3110
williamr@2
  3111
@param aRef A reference to a class T type object for which the cleanup item
williamr@2
  3112
            is being created.
williamr@2
  3113
williamr@2
  3114
@see TCleanupItem
williamr@2
  3115
@see CleanupClose
williamr@2
  3116
@see CleanupStack::PopAndDestroy()
williamr@2
  3117
*/
williamr@2
  3118
template <class T>
williamr@2
  3119
inline void CleanupClosePushL(T& aRef);
williamr@2
  3120
williamr@2
  3121
williamr@2
  3122
williamr@2
  3123
williamr@2
  3124
/**
williamr@2
  3125
@publishedAll
williamr@2
  3126
@released
williamr@2
  3127
williamr@2
  3128
A utility class used by the templated function CleanupReleasePushL() to create 
williamr@2
  3129
a TCleanupItem item that will perform a release type operation on
williamr@2
  3130
the class T type object.
williamr@2
  3131
williamr@2
  3132
@see CleanupReleasePushL()
williamr@2
  3133
*/
williamr@2
  3134
template <class T>
williamr@2
  3135
class CleanupRelease
williamr@2
  3136
	{
williamr@2
  3137
public:
williamr@2
  3138
	inline static void PushL(T& aRef);
williamr@2
  3139
private:
williamr@2
  3140
	static void Release(TAny *aPtr);
williamr@2
  3141
	};
williamr@2
  3142
	
williamr@2
  3143
	
williamr@2
  3144
williamr@2
  3145
	
williamr@2
  3146
/**
williamr@2
  3147
@publishedAll
williamr@2
  3148
@released
williamr@2
  3149
williamr@2
  3150
Constructs and pushes a TCleanupItem object onto the cleanup stack.
williamr@2
  3151
williamr@2
  3152
The TCleanupItem encapsulates:
williamr@2
  3153
williamr@2
  3154
1. a reference aRef to the object of type class T which is to be cleaned up
williamr@2
  3155
williamr@2
  3156
2. an associated cleanup operation.
williamr@2
  3157
williamr@2
  3158
The cleanup operation is the private static function Release() of the
williamr@2
  3159
templated class CleanupRelease and is invoked as a result of
williamr@2
  3160
a subsequent call to CleanupStack::PopAndDestroy().
williamr@2
  3161
williamr@2
  3162
CleanupRelease::Release() is passed a pointer to the class T object to be cleaned
williamr@2
  3163
up, and the function implements cleanup by calling Release() on the passed object.
williamr@2
  3164
The class T object must, therefore, define and implement (or inherit) a Release()
williamr@2
  3165
member function.
williamr@2
  3166
williamr@2
  3167
An example of its use:
williamr@2
  3168
williamr@2
  3169
@code
williamr@2
  3170
class RTestThree;
williamr@2
  3171
	{
williamr@2
  3172
public :
williamr@2
  3173
    ...
williamr@2
  3174
	IMPORT_C void Release();
williamr@2
  3175
	...
williamr@2
  3176
	}
williamr@2
  3177
...
williamr@2
  3178
RTestThree three;
williamr@2
  3179
CleanupReleasePushL(three);
williamr@2
  3180
...
williamr@2
  3181
CleanupStack::PopAndDestroy(); // <--- results in Release() being called on "three".
williamr@2
  3182
......
williamr@2
  3183
@endcode
williamr@2
  3184
williamr@2
  3185
@param aRef A reference to a class T type object for which the cleanup item 
williamr@2
  3186
            is being created.
williamr@2
  3187
williamr@2
  3188
@see TCleanupItem
williamr@2
  3189
@see CleanupRelease
williamr@2
  3190
@see CleanupStack::PopAndDestroy()
williamr@2
  3191
*/
williamr@2
  3192
template <class T>
williamr@2
  3193
inline void CleanupReleasePushL(T& aRef);
williamr@2
  3194
williamr@2
  3195
williamr@2
  3196
williamr@2
  3197
williamr@2
  3198
class CConsoleBase;
williamr@2
  3199
williamr@2
  3200
/**
williamr@2
  3201
@publishedPartner
williamr@2
  3202
@released
williamr@2
  3203
*/
williamr@2
  3204
class Console
williamr@2
  3205
	{
williamr@2
  3206
public:
williamr@2
  3207
	IMPORT_C static CConsoleBase* NewL(const TDesC& aTitle,TSize aSize);
williamr@2
  3208
	};
williamr@2
  3209
williamr@2
  3210
#include <e32base.inl>
williamr@2
  3211
williamr@4
  3212
#ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
williamr@4
  3213
#include <e32base_private.h>
williamr@4
  3214
#endif
williamr@4
  3215
williamr@2
  3216
#endif //__E32BASE_H__