os/kernelhwsrv/kerneltest/f32test/shostmassstorage/msman/src/cusbotgwatcher.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/shostmassstorage/msman/src/cusbotgwatcher.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,196 @@
     1.4 +// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <e32cmn.h>
    1.20 +#include <e32base.h>
    1.21 +#include <e32property.h>
    1.22 +#include <d32otgdi.h>
    1.23 +#include <e32debug.h>
    1.24 +
    1.25 +#include "cusbotg.h"
    1.26 +#include "cusbotgwatcher.h"
    1.27 +
    1.28 +#include "tmslog.h"
    1.29 +#include "debug.h"
    1.30 +
    1.31 +
    1.32 +CUsbOtgBaseWatcher::CUsbOtgBaseWatcher(RUsbOtgDriver& aLdd)
    1.33 +:   CActive(CActive::EPriorityStandard),
    1.34 +    iLdd(aLdd)
    1.35 +	{
    1.36 +    __MSFNLOG
    1.37 +	CActiveScheduler::Add(this);
    1.38 +	}
    1.39 +
    1.40 +
    1.41 +CUsbOtgBaseWatcher::~CUsbOtgBaseWatcher()
    1.42 +	{
    1.43 +    __MSFNLOG
    1.44 +	Cancel();
    1.45 +	}
    1.46 +
    1.47 +void CUsbOtgBaseWatcher::Start()
    1.48 +	{
    1.49 +    __MSFNLOG
    1.50 +	Post();
    1.51 +	}
    1.52 +
    1.53 +
    1.54 +
    1.55 +CRequestSessionWatcher* CRequestSessionWatcher::NewL(MUsbRequestSessionObserver& aObserver)
    1.56 +    {
    1.57 +    __MSFNSLOG
    1.58 +    CRequestSessionWatcher* r = new (ELeave) CRequestSessionWatcher(aObserver);
    1.59 +    r->ConstructL();
    1.60 +    return r;
    1.61 +    }
    1.62 +
    1.63 +CRequestSessionWatcher::CRequestSessionWatcher(MUsbRequestSessionObserver& aObserver)
    1.64 +:   CActive(EPriorityStandard),
    1.65 +    iObserver(aObserver)
    1.66 +    {
    1.67 +    __MSFNLOG
    1.68 +    }
    1.69 +
    1.70 +void CRequestSessionWatcher::ConstructL()
    1.71 +    {
    1.72 +    __MSFNLOG
    1.73 +    User::LeaveIfError(iProperty.Define(KUidUsbManCategory, KUsbRequestSessionProperty, RProperty::EInt));
    1.74 +    User::LeaveIfError(iProperty.Attach(KUidUsbManCategory, KUsbRequestSessionProperty));
    1.75 +    CActiveScheduler::Add(this);
    1.76 +
    1.77 +    // initial subscription and process current property value
    1.78 +	RunL();
    1.79 +    }
    1.80 +
    1.81 +
    1.82 +void CRequestSessionWatcher::DoCancel()
    1.83 +	{
    1.84 +    __MSFNLOG
    1.85 +	iProperty.Cancel();
    1.86 +	}
    1.87 +
    1.88 +
    1.89 +CRequestSessionWatcher::~CRequestSessionWatcher()
    1.90 +    {
    1.91 +    __MSFNLOG
    1.92 +    Cancel();
    1.93 +    iProperty.Close();
    1.94 +    iProperty.Delete(KUidUsbManCategory, KUsbRequestSessionProperty);
    1.95 +    }
    1.96 +
    1.97 +
    1.98 +void CRequestSessionWatcher::RunL()
    1.99 +    {
   1.100 +    __MSFNLOG
   1.101 +	// resubscribe before processing new value to prevent missing updates
   1.102 +	iProperty.Subscribe(iStatus);
   1.103 +	SetActive();
   1.104 +    TInt val;
   1.105 +    User::LeaveIfError(iProperty.Get(KUidUsbManCategory, KUsbRequestSessionProperty, val));
   1.106 +    __USBOTGPRINT1(_L(">> CUsbRequestSessionWatcher[%d]"), val);
   1.107 +
   1.108 +    switch(val)
   1.109 +        {
   1.110 +        case KUsbManSessionOpen:
   1.111 +            {
   1.112 +            iObserver.BusRequestL();
   1.113 +            }
   1.114 +            break;
   1.115 +        default:
   1.116 +            __USBOTGPRINT(_L("Event ignored"));
   1.117 +            break;
   1.118 +        }
   1.119 +    }
   1.120 +
   1.121 +TInt CRequestSessionWatcher::RunError(TInt aError)
   1.122 +    {
   1.123 +    __MSFNLOG
   1.124 +    __USBOTGPRINT1(_L("CUsbRequestSessionWatcher::RunError[%d]"), aError);
   1.125 +    return KErrNone;
   1.126 +    }
   1.127 +
   1.128 +
   1.129 +
   1.130 +
   1.131 +
   1.132 +
   1.133 +
   1.134 +
   1.135 +
   1.136 +CUsbOtgEventWatcher* CUsbOtgEventWatcher::NewL(RUsbOtgDriver& aLdd,
   1.137 +                                               CUsbOtg& aUsbOtg)
   1.138 +    {
   1.139 +    __MSFNSLOG
   1.140 +    CUsbOtgEventWatcher* r = new (ELeave) CUsbOtgEventWatcher(aLdd, aUsbOtg);
   1.141 +    r->ConstructL();
   1.142 +    return r;
   1.143 +    }
   1.144 +
   1.145 +CUsbOtgEventWatcher::CUsbOtgEventWatcher(RUsbOtgDriver& aLdd,
   1.146 +                                         CUsbOtg& aUsbOtg)
   1.147 +:   CUsbOtgBaseWatcher(aLdd),
   1.148 +    iUsbOtg(aUsbOtg)
   1.149 +    {
   1.150 +    __MSFNLOG
   1.151 +    }
   1.152 +
   1.153 +
   1.154 +void CUsbOtgEventWatcher::ConstructL()
   1.155 +    {
   1.156 +    __MSFNLOG
   1.157 +    }
   1.158 +
   1.159 +
   1.160 +void CUsbOtgEventWatcher::DoCancel()
   1.161 +	{
   1.162 +    __MSFNLOG
   1.163 +    iLdd.CancelOtgEventRequest();
   1.164 +	}
   1.165 +
   1.166 +
   1.167 +CUsbOtgEventWatcher::~CUsbOtgEventWatcher()
   1.168 +    {
   1.169 +    __MSFNLOG
   1.170 +    }
   1.171 +
   1.172 +
   1.173 +void CUsbOtgEventWatcher::Post()
   1.174 +    {
   1.175 +    __MSFNLOG
   1.176 +    iLdd.QueueOtgEventRequest(iEvent, iStatus);
   1.177 +    SetActive();
   1.178 +    }
   1.179 +
   1.180 +void CUsbOtgEventWatcher::RunL()
   1.181 +    {
   1.182 +    __MSFNLOG
   1.183 +
   1.184 +    TInt r = iStatus.Int();
   1.185 +    User::LeaveIfError(r);
   1.186 +
   1.187 +    __USBOTGPRINT1(_L(">> CUsbOtgEventWatcher[%x]"), iEvent);
   1.188 +    User::LeaveIfError(r);
   1.189 +
   1.190 +    iUsbOtg.HandleUsbOtgEvent(iEvent);
   1.191 +    Start();
   1.192 +    }
   1.193 +
   1.194 +TInt CUsbOtgEventWatcher::RunError(TInt aError)
   1.195 +    {
   1.196 +    __MSFNLOG
   1.197 +    __USBOTGPRINT1(_L("CUsbRequestSessionWatcher::RunError[%d]"), aError);
   1.198 +    return KErrNone;
   1.199 +    }