1 /* |
1 /* |
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2008 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". |
13 * |
13 * |
14 * Description: Implementation |
14 * Description: Implementation |
15 * |
15 * |
16 */ |
16 */ |
17 #include <usbuinotif.h> |
17 #include <usbuinotif.h> |
18 |
18 #include <usbhosterrors.h> |
|
19 |
|
20 #include "cusbotgwatcher.h" |
19 #include "cusbstatehostainitiate.h" |
21 #include "cusbstatehostainitiate.h" |
|
22 |
20 #ifndef STIF |
23 #ifndef STIF |
21 #include "cusbtimer.h" |
24 #include "cusbtimer.h" |
22 #include "cusbnotifmanager.h" |
25 #include "cusbnotifmanager.h" |
23 #else |
26 #else |
24 #include "mockcusbnotifmanager.h" |
27 #include "mockcusbnotifmanager.h" |
34 // --------------------------------------------------------------------------- |
37 // --------------------------------------------------------------------------- |
35 // |
38 // |
36 // --------------------------------------------------------------------------- |
39 // --------------------------------------------------------------------------- |
37 // |
40 // |
38 CUsbStateHostAInitiate::CUsbStateHostAInitiate(CUsbOtgWatcher& aWatcher) : |
41 CUsbStateHostAInitiate::CUsbStateHostAInitiate(CUsbOtgWatcher& aWatcher) : |
39 CUsbStateHostABase(aWatcher) |
42 CUsbStateHostABase(aWatcher), iDeviceAttached(EFalse) |
40 { |
43 { |
41 } |
44 } |
42 |
45 |
43 // --------------------------------------------------------------------------- |
46 // --------------------------------------------------------------------------- |
44 // |
47 // |
113 LOG_FUNC |
116 LOG_FUNC |
114 |
117 |
115 // do general things |
118 // do general things |
116 CUsbStateHostABase::JustAdvancedToThisStateL(); |
119 CUsbStateHostABase::JustAdvancedToThisStateL(); |
117 |
120 |
|
121 // clear this attribute, and wait for attachment |
|
122 // one attchment has to correspond to only one detachment |
|
123 iDeviceAttached = EFalse; // to catch not corresponding Detachment, if any |
|
124 |
118 TInt err = iWatcher.Usb().EnableFunctionDriverLoading(); |
125 TInt err = iWatcher.Usb().EnableFunctionDriverLoading(); |
119 |
126 |
120 if (KErrNone != err) |
127 if (KErrNone != err) |
121 { |
128 { |
122 LOG1( "EnableFunctionDriverLoading err = %d", err ); |
129 LOG1( "EnableFunctionDriverLoading err = %d", err ); |
134 TUint count(0); |
141 TUint count(0); |
135 |
142 |
136 while (count < maxTrial && KErrNone != busReqErr) |
143 while (count < maxTrial && KErrNone != busReqErr) |
137 { |
144 { |
138 busReqErr = iWatcher.Usb().BusRequest(); |
145 busReqErr = iWatcher.Usb().BusRequest(); |
139 LOG1( "BusRequest() err = %d" , err); |
146 LOG1( "BusRequest() busReqErr = %d" , busReqErr); |
140 |
147 |
141 if (KErrNone != busReqErr) |
148 if (KErrNone != busReqErr) |
142 { |
149 { |
143 err = iWatcher.Usb().BusClearError(); |
150 err = iWatcher.Usb().BusClearError(); |
144 if (KErrNone != err) |
151 if (KErrNone != err) |
226 |
234 |
227 HandleL(EUsbWatcherConnectedToOTG, EUsbStateHostHandleDropping); |
235 HandleL(EUsbWatcherConnectedToOTG, EUsbStateHostHandleDropping); |
228 return; |
236 return; |
229 } |
237 } |
230 |
238 |
231 if (KErrNone != aTdi.iError) |
239 switch (aTdi.iError) |
232 { |
240 // error in attachement |
233 switch (aTdi.iError) |
241 { |
234 // error in attachement |
242 case KErrNone: |
235 { |
243 { |
236 case KErrBadPower: |
244 break; |
237 { |
245 } |
238 LOG( "TooMuchPower" ); |
246 case KErrUsbDeviceDetachedDuringDriverLoading: |
239 HandleL( |
247 { |
240 EUsbWatcherErrDeviceRequiresTooMuchPowerOnEnumeration, |
248 //do not show error, due to device is already detached |
241 EUsbStateHostDelayNotAttachedHandle); |
249 // Device Detachment will not come after this (it was not attached yet) |
242 break; |
250 // therefore emulate detachment |
243 } |
251 // content of aTdi is not important, due to detachment anyway |
244 default: |
252 DeviceDetachedL(aTdi); |
245 { |
253 break; |
246 LOG1("AttachmentError aTdi.iError = %d" , aTdi.iError ); |
254 } |
247 HandleL(EUsbWatcherErrUnsupportedDevice, |
255 case KErrBadPower: |
248 EUsbStateHostHandleDropping); |
256 { |
249 break; |
257 LOG( "TooMuchPower" ); |
250 } |
258 HandleL(EUsbWatcherErrDeviceRequiresTooMuchPowerOnEnumeration, |
251 } |
259 EUsbStateHostDelayNotAttachedHandle); |
252 |
260 break; |
253 return; |
261 } |
254 } |
262 default: |
|
263 { |
|
264 LOG1("AttachmentError aTdi.iError = %d" , aTdi.iError ); |
|
265 HandleL(EUsbWatcherErrUnsupportedDevice, |
|
266 EUsbStateHostHandleDropping); |
|
267 } |
|
268 } |
|
269 } |
|
270 |
|
271 // --------------------------------------------------------------------------- |
|
272 // |
|
273 // --------------------------------------------------------------------------- |
|
274 // |
|
275 void CUsbStateHostAInitiate::DeviceDetachedL(TDeviceEventInformation aTdi) |
|
276 { |
|
277 LOG_FUNC |
|
278 |
|
279 // iDeviceAttached is used here to avoid one more state creation (init->attached->detached) |
|
280 // due to purpose of this state only to wait for drivers load |
|
281 if (!iDeviceAttached) |
|
282 { |
|
283 PANIC(EDeviceDetachedNotExpected) |
|
284 } |
|
285 |
|
286 // go out, and go in to the same state |
|
287 ChangeHostStateL( EUsbStateHostAInitiate); |
255 } |
288 } |
256 |
289 |
257 // --------------------------------------------------------------------------- |
290 // --------------------------------------------------------------------------- |
258 // |
291 // |
259 // --------------------------------------------------------------------------- |
292 // --------------------------------------------------------------------------- |
267 // --------------------------------------------------------------------------- |
300 // --------------------------------------------------------------------------- |
268 // |
301 // |
269 // --------------------------------------------------------------------------- |
302 // --------------------------------------------------------------------------- |
270 // |
303 // |
271 void CUsbStateHostAInitiate::DriverLoadPartialSuccessL( |
304 void CUsbStateHostAInitiate::DriverLoadPartialSuccessL( |
272 TDeviceEventInformation) |
305 TDeviceEventInformation aDei) |
273 { |
306 { |
274 LOG_FUNC |
307 LOG_FUNC |
275 iWatcher.NotifManager()->ShowNotifierL(KUsbUiNotifOtgWarning, |
308 |
276 EUsbOtgPartiallySupportedDevice, NULL); |
309 switch (aDei.iError) |
|
310 { |
|
311 case KErrUsbDeviceDetachedDuringDriverLoading: |
|
312 { |
|
313 //do not show warning, due to device is already detached |
|
314 break; |
|
315 } |
|
316 default: |
|
317 { |
|
318 iWatcher.NotifManager()->ShowNotifierL(KUsbUiNotifOtgWarning, |
|
319 EUsbOtgPartiallySupportedDevice, NULL); |
|
320 } |
|
321 } |
277 ChangeHostStateL( EUsbStateHostAHost); |
322 ChangeHostStateL( EUsbStateHostAHost); |
278 |
323 |
279 } |
324 } |
280 |
325 |
281 // --------------------------------------------------------------------------- |
326 // --------------------------------------------------------------------------- |