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" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\include\e32base.h
23 * Container Base Class
30 Base class for all classes to be instantiated on the heap.
32 By convention, all classes derived from CBase have a name beginning with the
35 The class has two important features:
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().
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.
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
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);
68 IMPORT_C virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1);
71 CBase& operator=(const CBase&);
78 class CBufBase : public CBase
83 Defines the interface for dynamic buffers.
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
89 The ExpandL() and Resize() functions allow some operations to be carried out
90 with greater efficiency
92 A Compress() function frees (back to the heap) any space which may have been
93 allocated, but not used
95 Ptr() and BackPtr() allow look-up of contiguous data from any given position,
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);
116 Compresses the buffer so as to occupy minimal space.
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.
124 Derived classes provide the implementation.
126 @see CBufFlat::Compress
127 @see CBufSeg::Compress
129 virtual void Compress()=0;
131 Deletes data from the buffer.
133 Derived classes provide the implementation.
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
138 @param aLength The number of bytes to be deleted; must be non-negative.
140 @see CBufFlat::Delete
143 virtual void Delete(TInt aPos,TInt aLength)=0;
145 Gets a pointer descriptor to represent the data from the specified position to
146 the end of the contiguous region containing that byte.
148 Derived classes provide the implementation.
150 @param aPos Buffer position: must be in range zero to Size().
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().
159 virtual TPtr8 Ptr(TInt aPos)=0;
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
165 Derived classes provide the implementation.
167 @param aPos Buffer position: must be in range zero to Size().
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.
177 @see CBufFlat::BackPtr
178 @see CBufSeg::BackPtr
180 virtual TPtr8 BackPtr(TInt aPos)=0;
182 virtual void DoInsertL(TInt aPos,const TAny* aPtr,TInt aLength)=0;
184 IMPORT_C CBufBase(TInt anExpandSize);
193 class CBufFlat : public CBufBase
198 Provides a flat storage dynamic buffer.
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
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.
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);
218 IMPORT_C CBufFlat(TInt anExpandSize);
220 IMPORT_C void DoInsertL(TInt aPos,const TAny* aPtr,TInt aLength);
230 class CBufSeg : public CBufBase
235 Provides a segmented dynamic buffer.
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.
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.
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.
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);
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);
266 IMPORT_C void DoInsertL(TInt aPos,const TAny* aPtr,TInt aLength);
268 TDblQue<TBufSegLink> iQue;
277 class TKeyArrayFix : public TKey
282 Defines the characteristics of a key used to access the elements of arrays
283 of fixed length objects.
285 An object of this type can represent three categories of key, depending on
286 the constructor used:
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.
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);
307 IMPORT_C virtual void Set(CBufBase* aBase,TInt aRecordLength);
308 IMPORT_C TAny* At(TInt anIndex) const;
312 friend class CArrayFixBase;
318 typedef CBufBase*(*TBufRep)(TInt anExpandSize);
319 class CArrayFixBase : public CBase
324 Base class for arrays of fixed length objects.
326 It provides implementation and public functions which are common to all arrays
329 The class is always derived from and is never instantiated explicitly.
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);
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);
371 class CArrayFix : public CArrayFixBase
376 A thin templated base class for arrays of fixed length objects.
378 The public functions provide standard array behaviour.
380 The class is always derived from and is never instantiated explicitly.
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);
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;
413 TEMPLATE_SPECIALIZATION class CArrayFix<TAny> : public CArrayFixBase
418 A template specialisation base class for arrays of fixed length
421 The public functions provide standard array behaviour.
423 The class is always derived from and is never instantiated explicitly.
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();
444 class CArrayFixFlat : public CArrayFix<T>
449 Array of fixed length objects contained within a flat dynamic buffer.
451 The elements of the array are instances of the template class T.
453 The flat dynamic buffer is an instance of a CBufFlat.
455 The elements can be T or R type objects and must have an accessible default
458 Note that, where possible, use the RArray<class T> class as this is more
466 inline explicit CArrayFixFlat(TInt aGranularity);
467 inline void SetReserveL(TInt aCount);
473 TEMPLATE_SPECIALIZATION class CArrayFixFlat<TAny> : public CArrayFix<TAny>
478 An array of fixed length untyped objects using a flat dynamic buffer.
480 The array elements are contained within a CBufFlat.
482 The class is useful for constructing an array of fixed length buffers, where
483 the length is decided at run time.
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.
493 inline CArrayFixFlat(TInt aRecordLength,TInt aGranularity);
494 inline void SetReserveL(TInt aCount);
500 TEMPLATE_SPECIALIZATION class CArrayFixFlat<TInt> : public CArrayFix<TInt>
505 Template specialisation base class for arrays of TInt types implemented in a
512 IMPORT_C explicit CArrayFixFlat(TInt aGranularity);
513 IMPORT_C ~CArrayFixFlat();
514 inline void SetReserveL(TInt aCount);
520 TEMPLATE_SPECIALIZATION class CArrayFixFlat<TUid> : public CArrayFix<TUid>
525 Template specialisation base class for arrays of TUid types implemented in a
532 IMPORT_C explicit CArrayFixFlat(TInt aGranularity);
533 IMPORT_C ~CArrayFixFlat();
534 inline void SetReserveL(TInt aCount);
541 class CArrayFixSeg : public CArrayFix<T>
546 Array of fixed length objects contained within a segmented buffer.
548 The elements of the array are instances of the template class T.
550 The segmented buffer is an instance of a CBufSeg.
552 The elements can be T or R type objects and must have an accessible default
559 inline explicit CArrayFixSeg(TInt aGranularity);
565 TEMPLATE_SPECIALIZATION class CArrayFixSeg<TAny> : public CArrayFix<TAny>
570 An array of fixed length untyped objects using a segmented dynamic buffer.
572 The array elements are contained within a CBufSeg.
574 The class is useful for constructing an array of fixed length buffers, where
575 the length is decided at run time.
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.
585 inline CArrayFixSeg(TInt aRecordLength,TInt aGranularity);
592 class CArrayPtr : public CArrayFix<T*>
597 A thin templated base class for arrays of pointers to objects.
599 The public functions contribute to standard array behaviour.
601 The class is always derived from and is never instantiated explicitly.
605 inline CArrayPtr(TBufRep aRep,TInt aGranularity);
606 void ResetAndDestroy();
614 class CArrayPtrFlat : public CArrayPtr<T>
619 Array of pointers to objects implemented using a flat dynamic buffer.
621 The elements of the array are pointers to instances of the template class T
622 and are contained within a CBufFlat.
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
629 Note that where possible, use the RPointerArray<class T> class as this is
633 @see CArrayPtr::ResetAndDestroy
638 inline explicit CArrayPtrFlat(TInt aGranularity);
639 inline void SetReserveL(TInt aCount);
646 class CArrayPtrSeg : public CArrayPtr<T>
651 Array of pointers to objects implemented using a segmented dynamic buffer.
653 The elements of the array are pointers to instances of the template class T
654 and are contained within a CBufSeg.
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
662 @see CArrayPtr::ResetAndDestroy
666 inline explicit CArrayPtrSeg(TInt aGranularity);
672 class TKeyArrayVar : public TKey
677 Defines the characteristics of a key used to access the elements of arrays
678 of variable length objects.
680 An object of this type can represent three categories of key, depending on
681 the constructor used:
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.
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.
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);
707 IMPORT_C virtual void Set(CBufBase* aBase);
708 IMPORT_C TAny* At(TInt anIndex) const;
711 friend class CArrayVarBase;
718 class CArrayVarBase : public CBase
723 An implementation base class for variable length arrays.
725 It provides implementation and public functions which are common to all
726 variable length type arrays.
728 The class is always derived from and is never instantiated explicitly.
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);
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);
763 class CArrayVar : public CArrayVarBase
768 A thin templated base class for variable length arrays.
770 The public functions provide standard array behaviour.
772 The class is always derived from and is never instantiated explicitly.
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;
795 TEMPLATE_SPECIALIZATION class CArrayVar<TAny> : public CArrayVarBase
800 A template specialisation base class for variable length arrays.
802 The array buffer organisation is defined at construction.
804 The class is useful for constructing an array of variable length buffers,
805 where the length is decided at run time.
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.
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);
824 class CArrayVarFlat : public CArrayVar<T>
829 Array of variable length objects implemented using a flat dynamic buffer.
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.
835 The elements can be T or R type objects and must have an accessible default
842 inline explicit CArrayVarFlat(TInt aGranularity);
849 class CArrayVarSeg : public CArrayVar<T>
854 Array of variable length objects implemented using a segmented dynamic buffer.
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.
860 The elements can be T or R type objects and must have an accessible default
867 inline explicit CArrayVarSeg(TInt aGranularity);
873 class TKeyArrayPak : public TKeyArrayVar
878 Defines the characteristics of a key used to access the elements of packed
881 An object of this type can represent three categories of key, depending on
882 the constructor used:
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.
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.
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);
908 IMPORT_C virtual void Set(CBufBase* aBase);
909 IMPORT_C TAny* At(TInt anIndex) const;
913 friend class CArrayPakBase;
919 class CArrayPakBase : public CBase
924 An implementation base class for all variable length, packed arrays.
926 The class is always derived from and is never instantiated explicitly.
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);
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);
965 class CArrayPak : public CArrayPakBase
970 A thin templated base class for variable length, packed, arrays.
972 The public functions provide standard array behaviour.
974 The class is always derived from and is never instantiated explicitly.
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;
997 TEMPLATE_SPECIALIZATION class CArrayPak<TAny> : public CArrayPakBase
1002 A template specialisation base class for variable length, packed, arrays.
1004 The array buffer organisation is defined at construction.
1006 The class is useful for constructing an array of variable length buffers,
1007 where the length is decided at run time.
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.
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);
1026 class CArrayPakFlat : public CArrayPak<T>
1031 Array of variable length objects packed into a flat buffer.
1033 The elements of the array are instances of the template class T and are
1034 contained within a flat dynamic buffer, a CBufFlat.
1036 The elements can be T or R type objects and must have an accessible default
1043 inline explicit CArrayPakFlat(TInt aGranularity);
1050 class CObject : public CBase
1055 Implements reference counting to track concurrent references to itself.
1057 An object of this type arranges automatic destruction of itself when the final
1058 reference is removed.
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.
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;
1081 IMPORT_C virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1);
1083 inline TInt UniqueID() const;
1089 CObjectCon* iContainer;
1093 friend class CObjectCon;
1094 friend class CObjectIx;
1104 struct TObjectDataStr //In use if this slot contains pointer to object.
1116 TObjectDataStr str; //This is in use if the slot contains pointer to CObject.
1117 TInt nextEmpty; //This is in use if the slot is empty. Points to the next empty slot ...
1118 //... in the list. 16 bits would be enough but ARM prefers 32 bytes.
1125 class CObjectIx : public CBase
1130 Generates handle numbers for reference counting objects.
1132 This is referred to as an object index.
1134 Adding a reference counting object to an object index is the way in which
1135 a unique handle number can be generated for that object. A handle number is
1136 the way in which an object, which is owned or managed by another thread or
1137 process can be identified.
1145 When ORd into the handle number, indicates that the reference
1146 counting object cannot be closed.
1148 ENoClose=KHandleNoClose,
1152 When ORed into the handle number, indicates that the handle
1155 ELocalHandle=KHandleFlagLocal
1158 IMPORT_C static CObjectIx* NewL();
1159 IMPORT_C ~CObjectIx();
1160 IMPORT_C TInt AddL(CObject* anObj);
1161 IMPORT_C void Remove(TInt aHandle);
1162 IMPORT_C CObject* At(TInt aHandle,TInt aUniqueID);
1163 IMPORT_C CObject* At(TInt aHandle);
1164 IMPORT_C CObject* AtL(TInt aHandle,TInt aUniqueID);
1165 IMPORT_C CObject* AtL(TInt aHandle);
1166 IMPORT_C TInt At(const CObject* anObject) const;
1167 IMPORT_C TInt Count(CObject* anObject) const;
1168 IMPORT_C CObject* operator[](TInt anIndex);
1169 inline TInt Count() const;
1170 inline TInt ActiveCount() const;
1172 IMPORT_C CObjectIx();
1176 TInt iNumEntries; // Number of actual entries in the index
1177 TInt iHighWaterMark; // points to at least 1 above the highest active index
1178 TInt iAllocated; // Max entries before realloc needed
1180 SObjectIxRec *iObjects;
1181 TInt iFree; // The index of the first free slot or -1.
1182 TInt iUpdateDisabled; // If >0, disables HWM update, reorder of the free list and memory shrinking.
1187 inline TBool IsLocalHandle(TInt aHandle)
1188 {return(aHandle&CObjectIx::ELocalHandle);}
1189 inline void SetLocalHandle(TInt &aHandle)
1190 {aHandle|=CObjectIx::ELocalHandle;}
1191 inline void UnSetLocalHandle(TInt &aHandle)
1192 {aHandle&=(~CObjectIx::ELocalHandle);}
1197 class CObjectCon : public CBase
1202 An object container.
1204 An object container acts as a home for a set of related reference counting
1207 A reference counting object, a CObject type, must be added to an object
1208 container. Only one instance of a given reference counting object can be
1209 held by an object container, i.e. each object within an object container
1212 Object containers are constructed by an object container index, a CObjectConIx
1215 Note that this class is not intended for user derivation.
1227 IMPORT_C static CObjectCon* NewL();
1228 IMPORT_C ~CObjectCon();
1229 IMPORT_C void Remove(CObject* anObj);
1230 IMPORT_C void AddL(CObject* anObj);
1231 IMPORT_C CObject* operator[](TInt anIndex);
1232 IMPORT_C CObject* At(TInt aFindHandle) const;
1233 IMPORT_C CObject* AtL(TInt aFindHandle) const;
1234 IMPORT_C TInt CheckUniqueFullName(const CObject* anOwner,const TDesC& aName) const;
1235 IMPORT_C TInt CheckUniqueFullName(const CObject* anObject) const;
1236 IMPORT_C TInt FindByName(TInt& aFindHandle,const TDesC& aMatch,TName& aName) const;
1237 IMPORT_C TInt FindByFullName(TInt& aFindHandle,const TDesC& aMatch,TFullName& aFullName) const;
1238 inline TInt UniqueID() const;
1239 inline TInt Count() const;
1241 IMPORT_C CObjectCon(TInt aUniqueID);
1242 TBool NamesMatch(const CObject* anObject, const CObject* aCurrentObject) const;
1243 TBool NamesMatch(const CObject* anObject, const TName& anObjectName, const CObject* aCurrentObject) const;
1246 The object container's unique Id value.
1255 friend class CObjectConIx;
1261 class CObjectConIx : public CBase
1266 A container for object containers
1268 This is referred to as a container index.
1270 The class provides the mechanism through which object containers, CObjectCon
1278 IMPORT_C static CObjectConIx* NewL();
1279 IMPORT_C ~CObjectConIx();
1280 IMPORT_C CObjectCon* Lookup(TInt aFindHandle) const;
1281 IMPORT_C CObjectCon* CreateL();
1282 IMPORT_C void Remove(CObjectCon* aCon);
1284 IMPORT_C CObjectConIx();
1285 IMPORT_C void CreateContainerL(CObjectCon*& anObject);
1287 CObjectCon* LookupByUniqueId(TInt aUniqueId) const;
1291 TUint16 iNextUniqueID;
1292 TUint16 iUniqueIDHasWrapped;
1293 CObjectCon** iContainers;
1303 class CBitMapAllocator : public CBase
1306 IMPORT_C static CBitMapAllocator* New(TInt aSize);
1307 IMPORT_C static CBitMapAllocator* NewL(TInt aSize);
1308 IMPORT_C ~CBitMapAllocator();
1309 IMPORT_C TInt Alloc();
1310 IMPORT_C TInt AllocFrom(TInt aPos);
1311 IMPORT_C TInt Alloc(TInt aCount, TInt& aConsecutive);
1312 IMPORT_C TInt AllocAligned(TInt anAlignment);
1313 IMPORT_C TInt AllocAlignedBlock(TInt anAlignment);
1314 IMPORT_C TInt AllocFromTop();
1315 IMPORT_C TInt AllocFromTopFrom(TInt aPos);
1316 IMPORT_C void AllocAt(TInt aPos);
1317 IMPORT_C void AllocAt(TInt aPos, TInt aCount);
1318 IMPORT_C TBool IsFree(TInt aPos);
1319 IMPORT_C TBool IsFree(TInt aPos, TInt aCount);
1320 IMPORT_C void Free(TInt aPos);
1321 IMPORT_C void Free(TInt aPos, TInt aCount);
1322 IMPORT_C TInt Avail();
1323 IMPORT_C TInt Size();
1324 IMPORT_C TInt ExtractRamPages(TInt aConsecutive,TInt& aPageNo);
1326 IMPORT_C CBitMapAllocator(TInt aSize,TInt aLength);
1333 // Forward Declaration of TCleanupStackItem
1334 class TCleanupStackItem;
1343 Defines a function which takes a single argument of type TAny* and returns
1346 An argument of this type is required by the constructors of a TCleanupItem
1349 typedef void (*TCleanupOperation)(TAny*);
1359 Encapsulates a cleanup operation and an object on which the operation
1362 The class allows cleanup to be more sophisticated than simply deleting objects,
1363 for example, releasing access to some shared resource.
1367 inline TCleanupItem(TCleanupOperation anOperation);
1368 inline TCleanupItem(TCleanupOperation anOperation,TAny* aPtr);
1370 TCleanupOperation iOperation;
1372 friend class TCleanupStackItem;
1378 class CCleanup : public CBase
1383 Implements the cleanup stack.
1385 An object of this type is created and used by the cleanup stack
1386 interface, CTrapCleanup.
1390 IMPORT_C static CCleanup* New();
1391 IMPORT_C static CCleanup* NewL();
1392 IMPORT_C ~CCleanup();
1393 IMPORT_C void NextLevel();
1394 IMPORT_C void PreviousLevel();
1395 IMPORT_C void PushL(TAny* aPtr);
1396 IMPORT_C void PushL(CBase* anObject);
1397 IMPORT_C void PushL(TCleanupItem anItem);
1398 IMPORT_C void Pop();
1399 IMPORT_C void Pop(TInt aCount);
1400 IMPORT_C void PopAll();
1401 IMPORT_C void PopAndDestroy();
1402 IMPORT_C void PopAndDestroy(TInt aCount);
1403 IMPORT_C void PopAndDestroyAll();
1404 IMPORT_C void Check(TAny* aExpectedItem);
1406 IMPORT_C void DoPop(TInt aCount,TBool aDestroy);
1407 IMPORT_C void DoPopAll(TBool aDestroy);
1409 IMPORT_C CCleanup();
1412 Pointer to the bottom of the cleanup stack.
1414 TCleanupStackItem* iBase;
1418 Pointer to the top of the cleanup stack.
1420 TCleanupStackItem* iTop;
1424 Pointer to the next availaible slot in the cleanup stack.
1426 TCleanupStackItem* iNext;
1432 NONSHARABLE_CLASS(TCleanupTrapHandler) : public TTrapHandler
1437 Implementation for a handler to work with the TRAP mechanism.
1439 This class does not normally need to be used or accessed directly by applications
1440 and third party code.
1444 TCleanupTrapHandler();
1445 virtual void Trap();
1446 virtual void UnTrap();
1448 virtual void Leave(TInt aValue);
1449 inline CCleanup& Cleanup();
1452 friend class CTrapCleanup;
1464 Automatically calls Close() on an object when that object goes out of scope.
1466 The behaviour takes advantage of the fact that the compiler automatically
1467 destroys objects that go out of scope.
1471 inline ~TAutoClose();
1472 inline void PushL();
1475 static void Close(TAny *aObj);
1478 An instance of the template class.
1486 class CTrapCleanup : public CBase
1491 Cleanup stack interface.
1493 The creation and destruction of a cleanup stack is done automatically by GUI
1494 applications and servers.
1498 IMPORT_C static CTrapCleanup* New();
1499 IMPORT_C ~CTrapCleanup();
1501 IMPORT_C CTrapCleanup();
1503 TCleanupTrapHandler iHandler;
1504 TTrapHandler* iOldHandler;
1510 class CCirBufBase : public CBase
1515 Base class for circular buffers.
1517 The class is part of the implementation of circular buffers and is never
1520 The class provides member functions that form part of the interface.
1524 IMPORT_C ~CCirBufBase();
1525 inline TInt Count() const;
1526 inline TInt Length() const;
1527 IMPORT_C void SetLengthL(TInt aLength);
1528 IMPORT_C void Reset();
1530 IMPORT_C CCirBufBase(TInt aSize);
1531 IMPORT_C TInt DoAdd(const TUint8* aPtr);
1532 IMPORT_C TInt DoAdd(const TUint8* aPtr,TInt aCount);
1533 IMPORT_C TInt DoRemove(TUint8* aPtr);
1534 IMPORT_C TInt DoRemove(TUint8* aPtr,TInt aCount);
1549 class CCirBuf : public CCirBufBase
1554 A circular buffer containing objects of a type defined by the
1560 #if defined(__VC32__)
1561 inline ~CCirBuf() {}
1563 inline TInt Add(const T* aPtr);
1564 inline TInt Add(const T* aPtr,TInt aCount);
1565 inline TInt Remove(T* aPtr);
1566 inline TInt Remove(T* aPtr,TInt aCount);
1572 class CCirBuffer : public CCirBuf<TUint8>
1577 Circular buffer of unsigned integers.
1579 The integer values range from -128 to +127.
1583 IMPORT_C CCirBuffer();
1584 IMPORT_C ~CCirBuffer();
1585 IMPORT_C TInt Get();
1586 IMPORT_C TInt Put(TInt aVal);
1592 class CActive : public CBase
1597 The core class of the active object abstraction.
1599 It encapsulates both the issuing of a request to an asynchronous service provider
1600 and the handling of completed requests. An application can have one or more
1601 active objects whose processing is controlled by an active scheduler.
1607 Defines standard priorities for active objects.
1612 A low priority, useful for active objects representing
1613 background processing.
1619 A priority higher than EPriorityIdle but lower than EPriorityStandard.
1625 Most active objects will have this priority.
1627 EPriorityStandard=0,
1631 A priority higher than EPriorityStandard; useful for active objects
1632 handling user input.
1634 EPriorityUserInput=10,
1638 A priority higher than EPriorityUserInput.
1643 IMPORT_C ~CActive();
1644 IMPORT_C void Cancel();
1645 IMPORT_C void Deque();
1646 IMPORT_C void SetPriority(TInt aPriority);
1647 inline TBool IsActive() const;
1648 inline TBool IsAdded() const;
1649 inline TInt Priority() const;
1651 IMPORT_C CActive(TInt aPriority);
1652 IMPORT_C void SetActive();
1656 Implements cancellation of an outstanding request.
1658 This function is called as part of the active object's Cancel().
1660 It must call the appropriate cancel function offered by the active object's
1661 asynchronous service provider. The asynchronous service provider's cancel
1662 is expected to act immediately.
1664 DoCancel() must not wait for event completion; this is handled by Cancel().
1666 @see CActive::Cancel
1668 virtual void DoCancel() =0;
1672 Handles an active object's request completion event.
1674 A derived class must provide an implementation to handle the
1675 completed request. If appropriate, it may issue another request.
1677 The function is called by the active scheduler when a request
1678 completion event occurs, i.e. after the active scheduler's
1679 WaitForAnyRequest() function completes.
1681 Before calling this active object's RunL() function, the active scheduler
1684 1. decided that this is the highest priority active object with
1687 2. marked this active object's request as complete (i.e. the request is no
1690 RunL() runs under a trap harness in the active scheduler. If it leaves,
1691 then the active scheduler calls RunError() to handle the leave.
1693 Note that once the active scheduler's Start() function has been called,
1694 all user code is run under one of the program's active object's RunL() or
1695 RunError() functions.
1697 @see CActiveScheduler::Start
1698 @see CActiveScheduler::Error
1699 @see CActiveScheduler::WaitForAnyRequest
1702 virtual void RunL() =0;
1703 IMPORT_C virtual TInt RunError(TInt aError);
1705 IMPORT_C virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1);
1709 The request status associated with an asynchronous request.
1711 This is passed as a parameter to all asynchronous service providers.
1713 The active scheduler uses this to check whether the active object's request
1716 The function can use the completion code to judge the success or otherwise
1719 TRequestStatus iStatus;
1724 friend class CActiveScheduler;
1725 friend class CServer;
1726 friend class CServer2;
1732 class CIdle : public CActive
1737 An active object that performs low-priority processing when no higher-priority
1738 active objects are ready to run.
1740 An idle time active object together with its associated callback function
1741 may be used to implement potentially long running background tasks, such as
1742 spreadsheet recalculation and word processor repagination.
1746 IMPORT_C static CIdle* New(TInt aPriority);
1747 IMPORT_C static CIdle* NewL(TInt aPriority);
1749 IMPORT_C void Start(TCallBack aCallBack);
1751 IMPORT_C CIdle(TInt aPriority);
1752 IMPORT_C void RunL();
1753 IMPORT_C void DoCancel();
1757 The callback object that encapsulates the background task.
1761 TCallBack iCallBack;
1767 class CAsyncOneShot : public CActive
1772 An active object that performs processing that is only performed once.
1774 The active object is intended to be given a low priority, so that it runs
1775 only when no higher-priority active objects are ready to run. In addition,
1776 the class ensures that the current thread cannot be closed until the active
1777 object is destroyed.
1779 The class needs to be derived from to make use of its behaviour, in particular,
1780 it needs to define and implement a RunL() function.
1782 NB: the constructor creates a process-relative handle to the current thread
1783 and this is stored within this object. If the thread subsequently dies abnormally,
1784 then this handle will not be closed, and the thread will not be destroyed
1785 until the process terminates.
1787 NB: if Call() is called from a different thread (for example, to implement
1788 a kind of inter-thread communication), a client-specific mechanism must be
1789 used to ensure that the thread that created this object is still alive.
1791 NB: if the thread that created this object has its own heap and terminates
1792 abnormally, then the handle stored within this object is lost.
1795 @see CAsyncOneShot::Call
1799 IMPORT_C CAsyncOneShot(TInt aPriority);
1800 IMPORT_C virtual void DoCancel();
1801 IMPORT_C virtual void Call();
1802 IMPORT_C virtual ~CAsyncOneShot();
1803 inline RThread& Thread();
1812 class CAsyncCallBack : public CAsyncOneShot
1817 An active object that performs its processing through an associated call back
1818 function, and which is only performed once.
1822 IMPORT_C CAsyncCallBack(TInt aPriority);
1823 IMPORT_C CAsyncCallBack(const TCallBack& aCallBack, TInt aPriority);
1824 IMPORT_C void Set(const TCallBack& aCallBack);
1825 IMPORT_C void CallBack();
1826 IMPORT_C virtual ~CAsyncCallBack();
1828 virtual void RunL();
1832 The callback object that encapsulates the callback function.
1834 TCallBack iCallBack;
1840 class TDeltaTimerEntry
1845 A timed event entry.
1847 An object of this type is added to a queue of timed events, as represented
1848 by a CDeltaTimer object. It represents a call back function that is called
1849 when the associated timed event expires.
1854 friend class CDeltaTimer;
1856 inline TDeltaTimerEntry(TCallBack& aCallback);
1857 inline TDeltaTimerEntry();
1858 inline void Set(TCallBack& aCallback);
1860 TCallBack iCallBack;
1861 TTickCountQueLink iLink;
1867 class CDeltaTimer : public CActive
1872 A queue of timed events.
1874 A timed event is a callback function encapsulated by a TDeltaTimerEntry object,
1875 and is intended to be called when the time interval represented by the event
1878 The queue itself is a TDeltaQue list. A timed event entry is added into a
1879 position in the queue that is determined by the time interval specified for
1880 that event. Although the time interval for a timed event is specified as an
1881 interval from the present moment, when added to the queue the implementation
1882 treats each event as having an interval from the previous timed event (or now).
1884 CDeltaTimer is an active object, driven by an RTimer which is usually set to
1885 expire upon completion of the event at the head of the queue. If the time to
1886 the next event is too great or an event at the head of the queue has been
1887 removed, the timer may be set to expire prior to the event at the head of the
1890 When the timer completes, the head of the queue is inspected to see whether
1891 the timed event at the head of the queue has expired. On expiry, the callback
1892 function represented by that timed event is called, and the timed event entry
1893 is removed from the queue. The queue then inspects further events for expiry,
1894 calling and removing them as necessary until either the queue is empty or there
1895 is an event in the future to wait for.
1897 Note that the tick period is the minimum time interval for an event and the
1898 granularity of all timings using the queue. Note that in general, any event
1899 may be called back some time after it has expired and that specifically the
1900 duration of all events will at least be rounded up to a muliple of the tick
1904 @see TDeltaTimerEntry
1911 IMPORT_C virtual void Queue(TTimeIntervalMicroSeconds32 aTimeInMicroSeconds, TDeltaTimerEntry& aEntry);
1912 IMPORT_C virtual void Remove(TDeltaTimerEntry& aEntry);
1913 IMPORT_C TInt QueueLong(TTimeIntervalMicroSeconds aTimeInMicroSeconds, TDeltaTimerEntry& aEntry);
1915 // Factory functions
1916 IMPORT_C static CDeltaTimer* NewL(TInt aPriority);
1917 IMPORT_C static CDeltaTimer* NewL(TInt aPriority, TTimeIntervalMicroSeconds32 aGranularity);
1924 CDeltaTimer(TInt aPriority, TInt aTickPeriod);
1931 void Activate(TBool aRequeueTimer = EFalse);
1935 The asynchronous timer.
1940 The list of timed event entries.
1942 TTickCountQue iQueue;
1945 The period of a tick count.
1947 const TInt iTickPeriod;
1950 Pseudo-lock on the the queue to avoid reentrancy problems
1958 class CTimer : public CActive
1963 Base class for a timer active object.
1965 This is an active object that uses the asynchronous services provided by RTimer,
1966 to generate events. These events occur either at a specific time specified
1967 as a TTime, or after an interval specified in microseconds.
1969 The RunL() virtual member function is called by the active scheduler after
1972 To write a class derived from CTimer, first define and implement a constructor
1973 through which the priority of the CTimer active object can be specified. Then
1974 define and implement a suitable RunL() function to handle the completion of
1975 a timer request. This function is not defined by CTimer itself and must, therefore,
1976 be provided by the derived class.
1978 This class is ultimately implemented in terms of the nanokernel tick, and
1979 therefore the granularity of the generated events is limited to the period of
1980 this timer. This is variant specific, but is usually 1 millisecond.
1982 Note that the CPeriodic and CHeartbeat classes are derived from CTimer, and
1983 answer most timing needs.
1992 IMPORT_C void At(const TTime& aTime);
1993 IMPORT_C void AtUTC(const TTime& aTimeInUTC);
1994 IMPORT_C void After(TTimeIntervalMicroSeconds32 anInterval);
1995 IMPORT_C void Lock(TTimerLockSpec aLock);
1996 IMPORT_C void Inactivity(TTimeIntervalSeconds aSeconds);
1997 IMPORT_C void HighRes(TTimeIntervalMicroSeconds32 aInterval);
1999 IMPORT_C CTimer(TInt aPriority);
2000 IMPORT_C void ConstructL();
2001 IMPORT_C void DoCancel();
2009 class CPeriodic : public CTimer
2014 Periodic timer active object.
2016 This class generates regular timer events and handles them with a callback
2017 function. The callback is specified as a parameter to Start().
2019 The callback may not be called immediately after the signal from the timer
2020 request has been generated, for the following reasons:
2022 1. the RunL() of another active object may be running at the time of the signal
2024 2. other active objects may have a higher priority than the CPeriodic
2026 If timing accuracy is important to your application, you can minimise the
2027 first problem by ensuring all RunL()s complete quickly, and can eliminate
2028 the second by giving the CPeriodic a higher priority than any other active
2029 object. Although it is generally recommended that timer-related active objects
2030 have a high priority, this will not address the problem of CPeriodic timers
2031 running behind, because active object scheduling is not pre-emptive.
2033 After a timer signal generated by a CPeriodic, the next signal is requested
2034 just before running the callback, and this request can be delayed for the
2035 same reasons that running the callback can be delayed. Therefore, a large
2036 number N of periods may add up to somewhat more than N times the requested
2037 period time. If absolute precision is required in tracking time, do not rely
2038 on counting the number of times the callback is called: read the value of
2039 the system clock every time you need it.
2041 For many applications, such precision is not required, for example, tick
2042 counting is sufficiently accurate for controlling time-outs in a communications
2045 Note that you should be familiar with CActive in order to understand
2046 CPeriodic behaviour, but not necessarily with CTimer.
2052 IMPORT_C static CPeriodic* New(TInt aPriority);
2053 IMPORT_C static CPeriodic* NewL(TInt aPriority);
2054 IMPORT_C ~CPeriodic();
2055 IMPORT_C void Start(TTimeIntervalMicroSeconds32 aDelay,TTimeIntervalMicroSeconds32 anInterval,TCallBack aCallBack);
2057 IMPORT_C CPeriodic(TInt aPriority);
2058 IMPORT_C void RunL();
2060 TTimeIntervalMicroSeconds32 iInterval;
2061 TCallBack iCallBack;
2072 Heartbeat timer call-back handling interface.
2074 The interface provides a pair of functions to handle the beating and
2075 synchronisation of heartbeat timers.
2077 The CHeartbeat active object class uses an object implementing the MBeating
2080 @see CHeartbeat::Start
2085 Handles a regular heartbeat timer event.
2087 This type of event is one where the timer completes in synchronisation
2088 with the system clock.
2090 virtual void Beat() =0;
2093 Synchronises the heartbeat timer with system clock.
2095 This function handles a heartbeat timer event where the timer completes out
2096 of synchronisation with the system clock, (i.e. one or more heartbeats have
2099 virtual void Synchronize() =0;
2105 class CHeartbeat : public CTimer
2112 This class generates regular heartbeat events on a fixed fraction of a second.
2113 It is more accurate than a CPeriodic timer, because it provides a function
2114 to restore timer accuracy if it gets out of synchronisation with the system
2117 The protected RunL() function is called when the timer completes. The RunL()
2118 function in turn calls either the MBeating::Beat() or the MBeating::Synchronize()
2119 functions; MBeating is specified as a parameter to the Start() function
2120 used to start the heartbeat timer.
2122 The relevant MBeating function may not be called immediately after the signal
2123 from the timer request has been generated, for the following reasons:
2125 1. the RunL() of another active object may be running at the time of the signal
2127 2. other active objects may have a higher priority than the CHeartbeat
2129 If no heartbeat is missed, then the Beat() function is called.
2131 If one or more heartbeats are missed then the Synchronize() function is called.
2132 It is important to bear in mind that the machine might be switched off after
2133 a few beats of the heart, and then Synchronize() will be called several days
2134 later. It is therefore essential that synchronisation is achieved as quickly
2135 as possible, rather than trying to catch up a tick at a time. In the context
2136 of an analogue clock, for instance, the clock should just redraw itself with
2137 the current time - rather than moving the hands round in steps until the time
2140 CHeartbeat is an active object, derived from CActive (via CTimer). You should
2141 be familiar with CActive in order to understand CHeartbeat behaviour, but
2142 not necessarily with CTimer.
2148 IMPORT_C static CHeartbeat* New(TInt aPriority);
2149 IMPORT_C static CHeartbeat* NewL(TInt aPriority);
2150 IMPORT_C ~CHeartbeat();
2151 IMPORT_C void Start(TTimerLockSpec aLock,MBeating *aBeating);
2153 IMPORT_C CHeartbeat(TInt aPriority);
2154 IMPORT_C void RunL();
2156 TTimerLockSpec iLock;
2170 Represents a session (version 2) for a client thread on the server-side.
2172 A session acts as a channel of communication between the client and the server.
2173 A client thread can have multiple concurrent sessions with a server.
2176 - restricted to the creating thread
2177 - can be shared with other threads in the same process
2178 - can be shared by all threads in the system.
2180 A server must define and implement a derived class. In particular,
2181 it must provide an implementation for the ServiceL() virtual function.
2183 (Note that this class should be used instead of CSession)
2185 class CSession2 : public CBase
2187 friend class CServer2;
2189 IMPORT_C virtual ~CSession2() =0;
2191 IMPORT_C virtual void CreateL(); // Default method, does nothing
2193 inline const CServer2* Server() const;
2194 IMPORT_C void ResourceCountMarkStart();
2195 IMPORT_C void ResourceCountMarkEnd(const RMessage2& aMessage);
2196 IMPORT_C virtual TInt CountResources();
2199 Handles the servicing of a client request that has been passed
2202 This function must be implemented in a derived class. The details of
2203 the request are contained within the message.
2205 @param aMessage The message containing the details of the client request.
2207 virtual void ServiceL(const RMessage2& aMessage) =0;
2208 IMPORT_C virtual void ServiceError(const RMessage2& aMessage,TInt aError);
2210 IMPORT_C CSession2();
2211 IMPORT_C virtual void Disconnect(const RMessage2& aMessage);
2212 IMPORT_C virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1);
2217 enum TPanicNo {ESesCountResourcesNotImplemented=1,ESesFoundResCountHeaven};
2219 TInt iResourceCountMark;
2221 const CServer2* iServer;
2229 Abstract base class for servers (version 2).
2231 This is an active object. It accepts requests from client threads and forwards
2232 them to the relevant server-side client session. It also handles the creation
2233 of server-side client sessions as a result of requests from client threads.
2235 A server must define and implement a derived class.
2237 (Note that this class should be used instead of CServer)
2239 class CServer2 : public CActive
2243 Defines the set of session types that the server can create.
2245 A specific session type is specified when the CServer2 object is created.
2250 The session is not sharable with other threads.
2252 EUnsharableSessions = EIpcSession_Unsharable,
2255 The session is sharable with other threads in the same process.
2257 ESharableSessions = EIpcSession_Sharable,
2260 The session is sharable with all other threads in the system.
2262 EGlobalSharableSessions = EIpcSession_GlobalSharable,
2265 IMPORT_C virtual ~CServer2() =0;
2266 IMPORT_C TInt Start(const TDesC& aName);
2267 IMPORT_C void StartL(const TDesC& aName);
2268 IMPORT_C void ReStart();
2271 Gets a handle to the server.
2273 Note that the RServer2 object is classified as Symbian internal, and its
2274 member functions cannot be acessed. However, the handle can be passed
2275 to the RSessionBase::CreateSession() variants that take a server handle.
2277 @return The handle to the server.
2279 inline RServer2 Server() const { return iServer; }
2281 inline const RMessage2& Message() const;
2282 IMPORT_C CServer2(TInt aPriority, TServerType aType=EUnsharableSessions);
2283 IMPORT_C void DoCancel();
2284 IMPORT_C void RunL();
2285 IMPORT_C TInt RunError(TInt aError);
2286 IMPORT_C virtual void DoConnect(const RMessage2& aMessage);
2287 IMPORT_C virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1);
2291 Creates a server-side session object.
2293 The session represents a communication link between a client and a server,
2294 and its creation is initiated by the client through a call to one of
2295 the RSessionBase::CreateSession() variants.
2297 A server must provide an implementation, which as a minimum should:
2299 - check that the version of the server is compatible with the client by
2300 comparing the client supplied version number against the server's version
2301 number; it should leave if there is incompatibility.
2303 - construct and return the server side client session object.
2305 @param aVersion The version information supplied by the client.
2306 @param aMessage Represents the details of the client request that is requesting
2307 the creation of the session.
2309 @return A pointer to the newly created server-side session object.
2311 @see User::QueryVersionSupported()
2313 IMPORT_C virtual CSession2* NewSessionL(const TVersion& aVersion,const RMessage2& aMessage) const =0;
2314 void Connect(const RMessage2& aMessage);
2315 void DoConnectL(const RMessage2& aMessage,CSession2* volatile& aSession);
2324 ESessionNotConnected,
2325 ESessionAlreadyConnected,
2326 EClientDoesntHaveRequiredCaps,
2333 TDblQue<CSession2> iSessionQ;
2335 TDblQueIter<CSession2> iSessionIter;
2337 void Disconnect(const RMessage2& aMessage);
2338 static void BadMessage(const RMessage2& aMessage);
2339 static void NotConnected(const RMessage2& aMessage);
2340 friend class CPolicyServer;
2346 A security policy framework built on top of the normal CServer2 class.
2348 The two major functions of the Policy Server framework are to check a received
2349 message against a security policy and then to perform an action depending on
2350 the result of this check. The exact behaviour is defined by the contents of
2351 the TPolicy structure given in the constructor for CPolicyServer.
2353 The processing performed when a server receives a message are describe below.
2354 This should aid understanding of the interaction of the TPolicy structure and
2355 virtual member functions which may be implemented by classes derived from CPolicyServer.
2357 Checking the Security Policy
2359 On receipt of a message, the message function number is used to search the
2360 list of ranges pointed to by TPolicy::iRanges. This yields a range
2361 number R, which is between 0 and TPolicy::iRangeCount-1.
2362 The policy index, X, for this range is then fetched from TPolicy::iElementsIndex[R].
2363 If the message is a Connect message, then X is fetched directly from TPolicy::iOnConnect
2366 The further action taken is determined by the value of X.
2367 - If X==TSpecialCase::EAlwaysPass,
2368 the message is processed as normal; either by passing it to the ServiceL()
2369 method of a session, or, in the case of a connection message, a new session
2371 - If X==TSpecialCase::ENotSupported,
2372 the message is completed with KErrNotSupported.
2373 - If X==TSpecialCase::ECustomCheck,
2374 a call to the virtual function CustomSecurityCheckL() is made. The implementation
2375 of this method must return one of the TCustomResult enumerations which determine
2376 what further action is to be taken:
2377 - TCustomResult::EPass
2378 The message is processed as normal; either by passing it to the ServiceL()
2379 method of a session, or, in the case of a connection message, a new session
2381 - TCustomResult::EFail
2382 This causes CheckFailedL() to be called with the action specified by the
2383 aAction reference given to CustomSecurityCheckL() (This defaults to
2384 TFailureAction::EFailClient.)
2385 - TCustomResult::EAsync
2386 The derived class is responsible for further processing of the message,
2387 the Policy Server framework will do nothing more with it.
2388 - If X < TSpecialCase::ESpecialCaseHardLimit,
2389 X is taken as an index into the array of TPolicyElement objects pointed
2390 to by TPolicy::iElements. The platform security attributes of the process
2391 which sent the message being processed are checked against the security
2392 policy specified in this TPolicyElement. If the process possesses all of
2393 the attributes specified then the message processed as normal. Otherwise,
2394 CheckFailedL() is called with the action value specified in the TPolicyElement .
2396 Handling Policy Check Failure
2398 The CheckFailedL() method is called when a security check has failed. It performs
2399 an action according to the aAction value given to it:
2401 - If aAction==TFailureAction::EFailClient, the message is completed with
2402 KErrPermissionDenied.
2403 - If aAction==TFailureAction::EPanicClient, the client thread is panicked.
2404 - If aAction < 0 a call to the virtual function CustomFailureActionL() is made.
2405 The implementation of this method must return one of the TCustomResult
2406 enumerations which determine what further action is to be taken:
2407 - TCustomResult::EPass
2408 The message is processed as normal; either by passing it to the ServiceL()
2409 method of a session, or, in the case of a connection message, a new session
2411 - TCustomResult::EFail
2412 The message is completed with KErrPermissionDenied.
2413 - TCustomResult::EAsync
2414 The derived class is responsible for further processing of the message,
2415 the Policy Server framework will do nothing more with it.
2420 class CPolicyServer : public CServer2
2423 /** Enumeration specifying action to take if a security check fails.
2424 Values >= 0 are handled by CheckFailedL(). Values < 0 are specific to the
2425 derived implementation of the policy server and will result in a call to
2426 CustomFailureActionL() if a security check fails. Attempts to use undefined
2427 values >= 0 will result in a panic in CheckFailedL().
2431 EFailClient = 0, /**< Complete message with KErrPermissionDenied */
2432 EPanicClient= 1, /**< Panic client */
2435 /** Enumeration of acceptable return codes from both of
2436 CustomSecurityCheckL() and CustomFailureActionL(). Results of EPass or EFail
2437 are handled by the CPolicyServer framework. No other action is required on
2438 the part of the derived implementation. However, results of EAsync imply
2439 that the derived implementation will call the appropriate function once the
2440 result is known. See CustomSecurityCheckL() and CustomFailureActionL for
2445 EPass = 0, /**< Security check passed. */
2446 EFail = 1, /**< Security check failed. */
2447 EAsync = 2, /**< Security checking will be performed asynchronously. */
2450 /** Class specifying a security check and the action to take
2452 If iAction is >=0 it must be a member of TFailureAction
2453 If iAction is <0 it is assumed to specify a custom action specific to the
2454 derived implementation. In this case, CustomFailureActionL must be implemented
2455 by the derived class.
2457 class TPolicyElement
2460 /** Security policy to check against the client which sent a message.
2462 This class can specify a security policy consisting of either:
2464 -# A check for between 0 and 7 capabilities
2465 -# A check for a given Secure ID along with 0-3 capabilities
2466 -# A check for a given Vendor ID along with 0-3 capabilities
2468 This member should only be initialised by one of the following macros:
2470 - _INIT_SECURITY_POLICY_PASS
2471 - _INIT_SECURITY_POLICY_FAIL
2472 - _INIT_SECURITY_POLICY_C1
2473 - _INIT_SECURITY_POLICY_C2
2474 - _INIT_SECURITY_POLICY_C3
2475 - _INIT_SECURITY_POLICY_C4
2476 - _INIT_SECURITY_POLICY_C5
2477 - _INIT_SECURITY_POLICY_C6
2478 - _INIT_SECURITY_POLICY_C7
2479 - _INIT_SECURITY_POLICY_S0
2480 - _INIT_SECURITY_POLICY_S1
2481 - _INIT_SECURITY_POLICY_S2
2482 - _INIT_SECURITY_POLICY_S3
2483 - _INIT_SECURITY_POLICY_V0
2484 - _INIT_SECURITY_POLICY_V1
2485 - _INIT_SECURITY_POLICY_V2
2486 - _INIT_SECURITY_POLICY_V3
2490 TStaticSecurityPolicy iPolicy;
2492 /** Action to take on failure. Either a value from TFailureAction
2493 or a negative value which has meaning to the CustomFailureActionL()
2494 method of a derived class.
2499 /** Special case values which can be used instead of a policy element index
2500 contained in the array TPolicy::iElementsIndex
2504 /** Indicates a custom check should be made by calling CustomSecurityCheckL() */
2507 /** Indicates that message is requesting an unsupported function.
2508 The message is completed with KErrNotSupported. */
2509 ENotSupported =254u,
2511 /** Indicates that the message is requesting an unrestricted function
2512 and therefore should be processed without any further checks. */
2515 ESpecialCaseLimit =252u, /**< @internalTechnology */
2516 ESpecialCaseHardLimit =250u /**< @internalTechnology */
2519 /** Object specifying which security checks to perform on each request
2520 number and what action to take if the check fails.
2522 Explanations of each of the members of this class are detailed below.
2524 As explained in CPolicyServer::CPolicyServer, it is important that the
2525 instance of this class (CPolicyServer::TPolicy) given to the policy
2526 server constructor, exists for the lifetime of the server. For this
2527 reason, as well as code size considerations, it is recommended that
2528 the TPolicy instance is const static data.
2529 The following code segment shows the recommended way of doing this.
2530 Further detail on what each of these statements means is given below.
2533 const TUint myRangeCount = 4;
2534 const TInt myRanges[myRangeCount] =
2536 0, //range is 0-2 inclusive
2537 3, //range is 3-6 inclusive
2539 8, //range is 8-KMaxTInt inclusive
2541 const TUint8 myElementsIndex[myRangeCount] =
2543 1, //applies to 0th range (req num: 0-2)
2544 CPolicyServer::ECustomCheck, //applies to 1st range (req num: 3-6)
2545 0, //applies to 2nd range (req num: 7)
2546 CPolicyServer::ENotSupported, //applies to 3rd range (req num: 8-KMaxTInt)
2548 const CPolicyServer::TPolicyElement myElements[] =
2550 {_INIT_SECURITY_POLICY_C1(ECapabilityDiskAdmin), CPolicyServer::EFailClient},
2551 {_INIT_SECURITY_POLICY_C1(ECapabilityLocation), CMyPolicyServer::EQueryUser},
2553 const CPolicySErver::TPolicy myPolicy =
2555 CPolicyServer::EAlwaysPass, //specifies all connect attempts should pass
2566 /** The index into iElements, or an allowed value of TSpecialCase,
2567 that is used to check a connection attempt . */
2570 /** Number of ranges in the iRanges array. */
2571 TUint16 iRangeCount;
2573 /** A pointer to an array of ordered ranges of request numbers. Each
2574 element in this array refers to the starting request number of a range.
2575 The range of the previous element is up to and including the current
2576 element minus 1. Thus an array like:
2578 const TInt myRanges[4] = {0, 3, 7, 8};
2581 - the 0th range is 0-2 (inclusive).
2582 - the 1st range is 3-6 (inclusive).
2583 - the 2nd range is solely request number 7.
2584 - the 3rd range is 8-KMaxTInt (inclusive).
2586 Note that the all possible request numbers must be accounted for. This
2587 implies that the first element must be 0. It also implies that the
2588 last range goes from the that element to KMaxTint. Finally, each
2589 element must be strictly greater than the previous element. As the
2590 first element is 0, this clearly implies that iRanges must not contain
2593 const TInt* iRanges;
2595 /** A pointer to an array of TUint8 values specifying the appropriate action
2596 to take for each range in iRanges. For example, the 0th element of
2597 iElementsIndex specifies the appropriate action to take for the 0th
2598 range in iRanges. As such, iElementsIndex must have precisely the same
2599 number of elements as iRanges.
2601 The following rules apply to the value of each element in iElementsIndex:
2602 -# Each value must be a valid index into iElements (that is, less than
2603 the number of elements in iElements) OR a valid value from
2605 -# Elements' values need not follow any special ordering.
2606 -# Elements may repeat values.
2608 Continuing the example from iRanges:
2610 const TInt myRanges[4] = {0, 3, 7, 8};
2611 const TUInt8 myElementsIndex[4] = {
2613 CPolicyServer::ECustomCheck,
2615 CPolicyServer::ENotSupported
2619 -# Requests within the first range of myRanges (request numbers 0-2)
2620 will be checked against the policy specified by the 1st element of
2622 -# Requests with the the second range of myRanges (request numbers
2623 3-6) require a custom check to determine if they are allowed. This requires
2624 derived server implementations to implement CustomSecurityCheckL()
2625 -# Requests within the third range of myRanges (request number 7) will
2626 be checked against the policy specified by the 0th element of iElements.
2627 -# Requests within the fourth range of myRanges (request numbers
2628 8-KMaxTInt) will automatically be completed with KErrNotSupported by
2629 the policy server framework.
2631 const TUint8* iElementsIndex;
2633 /** A pointer to an array of distinct policy elements.
2635 Continuing with the previous examples:
2637 const TInt myRanges[4] = {0, 3, 7, 8};
2638 const TUInt8 myElementsIndex[4] = {
2640 CPolicyServer::ECustomCheck,
2642 CPolicyServer::ENotSupported
2644 const TPolicyElement iElements[] = {
2645 {_INIT_SECURITY_POLICY_C1(ECapabilityDiskAdmin), CPolicyServer::EFailClient},
2646 {_INIT_SECURITY_POLICY_C1(ECapabilityLocation), CMyPolicyServer::EQueryUser}
2650 The instantiation of iElements specifies that:
2651 -# Request numbers 0-2 require the Location capability. As the
2652 iAction member of the 1st element specifies a custom action
2653 (represented by the negative number, CMyPolicyServer::EQueryUser),
2654 requests without Location will passed to the reimplementation of
2655 CustomFailureActionL.
2656 -# Request number 7 requires the DiskAdmin capability. Requestors
2657 without DiskAdmin will have their request completed with
2658 KErrPermissionDenied.
2660 const TPolicyElement* iElements;
2664 /** Process an accepted message which has passed its policy check.
2666 The message is either passed to the ServiceL() method of a session,
2667 or, in the case of a connection message, a new session is created.
2669 This is called by RunL() to process a message which has passed its security
2670 check. If the server implementation returns EAsync from either
2671 CustomSecurityCheckL() or CustomFailureActionL(), then it is the responsibility
2672 of the derived server implementation to call ProcessL at a later point if
2673 the messages passes the asynchronous check.
2675 This function should only ever be called by derived implementations if
2676 asynchronous security checks are in use.
2678 IMPORT_C void ProcessL(const RMessage2& aMsg);
2680 /** Called when a security check has failed.
2682 The aAction parameter determines the action taken:
2683 - If aAction==TFailureAction::EFailClient, the message is completed with
2684 KErrPermissionDenied.
2685 - If aAction==TFailureAction::EPanicClient, the client thread is panicked.
2686 - If aAction < 0 a call to the virtual function CustomFailureActionL() is made.
2688 This function should only ever be called by derived implementations if
2689 asynchronous security checks are in use.
2691 @param aMsg The message which failed its check.
2692 @param aAction The action to take. (See description.)
2693 @param aMissing A list of the security attributes that were missing from
2694 the checked process.
2696 IMPORT_C void CheckFailedL(const RMessage2& aMsg, TInt aAction, const TSecurityInfo& aMissing);
2698 /** Called if a leave occurs during processing of a message. The
2699 underlying framework ensures that leaves which occur during
2700 CSession2::ServiceL are passed to CSession2::ServiceError. Leaves occuring
2701 prior to this (ie. during CustomSecurityCheckL() or CustomFailureActionL() ) are
2702 completed with the leave code.
2704 This function should only ever be called by derived implementations if
2705 asynchronous security checks are in use. In this case the RunError() of
2706 that other active object must call ProcessError().
2708 @param aMsg The message being processed when the leave occurred.
2709 @param aError The leave code.
2711 IMPORT_C void ProcessError(const RMessage2& aMsg, TInt aError);
2714 /** Construct a policy server
2716 @param aPriority Active object priority for this server
2717 @param aPolicy Reference to a policy object describing the security checks
2718 required for each message type. The server does not make a
2719 copy of policy, and therefore this object must exist for the
2720 lifetime of the server. It is recommended that aPolicy
2721 is in const static data.
2722 @param aType Type of session sharing supported by this server
2724 IMPORT_C CPolicyServer(TInt aPriority, const TPolicy& aPolicy, TServerType aType=EUnsharableSessions);
2726 /** Performs a custom security check.
2727 Derived server classes must implement this function if any element in
2728 iElementsIndex has the value CPolicyServer::ECustomCheck.
2729 Similarly, if CPolicyServer::ECustomCheck is not used, then this function
2730 can be safely ignored.
2732 If CPolicyServer::ECustomCheck is used, there are two further cases to consider:
2733 -# The custom security check can synchronously decide if the message
2734 should pass. In this case, the derived implementation must simply return
2735 either EPass or EFail depending on the result of the security check.
2736 -# The custom security check needs to use asynchronous methods in order
2737 to determine whether the message should procceed. In this case, these
2738 asysnchronous methods should be started and then the EAsync value returned.
2739 Furthermore, implmentations returning EAsync commit to the following:
2740 - If the security check eventually passes, ProcessL() must be called with
2741 the appropriate message.
2742 - If the security check eventually fails, CheckFailedL() must be called
2744 - Pending messages on a given session need to be completed and discarded
2745 if the session is closed.
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.
2752 In both cases, synchronous and asynchronous, the derived implementation has the
2753 option of updating the aAction and/or aMissing parameters if that is
2756 @param aMsg The message to check.
2757 @param aAction A reference to the action to take if the security check
2758 fails. This is either a value from TFailureAction or a negative
2759 value which has meaning to the CustomFailureActionL() method of
2761 The policy server framework gives this value a default of
2762 EFailClient. If a derived implementation wishes a
2763 different value, then it should change this.
2764 @param aMissing A reference to the list of security attributes missing
2765 from the checked process. The policy server initialises this
2766 object to zero (that is a sid of 0, a vid of 0, and no capabilities).
2767 If derived implementations wish to take advantage of a list of
2768 missing attributes in their implementation of CustomFailureActionL(),
2769 then they should set those missing attributes here in
2770 CustomSecurityCheckL().
2771 @return A value from TCustomResult.
2772 @panic CBase 95 If the default implementation is called.
2774 IMPORT_C virtual TCustomResult CustomSecurityCheckL(const RMessage2& aMsg, TInt& aAction, TSecurityInfo& aMissing);
2776 /** Performs a custom action after the failure of a security check.
2777 Derived server classes must implement this function if the aAction value
2778 passed to CheckFailedL() is less than zero. This can happened if the policy
2779 specified a negative number in the iAction member of any of the
2780 TPolicyElements, or, if the derived CustomSecurityCheckL() modified the
2781 value of aAction prior to returning.
2783 If negative aAction values are used, there are two further cases to consider:
2784 -# The custom security check can synchronously decide if the message
2785 should pass. In this case, the derived implementation must simply return
2786 either EPass or EFail depending on the result of the security check.
2787 -# The custom security check needs to use asynchronous methods in order
2788 to determine whether the message should still proceed. In this case, these
2789 asysnchronous methods should be started and then the EAsync value returned.
2790 Furthermore, implmentations returning EAsync commit to the following:
2791 - If the security check eventually passes, ProcessL() must be called with
2792 the appropriate message.
2793 - If the security check eventually fails, or if a fatal error condition occurs,
2794 including if the previously mentioned call to ProcessL() leaves;
2795 then CPolicyServer::ProcessError() should be called passing the message and
2796 relevant error code.
2797 - Pending messages on a given session need to be completed and discarded
2798 if the session is closed.
2800 IMPORTANT NOTE. When processing a message asynchronously, a copy must be
2801 made of the RMessage2 object. Saving a refernece or pointer to the original
2802 message will produce unpredictable defects. This is because the object will
2803 be reused for the next message that the server receives.
2805 The default implementation of this function panics the server.
2807 @param aMsg The message to check
2808 @param aAction The custom failure action requested.
2809 This is either a value from TFailureAction or a negative
2810 value which has meaning to the CustomFailureActionL() method of
2812 @param aMissing A const reference to the list of security attributes missing
2813 from the checked process. There are two cases to consider:
2814 (a) If this message was checked (and failed) by a static policy
2815 applied by the policy server framework, aMissing will contain a
2816 list of the security attributes that caused the policy to fail. An
2817 completely zeroed aMissing implies that an always fail policy was
2819 (b) If this message was failed by a custom security check, then
2820 aMissing will be zeroed unless the CustomSecurityCheckL() method
2822 @return A value from TCustomResult.
2823 @panic CBase 95 If the default implementation is called.
2825 IMPORT_C virtual TCustomResult CustomFailureActionL(const RMessage2& aMsg, TInt aAction, const TSecurityInfo& aMissing);
2828 IMPORT_C virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1);
2830 IMPORT_C virtual void RunL();
2831 IMPORT_C virtual TInt RunError(TInt aError);
2832 const CPolicyServer::TPolicyElement* FindPolicyElement(TInt aFn, TUint& aSpecialCase) const;
2834 const TPolicy& iPolicy;
2840 class CActiveScheduler : public CBase
2845 Controls the handling of asynchronous requests as represented by
2848 An active scheduler is used to schedule the sequence in which active object request
2849 completion events are handled by a single event-handling thread.
2851 An active scheduler can be instantiated and used directly if either:
2853 - the RunL() function of all of its active objects is guaranteed not to leave, or
2855 - each of its active objects implements a suitable RunError() function to provide suitable cleanup
2857 If any of the active scheduler's active objects does not provide a RunError()
2858 function, then a CActiveScheduler derived class must be defined and an implementation
2859 of the Error() function provided to perform the cleanup required.
2861 There is one active scheduler per thread and the static functions provided by the
2862 class always refer to the current active scheduler.
2864 @see CActiveScheduler::Error
2866 @see CActiveSchedulerWait
2869 friend class CActiveSchedulerWait;
2872 typedef TLoop* TLoopOwner;
2874 IMPORT_C CActiveScheduler();
2875 IMPORT_C ~CActiveScheduler();
2876 IMPORT_C static void Install(CActiveScheduler* aScheduler);
2877 IMPORT_C static CActiveScheduler* Current();
2878 IMPORT_C static void Add(CActive* aActive);
2879 IMPORT_C static void Start();
2880 IMPORT_C static void Stop();
2881 IMPORT_C static TBool RunIfReady(TInt& aError, TInt aMinimumPriority);
2882 IMPORT_C static CActiveScheduler* Replace(CActiveScheduler* aNewActiveScheduler);
2883 IMPORT_C virtual void WaitForAnyRequest();
2884 IMPORT_C virtual void Error(TInt aError) const;
2885 IMPORT_C void Halt(TInt aExitCode) const;
2886 IMPORT_C TInt StackDepth() const;
2888 class TCleanupBundle
2891 CCleanup* iCleanupPtr;
2895 static void Start(TLoopOwner* aOwner);
2896 IMPORT_C virtual void OnStarting();
2897 IMPORT_C virtual void OnStopping();
2898 IMPORT_C virtual void Reserved_1();
2899 IMPORT_C virtual void Reserved_2();
2900 void Run(TLoopOwner* const volatile& aLoop);
2901 void DoRunL(TLoopOwner* const volatile& aLoop, CActive* volatile & aCurrentObj, TCleanupBundle* aCleanupBundle);
2903 IMPORT_C virtual TInt Extension_(TUint aExtensionId, TAny*& a0, TAny* a1);
2905 inline TInt Level() const; // deprecated
2908 TPriQue<CActive> iActiveQ;
2915 class CActiveSchedulerWait : public CBase
2920 Controls a single scheduling loop in the current active scheduler.
2922 This class provides better control of nested wait loops in the active
2925 Note that a CActiveSchedulerWait object can be used as a data member
2926 inside other CBase derived classes.
2928 @see CActiveScheduler
2932 IMPORT_C CActiveSchedulerWait();
2933 IMPORT_C ~CActiveSchedulerWait();
2934 IMPORT_C void Start();
2935 IMPORT_C void AsyncStop();
2936 IMPORT_C void AsyncStop(const TCallBack& aCallMeWhenStopped);
2937 inline TBool IsStarted() const;
2938 IMPORT_C TBool CanStopNow() const;
2940 CActiveScheduler::TLoopOwner iLoop;
2951 A collection of static functions that are used to add resources to and remove
2952 resources from the cleanup stack.
2956 IMPORT_C static void PushL(TAny* aPtr);
2957 IMPORT_C static void PushL(CBase* aPtr);
2958 IMPORT_C static void PushL(TCleanupItem anItem);
2959 IMPORT_C static void Pop();
2960 IMPORT_C static void Pop(TInt aCount);
2961 IMPORT_C static void PopAndDestroy();
2962 IMPORT_C static void PopAndDestroy(TInt aCount);
2963 IMPORT_C static void Check(TAny* aExpectedItem);
2964 inline static void Pop(TAny* aExpectedItem);
2965 inline static void Pop(TInt aCount, TAny* aLastExpectedItem);
2966 inline static void PopAndDestroy(TAny* aExpectedItem);
2967 inline static void PopAndDestroy(TInt aCount, TAny* aLastExpectedItem);
2977 A utility class used by the templated function CleanupDeletePushL() to create
2978 a TCleanupItem item that will perform a delete type operation on
2979 the class T type object.
2981 @see CleanupDeletePushL()
2987 inline static void PushL(T* aPtr);
2989 static void Delete(TAny *aPtr);
2999 Constructs and pushes a TCleanupItem object onto the cleanup stack.
3001 The TCleanupItem encapsulates:
3003 - the pointer aPtr to the object of type class T which is to be cleaned up
3005 - an associated cleanup operation.
3007 The cleanup operation is the private static function Delete() of the templated
3008 class CleanupDelete, and is called as a result of a subsequent call
3009 to CleanupStack::PopAndDestroy().
3011 CleanupDelete::Delete() is passed a pointer to the class T object to be cleaned
3012 up, and the function implements cleanup by deleting the passed object.
3014 An example of its use:
3018 CTestOne* one = new (ELeave) CTestOne;
3019 CleanupDeletePushL(one);
3021 CleanupStack::PopAndDestroy(); // <--- results in "one" being deleted.
3025 @param aPtr A pointer to a templated class T type object for which the cleanup item is being created.
3029 @see CleanupStack::PopAndDestroy()
3032 inline void CleanupDeletePushL(T* aPtr);
3041 A utility class used by the templated function CleanupArrayDeletePushL() to
3042 create a TCleanupItem item that will perform a delete type operation on an
3043 array of class T type objects.
3045 @see CleanupArrayDeletePushL()
3048 class CleanupArrayDelete
3051 inline static void PushL(T* aPtr);
3053 static void ArrayDelete(TAny *aPtr);
3063 Constructs and pushes a TCleanupItem object onto the cleanup stack.
3065 The TCleanupItem encapsulates:
3067 - the pointer aPtr to an array of type class T objects to be cleaned up
3069 - an associated cleanup operation.
3071 The cleanup operation is the private static function ArrayDelete() of the
3072 templated class CleanupArrayDelete, and is called as a result of
3073 a subsequent call to CleanupStack::PopAndDestroy().
3075 CleanupArrayDelete::ArrayDelete() is passed a pointer to the array of class T
3076 objects to be cleaned up, and the function implements cleanup by deleting
3077 the passed array using the delete [] operator.
3079 An example of its use:
3083 RTestOne* one = new (ELeave) RTestOne [KSomeArraySize];
3084 CleanupArrayDeletePushL(one);
3085 ... // Do something with the object.........
3086 CleanupStack::PopAndDestroy(); // <--- results in the array "one" being deleted.
3090 @param aPtr A pointer to an array of class T type objects for which
3091 the cleanup item is being created.
3094 @see CleanupArrayDelete
3095 @see CleanupStack::PopAndDestroy()
3098 inline void CleanupArrayDeletePushL(T* aPtr);
3107 A utility class used by the templated function CleanupClosePushL() to create
3108 a TCleanupItem item that will perform a close type operation on
3109 the class T type object.
3111 @see CleanupClosePushL()
3117 inline static void PushL(T& aRef);
3119 static void Close(TAny *aPtr);
3129 Constructs and pushes a TCleanupItem object onto the cleanup stack.
3131 The TCleanupItem encapsulates:
3133 1. a reference aRef to the object of type class T which is to be cleaned up
3135 2. an associated cleanup operation.
3137 The cleanup operation is the private static function Close() of the templated
3138 class CleanupClose and is invoked as a result of a subsequent call to
3139 CleanupStack::PopAndDestroy().
3141 CleanupClose::Close() is passed a pointer to the class T object to be cleaned
3142 up, and the function implements cleanup by calling Close() on the passed object.
3143 The class T object must, therefore, define and implement (or inherit) a Close()
3146 An example of its use:
3153 IMPORT_C void Close();
3158 CleanupClosePushL(two);
3160 CleanupStack::PopAndDestroy(); // <--- results in Close() being called on "two".
3164 In practice, this type of cleanup operation is commonly applied to handles
3165 to resources; if such handles are constructed on the program stack, then it is
3166 important that such handles are closed.
3168 @param aRef A reference to a class T type object for which the cleanup item
3173 @see CleanupStack::PopAndDestroy()
3176 inline void CleanupClosePushL(T& aRef);
3185 A utility class used by the templated function CleanupReleasePushL() to create
3186 a TCleanupItem item that will perform a release type operation on
3187 the class T type object.
3189 @see CleanupReleasePushL()
3192 class CleanupRelease
3195 inline static void PushL(T& aRef);
3197 static void Release(TAny *aPtr);
3207 Constructs and pushes a TCleanupItem object onto the cleanup stack.
3209 The TCleanupItem encapsulates:
3211 1. a reference aRef to the object of type class T which is to be cleaned up
3213 2. an associated cleanup operation.
3215 The cleanup operation is the private static function Release() of the
3216 templated class CleanupRelease and is invoked as a result of
3217 a subsequent call to CleanupStack::PopAndDestroy().
3219 CleanupRelease::Release() is passed a pointer to the class T object to be cleaned
3220 up, and the function implements cleanup by calling Release() on the passed object.
3221 The class T object must, therefore, define and implement (or inherit) a Release()
3224 An example of its use:
3231 IMPORT_C void Release();
3236 CleanupReleasePushL(three);
3238 CleanupStack::PopAndDestroy(); // <--- results in Release() being called on "three".
3242 @param aRef A reference to a class T type object for which the cleanup item
3247 @see CleanupStack::PopAndDestroy()
3250 inline void CleanupReleasePushL(T& aRef);
3264 IMPORT_C static CConsoleBase* NewL(const TDesC& aTitle,TSize aSize);
3267 #include <e32base.inl>
3269 #endif //__E32BASE_H__