usbengines/usbotgwatcher/src/cusbstatehostdelayhandle.cpp
branchRCL_3
changeset 5 7068aba64af5
child 6 a15c582fbf97
equal deleted inserted replaced
4:7e15987c4500 5:7068aba64af5
       
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include <usbuinotif.h>
       
    20 
       
    21 #include "cusbstatehostdelayhandle.h"
       
    22 #ifndef STIF
       
    23 #include "cusbnotifmanager.h"
       
    24 #else
       
    25 #include "mockcusbnotifmanager.h"
       
    26 #endif
       
    27 
       
    28 #include "errors.h"
       
    29 #include "debug.h"
       
    30 #include "panic.h"
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // 
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 CUsbStateHostDelayHandle::CUsbStateHostDelayHandle(CUsbOtgWatcher* aWatcher) :
       
    37     CUsbStateHostHandle(aWatcher)
       
    38     {
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // 
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CUsbStateHostDelayHandle* CUsbStateHostDelayHandle::NewL(CUsbOtgWatcher* aWatcher)
       
    46     {
       
    47         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostDelayHandle::NewL" ) );
       
    48 
       
    49     CUsbStateHostDelayHandle* self = new (ELeave) CUsbStateHostDelayHandle(aWatcher);
       
    50     CleanupStack::PushL(self);
       
    51     self->ConstructL();
       
    52     CleanupStack::Pop(self);
       
    53     return self;
       
    54     }
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // 
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 void CUsbStateHostDelayHandle::ConstructL()
       
    61     {
       
    62         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostDelayHandle::ConstructL" ) );
       
    63 
       
    64     iTooMuchPowerTimer = CUsbTimer::NewL(this, ETooMuchPowerRequiredTimer);
       
    65     iDriversNotFoundTimer = CUsbTimer::NewL(this, EDriversNotFoundTimer);
       
    66 
       
    67     }
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // 
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 CUsbStateHostDelayHandle::~CUsbStateHostDelayHandle()
       
    74     {
       
    75         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostDelayHandle::~CUsbStateHostDelayHandle" ) );
       
    76 
       
    77     delete iTooMuchPowerTimer;
       
    78     delete iDriversNotFoundTimer;
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // 
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 TUsbStateIds CUsbStateHostDelayHandle::Id()
       
    86     {
       
    87         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostDelayHandle::Id" ) );
       
    88 
       
    89     return EUsbStateHostDelayHandle;
       
    90     }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // 
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 void CUsbStateHostDelayHandle::JustAdvancedToThisStateL()
       
    97     {
       
    98         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostDelayHandle::JustAdvancedToThisStateL" ) );
       
    99         // first do something specific to entering this state
       
   100         // nothing by now, but something in the future
       
   101         
       
   102         // then do general things, defined in superclass
       
   103         CUsbStateHostHandle::JustAdvancedToThisStateL();
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // 
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 void CUsbStateHostDelayHandle::JustBeforeLeavingThisStateL()
       
   111     {
       
   112     iTooMuchPowerTimer->Cancel();
       
   113     iDriversNotFoundTimer->Cancel();
       
   114     
       
   115     // do general things for error handling 
       
   116     CUsbStateHostHandle::JustBeforeLeavingThisStateL();
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // 
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 void CUsbStateHostDelayHandle::DoHandleL()
       
   124     {
       
   125         FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbStateHostDelayHandle::DoHandleL iWhat = %d" ), iWhat));
       
   126 
       
   127     switch (iWhat)
       
   128         {
       
   129         case EUsbWatcherErrDriversNotFound:
       
   130             {
       
   131             FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostDelayHandle::DoHandleL DriversNotFound" ) );
       
   132                 
       
   133             iDriversNotFoundTimer->After(KTimeDriversNotFound);
       
   134             break;
       
   135                 
       
   136             }
       
   137 
       
   138         case EUsbWatcherErrDeviceRequiresTooMuchPowerOnEnumeration:
       
   139             {
       
   140                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostDelayHandle::DoHandleL EUsbWatcherErrDeviceRequiresTooMuchPowerOnEnumeration" ) );
       
   141 
       
   142             iTooMuchPowerTimer->After(KTimeTooMuchPowerRequired);
       
   143             break;
       
   144             }
       
   145 
       
   146         default:
       
   147             {
       
   148                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostDelayHandle::DoHandleL Pass request to CUsbStateHostHandle" ) );
       
   149                 Panic(EUnexpectedSituationToHandle);
       
   150             break;
       
   151             }
       
   152         }
       
   153     }
       
   154 
       
   155 /////////////////////////////////////////////////////////////////////////////////////
       
   156 // From VBus observer
       
   157 // ---------------------------------------------------------------------------
       
   158 // 
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 void CUsbStateHostDelayHandle::VBusUpL()
       
   162     {
       
   163         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostDelayHandle::VBusUpL" ) );
       
   164         // this is not expected, due to in this state vbus already up, since entering the state
       
   165         Panic(EVBusUpNotExpected);
       
   166     }
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // 
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 void CUsbStateHostDelayHandle::VBusDownL()
       
   173     {
       
   174         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostDelayHandle::VBusDownL" ) );
       
   175         // this is not expected, due to in this state vbus up during all the lifetime
       
   176         Panic(EVBusDownNotExpected);
       
   177     }
       
   178 
       
   179 // ---------------------------------------------------------------------------
       
   180 // 
       
   181 // ---------------------------------------------------------------------------
       
   182 //
       
   183 void CUsbStateHostDelayHandle::VBusErrorL()
       
   184     {
       
   185         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostDelayHandle::VBusErrorL" ) );
       
   186         iWatcher->Usb().BusClearError();
       
   187         HandleL(EUsbWatcherErrDeviceRequiresTooMuchPower, EUsbStateHostHandle);
       
   188     }
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 // this will drop VBus in a while => 
       
   192 // handle it in another state
       
   193 // ---------------------------------------------------------------------------
       
   194 //
       
   195 void CUsbStateHostDelayHandle::AVBusErrorL()
       
   196     {
       
   197         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostDelayHandle::AVBusErrorL" ) );
       
   198         HandleL(EUsbWatcherErrDeviceRequiresTooMuchPower, EUsbStateHostHandle);
       
   199     }
       
   200 
       
   201 // From Host Event notification observer
       
   202 // ---------------------------------------------------------------------------
       
   203 // 
       
   204 // ---------------------------------------------------------------------------
       
   205 //
       
   206 void CUsbStateHostDelayHandle::DeviceAttachedL(
       
   207         TDeviceEventInformation aDevEventInfo)
       
   208     {
       
   209         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostDelayHandle::DeviceAttachedL" ) );
       
   210 
       
   211         ChangeHostStateL(EUsbStateHostAInitiate);
       
   212         iWatcher->DeviceAttachedL(aDevEventInfo);
       
   213     }
       
   214 
       
   215 // ---------------------------------------------------------------------------
       
   216 // 
       
   217 // ---------------------------------------------------------------------------
       
   218 //
       
   219 void CUsbStateHostDelayHandle::DeviceDetachedL(TDeviceEventInformation)
       
   220     {
       
   221         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostDelayHandle::DeviceDetachedL" ) );
       
   222         ChangeHostStateL(EUsbStateHostAInitiate);
       
   223     }
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // 
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 void CUsbStateHostDelayHandle::BadHubPositionL()
       
   230     {
       
   231         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostDelayHandle::BadHubPositionL" ) );
       
   232 
       
   233         HandleL(EUsbWatcherHubsNotSupported, EUsbStateHostHandle);
       
   234     }
       
   235 
       
   236 
       
   237 // ---------------------------------------------------------------------------
       
   238 // 
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 void CUsbStateHostDelayHandle::SrpReceivedL()
       
   242     {
       
   243     FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostDelayHandle::SrpReceivedL" ) );
       
   244     // srp is not expected due to vbus is up in thes state   
       
   245     Panic(ESrpNotExpected);
       
   246     }
       
   247 
       
   248 // From TimerObserver
       
   249 // ---------------------------------------------------------------------------
       
   250 // 
       
   251 // ---------------------------------------------------------------------------
       
   252 //
       
   253 void CUsbStateHostDelayHandle::TimerElapsedL(TUsbTimerId aTimerId)
       
   254     {
       
   255     switch (aTimerId)
       
   256         {
       
   257         case ETooMuchPowerRequiredTimer:
       
   258             {
       
   259                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostDelayHandle::TimerElapsedL - ETooMuchPowerRequiredTimer" ) );
       
   260                 HandleL(EUsbWatcherErrDeviceRequiresTooMuchPower, EUsbStateHostHandle);
       
   261             break;
       
   262             }
       
   263         case EDriversNotFoundTimer:
       
   264             {
       
   265             FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostDelayHandle::TimerElapsedL - EDriversNotFoundTimer" ) );
       
   266             HandleL(EUsbWatcherErrUnsupportedDevice, EUsbStateHostHandle);
       
   267 
       
   268             break;
       
   269             }
       
   270         default:
       
   271             {
       
   272                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostDelayHandle::TimerElapsedL - Unknown timer" ) );
       
   273             Panic(EWrongTimerId);
       
   274             }
       
   275         }
       
   276     }