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