os/kernelhwsrv/kerneltest/f32test/shostmassstorage/msman/src/cusbotgwatcher.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200 (2014-06-10)
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include <e32cmn.h>
sl@0
    17
#include <e32base.h>
sl@0
    18
#include <e32property.h>
sl@0
    19
#include <d32otgdi.h>
sl@0
    20
#include <e32debug.h>
sl@0
    21
sl@0
    22
#include "cusbotg.h"
sl@0
    23
#include "cusbotgwatcher.h"
sl@0
    24
sl@0
    25
#include "tmslog.h"
sl@0
    26
#include "debug.h"
sl@0
    27
sl@0
    28
sl@0
    29
CUsbOtgBaseWatcher::CUsbOtgBaseWatcher(RUsbOtgDriver& aLdd)
sl@0
    30
:   CActive(CActive::EPriorityStandard),
sl@0
    31
    iLdd(aLdd)
sl@0
    32
	{
sl@0
    33
    __MSFNLOG
sl@0
    34
	CActiveScheduler::Add(this);
sl@0
    35
	}
sl@0
    36
sl@0
    37
sl@0
    38
CUsbOtgBaseWatcher::~CUsbOtgBaseWatcher()
sl@0
    39
	{
sl@0
    40
    __MSFNLOG
sl@0
    41
	Cancel();
sl@0
    42
	}
sl@0
    43
sl@0
    44
void CUsbOtgBaseWatcher::Start()
sl@0
    45
	{
sl@0
    46
    __MSFNLOG
sl@0
    47
	Post();
sl@0
    48
	}
sl@0
    49
sl@0
    50
sl@0
    51
sl@0
    52
CRequestSessionWatcher* CRequestSessionWatcher::NewL(MUsbRequestSessionObserver& aObserver)
sl@0
    53
    {
sl@0
    54
    __MSFNSLOG
sl@0
    55
    CRequestSessionWatcher* r = new (ELeave) CRequestSessionWatcher(aObserver);
sl@0
    56
    r->ConstructL();
sl@0
    57
    return r;
sl@0
    58
    }
sl@0
    59
sl@0
    60
CRequestSessionWatcher::CRequestSessionWatcher(MUsbRequestSessionObserver& aObserver)
sl@0
    61
:   CActive(EPriorityStandard),
sl@0
    62
    iObserver(aObserver)
sl@0
    63
    {
sl@0
    64
    __MSFNLOG
sl@0
    65
    }
sl@0
    66
sl@0
    67
void CRequestSessionWatcher::ConstructL()
sl@0
    68
    {
sl@0
    69
    __MSFNLOG
sl@0
    70
    User::LeaveIfError(iProperty.Define(KUidUsbManCategory, KUsbRequestSessionProperty, RProperty::EInt));
sl@0
    71
    User::LeaveIfError(iProperty.Attach(KUidUsbManCategory, KUsbRequestSessionProperty));
sl@0
    72
    CActiveScheduler::Add(this);
sl@0
    73
sl@0
    74
    // initial subscription and process current property value
sl@0
    75
	RunL();
sl@0
    76
    }
sl@0
    77
sl@0
    78
sl@0
    79
void CRequestSessionWatcher::DoCancel()
sl@0
    80
	{
sl@0
    81
    __MSFNLOG
sl@0
    82
	iProperty.Cancel();
sl@0
    83
	}
sl@0
    84
sl@0
    85
sl@0
    86
CRequestSessionWatcher::~CRequestSessionWatcher()
sl@0
    87
    {
sl@0
    88
    __MSFNLOG
sl@0
    89
    Cancel();
sl@0
    90
    iProperty.Close();
sl@0
    91
    iProperty.Delete(KUidUsbManCategory, KUsbRequestSessionProperty);
sl@0
    92
    }
sl@0
    93
sl@0
    94
sl@0
    95
