usbengines/usbotgwatcher/src/cusbstatehostainitiate.cpp
changeset 0 1e05558e2206
child 1 705ec7b86991
equal deleted inserted replaced
-1:000000000000 0:1e05558e2206
       
     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 "cusbstatehostainitiate.h"
       
    20 #ifndef STIF
       
    21 #include "cusbnotifmanager.h"
       
    22 #include "cusbtimer.h"
       
    23 #else
       
    24 #include "mockcusbnotifmanager.h"
       
    25 #include "mockcusbtimer.h"
       
    26 #endif
       
    27 #include "definitions.h"
       
    28 
       
    29 #include "errors.h"
       
    30 #include "debug.h"
       
    31 #include "panic.h"
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // 
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 CUsbStateHostAInitiate::CUsbStateHostAInitiate(CUsbOtgWatcher* aWatcher) :
       
    38     CUsbStateHostAInitiateBase(aWatcher)
       
    39     {
       
    40     }
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 // 
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 void CUsbStateHostAInitiate::ConstructL()
       
    47     {
       
    48         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiate::ConstructL" ) );
       
    49 
       
    50     CUsbStateHostAInitiateBase::ConstructL();
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // 
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 CUsbStateHostAInitiate* CUsbStateHostAInitiate::NewL(CUsbOtgWatcher* aWatcher)
       
    58     {
       
    59         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiate::NewL" ) );
       
    60 
       
    61     CUsbStateHostAInitiate* self = new (ELeave) CUsbStateHostAInitiate(
       
    62             aWatcher);
       
    63     CleanupStack::PushL(self);
       
    64     self->ConstructL();
       
    65     CleanupStack::Pop(self);
       
    66     return self;
       
    67     }
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // 
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 CUsbStateHostAInitiate::~CUsbStateHostAInitiate()
       
    74     {
       
    75         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiate::~CUsbStateHostAInitiate" ) );
       
    76     }
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // 
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 TUsbStateIds CUsbStateHostAInitiate::Id()
       
    83     {
       
    84         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiate::Id" ) );
       
    85 
       
    86     return EUsbStateHostAInitiate;
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // 
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 void CUsbStateHostAInitiate::JustAdvancedToThisStateL()
       
    94     {
       
    95         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiate::JustAdvancedToThisStateL" ) );
       
    96 
       
    97     iWatcher->PrintStateToLog();
       
    98 
       
    99     TInt err = iWatcher->Usb().EnableFunctionDriverLoading();
       
   100 
       
   101     if (KErrNone != err)
       
   102         {
       
   103             FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiate::JustAdvancedToThisStateL EnableFunctionDriverLoading error" ) );
       
   104         iWatcher->HandleHostProblemL(EUsbWatcherErrorInConnection);
       
   105         return;
       
   106         }
       
   107 
       
   108         FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbStateHostAInitiate::JustAdvancedToThisStateL EnableFunctionDriverLoading(); = %d" ), err));
       
   109 
       
   110     // do BusRequest, if down
       
   111 
       
   112     if (CUsbVBusObserver::EVBusUp != iWatcher->VBusObserver()->VBus())
       
   113         {
       
   114         const TUint maxTrial = 3;
       
   115         TInt busReqErr(KErrGeneral);
       
   116         TUint count(0);
       
   117 
       
   118         while (count < maxTrial && KErrNone != busReqErr)
       
   119             {
       
   120             busReqErr = iWatcher->Usb().BusRequest();
       
   121                 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbStateHostAInitiate::JustAdvancedToThisStateL BusRequest() = %d" ), err));
       
   122 
       
   123             if (KErrNone != busReqErr)
       
   124                 {
       
   125                 err = iWatcher->Usb().BusClearError();
       
   126                 if (KErrNone != err)
       
   127                     {
       
   128                     iWatcher->HandleHostProblemL(EUsbWatcherErrorInConnection);
       
   129                     return;
       
   130                     }
       
   131                 }
       
   132             ++count;
       
   133             }
       
   134         if (KErrNone != busReqErr)
       
   135             {
       
   136             iWatcher->HandleHostProblemL(EUsbWatcherErrorInConnection);
       
   137             return;
       
   138             }
       
   139         }
       
   140 
       
   141     // start timer, waiting for device attachment
       
   142     iAttachmentTimer->After(KTimeToWaitForDeviceAttachment);
       
   143 
       
   144     iWatcher->NotifManager()->BlinkIndicatorL(ETrue);
       
   145     }
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // 
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 void CUsbStateHostAInitiate::JustBeforeLeavingThisStateL()
       
   152     {
       
   153         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostAInitiate::JustBeforeLeavingThisStateL" ) );
       
   154     
       
   155         iWatcher->NotifManager()->BlinkIndicatorL(EFalse);
       
   156         
       
   157         CUsbStateHostAInitiateBase::JustBeforeLeavingThisStateL();
       
   158     }