|
1 /******************************************************************************* |
|
2 * Copyright (c) 2007, 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. This program and the accompanying materials |
|
4 * are made available under the terms of the Eclipse Public License v1.0 |
|
5 * which accompanies this distribution, and is available at |
|
6 * http://www.eclipse.org/legal/epl-v10.html |
|
7 * |
|
8 * Contributors: |
|
9 * Nokia Corporation - S60 implementation |
|
10 *******************************************************************************/ |
|
11 |
|
12 |
|
13 #include <swtlaffacade.h> |
|
14 #include "swtflipwatch.h" |
|
15 |
|
16 |
|
17 // Priority of the flip watch CActive. If for some reason the flip watch |
|
18 // CActive gets blocked, the watch timer should wait also. Therefore the |
|
19 // priority of the watch timer should be lower than this. |
|
20 const TInt KSwtFlipWatchPriority = 0; |
|
21 |
|
22 // Using a short delay on the flip watch will avoid ui unresponsiveness when |
|
23 // fast swaping the flip back and forth. |
|
24 const TInt KSwtFlipWatchTimeout = 250000; |
|
25 |
|
26 |
|
27 // ======== MEMBER FUNCTIONS ======== |
|
28 |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // CSwtFlipWatch::NewL |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 CSwtFlipWatch* CSwtFlipWatch::NewL(MSwtFlipObserver* aObserver) |
|
35 { |
|
36 CSwtFlipWatch* self = new(ELeave) CSwtFlipWatch(aObserver); |
|
37 CleanupStack::PushL(self); |
|
38 self->ConstructL(); |
|
39 CleanupStack::Pop(self); |
|
40 return self; |
|
41 } |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // CSwtFlipWatch::~CSwtFlipWatch |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 CSwtFlipWatch::~CSwtFlipWatch() |
|
48 { |
|
49 Cancel(); |
|
50 iProperty.Close(); |
|
51 |
|
52 if (iTimer) |
|
53 { |
|
54 iTimer->Cancel(); |
|
55 delete iTimer; |
|
56 } |
|
57 } |
|
58 |
|
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // CSwtFlipWatch::CSwtFlipWatch |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 CSwtFlipWatch::CSwtFlipWatch(MSwtFlipObserver* aObserver) |
|
65 : CActive(KSwtFlipWatchPriority), iObserver(aObserver) |
|
66 , iFlipOpen(ETrue) |
|
67 { |
|
68 ASSERT(iObserver); |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // CSwtFlipWatch::ConstructL |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 void CSwtFlipWatch::ConstructL() |
|
76 { |
|
77 User::LeaveIfError(iProperty.Attach(CSwtLafFacade::GetFlipWatchUid(), CSwtLafFacade::GetFlipWatchStatus())); |
|
78 iTimer = CSwtFlipWatchTimer::NewL(this); |
|
79 CActiveScheduler::Add(this); |
|
80 RunL(); |
|
81 } |
|
82 |
|
83 // --------------------------------------------------------------------------- |
|
84 // CSwtFlipWatch::DoCancel |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 void CSwtFlipWatch::DoCancel() |
|
88 { |
|
89 iProperty.Cancel(); |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // CSwtFlipWatch::RunL |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 void CSwtFlipWatch::RunL() |
|
97 { |
|
98 iTimer->Cancel(); |
|
99 iProperty.Subscribe(iStatus); |
|
100 iObserver->FlipChangingL(); |
|
101 iTimer->SetTimer(KSwtFlipWatchTimeout); |
|
102 SetActive(); |
|
103 } |
|
104 |
|
105 // --------------------------------------------------------------------------- |
|
106 // CSwtFlipWatch::HandleTimeoutL |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 void CSwtFlipWatch::HandleTimeoutL() |
|
110 { |
|
111 TInt flipStatus = 0; |
|
112 TBool flipOpen = ETrue; |
|
113 TInt err = iProperty.Get(flipStatus); |
|
114 if (err == KErrNone) |
|
115 { |
|
116 if (flipStatus == CSwtLafFacade::GetFlipWatchEnumerationStatus()) |
|
117 { |
|
118 flipOpen = EFalse; |
|
119 } |
|
120 if (iFlipOpen != flipOpen) |
|
121 { |
|
122 iObserver->FlipChangedL(flipOpen); |
|
123 iFlipOpen = flipOpen; |
|
124 } |
|
125 } |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------------------------- |
|
129 // CSwtFlipWatchTimer::NewL |
|
130 // --------------------------------------------------------------------------- |
|
131 // |
|
132 CSwtFlipWatchTimer* CSwtFlipWatchTimer::NewL(MSwtFlipWatchTimerHandler* aHandler) |
|
133 { |
|
134 CSwtFlipWatchTimer* self = new(ELeave) CSwtFlipWatchTimer(aHandler); |
|
135 CleanupStack::PushL(self); |
|
136 self->ConstructL(); |
|
137 CleanupStack::Pop(self); |
|
138 return self; |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------------------------- |
|
142 // CSwtFlipWatchTimer::CSwtFlipWatchTimer |
|
143 // --------------------------------------------------------------------------- |
|
144 // |
|
145 CSwtFlipWatchTimer::CSwtFlipWatchTimer(MSwtFlipWatchTimerHandler* aHandler) |
|
146 : CActive(KSwtFlipWatchPriority - 1) |
|
147 , iHandler(aHandler) |
|
148 { |
|
149 ASSERT(iHandler); |
|
150 } |
|
151 |
|
152 // --------------------------------------------------------------------------- |
|
153 // CSwtFlipWatchTimer::ConstructL |
|
154 // --------------------------------------------------------------------------- |
|
155 // |
|
156 void CSwtFlipWatchTimer::ConstructL() |
|
157 { |
|
158 TInt err = iTimer.CreateLocal(); |
|
159 User::LeaveIfError(err); |
|
160 CActiveScheduler::Add(this); |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------------------------- |
|
164 // CSwtFlipWatchTimer::~CSwtFlipWatchTimer |
|
165 // --------------------------------------------------------------------------- |
|
166 // |
|
167 CSwtFlipWatchTimer::~CSwtFlipWatchTimer() |
|
168 { |
|
169 Cancel(); |
|
170 iTimer.Close(); |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------------------------- |
|
174 // CSwtFlipWatchTimer::RunL |
|
175 // --------------------------------------------------------------------------- |
|
176 // |
|
177 void CSwtFlipWatchTimer::RunL() |
|
178 { |
|
179 iHandler->HandleTimeoutL(); |
|
180 } |
|
181 |
|
182 // --------------------------------------------------------------------------- |
|
183 // CSwtFlipWatchTimer::DoCancel |
|
184 // --------------------------------------------------------------------------- |
|
185 // |
|
186 void CSwtFlipWatchTimer::DoCancel() |
|
187 { |
|
188 iTimer.Cancel(); |
|
189 } |
|
190 |
|
191 // --------------------------------------------------------------------------- |
|
192 // CSwtFlipWatchTimer::SetTimer |
|
193 // --------------------------------------------------------------------------- |
|
194 // |
|
195 void CSwtFlipWatchTimer::SetTimer(TTimeIntervalMicroSeconds32 aDelay) |
|
196 { |
|
197 Cancel(); |
|
198 iTimer.After(iStatus, aDelay); |
|
199 SetActive(); |
|
200 } |