1 /* |
1 /* |
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
8 * |
8 * |
9 * Initial Contributors: |
9 * Initial Contributors: |
10 * Nokia Corporation - initial contribution. |
10 * Nokia Corporation - initial contribution. |
11 * |
11 * |
12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: Blink/show Usb indicator notifier implementation |
14 * Description: Blink/show Usb indicator notifier implementation |
15 * |
15 * |
16 */ |
16 */ |
17 |
|
18 |
17 |
19 #include <AknSmallIndicator.h> |
18 #include <AknSmallIndicator.h> |
20 #include <avkon.hrh> |
19 #include <avkon.hrh> |
21 #include <usbuinotif.h> |
20 #include <usbuinotif.h> |
22 |
21 |
31 |
30 |
32 // ----------------------------------------------------------------------------- |
31 // ----------------------------------------------------------------------------- |
33 // Two-phased constructor. |
32 // Two-phased constructor. |
34 // ----------------------------------------------------------------------------- |
33 // ----------------------------------------------------------------------------- |
35 // |
34 // |
36 CUsbIndicatorNotifier* CUsbIndicatorNotifier::NewL(CUsbNotifManager* aNotifManager, CUsbOtgWatcher* aOtgWatcher) |
35 CUsbIndicatorNotifier* CUsbIndicatorNotifier::NewL( |
37 { |
36 CUsbNotifManager& aNotifManager, CUsbOtgWatcher& aOtgWatcher) |
38 FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::NewL" )); |
37 { |
39 |
38 LOG_FUNC |
40 CUsbIndicatorNotifier* self = new (ELeave) CUsbIndicatorNotifier(aNotifManager, aOtgWatcher); |
39 |
|
40 CUsbIndicatorNotifier* self = new (ELeave) CUsbIndicatorNotifier( |
|
41 aNotifManager, aOtgWatcher); |
41 CleanupStack::PushL(self); |
42 CleanupStack::PushL(self); |
42 self->ConstructL(); |
43 self->ConstructL(); |
43 CleanupStack::Pop(self); |
44 CleanupStack::Pop(self); |
44 return self; |
45 return self; |
45 } |
46 } |
48 // Destructor |
49 // Destructor |
49 // --------------------------------------------------------------------------- |
50 // --------------------------------------------------------------------------- |
50 // |
51 // |
51 CUsbIndicatorNotifier::~CUsbIndicatorNotifier() |
52 CUsbIndicatorNotifier::~CUsbIndicatorNotifier() |
52 { |
53 { |
53 FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::~CUsbIndicatorNotifier" ) ); |
54 LOG_FUNC |
54 |
55 |
55 Close(); |
56 Close(); |
56 delete iIconBlinkingTimer; |
57 delete iIconBlinkingTimer; |
57 |
58 |
58 // Unsubscribe from VBus change notifications |
59 if (iOtgWatcher.VBusObserver()) |
59 if(iOtgWatcher) |
60 { |
60 { |
61 TRAP_IGNORE(iOtgWatcher.VBusObserver()->UnsubscribeL(*this)); |
61 if(iOtgWatcher->VBusObserver()) |
62 } |
62 { |
63 |
63 TRAPD(err, iOtgWatcher->VBusObserver()->UnsubscribeL(this)); |
64 // Unsubscribe from otg watcher states change notifications |
64 err=err; // to avoid warning; |
65 TRAP_IGNORE(iOtgWatcher.UnsubscribeL(*this)); |
65 } |
|
66 |
|
67 // Unsubscribe from otg watcher states change notifications |
|
68 TRAPD(err, iOtgWatcher->UnsubscribeL(this)); |
|
69 err=err; // to avoid warning; |
|
70 } |
|
71 } |
66 } |
72 |
67 |
73 // --------------------------------------------------------------------------- |
68 // --------------------------------------------------------------------------- |
74 // C++ constructor |
69 // C++ constructor |
75 // --------------------------------------------------------------------------- |
70 // --------------------------------------------------------------------------- |
76 // |
71 // |
77 CUsbIndicatorNotifier::CUsbIndicatorNotifier(CUsbNotifManager* aNotifManager, CUsbOtgWatcher* aOtgWatcher) : |
72 CUsbIndicatorNotifier::CUsbIndicatorNotifier(CUsbNotifManager& aNotifManager, |
78 CUsbNotifier(aNotifManager, KUsbUiNotifOtgIndicator, NULL), iOtgWatcher(aOtgWatcher) |
73 CUsbOtgWatcher& aOtgWatcher) : |
79 { |
74 CUsbNotifier(aNotifManager, KUsbUiNotifOtgIndicator, NULL), iOtgWatcher( |
80 FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::CUsbIndicatorNotifier" ) ); |
75 aOtgWatcher) |
|
76 { |
|
77 LOG_FUNC |
81 |
78 |
82 //To be changed to EAknIndicatorStateAnimate and remove iIconBlinkingTimer |
79 //To be changed to EAknIndicatorStateAnimate and remove iIconBlinkingTimer |
83 //when AVKON implements animation form of usb indicator. |
80 //when AVKON implements animation form of usb indicator. |
84 iIndicatorState = EAknIndicatorStateOn; |
81 iIndicatorState = EAknIndicatorStateOn; |
85 } |
82 } |
88 // Second-phase constructor |
85 // Second-phase constructor |
89 // --------------------------------------------------------------------------- |
86 // --------------------------------------------------------------------------- |
90 // |
87 // |
91 void CUsbIndicatorNotifier::ConstructL() |
88 void CUsbIndicatorNotifier::ConstructL() |
92 { |
89 { |
93 FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::ConstructL" ) ); |
90 LOG_FUNC |
94 |
91 |
95 // Subscribe for VBus change notifications |
92 // Subscribe for VBus change notifications |
96 iOtgWatcher->VBusObserver()->SubscribeL(this); |
93 iOtgWatcher.VBusObserver()->SubscribeL(*this); |
97 |
94 |
98 // Subscribe for otg watcher states change notifications |
95 // Subscribe for otg watcher states change notifications |
99 iOtgWatcher->SubscribeL(this); |
96 iOtgWatcher.SubscribeL(*this); |
100 |
97 |
101 iIconBlinkingTimer = CUsbTimer::NewL(this, EIconBlinkingTimer); |
98 iIconBlinkingTimer = CUsbTimer::NewL(*this, EIconBlinkingTimer); |
102 |
99 |
103 // check here for condition to set usb indicator |
100 // check here for condition to set usb indicator |
104 SetIndicatorL(); |
101 SetIndicatorL(); |
105 |
102 |
106 } |
103 } |
107 |
104 |
111 // form of the indicator. |
108 // form of the indicator. |
112 // --------------------------------------------------------------------------- |
109 // --------------------------------------------------------------------------- |
113 // |
110 // |
114 void CUsbIndicatorNotifier::ShowStaticL(TBool aVisible) |
111 void CUsbIndicatorNotifier::ShowStaticL(TBool aVisible) |
115 { |
112 { |
116 FTRACE( FPrint (_L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::ShowStaticL, aVisible=%d" ), aVisible)); |
113 LOG_FUNC |
|
114 |
|
115 LOG1("aVisible = %d" , aVisible); |
117 |
116 |
118 iIconBlinkingTimer->Cancel(); |
117 iIconBlinkingTimer->Cancel(); |
119 |
118 |
120 SetIndicatorStateL(aVisible ? EAknIndicatorStateOn : EAknIndicatorStateOff); |
119 SetIndicatorStateL(aVisible |
|
120 ? EAknIndicatorStateOn |
|
121 : EAknIndicatorStateOff); |
121 } |
122 } |
122 |
123 |
123 // --------------------------------------------------------------------------- |
124 // --------------------------------------------------------------------------- |
124 // |
125 // |
125 // --------------------------------------------------------------------------- |
126 // --------------------------------------------------------------------------- |
126 // |
127 // |
127 void CUsbIndicatorNotifier::BlinkL() |
128 void CUsbIndicatorNotifier::BlinkL() |
128 { |
129 { |
129 FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::BlinkL" )); |
130 LOG_FUNC |
130 |
131 |
131 // Will be canceled if active in After() |
132 // Will be canceled if active in After() |
132 iIconBlinkingTimer->After(0); |
133 iIconBlinkingTimer->After(0); |
133 } |
134 } |
134 |
135 |
136 // From base class CUsbNotifier |
137 // From base class CUsbNotifier |
137 // --------------------------------------------------------------------------- |
138 // --------------------------------------------------------------------------- |
138 // |
139 // |
139 void CUsbIndicatorNotifier::ShowL() |
140 void CUsbIndicatorNotifier::ShowL() |
140 { |
141 { |
141 FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::ShowL" ) ); |
142 LOG_FUNC |
142 |
143 |
143 ShowStaticL(ETrue); |
144 ShowStaticL(ETrue); |
144 } |
145 } |
145 |
146 |
146 // --------------------------------------------------------------------------- |
147 // --------------------------------------------------------------------------- |
147 // From CUsbNotifier |
148 // From CUsbNotifier |
148 // --------------------------------------------------------------------------- |
149 // --------------------------------------------------------------------------- |
149 // |
150 // |
150 void CUsbIndicatorNotifier::Close() |
151 void CUsbIndicatorNotifier::Close() |
151 { |
152 { |
152 FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::Close" ) ); |
153 LOG_FUNC |
153 |
154 |
154 iIconBlinkingTimer->Cancel(); |
155 iIconBlinkingTimer->Cancel(); |
155 TRAP_IGNORE( ShowStaticL(EFalse) ); |
156 TRAP_IGNORE( ShowStaticL(EFalse) ); |
156 } |
157 } |
157 |
158 |
158 // --------------------------------------------------------------------------- |
159 // --------------------------------------------------------------------------- |
163 { |
164 { |
164 switch (aTimerId) |
165 switch (aTimerId) |
165 { |
166 { |
166 case EIconBlinkingTimer: |
167 case EIconBlinkingTimer: |
167 { |
168 { |
168 SetIndicatorStateL(iIndicatorState ? EAknIndicatorStateOn : EAknIndicatorStateOff); |
169 SetIndicatorStateL(iIndicatorState |
169 |
170 ? EAknIndicatorStateOn |
170 iIndicatorState = (iIndicatorState == EAknIndicatorStateOn |
171 : EAknIndicatorStateOff); |
171 ? EAknIndicatorStateOff : EAknIndicatorStateOn); |
172 |
|
173 iIndicatorState |
|
174 = (iIndicatorState == EAknIndicatorStateOn |
|
175 ? EAknIndicatorStateOff |
|
176 : EAknIndicatorStateOn); |
172 |
177 |
173 // Will be canceled if active in After() |
178 // Will be canceled if active in After() |
174 iIconBlinkingTimer->After(KUsbIndicatorBlinkingInterval); |
179 iIconBlinkingTimer->After(KUsbIndicatorBlinkingInterval); |
175 break; |
180 break; |
176 } |
181 } |
177 default: |
182 default: |
178 { |
183 { |
179 FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::TimerElapsedL - Unknown timer" ) ); |
184 LOG1("Unknown timer id = %d", aTimerId) |
180 |
|
181 Panic(EWrongTimerId); |
185 Panic(EWrongTimerId); |
182 } |
186 } |
183 } |
187 } |
184 } |
188 } |
185 |
189 |
187 // Set USB indicator On or Off |
191 // Set USB indicator On or Off |
188 // --------------------------------------------------------------------------- |
192 // --------------------------------------------------------------------------- |
189 // |
193 // |
190 void CUsbIndicatorNotifier::SetIndicatorStateL(const TInt aState) |
194 void CUsbIndicatorNotifier::SetIndicatorStateL(const TInt aState) |
191 { |
195 { |
192 FTRACE( FPrint (_L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::SetIndicatorStateL - aState=%d" ), aState)); |
196 |
193 |
197 LOG1( "USB indicator State = %d" , aState); |
194 CAknSmallIndicator* indicator = CAknSmallIndicator::NewLC(TUid::Uid(EAknIndicatorUSBConnection)); |
198 |
195 indicator->SetIndicatorStateL( aState ); |
199 CAknSmallIndicator* indicator = CAknSmallIndicator::NewLC(TUid::Uid( |
196 CleanupStack::PopAndDestroy( indicator ); //indicator |
200 EAknIndicatorUSBConnection)); |
|
201 indicator->SetIndicatorStateL(aState); |
|
202 CleanupStack::PopAndDestroy(indicator); //indicator |
197 } |
203 } |
198 |
204 |
199 // --------------------------------------------------------------------------- |
205 // --------------------------------------------------------------------------- |
200 // |
206 // |
201 // --------------------------------------------------------------------------- |
207 // --------------------------------------------------------------------------- |
202 // |
208 // |
203 void CUsbIndicatorNotifier::OtgWatcherStateChangedL(TUsbStateIds aState) |
209 void CUsbIndicatorNotifier::OtgWatcherStateChangedL(TUsbStateIds aState) |
204 { |
210 { |
205 FTRACE( FPrint (_L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::OtgWatcherStateChangedL - aState=%d" ), aState)); |
|
206 SetIndicatorL(); |
211 SetIndicatorL(); |
207 } |
212 } |
208 |
213 |
209 // --------------------------------------------------------------------------- |
214 // --------------------------------------------------------------------------- |
210 // |
215 // |
211 // --------------------------------------------------------------------------- |
216 // --------------------------------------------------------------------------- |
212 // |
217 // |
213 void CUsbIndicatorNotifier::VBusDownL() |
218 void CUsbIndicatorNotifier::VBusDownL() |
214 { |
219 { |
215 FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::VBusDownL" ) ); |
|
216 SetIndicatorL(); |
220 SetIndicatorL(); |
217 } |
221 } |
218 |
222 |
219 // --------------------------------------------------------------------------- |
223 // --------------------------------------------------------------------------- |
220 // |
224 // |
221 // --------------------------------------------------------------------------- |
225 // --------------------------------------------------------------------------- |
222 // |
226 // |
223 void CUsbIndicatorNotifier::VBusUpL() |
227 void CUsbIndicatorNotifier::VBusUpL() |
224 { |
228 { |
225 FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::VBusUpL" ) ); |
|
226 SetIndicatorL(); |
229 SetIndicatorL(); |
227 } |
230 } |
228 |
231 |
229 // --------------------------------------------------------------------------- |
232 // --------------------------------------------------------------------------- |
230 // |
233 // |
231 // --------------------------------------------------------------------------- |
234 // --------------------------------------------------------------------------- |
232 // |
235 // |
233 void CUsbIndicatorNotifier::VBusObserverErrorL(TInt aError) |
236 void CUsbIndicatorNotifier::VBusObserverErrorL(TInt aError) |
234 { |
237 { |
235 FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::VBusObserverErrorL" ) ); |
238 // do nothing |
236 // do not care |
|
237 } |
239 } |
238 |
240 |
239 // --------------------------------------------------------------------------- |
241 // --------------------------------------------------------------------------- |
240 // |
242 // |
241 // --------------------------------------------------------------------------- |
243 // --------------------------------------------------------------------------- |
242 // |
244 // |
243 void CUsbIndicatorNotifier::SetIndicatorL() |
245 void CUsbIndicatorNotifier::SetIndicatorL() |
244 { |
246 { |
245 FLOG( _L( "[USBOTGWATCHER]\tCUsbIndicatorNotifier::SetIndicatorL" ) ); |
247 if (!(iOtgWatcher.IsDeviceA())) |
246 |
|
247 if (!(iOtgWatcher->IsDeviceA())) |
|
248 { |
248 { |
249 // if B, than other party (usbwatcher) takes care of usb indicator |
249 // if B, than other party (usbwatcher) takes care of usb indicator |
250 // in combined usbwatcher (if role swap allowed) one class has to manage usb indicator |
250 // in combined usbwatcher (if role swap allowed) one class has to manage usb indicator |
251 return; |
251 return; |
252 } |
252 } |
253 |
253 |
254 // if VBus Up and we are host -> show indicator |
254 // if VBus Up and we are host -> show indicator |
255 if ((iOtgWatcher->VBusObserver()->VBus() == CUsbVBusObserver::EVBusUp) && |
255 if ((iOtgWatcher.VBusObserver()->VBus() == CUsbVBusObserver::EVBusUp) |
256 (iOtgWatcher->CurrentHostState()->Id() == EUsbStateHostAHost)) |
256 && (iOtgWatcher.CurrentHostState()->Id() == EUsbStateHostAHost)) |
257 { |
257 { |
258 ShowStaticL(ETrue); |
258 ShowStaticL(ETrue); |
259 } |
259 } |
260 // if VBus up and we are not host -> Blink indicator |
260 // if VBus up and we are not host -> Blink indicator |
261 else if((iOtgWatcher->VBusObserver()->VBus() == CUsbVBusObserver::EVBusUp) && |
261 else if ((iOtgWatcher.VBusObserver()->VBus() == CUsbVBusObserver::EVBusUp) |
262 (iOtgWatcher->CurrentHostState()->Id() != EUsbStateHostAHost)) |
262 && (iOtgWatcher.CurrentHostState()->Id() != EUsbStateHostAHost)) |
263 { |
263 { |
264 BlinkL(); |
264 BlinkL(); |
265 } |
265 } |
266 else |
266 else |
267 // Otherwise do not show indicator |
267 // Otherwise do not show indicator |