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