|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 //DelayedFunctionCall.h |
|
18 //DFC caller and templated generic function call objects. |
|
19 |
|
20 #ifndef CDELAYEDFUNCTIONCALL_H__ |
|
21 #define CDELAYEDFUNCTIONCALL_H__ |
|
22 |
|
23 |
|
24 // INCLUDES |
|
25 #include <E32base.h> |
|
26 |
|
27 |
|
28 // CLASS DESCRIPTION |
|
29 |
|
30 /** |
|
31 * Abstract interface for function call object. |
|
32 */ |
|
33 class MFunctionCall |
|
34 { |
|
35 public: |
|
36 |
|
37 /** |
|
38 * Function execution. |
|
39 * |
|
40 * Executes the function call. |
|
41 * |
|
42 * If function execution fails (e.g. leaves), |
|
43 * leave code is stored in CDelayedFunctionCall host. |
|
44 */ |
|
45 virtual void InvokeL() = 0; |
|
46 |
|
47 virtual MFunctionCall* CloneLC() const = 0; |
|
48 |
|
49 |
|
50 /** |
|
51 * Public virtual destructor. |
|
52 * |
|
53 * Allows thus function call object deletion. |
|
54 */ |
|
55 virtual ~MFunctionCall() {} |
|
56 }; |
|
57 |
|
58 |
|
59 |
|
60 // CLASS DESCRIPTION |
|
61 |
|
62 /** |
|
63 * Delayed Function Call - caller. |
|
64 * |
|
65 * Executes DFC objects after given delay. |
|
66 */ |
|
67 class CDelayedFunctionCall : public CTimer |
|
68 { |
|
69 public: //Construction |
|
70 |
|
71 static inline CDelayedFunctionCall* NewLC(); |
|
72 static inline CDelayedFunctionCall* NewL(); |
|
73 inline ~CDelayedFunctionCall(); |
|
74 |
|
75 public: //Delayed call |
|
76 |
|
77 /** |
|
78 * Issues DFC call. Panics if CDelayedFunctionCall object |
|
79 * is already in use. |
|
80 * |
|
81 * @param aFC The FC object to execute. |
|
82 * @param aCallDelay The delay when to execute the FC. |
|
83 * @param aFCOwnershipTransf If ETrue, the aFC object |
|
84 * ownership is transferred to DFC caller and DFC caller |
|
85 * deletes object. If EFalse, no ownership transfer is done. |
|
86 */ |
|
87 inline void IssueDfc( MFunctionCall& aFC, TInt aCallDelay, TBool aFCOwnershipTransf = ETrue ); |
|
88 |
|
89 |
|
90 /** |
|
91 * Similar like IssueDfc() but pushes |
|
92 * release to CleanupStack ==> |
|
93 * if there happens a leave before the DFC gets scheduled, |
|
94 * DFC is canceled. |
|
95 */ |
|
96 inline void IssueDfcLC( MFunctionCall& aFC, TInt aCallDelay, TBool aFCOwnershipTransf = ETrue ); |
|
97 |
|
98 |
|
99 /** |
|
100 * Releases the DFC. |
|
101 * Cancels the call and deletes possibly owned FC. |
|
102 */ |
|
103 inline void Release(); |
|
104 |
|
105 |
|
106 /** |
|
107 * Delayed FC error handling. |
|
108 */ |
|
109 inline void LeaveIfFcFailedL(); |
|
110 |
|
111 /** |
|
112 * Tests was the FC executed or not. |
|
113 */ |
|
114 inline TBool FcExecuted(); |
|
115 |
|
116 |
|
117 private: |
|
118 inline CDelayedFunctionCall(); |
|
119 inline void RunL(); |
|
120 inline TInt RunError( TInt aError ); |
|
121 inline void InvokeL(); |
|
122 |
|
123 |
|
124 private: //data |
|
125 |
|
126 //REF/OWN: Function call object |
|
127 MFunctionCall* iFC; |
|
128 |
|
129 //OWN: Is function call object owned |
|
130 TBool iFCOwned; |
|
131 |
|
132 //OWN: Did function call leave |
|
133 TBool iFCLeft; |
|
134 |
|
135 //OWN: Was function called |
|
136 TBool iFCCalled; |
|
137 |
|
138 //OWN: Leave code from the function call |
|
139 TInt iFCLeaveErr; |
|
140 }; |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CDelayedFunctionCall public functions |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 inline CDelayedFunctionCall* CDelayedFunctionCall::NewLC() |
|
150 { |
|
151 CDelayedFunctionCall* self = new (ELeave) CDelayedFunctionCall(); |
|
152 CleanupStack::PushL( self ); |
|
153 self->ConstructL(); |
|
154 return self; |
|
155 } |
|
156 |
|
157 inline CDelayedFunctionCall* CDelayedFunctionCall::NewL() |
|
158 { |
|
159 CDelayedFunctionCall* self = NewLC(); |
|
160 CleanupStack::Pop( self ); |
|
161 return self; |
|
162 } |
|
163 |
|
164 |
|
165 inline CDelayedFunctionCall::~CDelayedFunctionCall() |
|
166 { |
|
167 Cancel(); |
|
168 if( iFCOwned ) |
|
169 { |
|
170 delete iFC; |
|
171 } |
|
172 } |
|
173 |
|
174 |
|
175 inline void CDelayedFunctionCall::IssueDfc( MFunctionCall& aFC, |
|
176 TInt aFCDelay, |
|
177 TBool aFCOwnershipTransf ) |
|
178 { |
|
179 __ASSERT_ALWAYS( !IsActive(), User::Panic( _L("DFC caller"), KErrInUse ) ); |
|
180 |
|
181 iFC = &aFC; |
|
182 iFCOwned = aFCOwnershipTransf; |
|
183 iFCLeft = EFalse; |
|
184 iFCLeaveErr = KErrNone; |
|
185 iFCCalled = EFalse; |
|
186 |
|
187 if( aFCDelay >= 0 ) |
|
188 { |
|
189 After( aFCDelay ); |
|
190 } |
|
191 else |
|
192 { |
|
193 InvokeL(); |
|
194 } |
|
195 } |
|
196 |
|
197 |
|
198 inline void CDelayedFunctionCall::IssueDfcLC( MFunctionCall& aFC, |
|
199 TInt aFCDelay, |
|
200 TBool aFCOwnershipTransf ) |
|
201 { |
|
202 IssueDfc( aFC, aFCDelay, aFCOwnershipTransf ); |
|
203 CleanupReleasePushL( *this ); |
|
204 } |
|
205 |
|
206 |
|
207 inline void CDelayedFunctionCall::Release() |
|
208 { |
|
209 Cancel(); |
|
210 if( iFCOwned ) |
|
211 { |
|
212 delete iFC; |
|
213 iFC = NULL; |
|
214 } |
|
215 } |
|
216 |
|
217 inline void CDelayedFunctionCall::LeaveIfFcFailedL() |
|
218 { |
|
219 if( iFCLeft ) |
|
220 { |
|
221 User::Leave( iFCLeaveErr ); |
|
222 } |
|
223 } |
|
224 |
|
225 |
|
226 inline TBool CDelayedFunctionCall::FcExecuted() |
|
227 { |
|
228 return iFCCalled; |
|
229 } |
|
230 |
|
231 |
|
232 |
|
233 // ----------------------------------------------------------------------------- |
|
234 // CDelayedFunctionCall private functions |
|
235 // ----------------------------------------------------------------------------- |
|
236 // |
|
237 inline CDelayedFunctionCall::CDelayedFunctionCall() |
|
238 : CTimer( CActive::EPriorityHigh ) |
|
239 { |
|
240 CActiveScheduler::Add( this ); |
|
241 } |
|
242 |
|
243 inline void CDelayedFunctionCall::RunL() |
|
244 { |
|
245 InvokeL(); |
|
246 } |
|
247 |
|
248 inline TInt CDelayedFunctionCall::RunError( TInt aError ) |
|
249 { |
|
250 iFCLeft = ETrue; |
|
251 iFCCalled = ETrue; |
|
252 iFCLeaveErr = aError; |
|
253 if( iFCOwned ) |
|
254 { |
|
255 delete iFC; |
|
256 iFC = NULL; |
|
257 } |
|
258 |
|
259 return KErrNone; |
|
260 } |
|
261 |
|
262 |
|
263 inline void CDelayedFunctionCall::InvokeL() |
|
264 { |
|
265 iFC->InvokeL(); |
|
266 iFCCalled = ETrue; |
|
267 if( iFCOwned ) |
|
268 { |
|
269 delete iFC; |
|
270 iFC = NULL; |
|
271 } |
|
272 } |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 // ============================================================================= |
|
281 // Generic Function Call classes |
|
282 // ============================================================================= |
|
283 |
|
284 |
|
285 // CLASS DESCRIPTION |
|
286 |
|
287 /** |
|
288 * Base class for generic function call objects. |
|
289 * Initializes function call members to zero |
|
290 * during the object construction. |
|
291 */ |
|
292 class TMemFillBase |
|
293 { |
|
294 protected: //Protected constructor & virtual destructor |
|
295 TMemFillBase( TUint aSize ) { Mem::FillZ( this, aSize); } |
|
296 virtual ~TMemFillBase() {} |
|
297 }; |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 // CLASS DESCRIPTION |
|
304 |
|
305 /** |
|
306 * Generic function call object for function that returns void. |
|
307 * |
|
308 * This function call object doesn't own any of the |
|
309 * call parameters, nor the called object. |
|
310 */ |
|
311 template< class C, |
|
312 class P1=TInt, |
|
313 class P2=TInt, |
|
314 class P3=TInt, |
|
315 class P4=TInt > |
|
316 class TGenericFuncCallVoid : public TMemFillBase, public MFunctionCall |
|
317 { |
|
318 private: //Function type shortcuts |
|
319 typedef void (C::*TFuncTypeVoid)(); |
|
320 typedef void (C::*TFuncType1)( P1 aP1 ); |
|
321 typedef void (C::*TFuncType2)( P1 aP1, P2 aP2 ); |
|
322 typedef void (C::*TFuncType3)( P1 aP1, P2 aP2, P3 aP3 ); |
|
323 typedef void (C::*TFuncType4)( P1 aP1, P2 aP2, P3 aP3, P4 aP4 ); |
|
324 |
|
325 |
|
326 public: //Construction / destruction |
|
327 TGenericFuncCallVoid( C& aObj, TFuncTypeVoid aFunc ) |
|
328 : TMemFillBase( sizeof( TGenericFuncCallVoid ) ), |
|
329 iObj( aObj ), |
|
330 iFVoid( aFunc ) |
|
331 {} |
|
332 |
|
333 TGenericFuncCallVoid( C& aObj, TFuncType1 aFunc, P1 aP1 ) |
|
334 : TMemFillBase( sizeof( TGenericFuncCallVoid ) ), |
|
335 iObj( aObj ), |
|
336 iF1( aFunc ), |
|
337 iP1( aP1 ) |
|
338 {} |
|
339 |
|
340 TGenericFuncCallVoid( C& aObj, TFuncType2 aFunc, P1 aP1, P2 aP2 ) |
|
341 : TMemFillBase( sizeof( TGenericFuncCallVoid ) ), |
|
342 iObj( aObj ), |
|
343 iF2( aFunc ), |
|
344 iP1( aP1 ), iP2( aP2 ) |
|
345 {} |
|
346 |
|
347 TGenericFuncCallVoid( C& aObj, TFuncType3 aFunc, P1 aP1 , P2 aP2, P3 aP3 ) |
|
348 : TMemFillBase( sizeof( TGenericFuncCallVoid ) ), |
|
349 iObj( aObj ), |
|
350 iF3( aFunc ), |
|
351 iP1( aP1 ), iP2( aP2 ), iP3( aP3 ) |
|
352 {} |
|
353 |
|
354 TGenericFuncCallVoid( C& aObj, TFuncType4 aFunc, P1 aP1 , P2 aP2, P3 aP3, P4 aP4 ) |
|
355 : TMemFillBase( sizeof( TGenericFuncCallVoid ) ), |
|
356 iObj( aObj ), |
|
357 iF4( aFunc ), |
|
358 iP1( aP1 ), iP2( aP2 ), iP3( aP3 ), iP4( aP4 ) |
|
359 {} |
|
360 |
|
361 ~TGenericFuncCallVoid() |
|
362 {} |
|
363 |
|
364 private: //From MFunctionCall |
|
365 |
|
366 void InvokeL() |
|
367 { |
|
368 if( iFVoid ) |
|
369 { |
|
370 (iObj.*iFVoid)(); |
|
371 } |
|
372 else if( iF1 ) |
|
373 { |
|
374 (iObj.*iF1)( iP1 ); |
|
375 } |
|
376 else if( iF2 ) |
|
377 { |
|
378 (iObj.*iF2)( iP1, iP2 ); |
|
379 } |
|
380 else if( iF3 ) |
|
381 { |
|
382 (iObj.*iF3)( iP1, iP2, iP3 ); |
|
383 } |
|
384 else if( iF4 ) |
|
385 { |
|
386 (iObj.*iF4)( iP1, iP2, iP3, iP4 ); |
|
387 } |
|
388 } |
|
389 |
|
390 MFunctionCall* TGenericFuncCallVoid::CloneLC() const |
|
391 { |
|
392 TAny* self = User::AllocL( sizeof( TGenericFuncCallVoid ) ); |
|
393 Mem::Copy( self, this, sizeof( TGenericFuncCallVoid ) ); |
|
394 TGenericFuncCallVoid* self2 = (TGenericFuncCallVoid*) self; |
|
395 CleanupDeletePushL( self2 ); |
|
396 return (MFunctionCall*) self2; |
|
397 } |
|
398 |
|
399 |
|
400 private: //Call data |
|
401 |
|
402 C& iObj; |
|
403 P1 iP1; |
|
404 P2 iP2; |
|
405 P3 iP3; |
|
406 P4 iP4; |
|
407 TFuncTypeVoid iFVoid; |
|
408 TFuncType1 iF1; |
|
409 TFuncType2 iF2; |
|
410 TFuncType3 iF3; |
|
411 TFuncType4 iF4; |
|
412 }; |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 // CLASS DESCRIPTION |
|
419 |
|
420 /** |
|
421 * Generic function call object for function that returns a value |
|
422 * (with by-value convention). |
|
423 * |
|
424 * This function call object doesn't own any of the |
|
425 * call parameters, nor the called object or the result. |
|
426 */ |
|
427 template< class C, |
|
428 class R, |
|
429 class P1=TInt, |
|
430 class P2=TInt, |
|
431 class P3=TInt, |
|
432 class P4=TInt > |
|
433 class TGenericFuncCallRetByValue : public TMemFillBase, public MFunctionCall |
|
434 { |
|
435 private: //Function type shortcuts |
|
436 typedef R (C::*TFuncTypeVoid)(); |
|
437 typedef R (C::*TFuncType1)( P1 aP1 ); |
|
438 typedef R (C::*TFuncType2)( P1 aP1, P2 aP2 ); |
|
439 typedef R (C::*TFuncType3)( P1 aP1, P2 aP2, P3 aP3 ); |
|
440 typedef R (C::*TFuncType4)( P1 aP1, P2 aP2, P3 aP3, P4 aP4 ); |
|
441 |
|
442 |
|
443 public: //Construction / destruction |
|
444 TGenericFuncCallRetByValue( C& aObj, TFuncTypeVoid aFunc ) |
|
445 : TMemFillBase( sizeof( TGenericFuncCallRetByValue ) ), |
|
446 iObj( aObj ), |
|
447 iFVoid( aFunc ) |
|
448 {} |
|
449 |
|
450 TGenericFuncCallRetByValue( C& aObj, TFuncType1 aFunc, P1 aP1 ) |
|
451 : TMemFillBase( sizeof( TGenericFuncCallRetByValue ) ), |
|
452 iObj( aObj ), |
|
453 iF1( aFunc ), |
|
454 iP1( aP1 ) |
|
455 {} |
|
456 |
|
457 TGenericFuncCallRetByValue( C& aObj, TFuncType2 aFunc, P1 aP1, P2 aP2 ) |
|
458 : TMemFillBase( sizeof( TGenericFuncCallRetByValue ) ), |
|
459 iObj( aObj ), |
|
460 iF2( aFunc ), |
|
461 iP1( aP1 ), iP2( aP2 ) |
|
462 {} |
|
463 |
|
464 TGenericFuncCallRetByValue( C& aObj, TFuncType3 aFunc, P1 aP1 , P2 aP2, P3 aP3 ) |
|
465 : TMemFillBase( sizeof( TGenericFuncCallRetByValue ) ), |
|
466 iObj( aObj ), |
|
467 iF3( aFunc ), |
|
468 iP1( aP1 ), iP2( aP2 ), iP3( aP3 ) |
|
469 {} |
|
470 |
|
471 TGenericFuncCallRetByValue( C& aObj, TFuncType4 aFunc, P1 aP1 , P2 aP2, P3 aP3, P4 aP4 ) |
|
472 : TMemFillBase( sizeof( TGenericFuncCallRetByValue ) ), |
|
473 iObj( aObj ), |
|
474 iF4( aFunc ), |
|
475 iP1( aP1 ), iP2( aP2 ), iP3( aP3 ), iP4( aP4 ) |
|
476 {} |
|
477 |
|
478 ~TGenericFuncCallRetByValue() |
|
479 {} |
|
480 |
|
481 private: //From MFunctionCall |
|
482 |
|
483 void InvokeL() |
|
484 { |
|
485 if( iFVoid ) |
|
486 { |
|
487 iReturnValue = (iObj.*iFVoid)(); |
|
488 } |
|
489 else if( iF1 ) |
|
490 { |
|
491 iReturnValue = (iObj.*iF1)( iP1 ); |
|
492 } |
|
493 else if( iF2 ) |
|
494 { |
|
495 iReturnValue = (iObj.*iF2)( iP1, iP2 ); |
|
496 } |
|
497 else if( iF3 ) |
|
498 { |
|
499 iReturnValue = (iObj.*iF3)( iP1, iP2, iP3 ); |
|
500 } |
|
501 else if( iF4 ) |
|
502 { |
|
503 iReturnValue = (iObj.*iF4)( iP1, iP2, iP3, iP4 ); |
|
504 } |
|
505 } |
|
506 |
|
507 MFunctionCall* TGenericFuncCallRetByValue::CloneLC() const |
|
508 { |
|
509 TAny* self = User::AllocL( sizeof( TGenericFuncCallRetByValue ) ); |
|
510 Mem::Copy( self, this, sizeof( TGenericFuncCallRetByValue ) ); |
|
511 TGenericFuncCallRetByValue* self2 = (TGenericFuncCallRetByValue*) self; |
|
512 CleanupDeletePushL( self2 ); |
|
513 return (MFunctionCall*) self2; |
|
514 } |
|
515 |
|
516 private: //Call data |
|
517 |
|
518 C& iObj; |
|
519 P1 iP1; |
|
520 P2 iP2; |
|
521 P3 iP3; |
|
522 P4 iP4; |
|
523 TFuncTypeVoid iFVoid; |
|
524 TFuncType1 iF1; |
|
525 TFuncType2 iF2; |
|
526 TFuncType3 iF3; |
|
527 TFuncType4 iF4; |
|
528 |
|
529 public: //Return value |
|
530 |
|
531 R iReturnValue; |
|
532 }; |
|
533 |
|
534 |
|
535 |
|
536 |
|
537 template< class P1=TInt, |
|
538 class P2=TInt, |
|
539 class P3=TInt, |
|
540 class P4=TInt > |
|
541 class TGenericGlobalFuncCallVoid : public TMemFillBase, public MFunctionCall |
|
542 { |
|
543 private: //Function type shortcuts |
|
544 typedef void (*TFuncTypeVoid)(); |
|
545 typedef void (*TFuncType1)( P1 aP1 ); |
|
546 typedef void (*TFuncType2)( P1 aP1, P2 aP2 ); |
|
547 typedef void (*TFuncType3)( P1 aP1, P2 aP2, P3 aP3 ); |
|
548 typedef void (*TFuncType4)( P1 aP1, P2 aP2, P3 aP3, P4 aP4 ); |
|
549 |
|
550 |
|
551 public: //Construction / destruction |
|
552 TGenericGlobalFuncCallVoid( TFuncTypeVoid aFunc ) |
|
553 : TMemFillBase( sizeof( TGenericGlobalFuncCallVoid ) ), |
|
554 iFVoid( aFunc ) |
|
555 {} |
|
556 |
|
557 TGenericGlobalFuncCallVoid( TFuncType1 aFunc, P1 aP1 ) |
|
558 : TMemFillBase( sizeof( TGenericGlobalFuncCallVoid ) ), |
|
559 iF1( aFunc ), |
|
560 iP1( aP1 ) |
|
561 {} |
|
562 |
|
563 TGenericGlobalFuncCallVoid( TFuncType2 aFunc, P1 aP1, P2 aP2 ) |
|
564 : TMemFillBase( sizeof( TGenericGlobalFuncCallVoid ) ), |
|
565 iF2( aFunc ), |
|
566 iP1( aP1 ), iP2( aP2 ) |
|
567 {} |
|
568 |
|
569 TGenericGlobalFuncCallVoid( TFuncType3 aFunc, P1 aP1 , P2 aP2, P3 aP3 ) |
|
570 : TMemFillBase( sizeof( TGenericGlobalFuncCallVoid ) ), |
|
571 iF3( aFunc ), |
|
572 iP1( aP1 ), iP2( aP2 ), iP3( aP3 ) |
|
573 {} |
|
574 |
|
575 TGenericGlobalFuncCallVoid( TFuncType4 aFunc, P1 aP1 , P2 aP2, P3 aP3, P4 aP4 ) |
|
576 : TMemFillBase( sizeof( TGenericGlobalFuncCallVoid ) ), |
|
577 iF4( aFunc ), |
|
578 iP1( aP1 ), iP2( aP2 ), iP3( aP3 ), iP4( aP4 ) |
|
579 {} |
|
580 |
|
581 ~TGenericGlobalFuncCallVoid() |
|
582 {} |
|
583 |
|
584 private: //From MFunctionCall |
|
585 |
|
586 void InvokeL() |
|
587 { |
|
588 if( iFVoid ) |
|
589 { |
|
590 (*iFVoid)(); |
|
591 } |
|
592 else if( iF1 ) |
|
593 { |
|
594 (*iF1)( iP1 ); |
|
595 } |
|
596 else if( iF2 ) |
|
597 { |
|
598 (*iF2)( iP1, iP2 ); |
|
599 } |
|
600 else if( iF3 ) |
|
601 { |
|
602 (*iF3)( iP1, iP2, iP3 ); |
|
603 } |
|
604 else if( iF4 ) |
|
605 { |
|
606 (*iF4)( iP1, iP2, iP3, iP4 ); |
|
607 } |
|
608 } |
|
609 |
|
610 MFunctionCall* TGenericGlobalFuncCallVoid::CloneLC() const |
|
611 { |
|
612 TAny* self = User::AllocL( sizeof( TGenericGlobalFuncCallVoid ) ); |
|
613 Mem::Copy( self, this, sizeof( TGenericGlobalFuncCallVoid ) ); |
|
614 TGenericGlobalFuncCallVoid* self2 = (TGenericGlobalFuncCallVoid*) self; |
|
615 CleanupDeletePushL( self2 ); |
|
616 return (MFunctionCall*) self2; |
|
617 } |
|
618 |
|
619 private: //Call data |
|
620 |
|
621 P1 iP1; |
|
622 P2 iP2; |
|
623 P3 iP3; |
|
624 P4 iP4; |
|
625 TFuncTypeVoid iFVoid; |
|
626 TFuncType1 iF1; |
|
627 TFuncType2 iF2; |
|
628 TFuncType3 iF3; |
|
629 TFuncType4 iF4; |
|
630 }; |
|
631 |
|
632 |
|
633 |
|
634 |
|
635 // CLASS DESCRIPTION |
|
636 |
|
637 |
|
638 /** |
|
639 * Generic function call object to delete objects. |
|
640 * |
|
641 * This function call object doesn't own any of the |
|
642 * parameters ==> the objects are deleted only when |
|
643 * the DFC is executed. |
|
644 * |
|
645 * If deleted objects are provided as pointer reference ( Class*& ), |
|
646 * the original pointer to object (e.g. class member) |
|
647 * is set to NULL during the deletion. |
|
648 */ |
|
649 template< class C1, |
|
650 class C2 = TAny*, |
|
651 class C3 = TAny* > |
|
652 class TGenericObjDelete : public TMemFillBase, public MFunctionCall |
|
653 { |
|
654 public: //Construction / destruction |
|
655 explicit TGenericObjDelete( C1 aObj1 ) |
|
656 : TMemFillBase( sizeof( TGenericObjDelete ) ), |
|
657 iObj1( aObj1 ) |
|
658 {} |
|
659 |
|
660 TGenericObjDelete( C1 aObj1, C2 aObj2 ) |
|
661 : TMemFillBase( sizeof( TGenericObjDelete ) ), |
|
662 iObj1( aObj1 ), |
|
663 iObj2( aObj2 ) |
|
664 {} |
|
665 |
|
666 TGenericObjDelete( C1 aObj1, C2 aObj2, C3 aObj3 ) |
|
667 : TMemFillBase( sizeof( TGenericObjDelete ) ), |
|
668 iObj1( aObj1 ), |
|
669 iObj2( aObj2 ), |
|
670 iObj3( aObj3 ) |
|
671 {} |
|
672 |
|
673 ~TGenericObjDelete() |
|
674 {} |
|
675 |
|
676 private: //From MFunctionCall |
|
677 |
|
678 void InvokeL() |
|
679 { |
|
680 delete iObj1; |
|
681 iObj1 = NULL; |
|
682 |
|
683 delete iObj2; |
|
684 iObj2 = NULL; |
|
685 |
|
686 delete iObj3; |
|
687 iObj3 = NULL; |
|
688 } |
|
689 |
|
690 MFunctionCall* TGenericObjDelete::CloneLC() const |
|
691 { |
|
692 TAny* self = User::AllocL( sizeof( TGenericObjDelete ) ); |
|
693 Mem::Copy( self, this, sizeof( TGenericObjDelete ) ); |
|
694 TGenericObjDelete* self2 = (TGenericObjDelete*) self; |
|
695 CleanupDeletePushL( self2 ); |
|
696 return (MFunctionCall*) self2; |
|
697 } |
|
698 |
|
699 private: //Call data |
|
700 |
|
701 C1 iObj1; |
|
702 C2 iObj2; |
|
703 C3 iObj3; |
|
704 }; |
|
705 |
|
706 |
|
707 #endif // CDELAYEDFUNCTIONCALL_H__ |
|
708 |
|
709 |
|
710 // End of File |
|
711 |
|
712 |