|
1 // Copyright (c) 2002-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 class CFrmwrkSession; |
|
17 |
|
18 #include "MWspEventCallback.h" |
|
19 #include "CWspEventDispatcher.h" |
|
20 #include "CTimeoutTimer.h" |
|
21 |
|
22 const TInt KSecondsToMicroSecondsFactor = 1000000; |
|
23 |
|
24 CWspEventDispatcher* CWspEventDispatcher::NewL(MWspEventCallback& aCallback) |
|
25 { |
|
26 CWspEventDispatcher* self = new (ELeave) CWspEventDispatcher(aCallback); |
|
27 CleanupStack::PushL(self); |
|
28 self->ConstructL(); |
|
29 CleanupStack::Pop(self); |
|
30 return self; |
|
31 } |
|
32 |
|
33 CWspEventDispatcher::~CWspEventDispatcher() |
|
34 { |
|
35 Cancel(); |
|
36 |
|
37 delete iTimer; |
|
38 } |
|
39 |
|
40 CWspEventDispatcher::CWspEventDispatcher(MWspEventCallback& aCallback) |
|
41 : CActive(EPriorityStandard), iCallback(aCallback) |
|
42 { |
|
43 CActiveScheduler::Add(this); |
|
44 } |
|
45 |
|
46 void CWspEventDispatcher::ConstructL() |
|
47 { |
|
48 iTimer = CTimeoutTimer::NewL(*this); |
|
49 } |
|
50 |
|
51 void CWspEventDispatcher::WaitForWspEvent(TInt aTimeoutValueSeconds) |
|
52 { |
|
53 |
|
54 if (!IsActive()) |
|
55 SetActive(); |
|
56 |
|
57 // Start the timeout timer |
|
58 |
|
59 iTimer->After(aTimeoutValueSeconds*KSecondsToMicroSecondsFactor); |
|
60 } |
|
61 |
|
62 void CWspEventDispatcher::WaitForWspEvent() |
|
63 { |
|
64 if (!IsActive()) |
|
65 { |
|
66 iStatus = KRequestPending; |
|
67 SetActive(); |
|
68 } |
|
69 } |
|
70 |
|
71 void CWspEventDispatcher::CancelWait() |
|
72 { |
|
73 Cancel(); |
|
74 } |
|
75 |
|
76 /* |
|
77 * Methods from CActive |
|
78 */ |
|
79 |
|
80 void CWspEventDispatcher::RunL() |
|
81 { |
|
82 // Record the iStatus |
|
83 TRequestStatus status = iStatus; |
|
84 |
|
85 // Cancel the timer |
|
86 iTimer->Cancel(); |
|
87 |
|
88 // Were waiting for WSP event |
|
89 iCallback.HandleWspEvent(status); |
|
90 } |
|
91 |
|
92 void CWspEventDispatcher::DoCancel() |
|
93 { |
|
94 TRequestStatus* pStat = &iStatus; |
|
95 |
|
96 User::RequestComplete(pStat, KErrCancel); |
|
97 iTimer->Cancel(); |
|
98 } |
|
99 |
|
100 /* |
|
101 * Methods from MTimeoutCallback |
|
102 */ |
|
103 |
|
104 void CWspEventDispatcher::Timeout() |
|
105 { |
|
106 TRequestStatus status; |
|
107 status = KRequestPending; |
|
108 iCallback.HandleWspEvent(status); |
|
109 } |
|
110 |