2
|
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: <This module contains the implementation of xxx
|
|
15 |
* class member functions...>
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
// INCLUDE FILES
|
|
20 |
#include <e32svr.h>
|
|
21 |
#include "TestServerEvent.h"
|
|
22 |
#include "TestThreadContainer.h"
|
|
23 |
#include "TestServerModuleIf.h"
|
|
24 |
#include "Logging.h"
|
|
25 |
|
|
26 |
// EXTERNAL DATA STRUCTURES
|
|
27 |
//extern ?external_data;
|
|
28 |
|
|
29 |
// EXTERNAL FUNCTION PROTOTYPES
|
|
30 |
//extern ?external_function( ?arg_type,?arg_type );
|
|
31 |
|
|
32 |
// CONSTANTS
|
|
33 |
//const ?type ?constant_var = ?constant;
|
|
34 |
|
|
35 |
// MACROS
|
|
36 |
//#define ?macro ?macro_def
|
|
37 |
|
|
38 |
// LOCAL CONSTANTS AND MACROS
|
|
39 |
//const ?type ?constant_var = ?constant;
|
|
40 |
//#define ?macro_name ?macro_def
|
|
41 |
|
|
42 |
// MODULE DATA STRUCTURES
|
|
43 |
//enum ?declaration
|
|
44 |
//typedef ?declaration
|
|
45 |
|
|
46 |
// LOCAL FUNCTION PROTOTYPES
|
|
47 |
//?type ?function_name( ?arg_type, ?arg_type );
|
|
48 |
|
|
49 |
// FORWARD DECLARATIONS
|
|
50 |
//class ?FORWARD_CLASSNAME;
|
|
51 |
|
|
52 |
// ================= MEMBER FUNCTIONS =========================================
|
|
53 |
|
|
54 |
/*
|
|
55 |
-------------------------------------------------------------------------------
|
|
56 |
|
|
57 |
Class: TEvent
|
|
58 |
|
|
59 |
Method: TEvent
|
|
60 |
|
|
61 |
Description: Default constructor
|
|
62 |
|
|
63 |
C++ default constructor can NOT contain any code, that
|
|
64 |
might leave.
|
|
65 |
|
|
66 |
<description of the functionality
|
|
67 |
description continues and...
|
|
68 |
continues.>
|
|
69 |
|
|
70 |
Parameters: <arg1>: <in/out/inout>: <accepted values>: <Description>
|
|
71 |
|
|
72 |
Return Values: <value_1: Description
|
|
73 |
value_n: Description line 1
|
|
74 |
description line 2>
|
|
75 |
|
|
76 |
Errors/Exceptions: <description how errors and exceptions are handled>
|
|
77 |
|
|
78 |
Status: Draft
|
|
79 |
|
|
80 |
-------------------------------------------------------------------------------
|
|
81 |
*/
|
|
82 |
TEvent::TEvent( TThreadId aTestThread ) :
|
|
83 |
TEventIf(),
|
|
84 |
iReq(NULL),
|
|
85 |
iThread( aTestThread ),
|
|
86 |
iEventPending(EFalse),
|
|
87 |
iExecution( NULL )
|
|
88 |
{
|
|
89 |
|
|
90 |
}
|
|
91 |
|
|
92 |
/*
|
|
93 |
-------------------------------------------------------------------------------
|
|
94 |
|
|
95 |
Class: TEvent
|
|
96 |
|
|
97 |
Method: ~TEvent
|
|
98 |
|
|
99 |
Description: Destructor
|
|
100 |
|
|
101 |
<description of the functionality
|
|
102 |
description continues and...
|
|
103 |
continues.>
|
|
104 |
|
|
105 |
Parameters: <arg1>: <in/out/inout>: <accepted values>: <Description>
|
|
106 |
|
|
107 |
Return Values: <value_1: Description
|
|
108 |
value_n: Description line 1
|
|
109 |
description line 2>
|
|
110 |
|
|
111 |
Errors/Exceptions: <description how errors and exceptions are handled>
|
|
112 |
|
|
113 |
Status: Draft
|
|
114 |
|
|
115 |
-------------------------------------------------------------------------------
|
|
116 |
*/
|
|
117 |
TEvent::~TEvent()
|
|
118 |
{
|
|
119 |
// Removed this call, to be studied @js
|
|
120 |
//Release(); //safety
|
|
121 |
}
|
|
122 |
|
|
123 |
|
|
124 |
/*
|
|
125 |
-------------------------------------------------------------------------------
|
|
126 |
|
|
127 |
Class: TEvent
|
|
128 |
|
|
129 |
Method: Set
|
|
130 |
|
|
131 |
Description: Set event.
|
|
132 |
|
|
133 |
Parameters: <arg1>: <in/out/inout>: <accepted values>: <Description>
|
|
134 |
|
|
135 |
Return Values: <value_1: Description
|
|
136 |
value_n: Description line 1
|
|
137 |
description line 2>
|
|
138 |
|
|
139 |
Errors/Exceptions: <description how errors and exceptions are handled>
|
|
140 |
|
|
141 |
Status: Draft
|
|
142 |
|
|
143 |
-------------------------------------------------------------------------------
|
|
144 |
*/
|
|
145 |
void TEvent::Set( TEventType aEventType )
|
|
146 |
{
|
|
147 |
iEventPending = ETrue;
|
|
148 |
iEventType = aEventType;
|
|
149 |
|
|
150 |
if( iReq )
|
|
151 |
{
|
|
152 |
CompletePendingWait( KErrNone );
|
|
153 |
if( iEventType == EIndication )
|
|
154 |
iEventPending = EFalse;
|
|
155 |
}
|
|
156 |
}
|
|
157 |
|
|
158 |
/*
|
|
159 |
-------------------------------------------------------------------------------
|
|
160 |
|
|
161 |
Class: TEvent
|
|
162 |
|
|
163 |
Method: EventPending
|
|
164 |
|
|
165 |
Description: Check event status.
|
|
166 |
|
|
167 |
Parameters: <arg1>: <in/out/inout>: <accepted values>: <Description>
|
|
168 |
|
|
169 |
Return Values: <value_1: Description
|
|
170 |
value_n: Description line 1
|
|
171 |
description line 2>
|
|
172 |
|
|
173 |
Errors/Exceptions: <description how errors and exceptions are handled>
|
|
174 |
|
|
175 |
Status: Draft
|
|
176 |
|
|
177 |
-------------------------------------------------------------------------------
|
|
178 |
*/
|
|
179 |
TBool TEvent::EventPending()
|
|
180 |
{
|
|
181 |
if( iEventPending )
|
|
182 |
{
|
|
183 |
// Indication events are signaled only once
|
|
184 |
if( iEventType == EIndication )
|
|
185 |
iEventPending = EFalse;
|
|
186 |
return ETrue;
|
|
187 |
}
|
|
188 |
return EFalse;
|
|
189 |
}
|
|
190 |
|
|
191 |
/*
|
|
192 |
-------------------------------------------------------------------------------
|
|
193 |
|
|
194 |
Class: TEvent
|
|
195 |
|
|
196 |
Method: WaitEventPending
|
|
197 |
|
|
198 |
Description: Check waiting status.
|
|
199 |
|
|
200 |
Parameters: <arg1>: <in/out/inout>: <accepted values>: <Description>
|
|
201 |
|
|
202 |
Return Values: <value_1: Description
|
|
203 |
value_n: Description line 1
|
|
204 |
description line 2>
|
|
205 |
|
|
206 |
Errors/Exceptions: <description how errors and exceptions are handled>
|
|
207 |
|
|
208 |
Status: Draft
|
|
209 |
|
|
210 |
-------------------------------------------------------------------------------
|
|
211 |
*/
|
|
212 |
TBool TEvent::WaitEventPending()
|
|
213 |
{
|
|
214 |
if( iReq )
|
|
215 |
{
|
|
216 |
return ETrue;
|
|
217 |
}
|
|
218 |
else
|
|
219 |
{
|
|
220 |
return EFalse;
|
|
221 |
}
|
|
222 |
}
|
|
223 |
|
|
224 |
/*
|
|
225 |
-------------------------------------------------------------------------------
|
|
226 |
|
|
227 |
Class: TEvent
|
|
228 |
|
|
229 |
Method: SetWaitPending
|
|
230 |
|
|
231 |
Description: First phase of waiting.
|
|
232 |
|
|
233 |
Parameters: <arg1>: <in/out/inout>: <accepted values>: <Description>
|
|
234 |
|
|
235 |
Return Values: <value_1: Description
|
|
236 |
value_n: Description line 1
|
|
237 |
description line 2>
|
|
238 |
|
|
239 |
Errors/Exceptions: <description how errors and exceptions are handled>
|
|
240 |
|
|
241 |
Status: Draft
|
|
242 |
|
|
243 |
-------------------------------------------------------------------------------
|
|
244 |
*/
|
|
245 |
TInt TEvent::SetWaitPending( TRequestStatus* aStatus )
|
|
246 |
{
|
|
247 |
if( aStatus )
|
|
248 |
{
|
|
249 |
iReq = aStatus;
|
|
250 |
}
|
|
251 |
else
|
|
252 |
{
|
|
253 |
iReq = &iRequestStatus;
|
|
254 |
}
|
|
255 |
__RDEBUG((_L("Set wait pending(%d) %x"), this, iReq ));
|
|
256 |
|
|
257 |
return KErrNone;
|
|
258 |
}
|
|
259 |
|
|
260 |
/*
|
|
261 |
-------------------------------------------------------------------------------
|
|
262 |
|
|
263 |
Class: TEvent
|
|
264 |
|
|
265 |
Method: CompletePendingWait
|
|
266 |
|
|
267 |
Description: Complete pending wait.
|
|
268 |
|
|
269 |
Parameters: <arg1>: <in/out/inout>: <accepted values>: <Description>
|
|
270 |
|
|
271 |
Return Values: <value_1: Description
|
|
272 |
value_n: Description line 1
|
|
273 |
description line 2>
|
|
274 |
|
|
275 |
Errors/Exceptions: <description how errors and exceptions are handled>
|
|
276 |
|
|
277 |
Status: Draft
|
|
278 |
|
|
279 |
-------------------------------------------------------------------------------
|
|
280 |
*/
|
|
281 |
void TEvent::CompletePendingWait( TInt aError )
|
|
282 |
{
|
|
283 |
_LIT( KTEvent, "TEvent" );
|
|
284 |
__ASSERT_ALWAYS( iReq, User::Panic( KTEvent, KErrGeneral ) );
|
|
285 |
|
|
286 |
RThread rt;
|
|
287 |
if( rt.Open( iThread ) == KErrNone )
|
|
288 |
{
|
|
289 |
__RDEBUG( (_L("Complete wait(%d) %x"), this, iReq ) );
|
|
290 |
rt.RequestComplete( iReq, aError );
|
|
291 |
}
|
|
292 |
rt.Close();
|
|
293 |
iReq = NULL;
|
|
294 |
|
|
295 |
}
|
|
296 |
|
|
297 |
/*
|
|
298 |
-------------------------------------------------------------------------------
|
|
299 |
|
|
300 |
Class: TEvent
|
|
301 |
|
|
302 |
Method: Wait
|
|
303 |
|
|
304 |
Description: Wait event.
|
|
305 |
Parameters: <arg1>: <in/out/inout>: <accepted values>: <Description>
|
|
306 |
|
|
307 |
Return Values: <value_1: Description
|
|
308 |
value_n: Description line 1
|
|
309 |
description line 2>
|
|
310 |
|
|
311 |
Errors/Exceptions: <description how errors and exceptions are handled>
|
|
312 |
|
|
313 |
Status: Draft
|
|
314 |
|
|
315 |
-------------------------------------------------------------------------------
|
|
316 |
*/
|
|
317 |
void TEvent::Wait()
|
|
318 |
{
|
|
319 |
|
|
320 |
User::WaitForRequest( iRequestStatus );
|
|
321 |
// else Wait was already completed from other thread
|
|
322 |
EventPending();
|
|
323 |
}
|
|
324 |
|
|
325 |
/*
|
|
326 |
-------------------------------------------------------------------------------
|
|
327 |
|
|
328 |
Class: TEvent
|
|
329 |
|
|
330 |
Method: Release
|
|
331 |
|
|
332 |
Description: Release event. Completes conceivably pending unset.
|
|
333 |
|
|
334 |
Parameters: <arg1>: <in/out/inout>: <accepted values>: <Description>
|
|
335 |
|
|
336 |
Return Values: <value_1: Description
|
|
337 |
value_n: Description line 1
|
|
338 |
description line 2>
|
|
339 |
|
|
340 |
Errors/Exceptions: <description how errors and exceptions are handled>
|
|
341 |
|
|
342 |
Status: Draft
|
|
343 |
|
|
344 |
-------------------------------------------------------------------------------
|
|
345 |
*/
|
|
346 |
void TEvent::Release()
|
|
347 |
{
|
|
348 |
if( iReq )
|
|
349 |
{
|
|
350 |
// Wait is pending and we received Release,
|
|
351 |
// so we complete event with Cancel
|
|
352 |
CompletePendingWait( KErrCancel );
|
|
353 |
iEventPending = ETrue;
|
|
354 |
}
|
|
355 |
|
|
356 |
if( iExecution )
|
|
357 |
{
|
|
358 |
|
|
359 |
iExecution->UnsetEvent( *this, iUnsetMessage );
|
|
360 |
iExecution = NULL;
|
|
361 |
|
|
362 |
}
|
|
363 |
|
|
364 |
}
|
|
365 |
|
|
366 |
/*
|
|
367 |
-------------------------------------------------------------------------------
|
|
368 |
|
|
369 |
Class: TEvent
|
|
370 |
|
|
371 |
Method: Unset
|
|
372 |
|
|
373 |
Description: Unset event. Unset blocks until Release is called
|
|
374 |
(i.e. iUnsetMessage is compeled from release).
|
|
375 |
|
|
376 |
Parameters: <arg1>: <in/out/inout>: <accepted values>: <Description>
|
|
377 |
|
|
378 |
Return Values: <value_1: Description
|
|
379 |
value_n: Description line 1
|
|
380 |
description line 2>
|
|
381 |
|
|
382 |
Errors/Exceptions: <description how errors and exceptions are handled>
|
|
383 |
|
|
384 |
Status: Draft
|
|
385 |
|
|
386 |
-------------------------------------------------------------------------------
|
|
387 |
*/
|
|
388 |
TInt TEvent::Unset( const RMessage2& aMessage, CTestExecution* aExecution )
|
|
389 |
{
|
|
390 |
|
|
391 |
if( iExecution )
|
|
392 |
{
|
|
393 |
return KErrAlreadyExists;
|
|
394 |
}
|
|
395 |
|
|
396 |
if( aExecution == NULL )
|
|
397 |
{
|
|
398 |
return KErrArgument;
|
|
399 |
}
|
|
400 |
|
|
401 |
iExecution = aExecution;
|
|
402 |
iUnsetMessage = aMessage;
|
|
403 |
|
|
404 |
return KErrNone;
|
|
405 |
|
|
406 |
}
|
|
407 |
|
|
408 |
// End of File
|