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