|
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 * Static "one shot" wait method. |
|
52 */ |
|
53 static inline void After8HrsL (); |
|
54 |
|
55 /** |
|
56 * Member wait method. |
|
57 */ |
|
58 inline void After ( TInt aWaitTimeMicroSeconds ); |
|
59 |
|
60 |
|
61 private: |
|
62 CUserAfter(); |
|
63 |
|
64 void RunL(); |
|
65 void RunError(); |
|
66 void DoCancel(); |
|
67 |
|
68 |
|
69 private: //data |
|
70 CActiveSchedulerWait iWait; |
|
71 |
|
72 }; |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CUserAfter public functions |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 inline CUserAfter* CUserAfter::NewL() |
|
82 { |
|
83 CUserAfter* self = CUserAfter::NewLC(); |
|
84 CleanupStack::Pop ( self ); |
|
85 return self; |
|
86 } |
|
87 |
|
88 inline CUserAfter* CUserAfter::NewLC() |
|
89 { |
|
90 CUserAfter* self = new ( ELeave ) CUserAfter(); |
|
91 CleanupStack::PushL ( self ); |
|
92 self->ConstructL(); |
|
93 return self; |
|
94 } |
|
95 |
|
96 |
|
97 inline CUserAfter::~CUserAfter() |
|
98 { |
|
99 CTimer::Cancel(); |
|
100 } |
|
101 |
|
102 inline void CUserAfter::After ( TInt aWaitTimeMicroSeconds ) |
|
103 { |
|
104 CTimer::After ( aWaitTimeMicroSeconds ); |
|
105 iWait.Start(); |
|
106 } |
|
107 |
|
108 |
|
109 inline void CUserAfter::AfterL ( TInt aWaitTimeMicroSeconds ) |
|
110 { |
|
111 CUserAfter* after = CUserAfter::NewL(); |
|
112 after->After ( aWaitTimeMicroSeconds ); |
|
113 delete after; |
|
114 } |
|
115 |
|
116 inline void CUserAfter::After8HrsL ( ) |
|
117 { |
|
118 CUserAfter* after = CUserAfter::NewL(); |
|
119 //aWaitTimeMicroSeconds range is +-2147483647, which is +-35 minutes, 47 seconds. |
|
120 for(TInt i =0 ; i<=16 ; i++) |
|
121 { |
|
122 after->After ( 2147483647 ); |
|
123 } |
|
124 delete after; |
|
125 } |
|
126 |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CUserAfter private functions |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 inline CUserAfter::CUserAfter() |
|
133 : CTimer ( CActive::EPriorityStandard ) |
|
134 { |
|
135 CActiveScheduler::Add ( this ); |
|
136 } |
|
137 |
|
138 |
|
139 inline void CUserAfter::RunL() |
|
140 { |
|
141 iWait.AsyncStop(); |
|
142 Cancel(); |
|
143 } |
|
144 |
|
145 inline void CUserAfter::RunError() |
|
146 { |
|
147 } |
|
148 |
|
149 inline void CUserAfter::DoCancel() |
|
150 { |
|
151 iWait.AsyncStop(); |
|
152 CTimer::DoCancel(); |
|
153 } |
|
154 |
|
155 |
|
156 #endif // CUSERAFTER_H__ |
|
157 |
|
158 // End of File |
|
159 |