os/kernelhwsrv/kerneltest/e32test/usb/t_usb_device/src/activedevicestatenotifier.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    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.
    17 // 
    18 //
    19 
    20 #include "general.h"
    21 #include "activerw.h"									// CActiveRW
    22 #include "config.h"
    23 #include "activeControl.h"
    24 #include "activedevicestatenotifier.h"
    25 
    26 extern CActiveControl* gActiveControl;
    27 extern RTest test;
    28 extern TBool gVerbose;
    29 extern TBool gSkip;
    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];
    35 
    36 //
    37 // --- class CActiveDeviceStateNotifier ---------------------------------------------------------
    38 //
    39 
    40 CActiveDeviceStateNotifier::CActiveDeviceStateNotifier(CConsoleBase* aConsole, RDEVCLIENT* aPort, TUint aPortNumber)
    41 	: CActive(EPriorityNormal),
    42 	  iConsole(aConsole),
    43 	  iPort(aPort),
    44 	  iDeviceState(0),
    45 	  iPortNumber(aPortNumber)
    46 	{
    47 	CActiveScheduler::Add(this);
    48 	}
    49 
    50 CActiveDeviceStateNotifier* CActiveDeviceStateNotifier::NewL(CConsoleBase* aConsole, RDEVCLIENT* aPort, TUint aPortNumber)
    51 	{
    52 	CActiveDeviceStateNotifier* self = new (ELeave) CActiveDeviceStateNotifier(aConsole, aPort, aPortNumber);
    53 	CleanupStack::PushL(self);
    54 	self->ConstructL();
    55 	CleanupStack::Pop();									// self
    56 	return self;
    57 	}
    58 
    59 
    60 void CActiveDeviceStateNotifier::ConstructL()
    61 	{}
    62 
    63 
    64 CActiveDeviceStateNotifier::~CActiveDeviceStateNotifier()
    65 	{
    66 	TUSB_VERBOSE_PRINT("CActiveDeviceStateNotifier::~CActiveDeviceStateNotifier()");
    67 	Cancel();												// base class
    68 	}
    69 
    70 
    71 void CActiveDeviceStateNotifier::DoCancel()
    72 	{
    73 	TUSB_VERBOSE_PRINT("CActiveDeviceStateNotifier::DoCancel()");
    74 	iPort->AlternateDeviceStatusNotifyCancel();
    75 	}
    76 
    77 
    78 void CActiveDeviceStateNotifier::RunL()
    79 	{
    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)
    84 		{
    85 		switch (iDeviceState)
    86 			{
    87 		case EUsbcDeviceStateUndefined:
    88 			TUSB_PRINT("Device State notifier: Undefined");
    89 			break;
    90 		case EUsbcDeviceStateAttached:
    91 			TUSB_PRINT("Device State notifier: Attached");
    92 			break;
    93 		case EUsbcDeviceStatePowered:
    94 			TUSB_PRINT("Device State notifier: Powered");
    95 			break;
    96 		case EUsbcDeviceStateDefault:
    97 			TUSB_PRINT("Device State notifier: Default");
    98 			break;
    99 		case EUsbcDeviceStateAddress:
   100 			TUSB_PRINT("Device State notifier: Address");
   101 			break;
   102 		case EUsbcDeviceStateConfigured:
   103 			TUSB_PRINT("Device State notifier: Configured");
   104 			break;
   105 		case EUsbcDeviceStateSuspended:
   106 			TUSB_PRINT("Device State notifier: Suspended");
   107 			break;
   108 		default:
   109 			TUSB_PRINT("Device State notifier: ***BAD***");
   110 			}
   111 		}
   112 	else if (iDeviceState & KUsbAlternateSetting)
   113 		{
   114 		TUint8 altSetting = iDeviceState & ~KUsbAlternateSetting;
   115 		TUSB_PRINT2("Device State notifier: Alternate interface %d setting has changed: now %d",
   116 					iPortNumber, altSetting);
   117 
   118 		// 	allocate endpoint DMA and double buffering for all endpoints on interface
   119 		for (TUint8 ifNumber = 0; ifNumber < 128; ifNumber++)
   120 			{
   121 			IFConfigPtr newIfPtr = gInterfaceConfig[ifNumber][altSetting];
   122 			if (newIfPtr)
   123 				{
   124 				if (newIfPtr->iPortNumber == iPortNumber)
   125 					{
   126 					// 	allocate endpoint DMA and double buffering for all endpoints on default interface
   127 					for (TUint8 i = 1; i <= newIfPtr->iInfoPtr->iTotalEndpointsUsed; i++)
   128 						{
   129 						newIfPtr->iEpDMA[i-1] ? gActiveControl->AllocateEndpointDMA(iPort,(TENDPOINTNUMBER)i) : gActiveControl->DeAllocateEndpointDMA(iPort,(TENDPOINTNUMBER)i);
   130 						#ifndef USB_SC
   131 						newIfPtr->iEpDoubleBuff[i-1] ? gActiveControl->AllocateDoubleBuffering(iPort,(TENDPOINTNUMBER)i) : gActiveControl->DeAllocateDoubleBuffering(iPort,(TENDPOINTNUMBER)i);
   132 						#endif
   133 						}
   134 					break;				
   135 					}
   136 				}
   137 			}
   138 							
   139 		if (gAltSettingOnNotify)
   140 			{
   141 			for (TUint16 i =0; i < KMaxConcurrentTests; i++)
   142 				{
   143 				if (gRW[i])
   144 					{
   145 					TUSB_VERBOSE_PRINT1("Resuming alternate Setting - activeRW index %d",i);
   146 					gRW[i]->ResumeAltSetting(altSetting);						
   147 					}
   148 				}
   149 			}
   150 		}
   151 	Activate();
   152 	}
   153 
   154 
   155 void CActiveDeviceStateNotifier::Activate()
   156 	{
   157 	__ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 661));
   158 	iPort->AlternateDeviceStatusNotify(iStatus, iDeviceState);
   159 	SetActive();
   160 	}
   161 
   162 
   163 // -eof-