usbengines/usbotgwatcher/src/cusbstatehosthandle.cpp
branchRCL_3
changeset 5 7068aba64af5
parent 3 47c263f7e521
child 6 a15c582fbf97
equal deleted inserted replaced
4:7e15987c4500 5:7068aba64af5
    42 // 
    42 // 
    43 // ---------------------------------------------------------------------------
    43 // ---------------------------------------------------------------------------
    44 //
    44 //
    45 CUsbStateHostHandle* CUsbStateHostHandle::NewL(CUsbOtgWatcher* aWatcher)
    45 CUsbStateHostHandle* CUsbStateHostHandle::NewL(CUsbOtgWatcher* aWatcher)
    46     {
    46     {
    47         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAHost::NewL" ) );
    47         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::NewL" ) );
    48 
    48 
    49     CUsbStateHostHandle* self = new (ELeave) CUsbStateHostHandle(aWatcher);
    49     CUsbStateHostHandle* self = new (ELeave) CUsbStateHostHandle(aWatcher);
    50     CleanupStack::PushL(self);
    50     CleanupStack::PushL(self);
    51     self->ConstructL();
    51     self->ConstructL();
    52     CleanupStack::Pop(self);
    52     CleanupStack::Pop(self);
    58 // ---------------------------------------------------------------------------
    58 // ---------------------------------------------------------------------------
    59 //
    59 //
    60 void CUsbStateHostHandle::ConstructL()
    60 void CUsbStateHostHandle::ConstructL()
    61     {
    61     {
    62         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::ConstructL" ) );
    62         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::ConstructL" ) );
    63 
       
    64     iTooMuchPowerTimer = CUsbTimer::NewL(this, ETooMuchPowerRequiredTimer);
       
    65     iDriversNotFoundTimer = CUsbTimer::NewL(this, EDriversNotFoundTimer);
       
    66 
       
    67     }
    63     }
    68 
    64 
    69 // ---------------------------------------------------------------------------
    65 // ---------------------------------------------------------------------------
    70 // 
    66 // 
    71 // ---------------------------------------------------------------------------
    67 // ---------------------------------------------------------------------------
    72 //
    68 //
    73 CUsbStateHostHandle::~CUsbStateHostHandle()
    69 CUsbStateHostHandle::~CUsbStateHostHandle()
    74     {
    70     {
    75         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::~CUsbStateHostHandle" ) );
    71         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::~CUsbStateHostHandle" ) );
    76 
    72 
    77     delete iTooMuchPowerTimer;
       
    78     delete iDriversNotFoundTimer;
       
    79     }
    73     }
    80 
    74 
    81 // ---------------------------------------------------------------------------
    75 // ---------------------------------------------------------------------------
    82 // 
    76 // 
    83 // ---------------------------------------------------------------------------
    77 // ---------------------------------------------------------------------------
   105 // 
    99 // 
   106 // ---------------------------------------------------------------------------
   100 // ---------------------------------------------------------------------------
   107 //
   101 //
   108 void CUsbStateHostHandle::JustBeforeLeavingThisStateL()
   102 void CUsbStateHostHandle::JustBeforeLeavingThisStateL()
   109     {
   103     {
   110     iTooMuchPowerTimer->Cancel();
       
   111     iDriversNotFoundTimer->Cancel();
       
   112     
       
   113     iWatcher->NotifManager()->CloseAllNotifiers();
   104     iWatcher->NotifManager()->CloseAllNotifiers();
   114     }
   105     }
   115 // ---------------------------------------------------------------------------
   106 // ---------------------------------------------------------------------------
   116 // 
   107 // 
   117 // ---------------------------------------------------------------------------
   108 // ---------------------------------------------------------------------------
   218 // ---------------------------------------------------------------------------
   209 // ---------------------------------------------------------------------------
   219 //
   210 //
   220 void CUsbStateHostHandle::DoHandleL()
   211 void CUsbStateHostHandle::DoHandleL()
   221     {
   212     {
   222         FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DoHandleL iWhat = %d" ), iWhat));
   213         FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DoHandleL iWhat = %d" ), iWhat));
   223 
   214         
   224     if (iTooMuchPowerTimer)
   215     // Drop VBus first    
   225         iTooMuchPowerTimer->Cancel();
   216     // Ignore any errors when calling BusDrop(). Those indicate that VBus already dropped 
   226 
   217     iWatcher->Usb().BusDrop();
       
   218     
   227     switch (iWhat)
   219     switch (iWhat)
   228         {
   220         {
   229         case EUsbWatcherErrDriversNotFound:
       
   230             {
       
   231             FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DoHandleL DriversNotFound" ) );
       
   232                 
   221                 
   233             iDriversNotFoundTimer->After(KTimeDriversNotFound);
       
   234             break;
       
   235                 
       
   236             }
       
   237         case EUsbWatcherHubsNotSupported:
   222         case EUsbWatcherHubsNotSupported:
   238             {
   223             {
   239                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DoHandleL EUsbWatcherHubsNotSupported" ) );
   224                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DoHandleL EUsbWatcherHubsNotSupported" ) );
   240             // Ignore any errors when calling BusDrop(). Those indicate that VBus already dropped 
       
   241             iWatcher->Usb().BusDrop();
       
   242             iWatcher->NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
   225             iWatcher->NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
   243                     EUsbOtgHubUnsupported, this);
   226                     EUsbOtgHubUnsupported, this);
   244             break;
   227             break;
   245             }
   228             }
   246         case EUsbWatcherErrDeviceRequiresTooMuchPowerOnEnumeration:
       
   247             {
       
   248                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DoHandleL EUsbWatcherErrDeviceRequiresTooMuchPowerOnEnumeration" ) );
       
   249 
       
   250             iTooMuchPowerTimer->After(KTimeTooMuchPowerRequired);
       
   251             break;
       
   252             }
       
   253         case EUsbWatcherErrDeviceRequiresTooMuchPower:
   229         case EUsbWatcherErrDeviceRequiresTooMuchPower:
   254             {
   230             {
   255                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DoHandleL EUsbWatcherErrDeviceRequiresTooMuchPower" ) );
   231                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DoHandleL EUsbWatcherErrDeviceRequiresTooMuchPower" ) );
   256             // Ignore any errors when calling BusDrop(). Those indicate that VBus already dropped 
       
   257             iWatcher->Usb().BusDrop();
       
   258             iWatcher->NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
   232             iWatcher->NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
   259                     EUsbOtgTooMuchPower, this);
   233                     EUsbOtgTooMuchPower, this);
   260             break;
   234             break;
   261             }
   235             }
   262         case EUsbWatcherErrUnsupportedDevice:
   236         case EUsbWatcherErrUnsupportedDevice:
   263             {
   237             {
   264                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DoHandleL EUsbWatcherErrUnsupportedDevice" ) );
   238                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DoHandleL EUsbWatcherErrUnsupportedDevice" ) );
   265             // Ignore any errors when calling BusDrop(). Those indicate that VBus already dropped 
       
   266             iWatcher->Usb().BusDrop();
       
   267             iWatcher->NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
   239             iWatcher->NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
   268                     EUsbOtgUnsupportedDevice, this);
   240                     EUsbOtgUnsupportedDevice, this);
   269             break;
   241             break;
   270             }
   242             }
   271         case EUsbWatcherConnectedToOTG:
   243         case EUsbWatcherConnectedToOTG:
   272             {
   244             {
   273                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DoHandleL EUsbWatcherConnectedToOTG" ) );
   245                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DoHandleL EUsbWatcherConnectedToOTG" ) );
   274                 
       
   275             // Ignore any errors when calling BusDrop(). Those indicate that VBus already dropped
       
   276             iWatcher->Usb().BusDrop();
       
   277             iWatcher->NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
   246             iWatcher->NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
   278                     EUsbOtgUnsupportedDevice, this);
   247                     EUsbOtgUnsupportedDevice, this);
       
   248                    
   279             break;
   249             break;
   280             }
   250             }
   281         case EUsbWatcherErrDandlingCable:
   251         case EUsbWatcherErrDandlingCable:
   282             {
   252             {
   283                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DoHandleL EUsbWatcherErrDandlingCable" ) );
   253                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DoHandleL EUsbWatcherErrDandlingCable" ) );
   284             // Ignore any errors when calling BusDrop(). Those indicate that VBus already dropped 
       
   285             iWatcher->Usb().BusDrop();
       
   286             iWatcher->NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
   254             iWatcher->NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
   287                     EUsbOtgErrorAttachTimedOut, this);
   255                     EUsbOtgErrorAttachTimedOut, this);
   288             break;
   256             break;
   289             }
   257             }
   290         case EUsbWatcherNoActivity:
   258         case EUsbWatcherNoActivity:
   291             {
   259             {
   292                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DoHandleL EUsbWatcherNoActivity" ) );
   260                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DoHandleL EUsbWatcherNoActivity" ) );
   293             // Ignore any errors when calling BusDrop(). Those indicate that VBus already dropped 
       
   294             iWatcher->Usb().BusDrop();
       
   295             iWatcher->NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
   261             iWatcher->NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
   296                     EUsbOtgUnsupportedDevice, this);
   262                     EUsbOtgUnsupportedDevice, this);
   297 
   263 
   298             break;
   264             break;
   299             }
   265             }
   300         case EUsbWatcherErrorInConnection:
   266         case EUsbWatcherErrorInConnection:
   301             {
   267             {
   302                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DoHandleL EUsbWatcherErrorInConnection" ) );
   268                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DoHandleL EUsbWatcherErrorInConnection" ) );
   303             // Ignore any errors when calling BusDrop(). Those indicate that VBus already dropped 
       
   304             iWatcher->Usb().BusDrop();
       
   305             iWatcher->NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
   269             iWatcher->NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
   306                     EUsbOtgErrorInConnection, this);
   270                     EUsbOtgErrorInConnection, this);
   307             break;
   271             break;
   308             }
   272             }
   309         case EUsbWatcherCanNotStartUsbServices:
   273         case EUsbWatcherCanNotStartUsbServices:
   319         case EUsbWatcherHostEventNotificationError:
   283         case EUsbWatcherHostEventNotificationError:
   320         case EUsbWatcherOtgStateError:
   284         case EUsbWatcherOtgStateError:
   321         case EUsbWatcherMessageNotificationError:
   285         case EUsbWatcherMessageNotificationError:
   322             {
   286             {
   323             FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DoHandleL Error from observer" ) );
   287             FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DoHandleL Error from observer" ) );
   324         // Ignore any errors when calling BusDrop(). Those indicate that VBus already dropped 
       
   325         iWatcher->Usb().BusDrop();
       
   326         iWatcher->NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
   288         iWatcher->NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
   327                 EUsbOtgErrorInConnection, this);
   289                 EUsbOtgErrorInConnection, this);
   328             break;
   290             break;
   329             }
   291             }
   330         default:
   292         default:
   331             {
   293             {
   332                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::WaitNotifierCompletedL Unexpected situation to be handled" ) );
   294                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DoHandleL Unexpected situation to be handled" ) );
   333             Panic(EUnexpectedSituationToHandle);
   295             Panic(EUnexpectedSituationToHandle);
   334             break;
   296             break;
   335             }
   297             }
   336         }
   298         }
   337     }
   299     }
   338 
   300 
   339 /////////////////////////////////////////////////////////////////////////////////////
   301 /////////////////////////////////////////////////////////////////////////////////////
   340 // just ignore all the events		
       
   341 // From VBus observer
   302 // From VBus observer
       
   303 // ---------------------------------------------------------------------------
       
   304 // 
       
   305 // ---------------------------------------------------------------------------
       
   306 //
       
   307 void CUsbStateHostHandle::VBusUpL()
       
   308     {
       
   309         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::VBusUpL" ) );
       
   310         // as result of BusRespondSrp() VBus might rise up.
       
   311         // role swap is not supported => drop vbus
       
   312         // when role swap is supported, leave this function empty
       
   313         
       
   314         iWatcher->Usb().BusDrop();
       
   315     }
       
   316 
       
   317 // ---------------------------------------------------------------------------
       
   318 // this is expected in the state, for example after calling BusDrop
       
   319 // ---------------------------------------------------------------------------
       
   320 //
   342 void CUsbStateHostHandle::VBusDownL()
   321 void CUsbStateHostHandle::VBusDownL()
   343     {
   322     {
   344         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::VBusDownL" ) );
   323         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::VBusDownL" ) );
   345     }
   324     }
   346 
   325 
       
   326 // ---------------------------------------------------------------------------
       
   327 // 
       
   328 // ---------------------------------------------------------------------------
       
   329 //
       
   330 void CUsbStateHostHandle::VBusErrorL()
       
   331     {
       
   332     FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::VBusErrorL" ) );
       
   333 
       
   334     iWatcher->Usb().BusClearError();
       
   335     }
       
   336 
   347 // From OTG state observer
   337 // From OTG state observer
   348 // ---------------------------------------------------------------------------
   338 // ---------------------------------------------------------------------------
   349 // 
   339 // this AIdle means that VBus gets down. From usbwatcher POV no need to change state here
   350 // ---------------------------------------------------------------------------
   340 // ---------------------------------------------------------------------------
   351 //
   341 //
   352 void CUsbStateHostHandle::AIdleL()
   342 void CUsbStateHostHandle::AIdleL()
   353     {
   343     {
   354         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::AIdleL" ) );
   344         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::AIdleL" ) );
   355 
   345 
   356     }
   346     }
   357 
   347 
   358 // ---------------------------------------------------------------------------
   348 // ---------------------------------------------------------------------------
   359 // 
   349 // this means VBus gets up (for example as result RespondSrp()). Do not change state to Host, due to for usbwatcher it would mean 
       
   350 // that device attached and driverls found.
   360 // ---------------------------------------------------------------------------
   351 // ---------------------------------------------------------------------------
   361 //
   352 //
   362 void CUsbStateHostHandle::AHostL()
   353 void CUsbStateHostHandle::AHostL()
   363     {
   354     {
   364         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::AHostL" ) );
   355         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::AHostL" ) );
   369 // ---------------------------------------------------------------------------
   360 // ---------------------------------------------------------------------------
   370 //
   361 //
   371 void CUsbStateHostHandle::APeripheralL()
   362 void CUsbStateHostHandle::APeripheralL()
   372     {
   363     {
   373         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::APeripheralL" ) );
   364         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::APeripheralL" ) );
   374 
   365         
   375     }
   366         ChangeHostStateL(EUsbStateHostAPeripheral);
   376 
   367 
   377 // ---------------------------------------------------------------------------
   368     }
       
   369 
       
   370 // ---------------------------------------------------------------------------
       
   371 // ignore any problems on VBus, just clear it
   378 // 
   372 // 
   379 // ---------------------------------------------------------------------------
   373 // ---------------------------------------------------------------------------
   380 //
   374 //
   381 void CUsbStateHostHandle::AVBusErrorL()
   375 void CUsbStateHostHandle::AVBusErrorL()
   382     {
   376     {
   383         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::AVBusErrorL" ) );
   377         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::AVBusErrorL" ) );
   384 
   378         iWatcher->Usb().BusClearError();
   385     }
       
   386 
       
   387 // ---------------------------------------------------------------------------
       
   388 // 
       
   389 // ---------------------------------------------------------------------------
       
   390 //
       
   391 void CUsbStateHostHandle::BIdleL()
       
   392     {
       
   393         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::BIdleL" ) );
       
   394 
       
   395     }
       
   396 
       
   397 // ---------------------------------------------------------------------------
       
   398 // 
       
   399 // ---------------------------------------------------------------------------
       
   400 //
       
   401 void CUsbStateHostHandle::BPeripheralL()
       
   402     {
       
   403         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::BPeripheralL" ) );
       
   404 
       
   405     }
       
   406 
       
   407 // ---------------------------------------------------------------------------
       
   408 // 
       
   409 // ---------------------------------------------------------------------------
       
   410 //
       
   411 void CUsbStateHostHandle::BHostL()
       
   412     {
       
   413         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::BHostL" ) );
       
   414 
       
   415     }
   379     }
   416 
   380 
   417 // From bus activity observer
   381 // From bus activity observer
   418 // ---------------------------------------------------------------------------
   382 // ---------------------------------------------------------------------------
   419 // 
   383 // 
   420 // ---------------------------------------------------------------------------
   384 // ---------------------------------------------------------------------------
   421 //
   385 //
   422 void CUsbStateHostHandle::BusIdleL()
   386 void CUsbStateHostHandle::BusIdleL()
   423     {
   387     {
   424         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::BusIdleL" ) );
   388         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::BusIdleL" ) );
   425 
       
   426     }
   389     }
   427 
   390 
   428 // ---------------------------------------------------------------------------
   391 // ---------------------------------------------------------------------------
   429 // 
   392 // 
   430 // ---------------------------------------------------------------------------
   393 // ---------------------------------------------------------------------------
   431 //
   394 //
   432 void CUsbStateHostHandle::BusActiveL()
   395 void CUsbStateHostHandle::BusActiveL()
   433     {
   396     {
   434         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::BusActiveL" ) );
   397         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::BusActiveL" ) );
   435 
       
   436     }
   398     }
   437 
   399 
   438 // From Host Event notification observer
   400 // From Host Event notification observer
   439 // ---------------------------------------------------------------------------
   401 // ---------------------------------------------------------------------------
   440 // 
   402 // 
   443 void CUsbStateHostHandle::DeviceAttachedL(
   405 void CUsbStateHostHandle::DeviceAttachedL(
   444         TDeviceEventInformation aDevEventInfo)
   406         TDeviceEventInformation aDevEventInfo)
   445     {
   407     {
   446         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DeviceAttachedL" ) );
   408         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DeviceAttachedL" ) );
   447 
   409 
   448     if (iTooMuchPowerTimer->IsActive() || iDriversNotFoundTimer->IsActive())
   410     } 
   449         {
       
   450         ChangeHostStateL(EUsbStateHostAInitiate);
       
   451         iWatcher->DeviceAttachedL(aDevEventInfo);
       
   452         return;
       
   453         }
       
   454      FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DeviceAttachedL Unexpected situation" ) );
       
   455     }
       
   456 
   411 
   457 // ---------------------------------------------------------------------------
   412 // ---------------------------------------------------------------------------
   458 // 
   413 // 
   459 // ---------------------------------------------------------------------------
   414 // ---------------------------------------------------------------------------
   460 //
   415 //
   461 void CUsbStateHostHandle::DeviceDetachedL(TDeviceEventInformation)
   416 void CUsbStateHostHandle::DeviceDetachedL(TDeviceEventInformation)
   462     {
   417     {
   463         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DeviceDetachedL" ) );
   418         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DeviceDetachedL" ) );
   464 
   419 
   465     }
   420     } 
   466 
   421 
   467 // ---------------------------------------------------------------------------
   422 // ---------------------------------------------------------------------------
   468 // 
   423 // 
   469 // ---------------------------------------------------------------------------
   424 // ---------------------------------------------------------------------------
   470 //
   425 //
   471 void CUsbStateHostHandle::DriverLoadSuccessL(TDeviceEventInformation)
   426 void CUsbStateHostHandle::DriverLoadSuccessL(TDeviceEventInformation)
   472     {
   427     {
   473         FLOG( _L( "[USBOTGWATCHER]\tCUsbState::DriverLoadSuccessL" ) );
   428         FLOG( _L( "[USBOTGWATCHER]\tCUsbState::DriverLoadSuccessL" ) );
   474     
   429     
   475     }
   430     }
   476 
   431     
   477 // ---------------------------------------------------------------------------
   432 // ---------------------------------------------------------------------------
   478 // 
   433 // 
   479 // ---------------------------------------------------------------------------
   434 // ---------------------------------------------------------------------------
   480 //
   435 //
   481 void CUsbStateHostHandle::DriverLoadPartialSuccessL(TDeviceEventInformation)
   436 void CUsbStateHostHandle::DriverLoadPartialSuccessL(TDeviceEventInformation)
   490 //
   445 //
   491 void CUsbStateHostHandle::DriverLoadFailureL(TDeviceEventInformation)
   446 void CUsbStateHostHandle::DriverLoadFailureL(TDeviceEventInformation)
   492     {
   447     {
   493         FLOG( _L( "[USBOTGWATCHER]\tCUsbState::DriverLoadFailureL" ) );
   448         FLOG( _L( "[USBOTGWATCHER]\tCUsbState::DriverLoadFailureL" ) );
   494     
   449     
   495     }
       
   496 
       
   497 // ---------------------------------------------------------------------------
       
   498 // 
       
   499 // ---------------------------------------------------------------------------
       
   500 //
       
   501 void CUsbStateHostHandle::BadHubPositionL()
       
   502     {
       
   503         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::BadHubPositionL" ) );
       
   504 
       
   505     if (iTooMuchPowerTimer->IsActive())
       
   506         {
       
   507         ChangeHostStateL(EUsbStateHostAInitiate);
       
   508         iWatcher->BadHubPositionL();
       
   509         }
       
   510     else
       
   511         {
       
   512             FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DeviceAttachedL Unexpected situation" ) );
       
   513         }
       
   514     }
       
   515 
       
   516 // ---------------------------------------------------------------------------
       
   517 // 
       
   518 // ---------------------------------------------------------------------------
       
   519 //
       
   520 void CUsbStateHostHandle::VBusErrorL()
       
   521     {
       
   522         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::VBusErrorL" ) );
       
   523 
       
   524     iWatcher->Usb().BusClearError();
       
   525     FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::VBusErrorL Unexpected situation" ) );
       
   526     }
   450     }
   527 
   451 
   528 // ---------------------------------------------------------------------------
   452 // ---------------------------------------------------------------------------
   529 // 
   453 // 
   530 // ---------------------------------------------------------------------------
   454 // ---------------------------------------------------------------------------
   541 //
   465 //
   542 void CUsbStateHostHandle::SrpReceivedL()
   466 void CUsbStateHostHandle::SrpReceivedL()
   543     {
   467     {
   544     FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::SrpReceivedL" ) );
   468     FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::SrpReceivedL" ) );
   545         
   469         
   546     if (CUsbVBusObserver::EVBusUp != iWatcher->VBusObserver()->VBus())
   470     TInt err = iWatcher->Usb().BusRespondSrp();
   547         {
   471     FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbStateHostHandle::SrpReceivedL BusRespondSrp()=%d" ), err));
   548         TInt err = iWatcher->Usb().BusRespondSrp();
   472     
   549         if (KErrNone != err)
   473     if (KErrNone != err)
   550             {
   474             {
   551             FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::SrpReceivedL BusRespondSrp error" ) );
   475             FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::SrpReceivedL BusRespondSrp error" ) );
   552             iWatcher->HandleHostProblemL(EUsbWatcherErrorInConnection);
   476             iWhat = EUsbWatcherErrorInConnection;
   553             }
   477             DoHandleL();
   554         else
   478             return;
   555             {
   479             }
   556             ChangeHostStateL(EUsbStateHostAInitiate);
       
   557             }
       
   558         }
       
   559 
       
   560     }
   480     }
   561 
   481 
   562 // ---------------------------------------------------------------------------
   482 // ---------------------------------------------------------------------------
   563 // 
   483 // 
   564 // ---------------------------------------------------------------------------
   484 // ---------------------------------------------------------------------------
   566 void CUsbStateHostHandle::SessionRequestedL()
   486 void CUsbStateHostHandle::SessionRequestedL()
   567     {
   487     {
   568         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::SessionRequestedL" ) );
   488         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::SessionRequestedL" ) );
   569 
   489 
   570     }
   490     }
   571 
       
   572 // From TimerObserver
       
   573 // ---------------------------------------------------------------------------
       
   574 // 
       
   575 // ---------------------------------------------------------------------------
       
   576 //
       
   577 void CUsbStateHostHandle::TimerElapsedL(TUsbTimerId aTimerId)
       
   578     {
       
   579     switch (aTimerId)
       
   580         {
       
   581         case ETooMuchPowerRequiredTimer:
       
   582             {
       
   583                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::TimerElapsedL - ETooMuchPowerRequiredTimer" ) );
       
   584             iWatcher->Usb().BusDrop();
       
   585             iWatcher->NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
       
   586                     EUsbOtgTooMuchPowerRequired, this);
       
   587             break;
       
   588             }
       
   589         case EDriversNotFoundTimer:
       
   590             {
       
   591             FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::TimerElapsedL - EDriversNotFoundTimer" ) );
       
   592             // Ignore any errors when calling BusDrop(). Those indicate that VBus already dropped 
       
   593             iWatcher->Usb().BusDrop();
       
   594             iWatcher->NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
       
   595                     EUsbOtgUnsupportedDevice, this);
       
   596 
       
   597             break;
       
   598             }
       
   599         default:
       
   600             {
       
   601                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::TimerElapsedL - Unknown timer" ) );
       
   602             Panic(EWrongTimerId);
       
   603             }
       
   604         }
       
   605     }