|
1 /* |
|
2 * Copyright (c) 2002 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 * Actively wait until observer is called, store the received values to same object |
|
16 * |
|
17 * |
|
18 * |
|
19 */ |
|
20 |
|
21 #ifndef __CObserverWait_H__ |
|
22 #define __CObserverWait_H__ |
|
23 |
|
24 // INCLUDES |
|
25 #include <e32base.h> |
|
26 #include <e32svr.h> |
|
27 |
|
28 #include "TStaticWrapper.h" |
|
29 |
|
30 //##ModelId=3EBA47C203C4 |
|
31 template < class T1, class T2 = TInt, class T3 = TInt, class T4 = TInt, class T5 = TInt, class T6 = TInt, class T7 = TInt > |
|
32 class CObserverWait : public CBase |
|
33 { |
|
34 //##ModelId=3EBA47C203DC |
|
35 CActiveSchedulerWait iWait; |
|
36 //##ModelId=3EBA47C203E4 |
|
37 TBool iTimeout; |
|
38 //##ModelId=3EBA47C3000C |
|
39 TStaticWrapperVoid<CObserverWait> iWrap; |
|
40 //##ModelId=3EBA47C30011 |
|
41 CAsyncCall* iCall; |
|
42 public: |
|
43 //##ModelId=3EBA47C3001A |
|
44 static CObserverWait* NewLC() |
|
45 { |
|
46 CObserverWait* _that = new( ELeave )CObserverWait; |
|
47 CleanupStack::PushL( _that ); |
|
48 _that->ConstructL(); |
|
49 return _that; |
|
50 } |
|
51 |
|
52 //##ModelId=3EBA47C3001C |
|
53 static CObserverWait* NewL() |
|
54 { |
|
55 CObserverWait* _that = NewLC(); |
|
56 CleanupStack::Pop(); |
|
57 return _that; |
|
58 } |
|
59 |
|
60 //##ModelId=3EBA47C3001E |
|
61 ~CObserverWait() |
|
62 { |
|
63 delete iCall; |
|
64 } |
|
65 |
|
66 protected: |
|
67 //##ModelId=3EBA47C3001F |
|
68 CObserverWait() |
|
69 : iWrap( this, &CObserverWait::Cancel ) |
|
70 { |
|
71 } |
|
72 //##ModelId=3EBA47C30020 |
|
73 void ConstructL() |
|
74 { |
|
75 iCall = CAsyncCall::NewL(); |
|
76 } |
|
77 |
|
78 public: |
|
79 |
|
80 //##ModelId=3EBA47C30021 |
|
81 void SetValue1( T1 aValue ) |
|
82 { |
|
83 iT1 = aValue; |
|
84 } |
|
85 //##ModelId=3EBA47C30023 |
|
86 void SetValue2( T2 aValue ) |
|
87 { |
|
88 iT2 = aValue; |
|
89 } |
|
90 //##ModelId=3EBA47C3002B |
|
91 void SetValue3( T3 aValue ) |
|
92 { |
|
93 iT3 = aValue; |
|
94 } |
|
95 //##ModelId=3EBA47C3002D |
|
96 void SetValue4( T4 aValue ) |
|
97 { |
|
98 iT4 = aValue; |
|
99 } |
|
100 //##ModelId=3EBA47C3002F |
|
101 void SetValue5( T5 aValue ) |
|
102 { |
|
103 iT5 = aValue; |
|
104 } |
|
105 //##ModelId=3EBA47C30039 |
|
106 void SetValue6( T6 aValue ) |
|
107 { |
|
108 iT6 = aValue; |
|
109 } |
|
110 //##ModelId=3EBA47C3003B |
|
111 void SetValue7( T7 aValue ) |
|
112 { |
|
113 iT7 = aValue; |
|
114 } |
|
115 |
|
116 //##ModelId=3EBA47C3003D |
|
117 TBool Wait( TInt aTimeout = -1 ) |
|
118 { |
|
119 iTimeout = EFalse; |
|
120 if ( aTimeout != -1 ) |
|
121 { |
|
122 iCall->Start( &iWrap, aTimeout ); |
|
123 } |
|
124 iWait.Start(); |
|
125 iCall->Stop(); |
|
126 return !Timeout(); |
|
127 } |
|
128 //##ModelId=3EBA47C3003F |
|
129 void Completed( TBool aPanic = ETrue ) |
|
130 { |
|
131 if ( iWait.IsStarted() ) |
|
132 { |
|
133 iWait.AsyncStop(); |
|
134 } |
|
135 else if ( aPanic ) |
|
136 { |
|
137 User::Panic( _L( "CObserverWait" ), 1 ); |
|
138 } |
|
139 } |
|
140 |
|
141 //##ModelId=3EBA47C30049 |
|
142 void Cancel() |
|
143 { |
|
144 if ( iWait.IsStarted() ) |
|
145 { |
|
146 iWait.AsyncStop(); |
|
147 } |
|
148 iTimeout = ETrue; |
|
149 } |
|
150 |
|
151 //##ModelId=3EBA47C3004A |
|
152 TBool Timeout() |
|
153 { |
|
154 return iTimeout; |
|
155 } |
|
156 |
|
157 //##ModelId=3EBA47C3004B |
|
158 T1 Value1() |
|
159 { |
|
160 return iT1; |
|
161 } |
|
162 //##ModelId=3EBA47C3004C |
|
163 T2 Value2() |
|
164 { |
|
165 return iT2; |
|
166 } |
|
167 //##ModelId=3EBA47C3004D |
|
168 T3 Value3() |
|
169 { |
|
170 return iT3; |
|
171 } |
|
172 //##ModelId=3EBA47C3004E |
|
173 T4 Value4() |
|
174 { |
|
175 return iT4; |
|
176 } |
|
177 //##ModelId=3EBA47C3004F |
|
178 T5 Value5() |
|
179 { |
|
180 return iT5; |
|
181 } |
|
182 //##ModelId=3EBA47C30050 |
|
183 T6 Value6() |
|
184 { |
|
185 return iT6; |
|
186 } |
|
187 //##ModelId=3EBA47C30059 |
|
188 T7 Value7() |
|
189 { |
|
190 return iT7; |
|
191 } |
|
192 |
|
193 private: |
|
194 |
|
195 //##ModelId=3EBA47C3005A |
|
196 T1 iT1; |
|
197 //##ModelId=3EBA47C3005B |
|
198 T2 iT2; |
|
199 //##ModelId=3EBA47C3005C |
|
200 T3 iT3; |
|
201 //##ModelId=3EBA47C3005D |
|
202 T4 iT4; |
|
203 //##ModelId=3EBA47C30068 |
|
204 T5 iT5; |
|
205 //##ModelId=3EBA47C30069 |
|
206 T6 iT6; |
|
207 //##ModelId=3EBA47C3006A |
|
208 T7 iT7; |
|
209 }; |
|
210 |
|
211 |
|
212 #endif // __CObserverWait_H__ |
|
213 // End of File |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 |