|
1 /* |
|
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <usbuinotif.h> |
|
19 #include <d32usbdi_errors.h> |
|
20 |
|
21 #include "cusbstatehosthandledropping.h" |
|
22 #ifndef STIF |
|
23 #include "cusbnotifmanager.h" |
|
24 #else |
|
25 #include "mockcusbnotifmanager.h" |
|
26 #endif |
|
27 |
|
28 #include "errors.h" |
|
29 #include "debug.h" |
|
30 #include "panic.h" |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 // --------------------------------------------------------------------------- |
|
35 // |
|
36 CUsbStateHostHandleDropping::CUsbStateHostHandleDropping( |
|
37 CUsbOtgWatcher& aWatcher) : |
|
38 CUsbStateHostHandle(aWatcher) |
|
39 { |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 CUsbStateHostHandleDropping* CUsbStateHostHandleDropping::NewL( |
|
47 CUsbOtgWatcher& aWatcher) |
|
48 { |
|
49 LOG_FUNC |
|
50 |
|
51 CUsbStateHostHandleDropping* self = |
|
52 new (ELeave) CUsbStateHostHandleDropping(aWatcher); |
|
53 CleanupStack::PushL(self); |
|
54 self->ConstructL(); |
|
55 CleanupStack::Pop(self); |
|
56 return self; |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 void CUsbStateHostHandleDropping::ConstructL() |
|
64 { |
|
65 LOG_FUNC |
|
66 CUsbStateHostHandle::ConstructL(); |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 CUsbStateHostHandleDropping::~CUsbStateHostHandleDropping() |
|
74 { |
|
75 LOG_FUNC |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 TUsbStateIds CUsbStateHostHandleDropping::Id() |
|
83 { |
|
84 return EUsbStateHostHandleDropping; |
|
85 } |
|
86 |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 void CUsbStateHostHandleDropping::JustBeforeLeavingThisStateL() |
|
92 { |
|
93 LOG_FUNC |
|
94 |
|
95 iWatcher.NotifManager()->CloseAllNotifiers(); |
|
96 |
|
97 // do general things |
|
98 CUsbStateHostHandle::JustBeforeLeavingThisStateL(); |
|
99 } |
|
100 |
|
101 // this means only one wait notifier at a time can be shown by this state |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 void CUsbStateHostHandleDropping::WaitNotifierCompletedL(TInt /*aFeedback*/) |
|
107 { |
|
108 LOG_FUNC |
|
109 |
|
110 switch (iWhat) |
|
111 { |
|
112 case EUsbWatcherHubsNotSupported: |
|
113 { |
|
114 LOG( "EUsbWatcherHubsNotSupported" ); |
|
115 ChangeHostStateL( EUsbStateHostAInitiate); |
|
116 break; |
|
117 } |
|
118 case EUsbWatcherErrDeviceRequiresTooMuchPower: |
|
119 { |
|
120 LOG( "EUsbWatcherErrDeviceRequiresTooMuchPower" ); |
|
121 ChangeHostStateL( EUsbStateHostAInitiate); |
|
122 break; |
|
123 } |
|
124 case EUsbWatcherErrUnsupportedDevice: |
|
125 { |
|
126 LOG("EUsbWatcherErrUnsupportedDevice" ); |
|
127 ChangeHostStateL( EUsbStateHostAInitiate); |
|
128 break; |
|
129 } |
|
130 case EUsbWatcherConnectedToOTG: |
|
131 { |
|
132 LOG("EUsbWatcherConnectedToOTG" ); |
|
133 ChangeHostStateL( EUsbStateHostAInitiate); |
|
134 break; |
|
135 } |
|
136 case EUsbWatcherErrDandlingCable: |
|
137 { |
|
138 LOG("EUsbWatcherErrDandlingCable" ); |
|
139 ChangeHostStateL( EUsbStateHostAInitiate); |
|
140 break; |
|
141 } |
|
142 case EUsbWatcherNoActivity: |
|
143 { |
|
144 LOG("EUsbWatcherNoActivity" ); |
|
145 ChangeHostStateL( EUsbStateHostAInitiate); |
|
146 break; |
|
147 } |
|
148 case EUsbWatcherErrorInConnection: |
|
149 { |
|
150 LOG( "EUsbWatcherErrorInConnection" ); |
|
151 ChangeHostStateL( EUsbStateHostAInitiate); |
|
152 break; |
|
153 } |
|
154 |
|
155 // fatal errors |
|
156 case EUsbWatcherCanNotStartUsbServices: |
|
157 { |
|
158 LOG( "EUsbWatcherCanNotStartUsbServices" ); |
|
159 |
|
160 // no break here |
|
161 } |
|
162 |
|
163 // no break statement for following cases |
|
164 case EUsbWatcherIdPinError: |
|
165 case EUsbWatcherVBusObserverError: |
|
166 case EUsbWatcherHostEventNotificationError: |
|
167 case EUsbWatcherOtgStateError: |
|
168 case EUsbWatcherMessageNotificationError: |
|
169 case EUsbWatcherCanNotStartSession: |
|
170 case EUsbWatcherCanNotEnableDriverLoading: |
|
171 case EUsbWatcherCanNotClearBusError: |
|
172 case EUsbWatcherCanNotRaiseVBus: |
|
173 { |
|
174 LOG("Fatal error" ); |
|
175 ChangeHostStateL( EUsbStateHostUndefined); |
|
176 break; |
|
177 } |
|
178 default: |
|
179 { |
|
180 LOG1("Unexpected situation to be handled iWhat = %d" , iWhat ); |
|
181 Panic( EUnexpectedSituationToHandle); |
|
182 break; |
|
183 } |
|
184 |
|
185 } |
|
186 } |
|
187 |
|
188 // --------------------------------------------------------------------------- |
|
189 // |
|
190 // --------------------------------------------------------------------------- |
|
191 // |
|
192 void CUsbStateHostHandleDropping::DoHandleL() |
|
193 { |
|
194 LOG_FUNC |
|
195 |
|
196 LOG1( "iWhat = %d" , iWhat); |
|
197 |
|
198 // Drop VBus first |
|
199 // Ignore any errors when calling BusDrop(). Those indicate that VBus already dropped |
|
200 iWatcher.Usb().BusDrop(); |
|
201 |
|
202 switch (iWhat) |
|
203 { |
|
204 |
|
205 case EUsbWatcherHubsNotSupported: |
|
206 { |
|
207 LOG("EUsbWatcherHubsNotSupported" ); |
|
208 iWatcher.NotifManager()->ShowNotifierL(KUsbUiNotifOtgError, |
|
209 EUsbOtgHubUnsupported, this); |
|
210 break; |
|
211 } |
|
212 case EUsbWatcherErrDeviceRequiresTooMuchPower: |
|
213 { |
|
214 LOG("EUsbWatcherErrDeviceRequiresTooMuchPower" ); |
|
215 iWatcher.NotifManager()->ShowNotifierL(KUsbUiNotifOtgError, |
|
216 EUsbOtgTooMuchPower, this); |
|
217 break; |
|
218 } |
|
219 case EUsbWatcherErrUnsupportedDevice: |
|
220 { |
|
221 LOG("EUsbWatcherErrUnsupportedDevice" ); |
|
222 iWatcher.NotifManager()->ShowNotifierL(KUsbUiNotifOtgError, |
|
223 EUsbOtgUnsupportedDevice, this); |
|
224 break; |
|
225 } |
|
226 case EUsbWatcherConnectedToOTG: |
|
227 { |
|
228 LOG("EUsbWatcherConnectedToOTG" ); |
|
229 iWatcher.NotifManager()->ShowNotifierL(KUsbUiNotifOtgError, |
|
230 EUsbOtgUnsupportedDevice, this); |
|
231 |
|
232 break; |
|
233 } |
|
234 case EUsbWatcherErrDandlingCable: |
|
235 { |
|
236 LOG( "EUsbWatcherErrDandlingCable" ); |
|
237 iWatcher.NotifManager()->ShowNotifierL(KUsbUiNotifOtgError, |
|
238 EUsbOtgErrorAttachTimedOut, this); |
|
239 break; |
|
240 } |
|
241 case EUsbWatcherNoActivity: |
|
242 { |
|
243 LOG( "EUsbWatcherNoActivity" ); |
|
244 iWatcher.NotifManager()->ShowNotifierL(KUsbUiNotifOtgError, |
|
245 EUsbOtgUnsupportedDevice, this); |
|
246 |
|
247 break; |
|
248 } |
|
249 case EUsbWatcherErrorInConnection: |
|
250 { |
|
251 LOG("EUsbWatcherErrorInConnection" ); |
|
252 iWatcher.NotifManager()->ShowNotifierL(KUsbUiNotifOtgError, |
|
253 EUsbOtgErrorInConnection, this); |
|
254 break; |
|
255 } |
|
256 case EUsbWatcherCanNotStartUsbServices: |
|
257 { |
|
258 LOG("EUsbWatcherCanNotStartUsbServices" ); |
|
259 // no break here |
|
260 } |
|
261 // no break in following cases |
|
262 case EUsbWatcherIdPinError: |
|
263 case EUsbWatcherVBusObserverError: |
|
264 case EUsbWatcherHostEventNotificationError: |
|
265 case EUsbWatcherOtgStateError: |
|
266 case EUsbWatcherMessageNotificationError: |
|
267 case EUsbWatcherCanNotStartSession: |
|
268 case EUsbWatcherCanNotEnableDriverLoading: |
|
269 case EUsbWatcherCanNotClearBusError: |
|
270 case EUsbWatcherCanNotRaiseVBus: |
|
271 { |
|
272 LOG1( "Fatal error iWhat = %d", iWhat ); |
|
273 iWatcher.NotifManager()->ShowNotifierL(KUsbUiNotifOtgError, |
|
274 EUsbOtgErrorInConnection, this); |
|
275 break; |
|
276 } |
|
277 default: |
|
278 { |
|
279 LOG1("Unexpected situation to be handled iWhat = %d", iWhat ); |
|
280 Panic( EUnexpectedSituationToHandle); |
|
281 break; |
|
282 } |
|
283 } |
|
284 } |
|
285 |
|
286 ///////////////////////////////////////////////////////////////////////////////////// |
|
287 // From VBus observer |
|
288 // --------------------------------------------------------------------------- |
|
289 // |
|
290 // --------------------------------------------------------------------------- |
|
291 // |
|
292 void CUsbStateHostHandleDropping::VBusUpL() |
|
293 { |
|
294 LOG_FUNC |
|
295 ChangeHostStateL( EUsbStateHostAInitiate); |
|
296 } |
|
297 |
|
298 // --------------------------------------------------------------------------- |
|
299 // this is expected in the state, for example after calling BusDrop |
|
300 // --------------------------------------------------------------------------- |
|
301 // |
|
302 void CUsbStateHostHandleDropping::VBusDownL() |
|
303 { |
|
304 LOG_FUNC |
|
305 } |
|
306 |
|
307 // From Host Event notification observer |
|
308 // --------------------------------------------------------------------------- |
|
309 // |
|
310 // --------------------------------------------------------------------------- |
|
311 // |
|
312 void CUsbStateHostHandleDropping::DeviceAttachedL( |
|
313 TDeviceEventInformation aDevEventInfo) |
|
314 { |
|
315 LOG_FUNC |
|
316 } |
|
317 |
|
318 // --------------------------------------------------------------------------- |
|
319 // |
|
320 // --------------------------------------------------------------------------- |
|
321 // |
|
322 void CUsbStateHostHandleDropping::DeviceDetachedL(TDeviceEventInformation) |
|
323 { |
|
324 LOG_FUNC |
|
325 } |
|
326 |
|
327 // --------------------------------------------------------------------------- |
|
328 // |
|
329 // --------------------------------------------------------------------------- |
|
330 // |
|
331 void CUsbStateHostHandleDropping::DriverLoadSuccessL(TDeviceEventInformation) |
|
332 { |
|
333 LOG_FUNC |
|
334 } |
|
335 |
|
336 // --------------------------------------------------------------------------- |
|
337 // |
|
338 // --------------------------------------------------------------------------- |
|
339 // |
|
340 void CUsbStateHostHandleDropping::DriverLoadPartialSuccessL( |
|
341 TDeviceEventInformation) |
|
342 { |
|
343 LOG_FUNC |
|
344 } |
|
345 |
|
346 // --------------------------------------------------------------------------- |
|
347 // |
|
348 // --------------------------------------------------------------------------- |
|
349 // |
|
350 void CUsbStateHostHandleDropping::DriverLoadFailureL(TDeviceEventInformation) |
|
351 { |
|
352 LOG_FUNC |
|
353 } |
|
354 |
|
355 // From message notification observer |
|
356 // --------------------------------------------------------------------------- |
|
357 // |
|
358 // --------------------------------------------------------------------------- |
|
359 // |
|
360 void CUsbStateHostHandleDropping::MessageNotificationReceivedL(TInt aMessage) |
|
361 { |
|
362 LOG_FUNC |
|
363 |
|
364 LOG1( "aMessage = %d", aMessage ) |
|
365 |
|
366 switch (aMessage) |
|
367 { |
|
368 // USBDI |
|
369 case KEventUsbBadDeviceDetached: |
|
370 { |
|
371 LOG("BadDeviceDetached" ); |
|
372 ChangeHostStateL( EUsbStateHostUndefined); |
|
373 break; |
|
374 } |
|
375 default: |
|
376 { |
|
377 LOG1( "Unhandled message aMessage = %d" , aMessage); |
|
378 break; |
|
379 } |
|
380 |
|
381 } |
|
382 } |