usbengines/usbotgwatcher/src/cusbstatehosthandle.cpp
changeset 25 8c311f9acc5e
parent 3 47c263f7e521
child 26 0ae0f29418cd
equal deleted inserted replaced
8:7e15987c4500 25:8c311f9acc5e
     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  *
    19 #include <usbuinotif.h>
    12  * Contributors:
       
    13  *
       
    14  * Description:  Implementation
       
    15  *
       
    16  */
    20 
    17 
    21 #include "cusbstatehosthandle.h"
    18 #include "cusbstatehosthandle.h"
    22 #ifndef STIF
       
    23 #include "cusbnotifmanager.h"
       
    24 #else
       
    25 #include "mockcusbnotifmanager.h"
       
    26 #endif
       
    27 
    19 
    28 #include "errors.h"
    20 #include "errors.h"
    29 #include "debug.h"
    21 #include "debug.h"
    30 #include "panic.h"
    22 #include "panic.h"
    31 
    23 
    32 // ---------------------------------------------------------------------------
    24 // ---------------------------------------------------------------------------
    33 // 
    25 // 
    34 // ---------------------------------------------------------------------------
    26 // ---------------------------------------------------------------------------
    35 //
    27 //
    36 CUsbStateHostHandle::CUsbStateHostHandle(CUsbOtgWatcher* aWatcher) :
    28 CUsbStateHostHandle::CUsbStateHostHandle(CUsbOtgWatcher& aWatcher) :
    37     CUsbState(aWatcher)
    29     CUsbStateHostABase(aWatcher)
    38     {
    30     {
    39     }
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // 
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CUsbStateHostHandle* CUsbStateHostHandle::NewL(CUsbOtgWatcher* aWatcher)
       
    46     {
       
    47         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAHost::NewL" ) );
       
    48 
       
    49     CUsbStateHostHandle* self = new (ELeave) CUsbStateHostHandle(aWatcher);
       
    50     CleanupStack::PushL(self);
       
    51     self->ConstructL();
       
    52     CleanupStack::Pop(self);
       
    53     return self;
       
    54     }
    31     }
    55 
    32 
    56 // ---------------------------------------------------------------------------
    33 // ---------------------------------------------------------------------------
    57 // 
    34 // 
    58 // ---------------------------------------------------------------------------
    35 // ---------------------------------------------------------------------------
    59 //
    36 //
    60 void CUsbStateHostHandle::ConstructL()
    37 void CUsbStateHostHandle::ConstructL()
    61     {
    38     {
    62         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::ConstructL" ) );
    39     LOG_FUNC
    63 
    40 
    64     iTooMuchPowerTimer = CUsbTimer::NewL(this, ETooMuchPowerRequiredTimer);
    41     CUsbStateHostABase::ConstructL();
    65     iDriversNotFoundTimer = CUsbTimer::NewL(this, EDriversNotFoundTimer);
       
    66 
    42 
    67     }
    43     }
    68 
    44 
    69 // ---------------------------------------------------------------------------
    45 // ---------------------------------------------------------------------------
    70 // 
    46 // 
    71 // ---------------------------------------------------------------------------
    47 // ---------------------------------------------------------------------------
    72 //
    48 //
    73 CUsbStateHostHandle::~CUsbStateHostHandle()
    49 CUsbStateHostHandle::~CUsbStateHostHandle()
    74     {
    50     {
    75         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::~CUsbStateHostHandle" ) );
    51     LOG_FUNC
    76 
       
    77     delete iTooMuchPowerTimer;
       
    78     delete iDriversNotFoundTimer;
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // 
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 TUsbStateIds CUsbStateHostHandle::Id()
       
    86     {
       
    87         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::Id" ) );
       
    88 
       
    89     return EUsbStateHostHandle;
       
    90     }
    52     }
    91 
    53 
    92 // ---------------------------------------------------------------------------
    54 // ---------------------------------------------------------------------------
    93 // 
    55 // 
    94 // ---------------------------------------------------------------------------
    56 // ---------------------------------------------------------------------------
    95 //
    57 //
    96 void CUsbStateHostHandle::JustAdvancedToThisStateL()
    58 void CUsbStateHostHandle::JustAdvancedToThisStateL()
    97     {
    59     {
    98         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::JustAdvancedToThisStateL" ) );
    60     LOG_FUNC
    99     iWatcher->PrintStateToLog();
       
   100 
    61 
       
    62     // first do general things
       
    63     CUsbStateHostABase::JustAdvancedToThisStateL();
       
    64 
       
    65     // then, do specific things
   101     DoHandleL();
    66     DoHandleL();
       
    67 
   102     }
    68     }
   103 
    69 
   104 // ---------------------------------------------------------------------------
       
   105 // 
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 void CUsbStateHostHandle::JustBeforeLeavingThisStateL()
       
   109     {
       
   110     iTooMuchPowerTimer->Cancel();
       
   111     iDriversNotFoundTimer->Cancel();
       
   112     
       
   113     iWatcher->NotifManager()->CloseAllNotifiers();
       
   114     }
       
   115 // ---------------------------------------------------------------------------
    70 // ---------------------------------------------------------------------------
   116 // 
    71 // 
   117 // ---------------------------------------------------------------------------
    72 // ---------------------------------------------------------------------------
   118 //
    73 //
   119 void CUsbStateHostHandle::SetWhat(TInt aWhat)
    74 void CUsbStateHostHandle::SetWhat(TInt aWhat)
   120     {
    75     {
   121     iWhat = aWhat;
    76     iWhat = aWhat;
   122     }
    77     }
   123 
    78 
   124 // this means only one wait notifier at a time can be shown by this state
    79 // From message notification observer
   125 // ---------------------------------------------------------------------------
    80 // ---------------------------------------------------------------------------
   126 // 
    81 // 
   127 // ---------------------------------------------------------------------------
    82 // ---------------------------------------------------------------------------
   128 //
    83 //
   129 void CUsbStateHostHandle::WaitNotifierCompletedL(TInt /*aFeedback*/)
    84 void CUsbStateHostHandle::MessageNotificationReceivedL(TInt aMessage)
   130     {
    85     {
   131         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::WaitNotifierCompletedL" ) );
    86     LOG_FUNC
   132     switch (iWhat)
    87     LOG1( "Unhandled message aMessage = %d" , aMessage);
   133         {
       
   134         case EUsbWatcherErrDriversNotFound:
       
   135             {
       
   136                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::WaitNotifierCompletedL DriversNotFound" ) );
       
   137             ChangeHostStateL(EUsbStateHostAInitiate);
       
   138             break;
       
   139             }
       
   140         case EUsbWatcherHubsNotSupported:
       
   141             {
       
   142                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::WaitNotifierCompletedL EUsbWatcherHubsNotSupported" ) );
       
   143             ChangeHostStateL(EUsbStateHostAInitiate);
       
   144             break;
       
   145             }
       
   146         case EUsbWatcherErrDeviceRequiresTooMuchPower:
       
   147             {
       
   148                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::WaitNotifierCompletedL EUsbWatcherErrDeviceRequiresTooMuchPower" ) );
       
   149             ChangeHostStateL(EUsbStateHostAInitiate);
       
   150             break;
       
   151             }
       
   152         case EUsbWatcherErrDeviceRequiresTooMuchPowerOnEnumeration:
       
   153             {
       
   154                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::WaitNotifierCompletedL EUsbWatcherErrDeviceRequiresTooMuchPowerOnEnumeration" ) );
       
   155             ChangeHostStateL(EUsbStateHostAInitiate);
       
   156             break;
       
   157             }
       
   158         case EUsbWatcherErrUnsupportedDevice:
       
   159             {
       
   160                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::WaitNotifierCompletedL EUsbWatcherErrUnsupportedDevice" ) );
       
   161             ChangeHostStateL(EUsbStateHostAInitiate);
       
   162             break;
       
   163             }
       
   164         case EUsbWatcherConnectedToOTG:
       
   165             {
       
   166                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::WaitNotifierCompletedL EUsbWatcherConnectedToOTG" ) );
       
   167             ChangeHostStateL(EUsbStateHostAInitiate);
       
   168             break;
       
   169             }
       
   170         case EUsbWatcherErrDandlingCable:
       
   171             {
       
   172                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::WaitNotifierCompletedL EUsbWatcherErrDandlingCable" ) );
       
   173             ChangeHostStateL(EUsbStateHostAInitiate);
       
   174             break;
       
   175             }
       
   176         case EUsbWatcherNoActivity:
       
   177             {
       
   178                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::WaitNotifierCompletedL EUsbWatcherNoActivity" ) );
       
   179             ChangeHostStateL(EUsbStateHostAInitiate);
       
   180             break;
       
   181             }
       
   182         case EUsbWatcherErrorInConnection:
       
   183             {
       
   184                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::WaitNotifierCompletedL EUsbWatcherErrorInConnection" ) );
       
   185             ChangeHostStateL(EUsbStateHostAInitiate);
       
   186             break;
       
   187             }
       
   188         case EUsbWatcherCanNotStartUsbServices:
       
   189             {
       
   190             FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::WaitNotifierCompletedL EUsbWatcherCanNotStartUsbServices" ) );
       
   191             
       
   192             break;                     
       
   193             }
       
   194         // errors from observers mapped to one
       
   195         case EUsbWatcherIdPinError:
       
   196         case EUsbWatcherVBusObserverError:
       
   197         case EUsbWatcherHostEventNotificationError:
       
   198         case EUsbWatcherOtgStateError:
       
   199         case EUsbWatcherMessageNotificationError:
       
   200             {
       
   201             // try to restore
       
   202             FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::WaitNotifierCompletedL Error in observer" ) );
       
   203             ChangeHostStateL(EUsbStateHostAInitiate);
       
   204             break;
       
   205             }
       
   206         default:
       
   207             {
       
   208                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::WaitNotifierCompletedL Unexpected situation to be handled" ) );
       
   209             Panic(EUnexpectedSituationToHandle);
       
   210             break;
       
   211             }
       
   212 
       
   213         }
       
   214     }
       
   215 
       
   216 // ---------------------------------------------------------------------------
       
   217 // 
       
   218 // ---------------------------------------------------------------------------
       
   219 //
       
   220 void CUsbStateHostHandle::DoHandleL()
       
   221     {
       
   222         FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DoHandleL iWhat = %d" ), iWhat));
       
   223 
       
   224     if (iTooMuchPowerTimer)
       
   225         iTooMuchPowerTimer->Cancel();
       
   226 
       
   227     switch (iWhat)
       
   228         {
       
   229         case EUsbWatcherErrDriversNotFound:
       
   230             {
       
   231             FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DoHandleL DriversNotFound" ) );
       
   232                 
       
   233             iDriversNotFoundTimer->After(KTimeDriversNotFound);
       
   234             break;
       
   235                 
       
   236             }
       
   237         case EUsbWatcherHubsNotSupported:
       
   238             {
       
   239                 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,
       
   243                     EUsbOtgHubUnsupported, this);
       
   244             break;
       
   245             }
       
   246         case EUsbWatcherErrDeviceRequiresTooMuchPowerOnEnumeration:
       
   247             {
       
   248                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DoHandleL EUsbWatcherErrDeviceRequiresTooMuchPowerOnEnumeration" ) );
       
   249 
       
   250             iTooMuchPowerTimer->After(KTimeTooMuchPowerRequired);
       
   251             break;
       
   252             }
       
   253         case EUsbWatcherErrDeviceRequiresTooMuchPower:
       
   254             {
       
   255                 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,
       
   259                     EUsbOtgTooMuchPower, this);
       
   260             break;
       
   261             }
       
   262         case EUsbWatcherErrUnsupportedDevice:
       
   263             {
       
   264                 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,
       
   268                     EUsbOtgUnsupportedDevice, this);
       
   269             break;
       
   270             }
       
   271         case EUsbWatcherConnectedToOTG:
       
   272             {
       
   273                 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,
       
   278                     EUsbOtgUnsupportedDevice, this);
       
   279             break;
       
   280             }
       
   281         case EUsbWatcherErrDandlingCable:
       
   282             {
       
   283                 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,
       
   287                     EUsbOtgErrorAttachTimedOut, this);
       
   288             break;
       
   289             }
       
   290         case EUsbWatcherNoActivity:
       
   291             {
       
   292                 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,
       
   296                     EUsbOtgUnsupportedDevice, this);
       
   297 
       
   298             break;
       
   299             }
       
   300         case EUsbWatcherErrorInConnection:
       
   301             {
       
   302                 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,
       
   306                     EUsbOtgErrorInConnection, this);
       
   307             break;
       
   308             }
       
   309         case EUsbWatcherCanNotStartUsbServices:
       
   310             {
       
   311             FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DoHandleL EUsbWatcherCanNotStartUsbServices" ) );
       
   312             iWatcher->NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
       
   313                 EUsbOtgErrorInConnection, this);
       
   314             break;           
       
   315             }
       
   316         // errors from observers mapped to one
       
   317         case EUsbWatcherIdPinError:
       
   318         case EUsbWatcherVBusObserverError:
       
   319         case EUsbWatcherHostEventNotificationError:
       
   320         case EUsbWatcherOtgStateError:
       
   321         case EUsbWatcherMessageNotificationError:
       
   322             {
       
   323             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,
       
   327                 EUsbOtgErrorInConnection, this);
       
   328             break;
       
   329             }
       
   330         default:
       
   331             {
       
   332                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::WaitNotifierCompletedL Unexpected situation to be handled" ) );
       
   333             Panic(EUnexpectedSituationToHandle);
       
   334             break;
       
   335             }
       
   336         }
       
   337     }
       
   338 
       
   339 /////////////////////////////////////////////////////////////////////////////////////
       
   340 // just ignore all the events		
       
   341 // From VBus observer
       
   342 void CUsbStateHostHandle::VBusDownL()
       
   343     {
       
   344         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::VBusDownL" ) );
       
   345     }
       
   346 
       
   347 // From OTG state observer
       
   348 // ---------------------------------------------------------------------------
       
   349 // 
       
   350 // ---------------------------------------------------------------------------
       
   351 //
       
   352 void CUsbStateHostHandle::AIdleL()
       
   353     {
       
   354         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::AIdleL" ) );
       
   355 
       
   356     }
       
   357 
       
   358 // ---------------------------------------------------------------------------
       
   359 // 
       
   360 // ---------------------------------------------------------------------------
       
   361 //
       
   362 void CUsbStateHostHandle::AHostL()
       
   363     {
       
   364         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::AHostL" ) );
       
   365     }
       
   366 
       
   367 // ---------------------------------------------------------------------------
       
   368 // 
       
   369 // ---------------------------------------------------------------------------
       
   370 //
       
   371 void CUsbStateHostHandle::APeripheralL()
       
   372     {
       
   373         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::APeripheralL" ) );
       
   374 
       
   375     }
       
   376 
       
   377 // ---------------------------------------------------------------------------
       
   378 // 
       
   379 // ---------------------------------------------------------------------------
       
   380 //
       
   381 void CUsbStateHostHandle::AVBusErrorL()
       
   382     {
       
   383         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::AVBusErrorL" ) );
       
   384 
       
   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     }
       
   416 
       
   417 // From bus activity observer
       
   418 // ---------------------------------------------------------------------------
       
   419 // 
       
   420 // ---------------------------------------------------------------------------
       
   421 //
       
   422 void CUsbStateHostHandle::BusIdleL()
       
   423     {
       
   424         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::BusIdleL" ) );
       
   425 
       
   426     }
       
   427 
       
   428 // ---------------------------------------------------------------------------
       
   429 // 
       
   430 // ---------------------------------------------------------------------------
       
   431 //
       
   432 void CUsbStateHostHandle::BusActiveL()
       
   433     {
       
   434         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::BusActiveL" ) );
       
   435 
       
   436     }
       
   437 
       
   438 // From Host Event notification observer
       
   439 // ---------------------------------------------------------------------------
       
   440 // 
       
   441 // ---------------------------------------------------------------------------
       
   442 //
       
   443 void CUsbStateHostHandle::DeviceAttachedL(
       
   444         TDeviceEventInformation aDevEventInfo)
       
   445     {
       
   446         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DeviceAttachedL" ) );
       
   447 
       
   448     if (iTooMuchPowerTimer->IsActive() || iDriversNotFoundTimer->IsActive())
       
   449         {
       
   450         ChangeHostStateL(EUsbStateHostAInitiate);
       
   451         iWatcher->DeviceAttachedL(aDevEventInfo);
       
   452         return;
       
   453         }
       
   454      FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DeviceAttachedL Unexpected situation" ) );
       
   455     }
       
   456 
       
   457 // ---------------------------------------------------------------------------
       
   458 // 
       
   459 // ---------------------------------------------------------------------------
       
   460 //
       
   461 void CUsbStateHostHandle::DeviceDetachedL(TDeviceEventInformation)
       
   462     {
       
   463         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::DeviceDetachedL" ) );
       
   464 
       
   465     }
       
   466 
       
   467 // ---------------------------------------------------------------------------
       
   468 // 
       
   469 // ---------------------------------------------------------------------------
       
   470 //
       
   471 void CUsbStateHostHandle::DriverLoadSuccessL(TDeviceEventInformation)
       
   472     {
       
   473         FLOG( _L( "[USBOTGWATCHER]\tCUsbState::DriverLoadSuccessL" ) );
       
   474     
       
   475     }
       
   476 
       
   477 // ---------------------------------------------------------------------------
       
   478 // 
       
   479 // ---------------------------------------------------------------------------
       
   480 //
       
   481 void CUsbStateHostHandle::DriverLoadPartialSuccessL(TDeviceEventInformation)
       
   482     {
       
   483         FLOG( _L( "[USBOTGWATCHER]\tCUsbState::DriverLoadPartialSuccessL" ) );
       
   484     
       
   485     }
       
   486 
       
   487 // ---------------------------------------------------------------------------
       
   488 // 
       
   489 // ---------------------------------------------------------------------------
       
   490 //
       
   491 void CUsbStateHostHandle::DriverLoadFailureL(TDeviceEventInformation)
       
   492     {
       
   493         FLOG( _L( "[USBOTGWATCHER]\tCUsbState::DriverLoadFailureL" ) );
       
   494     
       
   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     }
       
   527 
       
   528 // ---------------------------------------------------------------------------
       
   529 // 
       
   530 // ---------------------------------------------------------------------------
       
   531 //
       
   532 void CUsbStateHostHandle::MessageNotificationReceivedL(TInt)
       
   533     {
       
   534         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::MessageNotificationReceivedL" ) );
       
   535 
       
   536     }
       
   537 
       
   538 // ---------------------------------------------------------------------------
       
   539 // 
       
   540 // ---------------------------------------------------------------------------
       
   541 //
       
   542 void CUsbStateHostHandle::SrpReceivedL()
       
   543     {
       
   544     FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::SrpReceivedL" ) );
       
   545         
       
   546     if (CUsbVBusObserver::EVBusUp != iWatcher->VBusObserver()->VBus())
       
   547         {
       
   548         TInt err = iWatcher->Usb().BusRespondSrp();
       
   549         if (KErrNone != err)
       
   550             {
       
   551             FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::SrpReceivedL BusRespondSrp error" ) );
       
   552             iWatcher->HandleHostProblemL(EUsbWatcherErrorInConnection);
       
   553             }
       
   554         else
       
   555             {
       
   556             ChangeHostStateL(EUsbStateHostAInitiate);
       
   557             }
       
   558         }
       
   559 
    88 
   560     }
    89     }
   561 
    90 
   562 // ---------------------------------------------------------------------------
    91 // ---------------------------------------------------------------------------
   563 // 
    92 // 
   564 // ---------------------------------------------------------------------------
    93 // ---------------------------------------------------------------------------
   565 //
    94 //
   566 void CUsbStateHostHandle::SessionRequestedL()
    95 void CUsbStateHostHandle::SessionRequestedL()
   567     {
    96     {
   568         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostHandle::SessionRequestedL" ) );
    97     LOG_FUNC
   569 
       
   570     }
    98     }
   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     }