usbengines/usbotgwatcher/src/cusbstatehostainitiate.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 11 Jun 2010 14:38:00 +0300
changeset 38 218231f2b3b3
parent 35 9d8b04ca6939
child 63 ef2686f7597e
permissions -rw-r--r--
Revision: 201021 Kit: 2010123
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     1
/*
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     2
 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     3
 * All rights reserved.
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     8
 *
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
     9
 * Initial Contributors:
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    11
 *
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    12
 * Contributors:
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    13
 *
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    14
 * Description:  Implementation
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    15
 *
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    16
 */
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    17
#include <usbuinotif.h>
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    18
#include <usbhosterrors.h>
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    19
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    20
#include "cusbotgwatcher.h"
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    21
#include "cusbstatehostainitiate.h"
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    22
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    23
#ifndef STIF
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    24
#include "cusbtimer.h"
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    25
#include "cusbnotifmanager.h"
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    26
#else
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    27
#include "mockcusbnotifmanager.h"
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    28
#include "mockcusbtimer.h"
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    29
#endif
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    30
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    31
#include "definitions.h"
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    32
#include "errors.h"
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    33
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    34
#include "debug.h"
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    35
#include "panic.h"
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    36
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    37
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    38
// 
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    39
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    40
//
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    41
CUsbStateHostAInitiate::CUsbStateHostAInitiate(CUsbOtgWatcher& aWatcher) :
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    42
    CUsbStateHostABase(aWatcher), iDeviceAttached(EFalse)
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    43
    {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    44
    }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    45
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    46
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    47
// 
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    48
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    49
//
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    50
void CUsbStateHostAInitiate::ConstructL()
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    51
    {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    52
    LOG_FUNC
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    53
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    54
    CUsbStateHostABase::ConstructL();
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    55
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    56
    iAttachmentTimer = CUsbTimer::NewL(*this, EDeviceAttachmentTimer);
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    57
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    58
    }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    59
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    60
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    61
// 
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    62
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    63
//
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    64
CUsbStateHostAInitiate* CUsbStateHostAInitiate::NewL(CUsbOtgWatcher& aWatcher)
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    65
    {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    66
    LOG_FUNC
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    67
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    68
    CUsbStateHostAInitiate* self = new (ELeave) CUsbStateHostAInitiate(
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    69
            aWatcher);
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    70
    CleanupStack::PushL(self);
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    71
    self->ConstructL();
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    72
    CleanupStack::Pop(self);
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    73
    return self;
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    74
    }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    75
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    76
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    77
// 
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    78
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    79
//
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    80
CUsbStateHostAInitiate::~CUsbStateHostAInitiate()
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    81
    {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    82
    LOG_FUNC
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    83
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    84
    delete iAttachmentTimer;
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    85
    }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    86
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    87
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    88
// 
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    89
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    90
//
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    91
TUsbStateIds CUsbStateHostAInitiate::Id()
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    92
    {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    93
    return EUsbStateHostAInitiate;
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    94
    }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    95
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    96
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    97
// 
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    98
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
    99
