|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #ifndef CACTIVEWAITER_H |
|
17 #define CACTIVEWAITER_H |
|
18 |
|
19 #include <test/tefunit.h> |
|
20 |
|
21 /** |
|
22 An generic active object that can be used to wait for an iStatus to be signalled. |
|
23 This has a similar effect to User::WaitForRequest(), but works without |
|
24 blocking the thread (which allows other active objects within the thread |
|
25 to continue). Instead, a nested active scheduler loop is used. |
|
26 |
|
27 To use a CActiveWaiter, pass its iStatus to an asynchronous method, as usual. |
|
28 Then call WaitActive() instead of SetActive(). |
|
29 |
|
30 The call will block until the asynchronous completes. |
|
31 |
|
32 E.g. |
|
33 |
|
34 void CMyClass::Foo() |
|
35 { |
|
36 CActiveWaiter* waiter = new(ELeave)CActiveWaiter; |
|
37 |
|
38 iAsyncObj->Bar(waiter->iStatus); |
|
39 waiter->WaitActive(); |
|
40 |
|
41 delete waiter; |
|
42 } |
|
43 @internalTechnology |
|
44 @prototype |
|
45 */ |
|
46 class CActiveWaiter : public CActive |
|
47 { |
|
48 public: |
|
49 CActiveWaiter(); |
|
50 ~CActiveWaiter(); |
|
51 |
|
52 void WaitActive(); |
|
53 void SetActiveDontWait(); |
|
54 |
|
55 protected: |
|
56 // from CActive; |
|
57 void RunL(); |
|
58 void DoCancel(); |
|
59 |
|
60 private: |
|
61 CActiveSchedulerWait iScheduler; |
|
62 }; |
|
63 |
|
64 #endif CACTIVEWAITER_H |