|
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 #include "cactivewaiter.h" |
|
17 |
|
18 CActiveWaiter::CActiveWaiter() |
|
19 : CActive(CActive::EPriorityStandard) |
|
20 { |
|
21 CActiveScheduler::Add(this); |
|
22 } |
|
23 |
|
24 CActiveWaiter::~CActiveWaiter() |
|
25 { Cancel(); } |
|
26 |
|
27 void CActiveWaiter::WaitActive() |
|
28 { |
|
29 ASSERT(!iScheduler.IsStarted()); |
|
30 SetActive(); |
|
31 |
|
32 iScheduler.Start(); |
|
33 } |
|
34 |
|
35 /** |
|
36 Sets the active scheduler active and immidiately Cancels, calling the |
|
37 supplied cancel observer during DoCancel(); |
|
38 @param aCancelObserver performs and DoCancel() operations on behalf of this object |
|
39 */ |
|
40 void CActiveWaiter::SetActiveAndCancel(MActiveWaiterObserver& aCancelObserver) |
|
41 { |
|
42 ASSERT(!iScheduler.IsStarted()); |
|
43 ASSERT(iCancelObserver == NULL); |
|
44 SetActive(); |
|
45 |
|
46 iCancelObserver = &aCancelObserver; |
|
47 |
|
48 Cancel(); |
|
49 } |
|
50 |
|
51 /** |
|
52 Cancels the current operation, and stops the active scheduler loop, |
|
53 allowing a previous call to WaitActive() to return. |
|
54 @param aCancelObserver performs and DoCancel() operations on behalf of this object |
|
55 */ |
|
56 void CActiveWaiter::CancelWaitActive(MActiveWaiterObserver& aCancelObserver) |
|
57 { |
|
58 ASSERT(iScheduler.IsStarted()); |
|
59 ASSERT(iCancelObserver == NULL); |
|
60 |
|
61 iCancelObserver = &aCancelObserver; |
|
62 |
|
63 Cancel(); |
|
64 |
|
65 ASSERT(iScheduler.CanStopNow()); |
|
66 iScheduler.AsyncStop(); |
|
67 } |
|
68 |
|
69 void CActiveWaiter::RunL() |
|
70 { |
|
71 if (iScheduler.IsStarted()) |
|
72 { |
|
73 ASSERT(iScheduler.CanStopNow()); |
|
74 iScheduler.AsyncStop(); |
|
75 } |
|
76 } |
|
77 |
|
78 void CActiveWaiter::DoCancel() |
|
79 { |
|
80 ASSERT(iCancelObserver != NULL); |
|
81 |
|
82 iCancelObserver->DoCancel(); |
|
83 iCancelObserver = NULL; |
|
84 } |