usbengines/usbotgwatcher/src/cusbstatehosthandledropping.cpp
changeset 34 7858bc6ead78
parent 31 dfdd8240f7c8
child 35 9d8b04ca6939
equal deleted inserted replaced
31:dfdd8240f7c8 34:7858bc6ead78
     1 /*
       
     2  * Copyright (c) 2008 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 #include <usbuinotif.h>
       
    19 #include <d32usbdi_errors.h>
       
    20 
       
    21 #include "cusbotgwatcher.h"
       
    22 #include "cusbstatehosthandledropping.h"
       
    23 
       
    24 #ifndef STIF
       
    25 #include "cusbnotifmanager.h"
       
    26 #else
       
    27 #include "mockcusbnotifmanager.h"
       
    28 #endif
       
    29 
       
    30 #include "errors.h"
       
    31 #include "debug.h"
       
    32 #include "panic.h"
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // 
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 CUsbStateHostHandleDropping::CUsbStateHostHandleDropping(
       
    39         CUsbOtgWatcher& aWatcher) :
       
    40     CUsbStateHostHandle(aWatcher)
       
    41     {
       
    42     }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // 
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 CUsbStateHostHandleDropping* CUsbStateHostHandleDropping::NewL(
       
    49         CUsbOtgWatcher& aWatcher)
       
    50     {
       
    51     LOG_FUNC
       
    52 
       
    53     CUsbStateHostHandleDropping* self =
       
    54             new (ELeave) CUsbStateHostHandleDropping(aWatcher);
       
    55     CleanupStack::PushL(self);
       
    56     self->ConstructL();
       
    57     CleanupStack::Pop(self);
       
    58     return self;
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // 
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 void CUsbStateHostHandleDropping::ConstructL()
       
    66     {
       
    67     LOG_FUNC
       
    68     CUsbStateHostHandle::ConstructL();
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // 
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 CUsbStateHostHandleDropping::~CUsbStateHostHandleDropping()
       
    76     {
       
    77     LOG_FUNC
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // 
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 TUsbStateIds CUsbStateHostHandleDropping::Id()
       
    85     {
       
    86     return EUsbStateHostHandleDropping;
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // 
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 void CUsbStateHostHandleDropping::JustBeforeLeavingThisStateL()
       
    94     {
       
    95     LOG_FUNC
       
    96 
       
    97     iWatcher.NotifManager()->CloseAllNotifiers();
       
    98 
       
    99     // do general things 
       
   100     CUsbStateHostHandle::JustBeforeLeavingThisStateL();
       
   101     }
       
   102 
       
   103 // this means only one wait notifier at a time can be shown by this state
       
   104 // ---------------------------------------------------------------------------
       
   105 // 
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 void CUsbStateHostHandleDropping::WaitNotifierCompletedL(TInt /*aFeedback*/)
       
   109     {
       
   110     LOG_FUNC
       
   111 
       
   112     switch (iWhat)
       
   113         {
       
   114         case EUsbWatcherHubsNotSupported:
       
   115             {
       
   116             LOG( "EUsbWatcherHubsNotSupported" );
       
   117             ChangeHostStateL( EUsbStateHostAInitiate);
       
   118             break;
       
   119             }
       
   120         case EUsbWatcherErrDeviceRequiresTooMuchPower:
       
   121             {
       
   122             LOG( "EUsbWatcherErrDeviceRequiresTooMuchPower" );
       
   123             ChangeHostStateL( EUsbStateHostAInitiate);
       
   124             break;
       
   125             }
       
   126         case EUsbWatcherErrUnsupportedDevice:
       
   127             {
       
   128             LOG("EUsbWatcherErrUnsupportedDevice" );
       
   129             ChangeHostStateL( EUsbStateHostAInitiate);
       
   130             break;
       
   131             }
       
   132         case EUsbWatcherConnectedToOTG:
       
   133             {
       
   134             LOG("EUsbWatcherConnectedToOTG" );
       
   135             ChangeHostStateL( EUsbStateHostAInitiate);
       
   136             break;
       
   137             }
       
   138         case EUsbWatcherErrDandlingCable:
       
   139             {
       
   140             LOG("EUsbWatcherErrDandlingCable" );
       
   141             ChangeHostStateL( EUsbStateHostAInitiate);
       
   142             break;
       
   143             }
       
   144         case EUsbWatcherNoActivity:
       
   145             {
       
   146             LOG("EUsbWatcherNoActivity" );
       
   147             ChangeHostStateL( EUsbStateHostAInitiate);
       
   148             break;
       
   149             }
       
   150         case EUsbWatcherErrorInConnection:
       
   151             {
       
   152             LOG( "EUsbWatcherErrorInConnection" );
       
   153             ChangeHostStateL( EUsbStateHostAInitiate);
       
   154             break;
       
   155             }
       
   156 
       
   157             // fatal errors
       
   158         case EUsbWatcherCanNotStartUsbServices:
       
   159             {
       
   160             LOG( "EUsbWatcherCanNotStartUsbServices" );
       
   161 
       
   162             // no break here                     
       
   163             }
       
   164 
       
   165             // no break statement for following cases 
       
   166         case EUsbWatcherNoMemory:
       
   167         case EUsbWatcherIdPinError:
       
   168         case EUsbWatcherVBusObserverError:
       
   169         case EUsbWatcherHostEventNotificationError:
       
   170         case EUsbWatcherOtgStateError:
       
   171         case EUsbWatcherMessageNotificationError:
       
   172         case EUsbWatcherCanNotStartSession:
       
   173         case EUsbWatcherCanNotEnableDriverLoading:
       
   174         case EUsbWatcherCanNotClearBusError:
       
   175         case EUsbWatcherCanNotRaiseVBus:
       
   176             {
       
   177             LOG("Fatal error" );
       
   178             ChangeHostStateL( EUsbStateHostUndefined);
       
   179             break;
       
   180             }
       
   181         default:
       
   182             {
       
   183             LOG1("Unexpected situation to be handled iWhat = %d" , iWhat );
       
   184             PANIC( EUnexpectedSituationToHandle);
       
   185             break;
       
   186             }
       
   187 
       
   188         }
       
   189     }
       
   190 
       
   191 // ---------------------------------------------------------------------------
       
   192 // 
       
   193 // ---------------------------------------------------------------------------
       
   194 //
       
   195 void CUsbStateHostHandleDropping::DoHandleL()
       
   196     {
       
   197     LOG_FUNC
       
   198 
       
   199     LOG1( "iWhat = %d" , iWhat);
       
   200 
       
   201     // Drop VBus first    
       
   202     // Ignore any errors when calling BusDrop(). Those indicate that VBus already dropped 
       
   203     iWatcher.Usb().BusDrop();
       
   204 
       
   205     switch (iWhat)
       
   206         {
       
   207 
       
   208         case EUsbWatcherHubsNotSupported:
       
   209             {
       
   210             LOG("EUsbWatcherHubsNotSupported" );
       
   211             iWatcher.NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
       
   212                     EUsbOtgHubUnsupported, this);
       
   213             break;
       
   214             }
       
   215         case EUsbWatcherErrDeviceRequiresTooMuchPower:
       
   216             {
       
   217             LOG("EUsbWatcherErrDeviceRequiresTooMuchPower" );
       
   218             iWatcher.NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
       
   219                     EUsbOtgTooMuchPower, this);
       
   220             break;
       
   221             }
       
   222         case EUsbWatcherErrUnsupportedDevice:
       
   223             {
       
   224             LOG("EUsbWatcherErrUnsupportedDevice" );
       
   225             iWatcher.NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
       
   226                     EUsbOtgUnsupportedDevice, this);
       
   227             break;
       
   228             }
       
   229         case EUsbWatcherConnectedToOTG:
       
   230             {
       
   231             LOG("EUsbWatcherConnectedToOTG" );
       
   232             iWatcher.NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
       
   233                     EUsbOtgUnsupportedDevice, this);
       
   234 
       
   235             break;
       
   236             }
       
   237         case EUsbWatcherErrDandlingCable:
       
   238             {
       
   239             LOG( "EUsbWatcherErrDandlingCable" );
       
   240             iWatcher.NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
       
   241                     EUsbOtgErrorAttachTimedOut, this);
       
   242             break;
       
   243             }
       
   244         case EUsbWatcherNoActivity:
       
   245             {
       
   246             LOG( "EUsbWatcherNoActivity" );
       
   247             iWatcher.NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
       
   248                     EUsbOtgUnsupportedDevice, this);
       
   249 
       
   250             break;
       
   251             }
       
   252         case EUsbWatcherErrorInConnection:
       
   253             {
       
   254             LOG("EUsbWatcherErrorInConnection" );
       
   255             iWatcher.NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
       
   256                     EUsbOtgErrorInConnection, this);
       
   257             break;
       
   258             }
       
   259         case EUsbWatcherNoMemory:
       
   260             {
       
   261             LOG("EUsbWatcherNoMemory" );
       
   262             iWatcher.NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
       
   263                     EUsbOtgErrorNoMemory, this);
       
   264             break;
       
   265             }
       
   266         case EUsbWatcherCanNotStartUsbServices:
       
   267             {
       
   268             LOG("EUsbWatcherCanNotStartUsbServices" );
       
   269             // no break here
       
   270             }
       
   271             // no break in following cases
       
   272         case EUsbWatcherIdPinError:
       
   273         case EUsbWatcherVBusObserverError:
       
   274         case EUsbWatcherHostEventNotificationError:
       
   275         case EUsbWatcherOtgStateError:
       
   276         case EUsbWatcherMessageNotificationError:
       
   277         case EUsbWatcherCanNotStartSession:
       
   278         case EUsbWatcherCanNotEnableDriverLoading:
       
   279         case EUsbWatcherCanNotClearBusError:
       
   280         case EUsbWatcherCanNotRaiseVBus:
       
   281             {
       
   282             LOG1( "Fatal error iWhat = %d", iWhat );
       
   283             iWatcher.NotifManager()->ShowNotifierL(KUsbUiNotifOtgError,
       
   284                     EUsbOtgErrorInConnection, this);
       
   285             break;
       
   286             }
       
   287         default:
       
   288             {
       
   289             LOG1("Unexpected situation to be handled iWhat = %d", iWhat );
       
   290             PANIC( EUnexpectedSituationToHandle);
       
   291             break;
       
   292             }
       
   293         }
       
   294     }
       
   295 
       
   296 /////////////////////////////////////////////////////////////////////////////////////
       
   297 // From VBus observer
       
   298 // ---------------------------------------------------------------------------
       
   299 // 
       
   300 // ---------------------------------------------------------------------------
       
   301 //
       
   302 void CUsbStateHostHandleDropping::VBusUpL()
       
   303     {
       
   304     LOG_FUNC
       
   305     ChangeHostStateL( EUsbStateHostAInitiate);
       
   306     }
       
   307 
       
   308 // ---------------------------------------------------------------------------
       
   309 // this is expected in the state, for example after calling BusDrop
       
   310 // ---------------------------------------------------------------------------
       
   311 //
       
   312 void CUsbStateHostHandleDropping::VBusDownL()
       
   313     {
       
   314     LOG_FUNC
       
   315     }
       
   316 
       
   317 // From Host Event notification observer
       
   318 // ---------------------------------------------------------------------------
       
   319 // 
       
   320 // ---------------------------------------------------------------------------
       
   321 //
       
   322 void CUsbStateHostHandleDropping::AVBusErrorL()
       
   323     {
       
   324     LOG_FUNC
       
   325     iWatcher.Usb().BusClearError();
       
   326     }
       
   327 
       
   328 // ---------------------------------------------------------------------------
       
   329 // 
       
   330 // ---------------------------------------------------------------------------
       
   331 //
       
   332 void CUsbStateHostHandleDropping::DeviceAttachedL(
       
   333         TDeviceEventInformation aDevEventInfo)
       
   334     {
       
   335     LOG_FUNC
       
   336     }
       
   337 
       
   338 // ---------------------------------------------------------------------------
       
   339 // 
       
   340 // ---------------------------------------------------------------------------
       
   341 //
       
   342 void CUsbStateHostHandleDropping::DeviceDetachedL(TDeviceEventInformation)
       
   343     {
       
   344     LOG_FUNC
       
   345     }
       
   346 
       
   347 // ---------------------------------------------------------------------------
       
   348 // 
       
   349 // ---------------------------------------------------------------------------
       
   350 //
       
   351 void CUsbStateHostHandleDropping::DriverLoadSuccessL(TDeviceEventInformation)
       
   352     {
       
   353     LOG_FUNC
       
   354     }
       
   355 
       
   356 // ---------------------------------------------------------------------------
       
   357 // 
       
   358 // ---------------------------------------------------------------------------
       
   359 //
       
   360 void CUsbStateHostHandleDropping::DriverLoadPartialSuccessL(
       
   361         TDeviceEventInformation)
       
   362     {
       
   363     LOG_FUNC
       
   364     }
       
   365 
       
   366 // ---------------------------------------------------------------------------
       
   367 // 
       
   368 // ---------------------------------------------------------------------------
       
   369 //
       
   370 void CUsbStateHostHandleDropping::DriverLoadFailureL(TDeviceEventInformation)
       
   371     {
       
   372     LOG_FUNC
       
   373     }
       
   374 
       
   375 // From message notification observer
       
   376 // ---------------------------------------------------------------------------
       
   377 // 
       
   378 // ---------------------------------------------------------------------------
       
   379 //
       
   380 void CUsbStateHostHandleDropping::MessageNotificationReceivedL(TInt aMessage)
       
   381     {
       
   382     LOG_FUNC
       
   383 
       
   384     LOG1( "aMessage = %d", aMessage )
       
   385 
       
   386     switch (aMessage)
       
   387         {
       
   388         // USBDI
       
   389         case KEventUsbBadDeviceDetached:
       
   390             {
       
   391             LOG("BadDeviceDetached" );
       
   392             ChangeHostStateL( EUsbStateHostUndefined);
       
   393             break;
       
   394             }
       
   395         default:
       
   396             {
       
   397             LOG1( "Unhandled message aMessage = %d" , aMessage);
       
   398             break;
       
   399             }
       
   400 
       
   401         }
       
   402     }
       
   403 
       
   404 // ---------------------------------------------------------------------------
       
   405 // 
       
   406 // ---------------------------------------------------------------------------
       
   407 //
       
   408 void CUsbStateHostHandleDropping::VBusErrorL()
       
   409     {
       
   410     LOG_FUNC
       
   411     iWatcher.Usb().BusClearError();
       
   412     }