os/kernelhwsrv/kerneltest/e32test/usb/t_usb_device/src/activedevicestatenotifier.cpp
Update contrib.
1 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test/usb/t_usb_device/src/activestatenotifier.cpp
15 // USB Test Program T_USB_DEVICE, functional part.
16 // Device-side part, to work against T_USB_HOST running on the host.
21 #include "activerw.h" // CActiveRW
23 #include "activeControl.h"
24 #include "activedevicestatenotifier.h"
26 extern CActiveControl* gActiveControl;
28 extern TBool gVerbose;
30 extern TBool gStopOnFail;
31 extern TBool gAltSettingOnNotify;
32 extern TInt gSoakCount;
33 extern CActiveRW* gRW[KMaxConcurrentTests]; // the USB read/write active object
34 extern IFConfigPtr gInterfaceConfig [128] [KMaxInterfaceSettings];
37 // --- class CActiveDeviceStateNotifier ---------------------------------------------------------
40 CActiveDeviceStateNotifier::CActiveDeviceStateNotifier(CConsoleBase* aConsole, RDEVCLIENT* aPort, TUint aPortNumber)
41 : CActive(EPriorityNormal),
45 iPortNumber(aPortNumber)
47 CActiveScheduler::Add(this);
50 CActiveDeviceStateNotifier* CActiveDeviceStateNotifier::NewL(CConsoleBase* aConsole, RDEVCLIENT* aPort, TUint aPortNumber)
52 CActiveDeviceStateNotifier* self = new (ELeave) CActiveDeviceStateNotifier(aConsole, aPort, aPortNumber);
53 CleanupStack::PushL(self);
55 CleanupStack::Pop(); // self
60 void CActiveDeviceStateNotifier::ConstructL()
64 CActiveDeviceStateNotifier::~CActiveDeviceStateNotifier()
66 TUSB_VERBOSE_PRINT("CActiveDeviceStateNotifier::~CActiveDeviceStateNotifier()");
67 Cancel(); // base class
71 void CActiveDeviceStateNotifier::DoCancel()
73 TUSB_VERBOSE_PRINT("CActiveDeviceStateNotifier::DoCancel()");
74 iPort->AlternateDeviceStatusNotifyCancel();
78 void CActiveDeviceStateNotifier::RunL()
80 // This displays the device state.
81 // In a real world program, the user could take here appropriate action (cancel a
82 // transfer request or whatever).
83 if (!(iDeviceState & KUsbAlternateSetting) && gVerbose)
87 case EUsbcDeviceStateUndefined:
88 TUSB_PRINT("Device State notifier: Undefined");
90 case EUsbcDeviceStateAttached:
91 TUSB_PRINT("Device State notifier: Attached");
93 case EUsbcDeviceStatePowered:
94 TUSB_PRINT("Device State notifier: Powered");
96 case EUsbcDeviceStateDefault:
97 TUSB_PRINT("Device State notifier: Default");
99 case EUsbcDeviceStateAddress:
100 TUSB_PRINT("Device State notifier: Address");
102 case EUsbcDeviceStateConfigured:
103 TUSB_PRINT("Device State notifier: Configured");
105 case EUsbcDeviceStateSuspended:
106 TUSB_PRINT("Device State notifier: Suspended");
109 TUSB_PRINT("Device State notifier: ***BAD***");
112 else if (iDeviceState & KUsbAlternateSetting)
114 TUint8 altSetting = iDeviceState & ~KUsbAlternateSetting;
115 TUSB_PRINT2("Device State notifier: Alternate interface %d setting has changed: now %d",
116 iPortNumber, altSetting);
118 // allocate endpoint DMA and double buffering for all endpoints on interface
119 for (TUint8 ifNumber = 0; ifNumber < 128; ifNumber++)
121 IFConfigPtr newIfPtr = gInterfaceConfig[ifNumber][altSetting];
124 if (newIfPtr->iPortNumber == iPortNumber)
126 // allocate endpoint DMA and double buffering for all endpoints on default interface
127 for (TUint8 i = 1; i <= newIfPtr->iInfoPtr->iTotalEndpointsUsed; i++)
129 newIfPtr->iEpDMA[i-1] ? gActiveControl->AllocateEndpointDMA(iPort,(TENDPOINTNUMBER)i) : gActiveControl->DeAllocateEndpointDMA(iPort,(TENDPOINTNUMBER)i);
131 newIfPtr->iEpDoubleBuff[i-1] ? gActiveControl->AllocateDoubleBuffering(iPort,(TENDPOINTNUMBER)i) : gActiveControl->DeAllocateDoubleBuffering(iPort,(TENDPOINTNUMBER)i);
139 if (gAltSettingOnNotify)
141 for (TUint16 i =0; i < KMaxConcurrentTests; i++)
145 TUSB_VERBOSE_PRINT1("Resuming alternate Setting - activeRW index %d",i);
146 gRW[i]->ResumeAltSetting(altSetting);
155 void CActiveDeviceStateNotifier::Activate()
157 __ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 661));
158 iPort->AlternateDeviceStatusNotify(iStatus, iDeviceState);