1 /* |
|
2 * Copyright (c) 2005 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: Active object based wait. |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef CUSERAFTER_H__ |
|
19 #define CUSERAFTER_H__ |
|
20 |
|
21 // INCLUDES |
|
22 #include <e32base.h> |
|
23 |
|
24 |
|
25 // CLASS DESCRIPTION |
|
26 |
|
27 /** |
|
28 * Active object based wait. |
|
29 * |
|
30 * Similar like User::After() but doesn't block |
|
31 * whole thread, but current RunL() with |
|
32 * CActiveSchedulerWait. |
|
33 */ |
|
34 |
|
35 class CUserAfter : public CTimer |
|
36 { |
|
37 |
|
38 public: //Construction |
|
39 static inline CUserAfter* NewL(); |
|
40 static inline CUserAfter* NewLC(); |
|
41 ~CUserAfter(); |
|
42 |
|
43 |
|
44 public: //Wait support |
|
45 |
|
46 /** |
|
47 * Static "one shot" wait method. |
|
48 */ |
|
49 static inline void AfterL ( TInt aWaitTimeMicroSeconds ); |
|
50 |
|
51 /** |
|
52 * Member wait method. |
|
53 */ |
|
54 inline void After ( TInt aWaitTimeMicroSeconds ); |
|
55 |
|
56 |
|
57 private: |
|
58 CUserAfter(); |
|
59 |
|
60 void RunL(); |
|
61 void RunError(); |
|
62 void DoCancel(); |
|
63 |
|
64 |
|
65 private: //data |
|
66 |
|
67 /** |
|
68 * ActiveSchedulerWait |
|
69 * Own |
|
70 */ |
|
71 CActiveSchedulerWait iWait; |
|
72 |
|
73 }; |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CUserAfter public functions |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 inline CUserAfter* CUserAfter::NewL() |
|
83 { |
|
84 CUserAfter* self = CUserAfter::NewLC(); |
|
85 CleanupStack::Pop ( self ); |
|
86 return self; |
|
87 } |
|
88 |
|
89 inline CUserAfter* CUserAfter::NewLC() |
|
90 { |
|
91 CUserAfter* self = new ( ELeave ) CUserAfter(); |
|
92 CleanupStack::PushL ( self ); |
|
93 self->ConstructL(); |
|
94 return self; |
|
95 } |
|
96 |
|
97 |
|
98 inline CUserAfter::~CUserAfter() |
|
99 { |
|
100 CTimer::Cancel(); |
|
101 } |
|
102 |
|
103 inline void CUserAfter::After ( TInt aWaitTimeMicroSeconds ) |
|
104 { |
|
105 CTimer::After ( aWaitTimeMicroSeconds ); |
|
106 iWait.Start(); |
|
107 } |
|
108 |
|
109 |
|
110 inline void CUserAfter::AfterL ( TInt aWaitTimeMicroSeconds ) |
|
111 { |
|
112 CUserAfter* after = CUserAfter::NewL(); |
|
113 after->After ( aWaitTimeMicroSeconds ); |
|
114 delete after; |
|
115 } |
|
116 |
|
117 |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // CUserAfter private functions |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 inline CUserAfter::CUserAfter() |
|
124 : CTimer ( CActive::EPriorityStandard ) |
|
125 { |
|
126 CActiveScheduler::Add ( this ); |
|
127 } |
|
128 |
|
129 |
|
130 inline void CUserAfter::RunL() |
|
131 { |
|
132 iWait.AsyncStop(); |
|
133 Cancel(); |
|
134 } |
|
135 |
|
136 inline void CUserAfter::RunError() |
|
137 { |
|
138 } |
|
139 |
|
140 inline void CUserAfter::DoCancel() |
|
141 { |
|
142 iWait.AsyncStop(); |
|
143 CTimer::DoCancel(); |
|
144 } |
|
145 |
|
146 |
|
147 #endif // CUSERAFTER_H__ |
|
148 |
|
149 // End of File |
|
150 |
|