//
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   100
void CUsbStateHostAInitiate::JustBeforeLeavingThisStateL()
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   101
    {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   102
    LOG_FUNC
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   103
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   104
    iAttachmentTimer->Cancel();
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   105
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   106
    // do general things 
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   107
    CUsbStateHostABase::JustBeforeLeavingThisStateL();
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   108
    }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   109
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   110
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   111
// 
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   112
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   113
//
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   114
void CUsbStateHostAInitiate::JustAdvancedToThisStateL()
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   115
    {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   116
    LOG_FUNC
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   117
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   118
    // do general things 
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   119
    CUsbStateHostABase::JustAdvancedToThisStateL();
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   120
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   121
    // clear this attribute, and wait for attachment
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   122
    // one attchment has to correspond to only one detachment
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   123
    iDeviceAttached = EFalse; // to catch not corresponding Detachment, if any 
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   124
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   125
    TInt err = iWatcher.Usb().EnableFunctionDriverLoading();
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   126
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   127
    if (KErrNone != err)
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   128
        {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   129
        LOG1( "EnableFunctionDriverLoading err = %d", err );
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   130
        iWatcher.HandleHostProblemL(EUsbWatcherCanNotEnableDriverLoading,
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   131
                EUsbStateHostHandleDropping);
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   132
        return;
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   133
        }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   134
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   135
    // do BusRequest, if down
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   136
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   137
    if (CUsbVBusObserver::EVBusUp != iWatcher.VBusObserver()->VBus())
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   138
        {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   139
        const TUint maxTrial = 3;
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   140
        TInt busReqErr(KErrGeneral);
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   141
        TUint count(0);
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   142
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   143
        while (count < maxTrial && KErrNone != busReqErr)
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   144
            {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   145
            busReqErr = iWatcher.Usb().BusRequest();
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   146
            LOG1( "BusRequest() busReqErr = %d" , busReqErr);
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   147
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   148
            if (KErrNone != busReqErr)
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   149
                {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   150
                err = iWatcher.Usb().BusClearError();
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   151
                if (KErrNone != err)
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   152
                    {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   153
                    iWatcher.HandleHostProblemL(
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   154
                            EUsbWatcherCanNotClearBusError,
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   155
                            EUsbStateHostHandleDropping);
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   156
                    return;
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   157
                    }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   158
                }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   159
            ++count;
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   160
            }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   161
        if (KErrNone != busReqErr)
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   162
            {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   163
            iWatcher.HandleHostProblemL(EUsbWatcherCanNotRaiseVBus,
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   164
                    EUsbStateHostHandleDropping);
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   165
            return;
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   166
            }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   167
        }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   168
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   169
    // start timer, waiting for device attachment
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   170
    iAttachmentTimer->After(KTimeToWaitForDeviceAttachment);
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   171
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   172
    }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   173
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   174
// From TimerObserver
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   175
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   176
// 
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   177
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   178
//
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   179
void CUsbStateHostAInitiate::TimerElapsedL(TUsbTimerId aTimerId)
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   180
    {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   181
    LOG_FUNC
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   182
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   183
    switch (aTimerId)
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   184
        {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   185
        case EDeviceAttachmentTimer:
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   186
            {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   187
            LOG("AttachmentTimer" );
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   188
            HandleL(EUsbWatcherErrDandlingCable, EUsbStateHostHandleDropping);
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   189
            break;
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   190
            }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   191
        default:
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   192
            {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   193
            LOG1( "Unknown timer id = %d", aTimerId );
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   194
            PANIC( EWrongTimerId);
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   195
            }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   196
        }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   197
    }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   198
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   199
// From VBus observer
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   200
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   201
// 
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   202
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   203
//
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   204
void CUsbStateHostAInitiate::VBusUpL()
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   205
    {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   206
    LOG_FUNC
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   207
    }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   208
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   209
// From Host Event notification observer
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   210
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   211
// 
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   212
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   213
//
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   214
void CUsbStateHostAInitiate::DeviceAttachedL(TDeviceEventInformation aTdi)
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   215
    {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   216
    LOG_FUNC
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   217
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   218
    iDeviceAttached = ETrue;
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   219
    iAttachmentTimer->Cancel();
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   220
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   221
    // check if an OTG device connected
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   222
    TOtgDescriptor otgDescriptor;
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   223
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   224
    // ignore all the errors, assume we connected to not otg
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   225
    TInt err = iWatcher.Usb().GetOtgDescriptor(aTdi.iDeviceId, otgDescriptor);
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   226
    LOG1("GetOtgDescriptor() err = %d", err );
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   227
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   228
    TBool hnpSupported(otgDescriptor.iAttributes & EUsbOtgHNPSupported);
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   229
    TBool srpSupported(otgDescriptor.iAttributes & EUsbOtgSRPSupported);
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   230
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   231
    // OTG device supports both hnp and srp
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   232
    if (hnpSupported && srpSupported)
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   233
        {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   234
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   235
        HandleL(EUsbWatcherConnectedToOTG, EUsbStateHostHandleDropping);
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   236
        return;
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   237
        }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   238
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   239
    switch (aTdi.iError)
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   240
        // error in attachement
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   241
        {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   242
        case KErrNone:
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   243
            {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   244
            break;
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   245
            }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   246
        case KErrUsbDeviceDetachedDuringDriverLoading:
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   247
            {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   248
            //do not show error, due to device is already detached
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   249
            // Device Detachment will not come after this (it was not attached yet)
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   250
            // therefore emulate detachment
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   251
            // content of aTdi is not important, due to detachment anyway
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   252
            DeviceDetachedL(aTdi);
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   253
            break;
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   254
            }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   255
        case KErrBadPower:
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   256
            {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   257
            LOG( "TooMuchPower" );
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   258
            HandleL(EUsbWatcherErrDeviceRequiresTooMuchPowerOnEnumeration,
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   259
                    EUsbStateHostDelayNotAttachedHandle);
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   260
            break;
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   261
            }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   262
        default:
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   263
            {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   264
            LOG1("AttachmentError aTdi.iError = %d" , aTdi.iError );
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   265
            HandleL(EUsbWatcherErrUnsupportedDevice,
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   266
                    EUsbStateHostHandleDropping);
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   267
            }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   268
        }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   269
    }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   270
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   271
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   272
// 
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   273
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   274
//
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   275
void CUsbStateHostAInitiate::DeviceDetachedL(TDeviceEventInformation aTdi)
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   276
    {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   277
    LOG_FUNC
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   278
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   279
    // iDeviceAttached is used here to avoid one more state creation (init->attached->detached)
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   280
    // due to purpose of this state only to wait for drivers load
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   281
    if (!iDeviceAttached)
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   282
        {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   283
        PANIC(EDeviceDetachedNotExpected)
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   284
        }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   285
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   286
    // go out, and go in to the same state
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   287
    ChangeHostStateL( EUsbStateHostAInitiate);
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   288
    }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   289
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   290
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   291
// 
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   292
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   293
//
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   294
void CUsbStateHostAInitiate::DriverLoadSuccessL(TDeviceEventInformation)
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   295
    {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   296
    LOG_FUNC
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   297
    ChangeHostStateL( EUsbStateHostAHost);
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   298
    }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   299
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   300
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   301
// 
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   302
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   303
//
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   304
void CUsbStateHostAInitiate::DriverLoadPartialSuccessL(
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   305
        TDeviceEventInformation aDei)
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   306
    {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   307
    LOG_FUNC
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   308
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   309
    switch (aDei.iError)
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   310
        {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   311
        case KErrUsbDeviceDetachedDuringDriverLoading:
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   312
            {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   313
            //do not show warning, due to device is already detached
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   314
            break;
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   315
            }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   316
        default:
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   317
            {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   318
            iWatcher.NotifManager()->ShowNotifierL(KUsbUiNotifOtgWarning,
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   319
                    EUsbOtgPartiallySupportedDevice, NULL);
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   320
            }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   321
        }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   322
    ChangeHostStateL( EUsbStateHostAHost);
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   323
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   324
    }
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   325
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   326
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   327
// 
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   328
// ---------------------------------------------------------------------------
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   329
//
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   330
void CUsbStateHostAInitiate::DriverLoadFailureL(TDeviceEventInformation aDei)
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   331
    {
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   332
    LOG_FUNC
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   333
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   334
    HandleL(EUsbWatcherErrDriversNotFound, EUsbStateHostDelayAttachedHandle);
9d8b04ca6939 Revert last code drop.
Pat Downey <patd@symbian.org>
parents:
diff changeset
   335
    }