|
1 // Copyright (c) 2006-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 @internalTechnology |
|
23 @prototype |
|
24 */ |
|
25 class MActiveWaiterObserver |
|
26 { |
|
27 public: |
|
28 virtual void DoCancel() =0; |
|
29 }; |
|
30 |
|
31 /** |
|
32 An generic active object that can be used to wait for an iStatus to be signalled. |
|
33 This has a similar effect to User::WaitForRequest(), but works without |
|
34 blocking the thread (which allows other active objects within the thread |
|
35 to continue). Instead, a nested active scheduler loop is used. |
|
36 |
|
37 To use a CActiveWaiter, pass its iStatus to an asynchronous method, as usual. |
|
38 Then call WaitActive() instead of SetActive(). |
|
39 |
|
40 The call will block until the asynchronous completes. |
|
41 |
|
42 E.g. |
|
43 |
|
44 void CMyClass::Foo() |
|
45 { |
|
46 CActiveWaiter* waiter = new(ELeave)CActiveWaiter; |
|
47 |
|
48 iAsyncObj->Bar(waiter->iStatus); |
|
49 waiter->WaitActive(); |
|
50 |
|
51 delete waiter; |
|
52 } |
|
53 @internalTechnology |
|
54 @prototype |
|
55 */ |
|
56 class CActiveWaiter : public CActive |
|
57 { |
|
58 public: |
|
59 CActiveWaiter(); |
|
60 ~CActiveWaiter(); |
|
61 |
|
62 void WaitActive(); |
|
63 void SetActiveAndCancel(MActiveWaiterObserver& aCancelObserver); |
|
64 void CancelWaitActive(MActiveWaiterObserver& aCancelObserver); |
|
65 |
|
66 protected: |
|
67 // from CActive; |
|
68 void RunL(); |
|
69 void DoCancel(); |
|
70 |
|
71 private: |
|
72 CActiveSchedulerWait iScheduler; |
|
73 MActiveWaiterObserver* iCancelObserver; |
|
74 }; |
|
75 |
|
76 #endif CACTIVEWAITER_H |