os/kernelhwsrv/kerneltest/e32test/usb/t_usb_device/src/activedevicestatenotifier.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/usb/t_usb_device/src/activedevicestatenotifier.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,163 @@
     1.4 +// Copyright (c) 2000-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 +// e32test/usb/t_usb_device/src/activestatenotifier.cpp
    1.18 +// USB Test Program T_USB_DEVICE, functional part.
    1.19 +// Device-side part, to work against T_USB_HOST running on the host.
    1.20 +// 
    1.21 +//
    1.22 +
    1.23 +#include "general.h"
    1.24 +#include "activerw.h"									// CActiveRW
    1.25 +#include "config.h"
    1.26 +#include "activeControl.h"
    1.27 +#include "activedevicestatenotifier.h"
    1.28 +
    1.29 +extern CActiveControl* gActiveControl;
    1.30 +extern RTest test;
    1.31 +extern TBool gVerbose;
    1.32 +extern TBool gSkip;
    1.33 +extern TBool gStopOnFail;
    1.34 +extern TBool gAltSettingOnNotify;
    1.35 +extern TInt gSoakCount;
    1.36 +extern CActiveRW* gRW[KMaxConcurrentTests];				// the USB read/write active object
    1.37 +extern IFConfigPtr gInterfaceConfig [128] [KMaxInterfaceSettings];
    1.38 +
    1.39 +//
    1.40 +// --- class CActiveDeviceStateNotifier ---------------------------------------------------------
    1.41 +//
    1.42 +
    1.43 +CActiveDeviceStateNotifier::CActiveDeviceStateNotifier(CConsoleBase* aConsole, RDEVCLIENT* aPort, TUint aPortNumber)
    1.44 +	: CActive(EPriorityNormal),
    1.45 +	  iConsole(aConsole),
    1.46 +	  iPort(aPort),
    1.47 +	  iDeviceState(0),
    1.48 +	  iPortNumber(aPortNumber)
    1.49 +	{
    1.50 +	CActiveScheduler::Add(this);
    1.51 +	}
    1.52 +
    1.53 +CActiveDeviceStateNotifier* CActiveDeviceStateNotifier::NewL(CConsoleBase* aConsole, RDEVCLIENT* aPort, TUint aPortNumber)
    1.54 +	{
    1.55 +	CActiveDeviceStateNotifier* self = new (ELeave) CActiveDeviceStateNotifier(aConsole, aPort, aPortNumber);
    1.56 +	CleanupStack::PushL(self);
    1.57 +	self->ConstructL();
    1.58 +	CleanupStack::Pop();									// self
    1.59 +	return self;
    1.60 +	}
    1.61 +
    1.62 +
    1.63 +void CActiveDeviceStateNotifier::ConstructL()
    1.64 +	{}
    1.65 +
    1.66 +
    1.67 +CActiveDeviceStateNotifier::~CActiveDeviceStateNotifier()
    1.68 +	{
    1.69 +	TUSB_VERBOSE_PRINT("CActiveDeviceStateNotifier::~CActiveDeviceStateNotifier()");
    1.70 +	Cancel();												// base class
    1.71 +	}
    1.72 +
    1.73 +
    1.74 +void CActiveDeviceStateNotifier::DoCancel()
    1.75 +	{
    1.76 +	TUSB_VERBOSE_PRINT("CActiveDeviceStateNotifier::DoCancel()");
    1.77 +	iPort->AlternateDeviceStatusNotifyCancel();
    1.78 +	}
    1.79 +
    1.80 +
    1.81 +void CActiveDeviceStateNotifier::RunL()
    1.82 +	{
    1.83 +	// This displays the device state.
    1.84 +	// In a real world program, the user could take here appropriate action (cancel a
    1.85 +	// transfer request or whatever).
    1.86 +	if (!(iDeviceState & KUsbAlternateSetting) && gVerbose)
    1.87 +		{
    1.88 +		switch (iDeviceState)
    1.89 +			{
    1.90 +		case EUsbcDeviceStateUndefined:
    1.91 +			TUSB_PRINT("Device State notifier: Undefined");
    1.92 +			break;
    1.93 +		case EUsbcDeviceStateAttached:
    1.94 +			TUSB_PRINT("Device State notifier: Attached");
    1.95 +			break;
    1.96 +		case EUsbcDeviceStatePowered:
    1.97 +			TUSB_PRINT("Device State notifier: Powered");
    1.98 +			break;
    1.99 +		case EUsbcDeviceStateDefault:
   1.100 +			TUSB_PRINT("Device State notifier: Default");
   1.101 +			break;
   1.102 +		case EUsbcDeviceStateAddress:
   1.103 +			TUSB_PRINT("Device State notifier: Address");
   1.104 +			break;
   1.105 +		case EUsbcDeviceStateConfigured:
   1.106 +			TUSB_PRINT("Device State notifier: Configured");
   1.107 +			break;
   1.108 +		case EUsbcDeviceStateSuspended:
   1.109 +			TUSB_PRINT("Device State notifier: Suspended");
   1.110 +			break;
   1.111 +		default:
   1.112 +			TUSB_PRINT("Device State notifier: ***BAD***");
   1.113 +			}
   1.114 +		}
   1.115 +	else if (iDeviceState & KUsbAlternateSetting)
   1.116 +		{
   1.117 +		TUint8 altSetting = iDeviceState & ~KUsbAlternateSetting;
   1.118 +		TUSB_PRINT2("Device State notifier: Alternate interface %d setting has changed: now %d",
   1.119 +					iPortNumber, altSetting);
   1.120 +
   1.121 +		// 	allocate endpoint DMA and double buffering for all endpoints on interface
   1.122 +		for (TUint8 ifNumber = 0; ifNumber < 128; ifNumber++)
   1.123 +			{
   1.124 +			IFConfigPtr newIfPtr = gInterfaceConfig[ifNumber][altSetting];
   1.125 +			if (newIfPtr)
   1.126 +				{
   1.127 +				if (newIfPtr->iPortNumber == iPortNumber)
   1.128 +					{
   1.129 +					// 	allocate endpoint DMA and double buffering for all endpoints on default interface
   1.130 +					for (TUint8 i = 1; i <= newIfPtr->iInfoPtr->iTotalEndpointsUsed; i++)
   1.131 +						{
   1.132 +						newIfPtr->iEpDMA[i-1] ? gActiveControl->AllocateEndpointDMA(iPort,(TENDPOINTNUMBER)i) : gActiveControl->DeAllocateEndpointDMA(iPort,(TENDPOINTNUMBER)i);
   1.133 +						#ifndef USB_SC
   1.134 +						newIfPtr->iEpDoubleBuff[i-1] ? gActiveControl->AllocateDoubleBuffering(iPort,(TENDPOINTNUMBER)i) : gActiveControl->DeAllocateDoubleBuffering(iPort,(TENDPOINTNUMBER)i);
   1.135 +						#endif
   1.136 +						}
   1.137 +					break;				
   1.138 +					}
   1.139 +				}
   1.140 +			}
   1.141 +							
   1.142 +		if (gAltSettingOnNotify)
   1.143 +			{
   1.144 +			for (TUint16 i =0; i < KMaxConcurrentTests; i++)
   1.145 +				{
   1.146 +				if (gRW[i])
   1.147 +					{
   1.148 +					TUSB_VERBOSE_PRINT1("Resuming alternate Setting - activeRW index %d",i);
   1.149 +					gRW[i]->ResumeAltSetting(altSetting);						
   1.150 +					}
   1.151 +				}
   1.152 +			}
   1.153 +		}
   1.154 +	Activate();
   1.155 +	}
   1.156 +
   1.157 +
   1.158 +void CActiveDeviceStateNotifier::Activate()
   1.159 +	{
   1.160 +	__ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 661));
   1.161 +	iPort->AlternateDeviceStatusNotify(iStatus, iDeviceState);
   1.162 +	SetActive();
   1.163 +	}
   1.164 +
   1.165 +
   1.166 +// -eof-