1 /* |
1 /* |
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2008-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 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation |
|
15 * |
8 * |
16 */ |
9 * Initial Contributors: |
17 |
10 * Nokia Corporation - initial contribution. |
18 |
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation |
|
15 * |
|
16 */ |
19 #include <usbpersonalityids.h> |
17 #include <usbpersonalityids.h> |
20 #include <usbuinotif.h> |
18 #include <usbuinotif.h> |
21 #include <UsbWatcherInternalPSKeys.h> |
19 #include <UsbWatcherInternalPSKeys.h> |
22 |
|
23 #include "cusbotgwatcher.h" |
20 #include "cusbotgwatcher.h" |
24 #include "cusbstate.h" |
21 #include "cusbstate.h" |
25 |
|
26 #include "cusbstatehostainitiate.h" |
22 #include "cusbstatehostainitiate.h" |
27 #include "cusbstatehostahost.h" |
23 #include "cusbstatehostahost.h" |
28 #include "cusbstatehostaperipheral.h" |
24 #include "cusbstatehostaperipheral.h" |
29 #include "cusbstatehostaidle.h" |
|
30 #include "cusbstatehosthandle.h" |
25 #include "cusbstatehosthandle.h" |
31 |
26 #include "cusbstatehostdelayhandle.h" |
|
27 #include "cusbstatehostdelayattachedhandle.h" |
|
28 #include "cusbstatehostdelaynotattachedhandle.h" |
|
29 #include "cusbstatehosthandledropping.h" |
|
30 #include "cusbstatehostundefined.h" |
32 #include "cusbwarningnotifier.h" |
31 #include "cusbwarningnotifier.h" |
33 |
|
34 #ifndef STIF |
32 #ifndef STIF |
35 #include "cusbnotifmanager.h" |
33 #include "cusbnotifmanager.h" |
36 #else |
34 #else |
37 #include "mockcusbnotifmanager.h" |
35 #include "mockcusbnotifmanager.h" |
38 #endif |
36 #endif |
39 |
|
40 #include "errors.h" |
37 #include "errors.h" |
41 #include "debug.h" |
38 #include "debug.h" |
42 #include "panic.h" |
39 #include "panic.h" |
43 |
|
44 _LIT_SECURITY_POLICY_PASS( KAlwaysPassPolicy ); |
40 _LIT_SECURITY_POLICY_PASS( KAlwaysPassPolicy ); |
45 _LIT_SECURITY_POLICY_C1( KLocalServicesPolicy, ECapabilityLocalServices ); |
41 _LIT_SECURITY_POLICY_C1( KLocalServicesPolicy, ECapabilityLocalServices ); |
46 |
42 |
47 // --------------------------------------------------------------------------- |
43 // --------------------------------------------------------------------------- |
48 // |
44 // |
49 // --------------------------------------------------------------------------- |
45 // --------------------------------------------------------------------------- |
50 // |
46 // |
51 CUsbOtgWatcher::CUsbOtgWatcher(RUsb& aUsbMan) : |
47 CUsbOtgWatcher::CUsbOtgWatcher(RUsb& aUsbMan) : |
52 iUsb(aUsbMan), iPersonalityId(KUsbPersonalityIdMTP) |
48 iUsb(aUsbMan), iPersonalityId(KUsbPersonalityIdMTP), iUsbServiceRequest( |
53 { |
49 CUsbServiceControl::ERequestUndefined) |
54 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::CUsbOtgWatcher" ) ); |
50 { |
|
51 LOG_FUNC |
55 } |
52 } |
56 |
53 |
57 // --------------------------------------------------------------------------- |
54 // --------------------------------------------------------------------------- |
58 // |
55 // |
59 // --------------------------------------------------------------------------- |
56 // --------------------------------------------------------------------------- |
60 // |
57 // |
61 void CUsbOtgWatcher::ConstructL() |
58 void CUsbOtgWatcher::ConstructL() |
62 { |
59 { |
63 |
60 LOG_FUNC |
64 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::ConstructL" ) ); |
|
65 |
61 |
66 #ifdef _DEBUG |
62 #ifdef _DEBUG |
67 SelfTestL(); |
63 SelfTestL(); |
68 #endif |
64 #endif |
69 |
65 |
70 #ifndef STIF |
66 #ifndef STIF |
71 User::LeaveIfError(RProperty::Define( KPSUidUsbWatcher, |
67 User::LeaveIfError(RProperty::Define(KPSUidUsbWatcher, |
72 KUsbWatcherIsPeripheralConnected, RProperty::EInt, KAlwaysPassPolicy, |
68 KUsbWatcherIsPeripheralConnected, RProperty::EInt, |
73 KLocalServicesPolicy ) ); |
69 KAlwaysPassPolicy, KLocalServicesPolicy)); |
74 |
70 |
75 User::LeaveIfError( RProperty::Set( KPSUidUsbWatcher, |
71 User::LeaveIfError(RProperty::Set(KPSUidUsbWatcher, |
76 KUsbWatcherIsPeripheralConnected, |
72 KUsbWatcherIsPeripheralConnected, |
77 KUsbWatcherPeripheralIsNotConnected ) ); |
73 KUsbWatcherPeripheralIsNotConnected)); |
78 #endif |
74 #endif |
79 |
75 |
80 iUsbServiceControl = CUsbServiceControl::NewL(this, iUsb); |
76 iUsbServiceControl = CUsbServiceControl::NewL(*this, iUsb); |
81 |
77 |
82 User::LeaveIfError(iStates.Append(CUsbState::NewL(this))); |
78 User::LeaveIfError(iStates.Append(CUsbStateHostUndefined::NewL(*this))); |
83 User::LeaveIfError(iStates.Append(CUsbStateHostAInitiate::NewL(this))); |
79 User::LeaveIfError(iStates.Append(CUsbStateHostAInitiate::NewL(*this))); |
84 User::LeaveIfError(iStates.Append(CUsbStateHostAHost::NewL(this))); |
80 User::LeaveIfError(iStates.Append(CUsbStateHostAHost::NewL(*this))); |
85 User::LeaveIfError(iStates.Append(CUsbStateHostAPeripheral::NewL(this))); |
81 User::LeaveIfError(iStates.Append(CUsbStateHostAPeripheral::NewL(*this))); |
86 User::LeaveIfError(iStates.Append(CUsbStateHostAIdle::NewL(this))); |
82 |
87 User::LeaveIfError(iStates.Append(CUsbStateHostHandle::NewL(this))); |
83 User::LeaveIfError(iStates.Append(CUsbStateHostDelayAttachedHandle::NewL( |
|
84 *this))); |
|
85 User::LeaveIfError(iStates.Append( |
|
86 CUsbStateHostDelayNotAttachedHandle::NewL(*this))); |
|
87 User::LeaveIfError(iStates.Append( |
|
88 CUsbStateHostHandleDropping::NewL(*this))); |
88 |
89 |
89 iIdPinObserver = CUsbIdPinObserver::NewL(); |
90 iIdPinObserver = CUsbIdPinObserver::NewL(); |
90 iVBusObserver = CUsbVBusObserver::NewL(); |
91 iVBusObserver = CUsbVBusObserver::NewL(); |
91 iOtgStateObserver = CUsbOtgStateObserver::NewL(); |
92 iOtgStateObserver = CUsbOtgStateObserver::NewL(); |
92 iBusActivityObserver = CUsbBusActivityObserver::NewL(); |
93 iBusActivityObserver = CUsbBusActivityObserver::NewL(); |
93 iHostEventNotificationObserver = CUsbHostEventNotificationObserver::NewL( |
94 iHostEventNotificationObserver = CUsbHostEventNotificationObserver::NewL( |
94 &iUsb); |
95 &iUsb); |
95 iMessageNotificationObserver = CUsbMessageNotificationObserver::NewL( |
96 iMessageNotificationObserver = CUsbMessageNotificationObserver::NewL( |
96 &iUsb); |
97 &iUsb); |
97 |
98 |
98 iHostState = iStates[EUsbStateUndefined]; |
99 iHostState = iStates[EUsbStateHostUndefined]; |
99 |
100 |
100 // Notif manager must be created at least after VBus observer and iHostState initialization |
101 // Notif manager must be created at least after VBus observer and iHostState initialization |
101 // to allow USb indicator subscribe to its notifications at construction and check their's current states |
102 // to allow USb indicator subscribe to its notifications at construction and check their's current states |
102 iNotifManager = CUsbNotifManager::NewL(this); |
103 iNotifManager = CUsbNotifManager::NewL(*this); |
103 |
104 |
104 iIdPinObserver->SubscribeL(this); |
105 iVBusObserver->SubscribeL(*this); |
|
106 iOtgStateObserver->SubscribeL(*this); |
|
107 iBusActivityObserver->SubscribeL(*this); |
|
108 iHostEventNotificationObserver->SubscribeL(*this); |
|
109 iMessageNotificationObserver->SubscribeL(*this); |
|
110 iIdPinObserver->SubscribeL(*this); |
105 |
111 |
106 if (CUsbIdPinObserver::EIdPinOn == iIdPinObserver->IdPin()) |
112 if (CUsbIdPinObserver::EIdPinOn == iIdPinObserver->IdPin()) |
107 { |
113 { |
108 StartSessionL(); |
114 StartSessionL(); |
109 } |
115 } |
220 // |
253 // |
221 // --------------------------------------------------------------------------- |
254 // --------------------------------------------------------------------------- |
222 // |
255 // |
223 void CUsbOtgWatcher::SetPreviousPersonalityL() |
256 void CUsbOtgWatcher::SetPreviousPersonalityL() |
224 { |
257 { |
225 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SetPreviousPersonalityL" ) ); |
258 LOG_FUNC |
226 |
259 |
227 iState->SetPreviousPersonalityL(); |
260 iState->SetPreviousPersonalityL(); |
228 } |
261 } |
229 |
262 |
230 // --------------------------------------------------------------------------- |
263 // --------------------------------------------------------------------------- |
231 // |
264 // |
232 // --------------------------------------------------------------------------- |
265 // --------------------------------------------------------------------------- |
233 // |
266 // |
234 void CUsbOtgWatcher::CancelSetPreviousPersonalityL() |
267 void CUsbOtgWatcher::CancelSetPreviousPersonalityL() |
235 { |
268 { |
236 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::CancelSetPreviousPersonalityL" ) ); |
269 LOG_FUNC |
237 |
270 |
238 iState->CancelSetPreviousPersonalityL(); |
271 iState->CancelSetPreviousPersonalityL(); |
239 } |
272 } |
240 |
273 |
241 // --------------------------------------------------------------------------- |
274 // --------------------------------------------------------------------------- |
242 // |
275 // |
243 // --------------------------------------------------------------------------- |
276 // --------------------------------------------------------------------------- |
244 // |
277 // |
245 void CUsbOtgWatcher::SetPreviousPreviousPersonalityOnDisconnectL() |
278 void CUsbOtgWatcher::SetPreviousPreviousPersonalityOnDisconnectL() |
246 { |
279 { |
247 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SetPreviousPreviousPersonalityOnDisconnectL" ) ); |
280 LOG_FUNC |
248 |
281 |
249 } |
282 } |
250 |
283 |
251 // From IdPin observer |
284 // From IdPin observer |
252 // --------------------------------------------------------------------------- |
285 // --------------------------------------------------------------------------- |
253 // |
286 // |
254 // --------------------------------------------------------------------------- |
287 // --------------------------------------------------------------------------- |
255 // |
288 // |
256 void CUsbOtgWatcher::StartSessionL() |
289 void CUsbOtgWatcher::StartSessionL() |
257 { |
290 { |
258 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::StartSessionL" ) ); |
291 LOG_FUNC |
259 |
292 |
260 if (!CanStartSessionL()) |
293 if (!CanStartSessionL()) |
261 { |
294 { |
262 HandleHostProblemL(EUsbWatcherErrorInConnection); |
295 HandleHostProblemL(EUsbWatcherCanNotStartSession, |
|
296 EUsbStateHostHandleDropping); |
263 return; |
297 return; |
264 } |
298 } |
265 |
299 |
|
300 iUsbServiceRequest = CUsbServiceControl::EStartUsbService; |
266 TInt err = iUsbServiceControl->StartL(iPersonalityId); |
301 TInt err = iUsbServiceControl->StartL(iPersonalityId); |
267 if (KErrNone != err) |
302 if (KErrNone != err) |
268 { |
303 { |
269 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbOtgWatcher::StartSessionL Can not start usb services. reason = %d" ), err)); |
304 LOG1( "Can not start usb services. err = %d" , err); |
270 HandleHostProblemL(EUsbWatcherCanNotStartUsbServices); |
305 HandleHostProblemL(EUsbWatcherCanNotStartUsbServices, |
|
306 EUsbStateHostHandleDropping); |
271 return; |
307 return; |
272 } |
308 } |
273 |
309 |
274 // call back from iUsbServiceControl->Start(iPersonalityId) call is UsbServiceControlReqCompletedL(TInt aError) |
310 // call back from iUsbServiceControl->Start(iPersonalityId) call is UsbServiceControlReqCompletedL(TInt aError) |
275 // so, continue there if everything is OK |
311 // so, continue there if everything is OK |
278 |
314 |
279 // --------------------------------------------------------------------------- |
315 // --------------------------------------------------------------------------- |
280 // |
316 // |
281 // --------------------------------------------------------------------------- |
317 // --------------------------------------------------------------------------- |
282 // |
318 // |
283 void CUsbOtgWatcher::HandleHostProblemL(TInt aWhatKindOf) |
319 void CUsbOtgWatcher::HandleHostProblemL(TInt aWhatKindOf, |
284 { |
320 TUsbStateIds aInState) |
285 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::HandleProblemL" ) ); |
321 { |
286 HostHandle()->SetWhat(aWhatKindOf); |
322 LOG_FUNC |
287 ChangeHostStateL(EUsbStateHostHandle); |
323 HostHandle(aInState)->SetWhat(aWhatKindOf); |
|
324 ChangeHostStateL(aInState); |
288 } |
325 } |
289 |
326 |
290 // --------------------------------------------------------------------------- |
327 // --------------------------------------------------------------------------- |
291 // |
328 // |
292 // --------------------------------------------------------------------------- |
329 // --------------------------------------------------------------------------- |
293 // |
330 // |
294 void CUsbOtgWatcher::IdPinOnL() |
331 void CUsbOtgWatcher::IdPinOnL() |
295 { |
332 { |
296 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::IdPinOnL" ) ); |
333 LOG_FUNC |
297 StartSessionL(); |
334 StartSessionL(); |
298 } |
335 } |
299 |
336 |
300 // --------------------------------------------------------------------------- |
337 // --------------------------------------------------------------------------- |
301 // |
338 // |
302 // --------------------------------------------------------------------------- |
339 // --------------------------------------------------------------------------- |
303 // |
340 // |
304 void CUsbOtgWatcher::IdPinOffL() |
341 void CUsbOtgWatcher::IdPinOffL() |
305 { |
342 { |
306 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::IdPinOffL" ) ); |
343 LOG_FUNC |
307 |
344 |
308 // for example, USB failed to start |
345 ChangeHostStateL(EUsbStateHostUndefined); |
309 if(NULL == iHostState) return; |
|
310 |
|
311 iVBusObserver->UnsubscribeL(this); |
|
312 iOtgStateObserver->UnsubscribeL(this); |
|
313 iBusActivityObserver->UnsubscribeL(this); |
|
314 iHostEventNotificationObserver->UnsubscribeL(this); |
|
315 iMessageNotificationObserver->UnsubscribeL(this); |
|
316 |
|
317 iHostState->JustBeforeLeavingThisStateL(); |
|
318 |
|
319 iHostState = NULL; |
|
320 |
346 |
321 iNotifManager->CloseAllNotifiers(); |
347 iNotifManager->CloseAllNotifiers(); |
322 |
348 |
323 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::IdPinOffL Before DisableFunctionDriverLoad " ) ); |
|
324 Usb().DisableFunctionDriverLoading(); |
349 Usb().DisableFunctionDriverLoading(); |
325 |
350 |
326 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::IdPinOffL Before TryStop" ) ); |
351 iUsbServiceRequest = CUsbServiceControl::EStopUsbService; |
327 |
|
328 TInt err = iUsbServiceControl->StopL(); |
352 TInt err = iUsbServiceControl->StopL(); |
329 |
353 |
|
354 LOG1( "iUsbServiceControl->Stop() err = %d", err ); |
|
355 |
330 if (KErrNone != err) |
356 if (KErrNone != err) |
331 { |
357 { |
332 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::IdPinOnL ErrorStoppingUsbServices" ) ); |
358 LOG( "ErrorStoppingUsbServices" ); |
333 Panic(ECanNotStopUsbServices); |
359 Panic(ECanNotStopUsbServices); |
334 } |
360 } |
335 |
|
336 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::IdPinOffL iUsbServiceControl->Stop() OK" ) ); |
|
337 } |
361 } |
338 |
362 |
339 // --------------------------------------------------------------------------- |
363 // --------------------------------------------------------------------------- |
340 // |
364 // |
341 // --------------------------------------------------------------------------- |
365 // --------------------------------------------------------------------------- |
342 // |
366 // |
343 void CUsbOtgWatcher::IdPinErrorL(TInt aError) |
367 void CUsbOtgWatcher::IdPinErrorL(TInt aError) |
344 { |
368 { |
345 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::IdPinErrorL" ) ); |
369 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
346 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
370 HandleHostProblemL(EUsbWatcherIdPinError, EUsbStateHostHandleDropping); |
347 HandleHostProblemL(EUsbWatcherIdPinError); |
|
348 |
371 |
349 } |
372 } |
350 |
373 |
351 // From VBus observer |
374 // From VBus observer |
352 // --------------------------------------------------------------------------- |
375 // --------------------------------------------------------------------------- |
353 // |
376 // |
354 // --------------------------------------------------------------------------- |
377 // --------------------------------------------------------------------------- |
355 // |
378 // |
356 void CUsbOtgWatcher::VBusDownL() |
379 void CUsbOtgWatcher::VBusDownL() |
357 { |
380 { |
358 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::VBusDownL" ) ); |
|
359 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
381 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
360 iHostState->VBusDownL(); |
382 iHostState->VBusDownL(); |
361 } |
383 } |
362 |
384 |
363 // --------------------------------------------------------------------------- |
385 // --------------------------------------------------------------------------- |
364 // |
386 // |
365 // --------------------------------------------------------------------------- |
387 // --------------------------------------------------------------------------- |
366 // |
388 // |
367 void CUsbOtgWatcher::VBusUpL() |
389 void CUsbOtgWatcher::VBusUpL() |
368 { |
390 { |
369 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::VBusUpL" ) ); |
|
370 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
391 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
371 iHostState->VBusUpL(); |
392 iHostState->VBusUpL(); |
372 } |
393 } |
373 |
394 |
374 // --------------------------------------------------------------------------- |
395 // --------------------------------------------------------------------------- |
375 // |
396 // |
376 // --------------------------------------------------------------------------- |
397 // --------------------------------------------------------------------------- |
377 // |
398 // |
378 void CUsbOtgWatcher::VBusObserverErrorL(TInt aError) |
399 void CUsbOtgWatcher::VBusObserverErrorL(TInt aError) |
379 { |
400 { |
380 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::VBusObserverErrorL" ) ); |
401 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
381 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
402 HandleHostProblemL(EUsbWatcherVBusObserverError, |
382 HandleHostProblemL(EUsbWatcherVBusObserverError); |
403 EUsbStateHostHandleDropping); |
383 } |
404 } |
384 |
405 |
385 // From OTG state observer |
406 // From OTG state observer |
386 // --------------------------------------------------------------------------- |
407 // --------------------------------------------------------------------------- |
387 // |
408 // |
388 // --------------------------------------------------------------------------- |
409 // --------------------------------------------------------------------------- |
389 // |
410 // |
390 void CUsbOtgWatcher::AIdleL() |
411 void CUsbOtgWatcher::AIdleL() |
391 { |
412 { |
392 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::AIdleL" ) ); |
|
393 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
413 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
394 iHostState->AIdleL(); |
414 iHostState->AIdleL(); |
395 } |
415 } |
396 |
416 |
397 // --------------------------------------------------------------------------- |
417 // --------------------------------------------------------------------------- |
398 // |
418 // |
399 // --------------------------------------------------------------------------- |
419 // --------------------------------------------------------------------------- |
400 // |
420 // |
401 void CUsbOtgWatcher::AHostL() |
421 void CUsbOtgWatcher::AHostL() |
402 { |
422 { |
403 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::AHostL" ) ); |
|
404 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
423 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
405 iHostState->AHostL(); |
424 iHostState->AHostL(); |
406 } |
425 } |
407 |
426 |
408 // --------------------------------------------------------------------------- |
427 // --------------------------------------------------------------------------- |
409 // |
428 // |
410 // --------------------------------------------------------------------------- |
429 // --------------------------------------------------------------------------- |
411 // |
430 // |
412 void CUsbOtgWatcher::APeripheralL() |
431 void CUsbOtgWatcher::APeripheralL() |
413 { |
432 { |
414 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::APeripheralL" ) ); |
|
415 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
433 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
416 iHostState->APeripheralL(); |
434 iHostState->APeripheralL(); |
417 } |
435 } |
418 |
436 |
419 // --------------------------------------------------------------------------- |
437 // --------------------------------------------------------------------------- |
420 // |
438 // |
421 // --------------------------------------------------------------------------- |
439 // --------------------------------------------------------------------------- |
422 // |
440 // |
423 void CUsbOtgWatcher::AVBusErrorL() |
441 void CUsbOtgWatcher::AVBusErrorL() |
424 { |
442 { |
425 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::AVBusErrorL" ) ); |
|
426 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
443 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
427 iHostState->AVBusErrorL(); |
444 iHostState->AVBusErrorL(); |
428 } |
445 } |
429 |
446 |
430 // --------------------------------------------------------------------------- |
447 // --------------------------------------------------------------------------- |
431 // |
448 // |
432 // --------------------------------------------------------------------------- |
449 // --------------------------------------------------------------------------- |
433 // |
450 // |
434 void CUsbOtgWatcher::BIdleL() |
451 void CUsbOtgWatcher::BIdleL() |
435 { |
452 { |
436 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::BIdleL" ) ); |
|
437 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
453 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
438 iHostState->BIdleL(); |
454 iHostState->BIdleL(); |
439 } |
455 } |
440 |
456 |
441 // --------------------------------------------------------------------------- |
457 // --------------------------------------------------------------------------- |
442 // |
458 // |
443 // --------------------------------------------------------------------------- |
459 // --------------------------------------------------------------------------- |
444 // |
460 // |
445 void CUsbOtgWatcher::BPeripheralL() |
461 void CUsbOtgWatcher::BPeripheralL() |
446 { |
462 { |
447 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::BPeripheralL" ) ); |
|
448 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
463 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
449 iHostState->BPeripheralL(); |
464 iHostState->BPeripheralL(); |
450 } |
465 } |
451 |
466 |
452 // --------------------------------------------------------------------------- |
467 // --------------------------------------------------------------------------- |
453 // |
468 // |
454 // --------------------------------------------------------------------------- |
469 // --------------------------------------------------------------------------- |
455 // |
470 // |
456 void CUsbOtgWatcher::BHostL() |
471 void CUsbOtgWatcher::BHostL() |
457 { |
472 { |
458 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::BHostL" ) ); |
|
459 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
473 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
460 iHostState->BHostL(); |
474 iHostState->BHostL(); |
461 } |
475 } |
462 |
476 |
463 // --------------------------------------------------------------------------- |
477 // --------------------------------------------------------------------------- |
464 // |
478 // |
465 // --------------------------------------------------------------------------- |
479 // --------------------------------------------------------------------------- |
466 // |
480 // |
467 void CUsbOtgWatcher::OtgStateErrorL(TInt aError) |
481 void CUsbOtgWatcher::OtgStateErrorL(TInt aError) |
468 { |
482 { |
469 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::OtgStateErrorL" ) ); |
483 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
470 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
484 HandleHostProblemL(EUsbWatcherOtgStateError, EUsbStateHostHandleDropping); |
471 HandleHostProblemL(EUsbWatcherOtgStateError); |
|
472 } |
485 } |
473 |
486 |
474 // From bus activity observer |
487 // From bus activity observer |
475 // --------------------------------------------------------------------------- |
488 // --------------------------------------------------------------------------- |
476 // |
489 // |
477 // --------------------------------------------------------------------------- |
490 // --------------------------------------------------------------------------- |
478 // |
491 // |
479 void CUsbOtgWatcher::BusIdleL() |
492 void CUsbOtgWatcher::BusIdleL() |
480 { |
493 { |
481 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::BusIdleL" ) ); |
|
482 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
494 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
483 iHostState->BusIdleL(); |
495 iHostState->BusIdleL(); |
484 } |
496 } |
485 |
497 |
486 // --------------------------------------------------------------------------- |
498 // --------------------------------------------------------------------------- |
487 // |
499 // |
488 // --------------------------------------------------------------------------- |
500 // --------------------------------------------------------------------------- |
489 // |
501 // |
490 void CUsbOtgWatcher::BusActiveL() |
502 void CUsbOtgWatcher::BusActiveL() |
491 { |
503 { |
492 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::BusActiveL" ) ); |
|
493 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
504 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
494 iHostState->BusActiveL(); |
505 iHostState->BusActiveL(); |
495 } |
506 } |
496 |
507 |
497 // --------------------------------------------------------------------------- |
508 // --------------------------------------------------------------------------- |
498 // |
509 // |
499 // --------------------------------------------------------------------------- |
510 // --------------------------------------------------------------------------- |
500 // |
511 // |
501 void CUsbOtgWatcher::BusActivityErrorL(TInt aError) |
512 void CUsbOtgWatcher::BusActivityErrorL(TInt aError) |
502 { |
513 { |
503 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::BusActivityErrorL" ) ); |
|
504 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
514 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
505 // no action, continue |
515 // no action, continue |
506 } |
516 } |
507 |
517 |
508 // From Host Event notification observer |
518 // From Host Event notification observer |
510 // |
520 // |
511 // --------------------------------------------------------------------------- |
521 // --------------------------------------------------------------------------- |
512 // |
522 // |
513 void CUsbOtgWatcher::DeviceAttachedL(TDeviceEventInformation aTdi) |
523 void CUsbOtgWatcher::DeviceAttachedL(TDeviceEventInformation aTdi) |
514 { |
524 { |
515 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::DeviceAttachedL" ) ); |
|
516 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
525 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
517 iHostState->DeviceAttachedL(aTdi); |
526 iHostState->DeviceAttachedL(aTdi); |
518 } |
527 } |
519 |
528 |
520 // --------------------------------------------------------------------------- |
529 // --------------------------------------------------------------------------- |
521 // |
530 // |
522 // --------------------------------------------------------------------------- |
531 // --------------------------------------------------------------------------- |
523 // |
532 // |
524 void CUsbOtgWatcher::DeviceDetachedL(TDeviceEventInformation aTdi) |
533 void CUsbOtgWatcher::DeviceDetachedL(TDeviceEventInformation aTdi) |
525 { |
534 { |
526 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::DeviceDetachedL" ) ); |
|
527 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
535 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
528 iHostState->DeviceDetachedL(aTdi); |
536 iHostState->DeviceDetachedL(aTdi); |
529 } |
537 } |
530 |
538 |
531 // --------------------------------------------------------------------------- |
539 // --------------------------------------------------------------------------- |
532 // |
540 // |
533 // --------------------------------------------------------------------------- |
541 // --------------------------------------------------------------------------- |
534 // |
542 // |
535 void CUsbOtgWatcher::DriverLoadSuccessL(TDeviceEventInformation aTdi) |
543 void CUsbOtgWatcher::DriverLoadSuccessL(TDeviceEventInformation aTdi) |
536 { |
544 { |
537 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::DriverLoadSuccessL" ) ); |
|
538 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
545 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
539 iHostState->DriverLoadSuccessL(aTdi); |
546 iHostState->DriverLoadSuccessL(aTdi); |
540 } |
547 } |
541 |
548 |
542 // --------------------------------------------------------------------------- |
549 // --------------------------------------------------------------------------- |
543 // |
550 // |
544 // --------------------------------------------------------------------------- |
551 // --------------------------------------------------------------------------- |
545 // |
552 // |
546 void CUsbOtgWatcher::DriverLoadPartialSuccessL(TDeviceEventInformation aTdi) |
553 void CUsbOtgWatcher::DriverLoadPartialSuccessL(TDeviceEventInformation aTdi) |
547 { |
554 { |
548 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::DriverLoadPartialSuccessL" ) ); |
|
549 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
555 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
550 iHostState->DriverLoadPartialSuccessL(aTdi); |
556 iHostState->DriverLoadPartialSuccessL(aTdi); |
551 } |
557 } |
552 |
558 |
553 // --------------------------------------------------------------------------- |
559 // --------------------------------------------------------------------------- |
554 // |
560 // |
555 // --------------------------------------------------------------------------- |
561 // --------------------------------------------------------------------------- |
556 // |
562 // |
557 void CUsbOtgWatcher::DriverLoadFailureL(TDeviceEventInformation aTdi) |
563 void CUsbOtgWatcher::DriverLoadFailureL(TDeviceEventInformation aTdi) |
558 { |
564 { |
559 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::DriverLoadFailureL" ) ); |
|
560 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
565 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
561 iHostState->DriverLoadFailureL(aTdi); |
566 iHostState->DriverLoadFailureL(aTdi); |
562 } |
567 } |
563 |
568 |
564 // --------------------------------------------------------------------------- |
569 // --------------------------------------------------------------------------- |
565 // |
570 // |
566 // --------------------------------------------------------------------------- |
571 // --------------------------------------------------------------------------- |
567 // |
572 // |
568 void CUsbOtgWatcher::HostEventNotificationErrorL(TInt aError) |
573 void CUsbOtgWatcher::HostEventNotificationErrorL(TInt aError) |
569 { |
574 { |
570 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::HostEventNotificationErrorL" ) ); |
575 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
571 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
576 HandleHostProblemL(EUsbWatcherHostEventNotificationError, |
572 HandleHostProblemL(EUsbWatcherHostEventNotificationError); |
577 EUsbStateHostHandleDropping); |
573 } |
578 } |
574 |
579 |
575 // From message notification observer |
580 // From message notification observer |
576 // --------------------------------------------------------------------------- |
581 // --------------------------------------------------------------------------- |
577 // |
582 // |
578 // --------------------------------------------------------------------------- |
583 // --------------------------------------------------------------------------- |
579 // |
584 // |
580 void CUsbOtgWatcher::MessageNotificationReceivedL(TInt aMessage) |
585 void CUsbOtgWatcher::MessageNotificationReceivedL(TInt aMessage) |
581 { |
586 { |
582 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::MessageNotificationReceivedL" ) ); |
|
583 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
587 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
584 iHostState->MessageNotificationReceivedL(aMessage); |
588 iHostState->MessageNotificationReceivedL(aMessage); |
585 } |
589 } |
586 |
590 |
587 // --------------------------------------------------------------------------- |
591 // --------------------------------------------------------------------------- |
588 // |
592 // |
589 // --------------------------------------------------------------------------- |
593 // --------------------------------------------------------------------------- |
590 // |
594 // |
591 void CUsbOtgWatcher::BadHubPositionL() |
595 void CUsbOtgWatcher::BadHubPositionL() |
592 { |
596 { |
593 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::BadHubPositionL" ) ); |
|
594 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
597 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
595 iHostState->BadHubPositionL(); |
598 iHostState->BadHubPositionL(); |
596 } |
599 } |
597 |
600 |
598 // --------------------------------------------------------------------------- |
601 // --------------------------------------------------------------------------- |
599 // |
602 // |
600 // --------------------------------------------------------------------------- |
603 // --------------------------------------------------------------------------- |
601 // |
604 // |
602 void CUsbOtgWatcher::VBusErrorL() |
605 void CUsbOtgWatcher::VBusErrorL() |
603 { |
606 { |
604 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::VBusErrorL" ) ); |
|
605 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
607 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
606 iHostState->VBusErrorL(); |
608 iHostState->VBusErrorL(); |
607 } |
609 } |
608 |
610 |
609 // --------------------------------------------------------------------------- |
611 // --------------------------------------------------------------------------- |
610 // |
612 // |
611 // --------------------------------------------------------------------------- |
613 // --------------------------------------------------------------------------- |
612 // |
614 // |
613 void CUsbOtgWatcher::SrpReceivedL() |
615 void CUsbOtgWatcher::SrpReceivedL() |
614 { |
616 { |
615 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SrpReceivedL" ) ); |
|
616 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
617 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
617 iHostState->SrpReceivedL(); |
618 iHostState->SrpReceivedL(); |
618 } |
619 } |
619 |
620 |
620 // --------------------------------------------------------------------------- |
621 // --------------------------------------------------------------------------- |
621 // |
622 // |
622 // --------------------------------------------------------------------------- |
623 // --------------------------------------------------------------------------- |
623 // |
624 // |
624 void CUsbOtgWatcher::SessionRequestedL() |
625 void CUsbOtgWatcher::SessionRequestedL() |
625 { |
626 { |
626 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SessionRequestedL" ) ); |
|
627 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
627 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
628 iHostState->SessionRequestedL(); |
628 iHostState->SessionRequestedL(); |
629 } |
629 } |
630 |
630 |
631 // --------------------------------------------------------------------------- |
631 // --------------------------------------------------------------------------- |
632 // |
632 // |
633 // --------------------------------------------------------------------------- |
633 // --------------------------------------------------------------------------- |
634 // |
634 // |
635 void CUsbOtgWatcher::MessageNotificationErrorL(TInt aError) |
635 void CUsbOtgWatcher::MessageNotificationErrorL(TInt aError) |
636 { |
636 { |
637 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::MessageNotificationErrorL" ) ); |
637 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
638 __ASSERT_DEBUG(iHostState != NULL, Panic(EBadHostState)); |
638 HandleHostProblemL(EUsbWatcherMessageNotificationError, |
639 HandleHostProblemL(EUsbWatcherMessageNotificationError); |
639 EUsbStateHostHandleDropping); |
640 } |
640 } |
641 |
641 |
642 // --------------------------------------------------------------------------- |
642 // --------------------------------------------------------------------------- |
643 // getters |
643 // getters |
644 // --------------------------------------------------------------------------- |
644 // --------------------------------------------------------------------------- |
864 // |
851 // |
865 // --------------------------------------------------------------------------- |
852 // --------------------------------------------------------------------------- |
866 // |
853 // |
867 void CUsbOtgWatcher::UsbServiceControlReqCompletedL(TInt aError) |
854 void CUsbOtgWatcher::UsbServiceControlReqCompletedL(TInt aError) |
868 { |
855 { |
869 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbOtgWatcher::UsbServiceControlReqCompleted Error returned by UsbServiceControl = %d" ), aError)); |
856 LOG_FUNC |
870 |
857 |
871 switch(aError) |
858 LOG1( "aError = %d" , aError); |
872 { |
859 |
873 case KErrInUse: |
860 switch (aError) |
874 // usb services already started (this might happen if more than one idpin on event come) |
861 { |
875 { |
862 case KErrInUse: |
876 return; |
863 // usb services already started (this might happen if more than one idpin on event come) |
877 } |
864 { |
878 |
865 return; |
879 case KErrNone: |
866 } |
880 { |
867 |
881 break; // do normal routine |
868 case KErrNone: |
882 } |
869 { |
883 |
870 break; // do normal routine |
884 default: // handle the issue |
871 } |
885 { |
872 |
886 HandleHostProblemL(EUsbWatcherCanNotStartUsbServices); |
873 default: // handle the issue |
887 return; |
874 { |
888 } |
875 if (iUsbServiceRequest == CUsbServiceControl::EStartUsbService) // Handle only start issues |
889 } |
876 { |
|
877 HandleHostProblemL(EUsbWatcherCanNotStartUsbServices, |
|
878 EUsbStateHostHandleDropping); |
|
879 } |
|
880 |
|
881 iUsbServiceRequest = CUsbServiceControl::ERequestUndefined; |
|
882 return; |
|
883 } |
|
884 } |
|
885 |
|
886 iUsbServiceRequest = CUsbServiceControl::ERequestUndefined; |
890 |
887 |
891 TUsbServiceState serviceState; |
888 TUsbServiceState serviceState; |
892 TInt err = iUsb.GetServiceState(serviceState); |
889 TInt err = iUsb.GetServiceState(serviceState); |
893 |
890 |
894 if (KErrNone != err) |
891 if (KErrNone != err) |
895 { |
892 { |
896 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbOtgWatcher::UsbServiceControlReqCompleted Error when requesting GetServiceState = %d" ), err)); |
893 LOG1( "Error when requesting GetServiceState = %d" , err); |
897 HandleHostProblemL(EUsbWatcherCanNotStartUsbServices); |
894 HandleHostProblemL(EUsbWatcherCanNotStartUsbServices, |
|
895 EUsbStateHostHandleDropping); |
898 return; |
896 return; |
899 } |
897 } |
900 |
898 |
901 switch (serviceState) |
899 switch (serviceState) |
902 { |
900 { |
903 case EUsbServiceIdle: // just stopped usb service |
901 case EUsbServiceIdle: // just stopped usb service |
904 { |
902 { |
905 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::UsbServiceControlReqCompletedL UsbServiceState == EUsbServiceIdle" ) ); |
903 LOG("UsbServiceState == EUsbServiceIdle" ); |
906 // do nothing |
904 // do nothing |
907 break; |
905 break; |
908 } |
906 } |
909 |
907 |
910 case EUsbServiceStarted: // just started usb service |
908 case EUsbServiceStarted: // just started usb service |
911 { |
909 { |
912 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::UsbServiceControlReqCompletedL UsbServiceState == EUsbServiceStarted" ) ); |
910 LOG( "UsbServiceState == EUsbServiceStarted" ); |
913 |
911 |
914 iHostState = iStates[EUsbStateHostAInitiate]; |
912 ChangeHostStateL(EUsbStateHostAInitiate); |
915 |
|
916 iHostState->JustAdvancedToThisStateL(); // do any initial activity, once advanced to the state |
|
917 |
|
918 iVBusObserver->SubscribeL(this); |
|
919 iOtgStateObserver->SubscribeL(this); |
|
920 iBusActivityObserver->SubscribeL(this); |
|
921 iHostEventNotificationObserver->SubscribeL(this); |
|
922 iMessageNotificationObserver->SubscribeL(this); |
|
923 |
913 |
924 break; |
914 break; |
925 } |
915 } |
926 case EUsbServiceStarting: |
916 case EUsbServiceStarting: |
927 { |
917 { |
928 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::UsbServiceControlReqCompletedL UsbServiceState == EUsbServiceStarting" ) ); |
918 LOG("UsbServiceState == EUsbServiceStarting" ); |
929 // should not receive that, due to call back is called when service stopped or started |
919 // should not receive that, due to call back is called when service stopped or started |
930 // therefore scream |
920 // therefore scream |
|
921 // no break statement here |
931 } |
922 } |
932 case EUsbServiceStopping: |
923 case EUsbServiceStopping: |
933 { |
924 { |
934 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::UsbServiceControlReqCompletedL UsbServiceState == EUsbServiceStopping" ) ); |
925 LOG("UsbServiceState == EUsbServiceStopping" ); |
935 // should not receive that, due to call back is called when service stopped or started |
926 // should not receive that, due to call back is called when service stopped or started |
936 // therefore scream |
927 // therefore scream |
|
928 // no break statement here |
937 } |
929 } |
938 case EUsbServiceFatalError: |
930 case EUsbServiceFatalError: |
939 { |
931 { |
940 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::UsbServiceControlReqCompletedL UsbServiceState == EUsbServiceFatalError" ) ); |
932 LOG( "UsbServiceState == EUsbServiceFatalError" ); |
941 Panic(EUnexpectedUsbServiceState); |
933 Panic(EUnexpectedUsbServiceState); |
942 break; |
934 break; |
943 } |
935 } |
944 |
936 |
945 default: |
937 default: |
946 { |
938 { |
947 Panic(EUnknownUsbServiceState); |
939 Panic(EUnknownUsbServiceState); |
948 } |
940 } |
949 } |
941 } |
950 |
|
951 } |
942 } |
952 |
943 |
953 // --------------------------------------------------------------------------- |
944 // --------------------------------------------------------------------------- |
954 // |
945 // |
955 // --------------------------------------------------------------------------- |
946 // --------------------------------------------------------------------------- |
956 // |
947 // |
957 TInt CUsbOtgWatcher::SelfTestL() |
948 TInt CUsbOtgWatcher::SelfTestL() |
958 { |
949 { |
959 #ifdef _DEBUG |
950 #ifdef _DEBUG |
960 |
951 LOG_FUNC |
961 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SelfTestL Creating observers." ) ); |
|
962 |
952 |
963 // create all the observers |
953 // create all the observers |
964 iIdPinObserver = CUsbIdPinObserver::NewL(); |
954 iIdPinObserver = CUsbIdPinObserver::NewL(); |
965 iVBusObserver = CUsbVBusObserver::NewL(); |
955 iVBusObserver = CUsbVBusObserver::NewL(); |
966 iOtgStateObserver = CUsbOtgStateObserver::NewL(); |
956 iOtgStateObserver = CUsbOtgStateObserver::NewL(); |
967 iBusActivityObserver = |
957 iBusActivityObserver = CUsbBusActivityObserver::NewL(); |
968 CUsbBusActivityObserver::NewL(); |
958 iHostEventNotificationObserver = CUsbHostEventNotificationObserver::NewL( |
969 iHostEventNotificationObserver = |
959 &iUsb); |
970 CUsbHostEventNotificationObserver::NewL(&iUsb); |
960 iMessageNotificationObserver = CUsbMessageNotificationObserver::NewL( |
971 iMessageNotificationObserver = |
961 &iUsb); |
972 CUsbMessageNotificationObserver::NewL(&iUsb); |
962 |
973 |
963 LOG( "Observers getters" ); |
974 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SelfTestL Observers getters." ) ); |
|
975 |
964 |
976 if (iIdPinObserver != IdPinObserver()) |
965 if (iIdPinObserver != IdPinObserver()) |
977 { |
966 { |
978 User::Leave(KErrGeneral); |
967 User::Leave(KErrGeneral); |
979 } |
968 } |
996 if (iMessageNotificationObserver != MessageNotificationObserver()) |
985 if (iMessageNotificationObserver != MessageNotificationObserver()) |
997 { |
986 { |
998 User::Leave(KErrGeneral); |
987 User::Leave(KErrGeneral); |
999 } |
988 } |
1000 |
989 |
1001 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SelfTestL Observers destructors." ) ); |
990 LOG( "Observers destructors" ); |
1002 |
991 |
1003 // idpinobserver is deleted later |
992 // idpinobserver is deleted later |
1004 // Vbus observer is deleted later |
993 // Vbus observer is deleted later |
1005 |
994 |
1006 delete iOtgStateObserver; |
995 delete iOtgStateObserver; |
1007 iOtgStateObserver = 0; |
996 iOtgStateObserver = 0; |
1008 delete iBusActivityObserver; |
997 delete iBusActivityObserver; |
1009 iBusActivityObserver = 0; |
998 iBusActivityObserver = 0; |
1010 delete iHostEventNotificationObserver; |
999 delete iHostEventNotificationObserver; |
1011 iHostEventNotificationObserver = 0; |
1000 iHostEventNotificationObserver = 0; |
1012 delete iMessageNotificationObserver; |
1001 delete iMessageNotificationObserver; |
1013 iMessageNotificationObserver = 0; |
1002 iMessageNotificationObserver = 0; |
1014 |
1003 |
1015 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SelfTestL Creating states." ) ); |
1004 LOG("Creating states"); |
1016 |
1005 |
1017 User::LeaveIfError(iStates.Append(CUsbState::NewL(this))); |
1006 User::LeaveIfError(iStates.Append(CUsbStateHostUndefined::NewL(*this))); |
1018 User::LeaveIfError(iStates.Append(CUsbStateHostAInitiate::NewL(this))); |
1007 User::LeaveIfError(iStates.Append(CUsbStateHostAInitiate::NewL(*this))); |
1019 User::LeaveIfError(iStates.Append(CUsbStateHostAHost::NewL(this))); |
1008 User::LeaveIfError(iStates.Append(CUsbStateHostAHost::NewL(*this))); |
1020 User::LeaveIfError(iStates.Append(CUsbStateHostAPeripheral::NewL(this))); |
1009 User::LeaveIfError(iStates.Append(CUsbStateHostAPeripheral::NewL(*this))); |
1021 User::LeaveIfError(iStates.Append(CUsbStateHostAIdle::NewL(this))); |
1010 User::LeaveIfError(iStates.Append(CUsbStateHostDelayAttachedHandle::NewL( |
1022 User::LeaveIfError(iStates.Append(CUsbStateHostHandle::NewL(this))); |
1011 *this))); |
1023 |
1012 User::LeaveIfError(iStates.Append( |
1024 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SelfTestL Check State()" ) ); |
1013 CUsbStateHostDelayNotAttachedHandle::NewL(*this))); |
|
1014 User::LeaveIfError(iStates.Append( |
|
1015 CUsbStateHostHandleDropping::NewL(*this))); |
|
1016 |
|
1017 LOG("Check State()" ); |
1025 |
1018 |
1026 if (iStates[EUsbStateHostAInitiate] != State(EUsbStateHostAInitiate)) |
1019 if (iStates[EUsbStateHostAInitiate] != State(EUsbStateHostAInitiate)) |
1027 { |
1020 { |
1028 User::Leave(KErrGeneral); |
1021 User::Leave(KErrGeneral); |
1029 } |
1022 } |
1030 |
1023 |
1031 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SelfTestL Check CurrentHostState()" ) ); |
1024 LOG("Check CurrentHostState()" ); |
1032 |
1025 |
1033 iHostState = iStates[EUsbStateHostAInitiate]; |
1026 iHostState = iStates[EUsbStateHostAInitiate]; |
1034 |
1027 |
1035 if (iStates[EUsbStateHostAInitiate] != CurrentHostState()) |
1028 if (iStates[EUsbStateHostAInitiate] != CurrentHostState()) |
1036 { |
1029 { |
1037 User::Leave(KErrGeneral); |
1030 User::Leave(KErrGeneral); |
1038 } |
1031 } |
1039 |
1032 |
1040 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SelfTestL NotifManager and WarningNotifier." ) ); |
1033 LOG("NotifManager and WarningNotifier." ); |
1041 |
1034 |
1042 CUsbNotifManager* usbnotifmanager = CUsbNotifManager::NewL(this); |
1035 CUsbNotifManager* usbnotifmanager = CUsbNotifManager::NewL(*this); |
1043 RNotifier rnotifier; |
1036 RNotifier rnotifier; |
1044 User::LeaveIfError(rnotifier.Connect()); |
1037 User::LeaveIfError(rnotifier.Connect()); |
1045 CUsbWarningNotifier* usbnotifier = CUsbWarningNotifier::NewL(rnotifier, |
1038 CUsbWarningNotifier* usbnotifier = CUsbWarningNotifier::NewL(rnotifier, |
1046 usbnotifmanager, EUsbOtgPartiallySupportedDevice); |
1039 *usbnotifmanager, EUsbOtgPartiallySupportedDevice); |
1047 usbnotifier->IsFeedbackNeeded(); |
1040 usbnotifier->IsFeedbackNeeded(); |
1048 |
1041 |
1049 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SelfTestL NotifManager and WarningNotifier destruction." ) ); |
1042 LOG( "NotifManager and WarningNotifier destruction." ); |
1050 |
1043 |
1051 delete usbnotifier; |
1044 delete usbnotifier; |
1052 rnotifier.Close(); |
1045 rnotifier.Close(); |
1053 delete usbnotifmanager; |
1046 delete usbnotifmanager; |
1054 |
1047 |
1055 // VBus observer is deleted here, due to it is used by usbnotifmanager.usbindicatornotifier |
1048 // VBus observer is deleted here, due to it is used by usbnotifmanager.usbindicatornotifier |
1056 delete iVBusObserver; |
1049 delete iVBusObserver; |
1057 iVBusObserver = 0; |
1050 iVBusObserver = 0; |
1058 |
1051 |
1059 // id pin observer is deleted here due to it is used by usbnotifmanager.usbindicatornotifier |
1052 // id pin observer is deleted here due to it is used by usbnotifmanager.usbindicatornotifier |
1060 delete iIdPinObserver; |
1053 delete iIdPinObserver; |
1061 iIdPinObserver = 0; |
1054 iIdPinObserver = 0; |
1062 |
1055 |
1063 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SelfTestL Destructing states." ) ); |
1056 LOG("Destructing states"); |
1064 |
1057 |
1065 iStates.ResetAndDestroy(); |
1058 iStates.ResetAndDestroy(); |
1066 |
1059 |
1067 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SelfTestL Check UsbServiceControl" ) ); |
1060 LOG( "Check UsbServiceControl" ); |
1068 |
1061 |
1069 CUsbServiceControl* usbServiceControl = CUsbServiceControl::NewL(this, |
1062 CUsbServiceControl* usbServiceControl = CUsbServiceControl::NewL(*this, |
1070 iUsb); |
1063 iUsb); |
1071 usbServiceControl->RunError(KErrNone); |
1064 usbServiceControl->RunError(KErrNone); |
1072 delete usbServiceControl; |
1065 delete usbServiceControl; |
1073 |
1066 |
1074 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SelfTestL All completed OK." ) ); |
1067 LOG("All completed OK" ); |
1075 #endif |
1068 #endif |
1076 return KErrNone; |
1069 return KErrNone; |
1077 |
1070 |
1078 } |
1071 } |
1079 |
1072 |
1080 // --------------------------------------------------------------------------- |
1073 // --------------------------------------------------------------------------- |
1081 // |
1074 // |
1082 // --------------------------------------------------------------------------- |
1075 // --------------------------------------------------------------------------- |
1083 // |
1076 // |
1084 void CUsbOtgWatcher::SubscribeL(MUsbOtgWatcherStateObserver* aObserver) |
1077 void CUsbOtgWatcher::SubscribeL(MUsbOtgWatcherStateObserver& aObserver) |
1085 { |
1078 { |
1086 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::SubscribeL" ) ); |
1079 LOG_FUNC |
1087 |
1080 |
1088 User::LeaveIfError(iOtgStateObservers.Append(aObserver)); |
1081 // check if the same observer already exist in a list |
1089 |
1082 if (KErrNotFound != iOtgStateObservers.Find(&aObserver)) |
1090 } |
1083 { |
1091 |
1084 LOG( "Observer already exists" ); |
1092 // --------------------------------------------------------------------------- |
1085 Panic(EObserverAlreadyExists); |
1093 // |
|
1094 // --------------------------------------------------------------------------- |
|
1095 // |
|
1096 void CUsbOtgWatcher::UnsubscribeL(MUsbOtgWatcherStateObserver* aObserver) |
|
1097 { |
|
1098 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::UnsubscribeL" ) ); |
|
1099 if (0 == iOtgStateObservers.Count()) // no items |
|
1100 { |
|
1101 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::UnsubscribeL No observers" ) ); |
|
1102 return; |
1086 return; |
1103 } |
1087 } |
1104 |
1088 iOtgStateObservers.AppendL(&aObserver); |
1105 TInt i(0); |
1089 |
1106 while (i < iOtgStateObservers.Count() && aObserver != iOtgStateObservers[i]) |
1090 } |
1107 ++i; |
1091 |
1108 |
1092 // --------------------------------------------------------------------------- |
1109 if (aObserver == iOtgStateObservers[i]) // found |
1093 // |
1110 { |
1094 // --------------------------------------------------------------------------- |
1111 iOtgStateObservers.Remove(i); |
1095 // |
1112 } |
1096 void CUsbOtgWatcher::UnsubscribeL(MUsbOtgWatcherStateObserver& aObserver) |
1113 else |
1097 { |
1114 { |
1098 LOG_FUNC |
1115 FLOG( _L( "[USBOTGWATCHER]\tCUsbOtgWatcher::UnsubscribeL CanNotGetUsbOtgStateWatcherObserver" ) ); |
1099 |
|
1100 TInt i(iOtgStateObservers.Find(&aObserver)); |
|
1101 if (KErrNotFound == i) |
|
1102 { |
|
1103 LOG( "Observer not found" ); |
1116 Panic(ECanNotFindUsbOtgWatcherStateObserver); |
1104 Panic(ECanNotFindUsbOtgWatcherStateObserver); |
1117 } |
1105 return; |
1118 } |
1106 } |
|
1107 |
|
1108 iOtgStateObservers.Remove(i); |
|
1109 } |