void CRequestSessionWatcher::RunL()
sl@0
    96
    {
sl@0
    97
    __MSFNLOG
sl@0
    98
	// resubscribe before processing new value to prevent missing updates
sl@0
    99
	iProperty.Subscribe(iStatus);
sl@0
   100
	SetActive();
sl@0
   101
    TInt val;
sl@0
   102
    User::LeaveIfError(iProperty.Get(KUidUsbManCategory, KUsbRequestSessionProperty, val));
sl@0
   103
    __USBOTGPRINT1(_L(">> CUsbRequestSessionWatcher[%d]"), val);
sl@0
   104
sl@0
   105
    switch(val)
sl@0
   106
        {
sl@0
   107
        case KUsbManSessionOpen:
sl@0
   108
            {
sl@0
   109
            iObserver.BusRequestL();
sl@0
   110
            }
sl@0
   111
            break;
sl@0
   112
        default:
sl@0
   113
            __USBOTGPRINT(_L("Event ignored"));
sl@0
   114
            break;
sl@0
   115
        }
sl@0
   116
    }
sl@0
   117
sl@0
   118
TInt CRequestSessionWatcher::RunError(TInt aError)
sl@0
   119
    {
sl@0
   120
    __MSFNLOG
sl@0
   121
    __USBOTGPRINT1(_L("CUsbRequestSessionWatcher::RunError[%d]"), aError);
sl@0
   122
    return KErrNone;
sl@0
   123
    }
sl@0
   124
sl@0
   125
sl@0
   126
sl@0
   127
sl@0
   128
sl@0
   129
sl@0
   130
sl@0
   131
sl@0
   132
sl@0
   133
CUsbOtgEventWatcher* CUsbOtgEventWatcher::NewL(RUsbOtgDriver& aLdd,
sl@0
   134
                                               CUsbOtg& aUsbOtg)
sl@0
   135
    {
sl@0
   136
    __MSFNSLOG
sl@0
   137
    CUsbOtgEventWatcher* r = new (ELeave) CUsbOtgEventWatcher(aLdd, aUsbOtg);
sl@0
   138
    r->ConstructL();
sl@0
   139
    return r;
sl@0
   140
    }
sl@0
   141
sl@0
   142
CUsbOtgEventWatcher::CUsbOtgEventWatcher(RUsbOtgDriver& aLdd,
sl@0
   143
                                         CUsbOtg& aUsbOtg)
sl@0
   144
:   CUsbOtgBaseWatcher(aLdd),
sl@0
   145
    iUsbOtg(aUsbOtg)
sl@0
   146
    {
sl@0
   147
    __MSFNLOG
sl@0
   148
    }
sl@0
   149
sl@0
   150
sl@0
   151
void CUsbOtgEventWatcher::ConstructL()
sl@0
   152
    {
sl@0
   153
    __MSFNLOG
sl@0
   154
    }
sl@0
   155
sl@0
   156
sl@0
   157
void CUsbOtgEventWatcher::DoCancel()
sl@0
   158
	{
sl@0
   159
    __MSFNLOG
sl@0
   160
    iLdd.CancelOtgEventRequest();
sl@0
   161
	}
sl@0
   162
sl@0
   163
sl@0
   164
CUsbOtgEventWatcher::~CUsbOtgEventWatcher()
sl@0
   165
    {
sl@0
   166
    __MSFNLOG
sl@0
   167
    }
sl@0
   168
sl@0
   169
sl@0
   170
void CUsbOtgEventWatcher::Post()
sl@0
   171
    {
sl@0
   172
    __MSFNLOG
sl@0
   173
    iLdd.QueueOtgEventRequest(iEvent, iStatus);
sl@0
   174
    SetActive();
sl@0
   175
    }
sl@0
   176
sl@0
   177
void CUsbOtgEventWatcher::RunL()
sl@0
   178
    {
sl@0
   179
    __MSFNLOG
sl@0
   180
sl@0
   181
    TInt r = iStatus.Int();
sl@0
   182
    User::LeaveIfError(r);
sl@0
   183
sl@0
   184
    __USBOTGPRINT1(_L(">> CUsbOtgEventWatcher[%x]"), iEvent);
sl@0
   185
    User::LeaveIfError(r);
sl@0
   186
sl@0
   187
    iUsbOtg.HandleUsbOtgEvent(iEvent);
sl@0
   188
    Start();
sl@0
   189
    }
sl@0
   190
sl@0
   191
TInt CUsbOtgEventWatcher::RunError(TInt aError)
sl@0
   192
    {
sl@0
   193
    __MSFNLOG
sl@0
   194
    __USBOTGPRINT1(_L("CUsbRequestSessionWatcher::RunError[%d]"), aError);
sl@0
   195
    return KErrNone;
sl@0
   196
    }