kerneltest/e32test/usbho/t_usbdi/src/FDFActor.cpp
changeset 253 d37db4dcc88d
parent 0 a41df078684a
child 257 3e88ff8f41d5
equal deleted inserted replaced
252:0a40b8675b23 253:d37db4dcc88d
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    19 #include "FDFActor.h"
    19 #include "FDFActor.h"
    20 #include "testdebug.h"
    20 #include "testdebug.h"
    21 #include <Usb.h>
    21 #include <Usb.h>
    22 #include "UsbDescriptorOffsets.h"
    22 #include "UsbDescriptorOffsets.h"
    23 #include "BaseTestCase.h"
    23 #include "BaseTestCase.h"
       
    24 #include "OstTraceDefinitions.h"
       
    25 #ifdef OST_TRACE_COMPILER_IN_USE
       
    26 #include "FDFActorTraces.h"
       
    27 #endif
    24 #include <e32property.h>
    28 #include <e32property.h>
    25 
    29 
    26 extern RTest gtest;
    30 extern RTest gtest;
    27 
    31 
    28 namespace NUnitTesting_USBDI
    32 namespace NUnitTesting_USBDI
    32 
    36 
    33 static const TInt KNonExistantStringNumber = 97; //the device does not have a string descriptor associated with the number 97
    37 static const TInt KNonExistantStringNumber = 97; //the device does not have a string descriptor associated with the number 97
    34 
    38 
    35 CActorFDF* CActorFDF::NewL(MUsbBusObserver& aObserver)
    39 CActorFDF* CActorFDF::NewL(MUsbBusObserver& aObserver)
    36 	{
    40 	{
       
    41 	OstTraceFunctionEntry1( CACTORFDF_NEWL_ENTRY, ( TUint )&( aObserver ) );
    37 	CActorFDF* self = new (ELeave) CActorFDF(aObserver);
    42 	CActorFDF* self = new (ELeave) CActorFDF(aObserver);
    38 	CleanupStack::PushL(self);
    43 	CleanupStack::PushL(self);
    39 	self->ConstructL();
    44 	self->ConstructL();
    40 	CleanupStack::Pop(self);
    45 	CleanupStack::Pop(self);
       
    46 	OstTraceFunctionExit1( CACTORFDF_NEWL_EXIT, ( TUint )( self ) );
    41 	return self;
    47 	return self;
    42 	}
    48 	}
    43 
    49 
    44 
    50 
    45 CActorFDF::CActorFDF(MUsbBusObserver& aObserver)
    51 CActorFDF::CActorFDF(MUsbBusObserver& aObserver)
    46 :	CActive(EPriorityStandard),
    52 :	CActive(EPriorityStandard),
    47 	iObserver(aObserver)
    53 	iObserver(aObserver)
    48 	{
    54 	{
       
    55 	OstTraceFunctionEntryExt( CACTORFDF_CACTORFDF_ENTRY, this );
       
    56 	OstTraceFunctionExit1( CACTORFDF_CACTORFDF_EXIT, this );
    49 	}
    57 	}
    50 
    58 
    51 
    59 
    52 void CActorFDF::ConstructL()
    60 void CActorFDF::ConstructL()
    53 	{
    61 	{
    54 	LOG_FUNC
    62 	OstTraceFunctionEntry1( CACTORFDF_CONSTRUCTL_ENTRY, this );
    55 	CActiveScheduler::Add(this);
    63 	CActiveScheduler::Add(this);
    56 	
    64 	
    57 	TInt err(iDriver.Open());
    65 	TInt err(iDriver.Open());
    58 	if(err != KErrNone)
    66 	if(err != KErrNone)
    59 		{
    67 		{
    60 		RDebug::Printf("<Error %d> Unable to open driver channel",err);
    68 		OstTrace1(TRACE_NORMAL, CACTORFDF_CONSTRUCTL, "<Error %d> Unable to open driver channel",err);
    61 		User::Leave(err);
    69 		User::Leave(err);
    62 		}		
    70 		}		
    63 	
    71 	
    64 	RDebug::Printf("PBASE-T_USBDI-xxxx: Stack starting");
    72 	OstTrace0(TRACE_NORMAL, CACTORFDF_CONSTRUCTL_DUP01, "PBASE-T_USBDI-xxxx: Stack starting");
    65 	/*
    73 	/*
    66 	@SYMTestCaseID				PBASE-T_USBDI-xxxx
    74 	@SYMTestCaseID				PBASE-T_USBDI-xxxx
    67 	@SYMTestCaseDesc			Test for host stack initiation
    75 	@SYMTestCaseDesc			Test for host stack initiation
    68 	@SYMFssID 
    76 	@SYMFssID 
    69 	@SYMPREQ					1782
    77 	@SYMPREQ					1782
    76 	*/
    84 	*/
    77 	err = iDriver.StartHost();
    85 	err = iDriver.StartHost();
    78 	if(err != KErrNone)
    86 	if(err != KErrNone)
    79 		{
    87 		{
    80 		// Test case did not run successfully
    88 		// Test case did not run successfully
    81 		RDebug::Printf("<Error %d> USB Host stack not starting",err);		
    89 		OstTrace1(TRACE_NORMAL, CACTORFDF_CONSTRUCTL_DUP02, "<Error %d> USB Host stack not starting",err);		
    82 		gtest(EFalse);
    90 		gtest(EFalse);
    83 		}
    91 		}
    84 	  
    92 	  
    85 	RDebug::Printf("starting t_usbhost_usbman.exe");
    93 	OstTrace0(TRACE_NORMAL, CACTORFDF_CONSTRUCTL_DUP03, "starting t_usbhost_usbman.exe");
    86 	TInt r = iOtgUsbMan.Create(_L("t_usbhost_usbman.exe"), KNullDesC); //LIT does not seem to work here
    94 	TInt r = iOtgUsbMan.Create(_L("t_usbhost_usbman.exe"), KNullDesC); //LIT does not seem to work here
    87 	if(r != KErrNone && r != KErrAlreadyExists)
    95 	if(r != KErrNone && r != KErrAlreadyExists)
    88 		{
    96 		{
    89   		RDebug::Printf("can't start t_usbhost_usbman.exe");
    97   		OstTrace0(TRACE_NORMAL, CACTORFDF_CONSTRUCTL_DUP04, "can't start t_usbhost_usbman.exe");
    90 		gtest(EFalse);
    98 		gtest(EFalse);
    91 		}
    99 		}
    92 	
   100 	
    93     // create a publish/subscribe key to allow usbhost_usbman to be killed
   101     // create a publish/subscribe key to allow usbhost_usbman to be killed
    94     // cleanly
   102     // cleanly
    95     static _LIT_SECURITY_POLICY_PASS(KAllowAllPolicy);
   103     static _LIT_SECURITY_POLICY_PASS(KAllowAllPolicy);
    96     r = RProperty::Define(KWordOfDeathCat, KWordOfDeathKey, RProperty::EInt,KAllowAllPolicy, KAllowAllPolicy, 0);
   104     r = RProperty::Define(KWordOfDeathCat, KWordOfDeathKey, RProperty::EInt,KAllowAllPolicy, KAllowAllPolicy, 0);
    97 	if(r != KErrNone && r != KErrAlreadyExists)
   105 	if(r != KErrNone && r != KErrAlreadyExists)
    98         {
   106         {
    99         RDebug::Printf("Could not create the WordOfDeath P&S   (%d)", r);
   107         OstTrace1(TRACE_NORMAL, CACTORFDF_CONSTRUCTL_DUP05, "Could not create the WordOfDeath P&S   (%d)", r);
   100  		gtest(EFalse);
   108  		gtest(EFalse);
   101         }
   109         }
   102 
   110 
   103 	iOtgUsbMan.Resume();	
   111 	iOtgUsbMan.Resume();	
   104 	
   112 	
   105 	User::After(1500000); //allow time for t_usbhost_usbman.exe to start	
   113 	User::After(1500000); //allow time for t_usbhost_usbman.exe to start	
       
   114 	OstTraceFunctionExit1( CACTORFDF_CONSTRUCTL_EXIT, this );
   106 	}
   115 	}
   107 
   116 
   108 void KillTest()
   117 void KillTest()
   109 	{
   118 	{
   110 	RDebug::Printf("BEFORE gtest(EFalse)");
   119 	OstTraceFunctionEntry0( _KILLTEST_ENTRY );
       
   120 	OstTrace0(TRACE_NORMAL, KILLTEST_KILLTEST, "BEFORE gtest(EFalse)");
   111 	gtest(EFalse);
   121 	gtest(EFalse);
   112 	RDebug::Printf("AFTER gtest(EFalse)");
   122 	OstTrace0(TRACE_NORMAL, KILLTEST_KILLTEST_DUP01, "AFTER gtest(EFalse)");
       
   123 	OstTraceFunctionExit0( _KILLTEST_EXIT );
   113 	}
   124 	}
   114 
   125 
   115 CActorFDF::~CActorFDF()
   126 CActorFDF::~CActorFDF()
   116 	{
   127 	{
   117 	LOG_FUNC
   128 	OstTraceFunctionEntry1( CACTORFDF_CACTORFDF_ENTRY_DUP01, this );
   118 	Cancel();
   129 	Cancel();
   119 	
   130 	
   120 	// Destroy all test device objects that represented connected devices
   131 	// Destroy all test device objects that represented connected devices
   121 	
   132 	
   122 	RHashMap<TUint,CUsbTestDevice*>::TIter it(iDevices);
   133 	RHashMap<TUint,CUsbTestDevice*>::TIter it(iDevices);
   124 	for(count=0; count<iDevices.Count(); count++)
   135 	for(count=0; count<iDevices.Count(); count++)
   125 		{
   136 		{
   126 		delete *it.NextValue();
   137 		delete *it.NextValue();
   127 		}
   138 		}
   128 
   139 
   129 	RDebug::Printf("killing t_usbhost_usbman.exe");
   140 	OstTrace0(TRACE_NORMAL, CACTORFDF_DCACTORFDF, "killing t_usbhost_usbman.exe");
   130 	TInt r = RProperty::Set(KWordOfDeathCat, KWordOfDeathKey, KErrAbort);   // Send the word of death
   141 	TInt r = RProperty::Set(KWordOfDeathCat, KWordOfDeathKey, KErrAbort);   // Send the word of death
   131     if(r != KErrNone)
   142     if(r != KErrNone)
   132         {
   143         {
   133         RDebug::Printf("failed to kill t_usbhost-usbhan  (%d)", r);      
   144         OstTrace1(TRACE_NORMAL, CACTORFDF_DCACTORFDF_DUP01, "failed to kill t_usbhost-usbhan  (%d)", r);      
   134 		RProperty::Delete(KWordOfDeathCat, KWordOfDeathKey); //try to clean this up ready for next test
   145 		RProperty::Delete(KWordOfDeathCat, KWordOfDeathKey); //try to clean this up ready for next test
   135 		User::After(1000000); //allow time for property to clean up
   146 		User::After(1000000); //allow time for property to clean up
   136 		gtest(EFalse);
   147 		gtest(EFalse);
   137        }
   148        }
   138 	User::After(1000000); //allow time for t_usbhost_usbman.exe to clean up
   149 	User::After(1000000); //allow time for t_usbhost_usbman.exe to clean up
   139 
   150 
   140 	// Stop the USB Hub driver
   151 	// Stop the USB Hub driver
   141 		
   152 		
   142 	RDebug::Printf("UT-USBD-P1782-TN0001: Hub driver stopping...");
   153 	OstTrace0(TRACE_NORMAL, CACTORFDF_DCACTORFDF_DUP02, "UT-USBD-P1782-TN0001: Hub driver stopping...");
   143 
   154 
   144 	// Close the channel to the USB Hub driver	
   155 	// Close the channel to the USB Hub driver	
   145 	iDriver.Close();	
   156 	iDriver.Close();	
   146 	
   157 	
   147 	User::After(500000);
   158 	User::After(500000);
   155 		r = RProperty::Delete(KWordOfDeathCat, KWordOfDeathKey);
   166 		r = RProperty::Delete(KWordOfDeathCat, KWordOfDeathKey);
   156 		if(r != KErrNone)
   167 		if(r != KErrNone)
   157 			//give up
   168 			//give up
   158 			{
   169 			{
   159 			User::After(1000000); //allow time for property to clean up JUST IN CASE it can despite returning an error!
   170 			User::After(1000000); //allow time for property to clean up JUST IN CASE it can despite returning an error!
   160 	        RDebug::Printf("failed to delete wordofdeath P&S  (%d)", r);
   171 	        OstTrace1(TRACE_NORMAL, CACTORFDF_DCACTORFDF_DUP03, "failed to delete wordofdeath P&S  (%d)", r);
   161 			gtest(EFalse);
   172 			gtest(EFalse);
   162 			}
   173 			}
   163         }
   174         }
   164 
   175 
       
   176 	OstTraceFunctionExit1( CACTORFDF_CACTORFDF_EXIT_DUP01, this );
   165 	}
   177 	}
   166 	
   178 	
   167 void CActorFDF::DoCancel()
   179 void CActorFDF::DoCancel()
   168 	{
   180 	{
   169 	LOG_FUNC
   181 OstTraceFunctionEntry1( CACTORFDF_DOCANCEL_ENTRY, this );
   170 
   182 
   171 
   183 
   172 	RDebug::Printf("Cancelling bus event notifications");
   184 	OstTrace0(TRACE_NORMAL, CACTORFDF_DOCANCEL, "Cancelling bus event notifications");
   173 	iDriver.CancelWaitForBusEvent();
   185 	iDriver.CancelWaitForBusEvent();
   174 	gtest((iStatus == KErrCancel) || (iStatus == KErrNone));	
   186 	gtest((iStatus == KErrCancel) || (iStatus == KErrNone));	
   175 	RDebug::Printf("Bus event notifications successfully cancelled");	
   187 	OstTrace0(TRACE_NORMAL, CACTORFDF_DOCANCEL_DUP01, "Bus event notifications successfully cancelled");
       
   188 	OstTraceFunctionExit1( CACTORFDF_DOCANCEL_EXIT, this );
   176 	}
   189 	}
   177 	
   190 	
   178 void CActorFDF::Monitor()
   191 void CActorFDF::Monitor()
   179 	{
   192 	{
   180 	LOG_FUNC
   193 OstTraceFunctionEntry1( CACTORFDF_MONITOR_ENTRY, this );
   181 
   194 
   182 	RDebug::Printf("Monitoring bus events");
   195 	OstTrace0(TRACE_NORMAL, CACTORFDF_MONITOR, "Monitoring bus events");
   183 	iDriver.WaitForBusEvent(iBusEvent,iStatus);
   196 	iDriver.WaitForBusEvent(iBusEvent,iStatus);
   184 	SetActive();
   197 	SetActive();
       
   198 	OstTraceFunctionExit1( CACTORFDF_MONITOR_EXIT, this );
   185 	}
   199 	}
   186 	
   200 	
   187 	
   201 	
   188 			
   202 			
   189 CUsbTestDevice& CActorFDF::DeviceL(TUint aDeviceHandle)
   203 CUsbTestDevice& CActorFDF::DeviceL(TUint aDeviceHandle)
   190 	{
   204 	{
       
   205 	OstTraceFunctionEntryExt( CACTORFDF_DEVICEL_ENTRY, this );
   191 	return *iDevices.FindL(aDeviceHandle);
   206 	return *iDevices.FindL(aDeviceHandle);
   192 	}
   207 	}
   193 	
   208 	
   194 void CActorFDF::RunL()
   209 void CActorFDF::RunL()
   195 	{
   210 	{
   196 	LOG_FUNC
   211 OstTraceFunctionEntry1( CACTORFDF_RUNL_ENTRY, this );
   197 
   212 
   198 	// Obtain completion code
   213 	// Obtain completion code
   199 	TInt completionCode(iStatus.Int());
   214 	TInt completionCode(iStatus.Int());
   200 	RDebug::Printf("Completion code  : %d",completionCode);
   215 	OstTrace1(TRACE_NORMAL, CACTORFDF_RUNL, "Completion code  : %d",completionCode);
   201 	
   216 	
   202 	 if(completionCode == KErrNone)
   217 	 if(completionCode == KErrNone)
   203 		{
   218 		{
   204 		if(iBusEvent.iEventType == RUsbHubDriver::TBusEvent::EDeviceAttached)
   219 		if(iBusEvent.iEventType == RUsbHubDriver::TBusEvent::EDeviceAttached)
   205 			{
   220 			{
   206 			// Device Attached
   221 			// Device Attached
   207 			RDebug::Printf("Usb device attached: %d",iBusEvent.iDeviceHandle);
   222 			OstTrace1(TRACE_NORMAL, CACTORFDF_RUNL_DUP01, "Usb device attached: %d",iBusEvent.iDeviceHandle);
   208 			
   223 			
   209 			// Create the test device object
   224 			// Create the test device object
   210 			iDevices.InsertL(iBusEvent.iDeviceHandle,CUsbTestDevice::NewL(iDriver,iBusEvent.iDeviceHandle,iObserver));
   225 			iDevices.InsertL(iBusEvent.iDeviceHandle,CUsbTestDevice::NewL(iDriver,iBusEvent.iDeviceHandle,iObserver));
   211 			
   226 			
   212 			// Notify observer
   227 			// Notify observer
   213 			iObserver.DeviceInsertedL(iBusEvent.iDeviceHandle);
   228 			iObserver.DeviceInsertedL(iBusEvent.iDeviceHandle);
   214 			}
   229 			}
   215 		else if(iBusEvent.iEventType == RUsbHubDriver::TBusEvent::EDeviceRemoved)
   230 		else if(iBusEvent.iEventType == RUsbHubDriver::TBusEvent::EDeviceRemoved)
   216 			{
   231 			{
   217 			// Device Removed
   232 			// Device Removed
   218 			RDebug::Printf("Usb device removed: %d",iBusEvent.iDeviceHandle);
   233 			OstTrace1(TRACE_NORMAL, CACTORFDF_RUNL_DUP02, "Usb device removed: %d",iBusEvent.iDeviceHandle);
   219 			
   234 			
   220 			// Notify observer
   235 			// Notify observer
   221 			iObserver.DeviceRemovedL(iBusEvent.iDeviceHandle);
   236 			iObserver.DeviceRemovedL(iBusEvent.iDeviceHandle);
   222 			
   237 			
   223 			// Destroy the device for the handle and remove from the map
   238 			// Destroy the device for the handle and remove from the map
   225 			iDevices.Remove(iBusEvent.iDeviceHandle);
   240 			iDevices.Remove(iBusEvent.iDeviceHandle);
   226 			}
   241 			}
   227 		else
   242 		else
   228 			{
   243 			{
   229 			// TODO: Upcall for USB Man etc
   244 			// TODO: Upcall for USB Man etc
   230 			RDebug::Printf("<Warning> Bus event %d occured, still monitoring, reason = %d",iBusEvent.iEventType, iBusEvent.iReason);
   245 			OstTraceExt2(TRACE_NORMAL, CACTORFDF_RUNL_DUP03, "<Warning> Bus event %d occured, still monitoring, reason = %d",iBusEvent.iEventType, iBusEvent.iReason);
   231 			iDriver.WaitForBusEvent(iBusEvent,iStatus);
   246 			iDriver.WaitForBusEvent(iBusEvent,iStatus);
   232 			SetActive();
   247 			SetActive();
   233 			}
   248 			}
   234 		}
   249 		}
   235 	else
   250 	else
   236 		{
   251 		{
   237 		RDebug::Printf("<Error %d> Bus event %d",completionCode,iBusEvent.iEventType);
   252 		OstTraceExt2(TRACE_NORMAL, CACTORFDF_RUNL_DUP04, "<Error %d> Bus event %d",completionCode,iBusEvent.iEventType);
   238 		iObserver.BusErrorL(completionCode);
   253 		iObserver.BusErrorL(completionCode);
   239 		}
   254 		}
       
   255 	OstTraceFunctionExit1( CACTORFDF_RUNL_EXIT, this );
   240 	}
   256 	}
   241 	
   257 	
   242 
   258 
   243 TInt CActorFDF::RunError(TInt aError)
   259 TInt CActorFDF::RunError(TInt aError)
   244 	{
   260 	{
   245 	LOG_FUNC
   261 OstTraceFunctionEntryExt( CACTORFDF_RUNERROR_ENTRY, this );
   246 
   262 
   247 	RDebug::Printf("<Error %d> CActorFDF::RunError",aError);
   263 	OstTrace1(TRACE_NORMAL, CACTORFDF_RUNERROR, "<Error %d> CActorFDF::RunError",aError);
       
   264 	OstTraceFunctionExitExt( CACTORFDF_RUNERROR_EXIT, this, KErrNone );
   248 	return KErrNone;
   265 	return KErrNone;
   249 	}
   266 	}
   250 	
   267 	
   251 	
   268 	
   252 	
   269 	
   258 	
   275 	
   259 	
   276 	
   260 	
   277 	
   261 CUsbTestDevice* CUsbTestDevice::NewL(RUsbHubDriver& aHubDriver,TUint aDeviceHandle,MUsbBusObserver& aObserver)
   278 CUsbTestDevice* CUsbTestDevice::NewL(RUsbHubDriver& aHubDriver,TUint aDeviceHandle,MUsbBusObserver& aObserver)
   262 	{
   279 	{
       
   280 	OstTraceFunctionEntryExt( CUSBTESTDEVICE_NEWL_ENTRY, 0 );
   263 	CUsbTestDevice* self = new (ELeave) CUsbTestDevice(aHubDriver,aDeviceHandle,aObserver);
   281 	CUsbTestDevice* self = new (ELeave) CUsbTestDevice(aHubDriver,aDeviceHandle,aObserver);
   264 	CleanupStack::PushL(self);
   282 	CleanupStack::PushL(self);
   265 	self->ConstructL();
   283 	self->ConstructL();
   266 	CleanupStack::Pop(self);
   284 	CleanupStack::Pop(self);
       
   285 	OstTraceFunctionExit1( CUSBTESTDEVICE_NEWL_EXIT, ( TUint )( self ) );
   267 	return self;
   286 	return self;
   268 	}
   287 	}
   269 	
   288 	
   270 CUsbTestDevice::CUsbTestDevice(RUsbHubDriver& aHubDriver,TUint aHandle,MUsbBusObserver& aObserver)
   289 CUsbTestDevice::CUsbTestDevice(RUsbHubDriver& aHubDriver,TUint aHandle,MUsbBusObserver& aObserver)
   271 :	CActive(EPriorityUserInput),
   290 :	CActive(EPriorityUserInput),
   272 	iDriver(aHubDriver),
   291 	iDriver(aHubDriver),
   273 	iHandle(aHandle),
   292 	iHandle(aHandle),
   274 	iObserver(aObserver)
   293 	iObserver(aObserver)
   275 	{
   294 	{
   276 	LOG_FUNC
   295 OstTraceFunctionEntryExt( CUSBTESTDEVICE_CUSBTESTDEVICE_ENTRY, this );
   277 
   296 
   278 	CActiveScheduler::Add(this);
   297 	CActiveScheduler::Add(this);
       
   298 	OstTraceFunctionExit1( CUSBTESTDEVICE_CUSBTESTDEVICE_EXIT, this );
   279 	}
   299 	}
   280 	
   300 	
   281 CUsbTestDevice::~CUsbTestDevice()
   301 CUsbTestDevice::~CUsbTestDevice()
   282 	{
   302 	{
   283 	LOG_FUNC
   303 	OstTraceFunctionEntry1( CUSBTESTDEVICE_CUSBTESTDEVICE_ENTRY_DUP01, this );
   284 	Cancel();
   304 	Cancel();
   285 	iDevice.Close();
   305 	iDevice.Close();
       
   306 	OstTraceFunctionExit1( CUSBTESTDEVICE_CUSBTESTDEVICE_EXIT_DUP01, this );
   286 	}
   307 	}
   287 	
   308 	
   288 void CUsbTestDevice::ConstructL()
   309 void CUsbTestDevice::ConstructL()
   289 	{
   310 	{
   290 	LOG_FUNC
   311 OstTraceFunctionEntry1( CUSBTESTDEVICE_CONSTRUCTL_ENTRY, this );
   291 
   312 
   292 	// Open the usb device object
   313 	// Open the usb device object
   293 	User::LeaveIfError(iDevice.Open(iDriver,iHandle));
   314 	User::LeaveIfError(iDevice.Open(iDriver,iHandle));
   294 
   315 
   295 	TInt err(iDevice.GetDeviceDescriptor(iDeviceDescriptor));
   316 	TInt err(iDevice.GetDeviceDescriptor(iDeviceDescriptor));
   296 	if(err != KErrNone)
   317 	if(err != KErrNone)
   297 		{
   318 		{
   298 		RDebug::Printf("<Error %d> Getting device (%d) descriptor",err,iHandle);
   319 		OstTraceExt2(TRACE_NORMAL, CUSBTESTDEVICE_CONSTRUCTL, "<Error %d> Getting device (%u) descriptor",err,iHandle);
   299 		User::Leave(err);
   320 		User::Leave(err);
   300 		}
   321 		}
   301 	
   322 	
   302 	err = iDevice.GetConfigurationDescriptor(iConfigDescriptor);
   323 	err = iDevice.GetConfigurationDescriptor(iConfigDescriptor);
   303 	if(err != KErrNone)
   324 	if(err != KErrNone)
   304 		{
   325 		{
   305 		RDebug::Printf("<Error %d> Getting device (%d) configuration descriptor",err,iHandle);
   326 		OstTraceExt2(TRACE_NORMAL, CUSBTESTDEVICE_CONSTRUCTL_DUP01, "<Error %d> Getting device (%u) configuration descriptor",err,iHandle);
   306 		User::Leave(err);
   327 		User::Leave(err);
   307 		}
   328 		}
   308 
   329 
   309 	iDeviceSpec = iDeviceDescriptor.USBBcd();
   330 	iDeviceSpec = iDeviceDescriptor.USBBcd();
   310 	iPid = iDeviceDescriptor.ProductId();
   331 	iPid = iDeviceDescriptor.ProductId();
   311 	iVid = iDeviceDescriptor.VendorId();
   332 	iVid = iDeviceDescriptor.VendorId();
   312 	
   333 	
   313 	RDebug::Printf("%dmA configuration maximum power consumption",iConfigDescriptor.MaxPower()*2);
   334 	OstTrace1(TRACE_NORMAL, CUSBTESTDEVICE_CONSTRUCTL_DUP02, "%dmA configuration maximum power consumption",iConfigDescriptor.MaxPower()*2);
   314 	RDebug::Printf("%d number of interface(s)",iConfigDescriptor.NumInterfaces());
   335 	OstTrace1(TRACE_NORMAL, CUSBTESTDEVICE_CONSTRUCTL_DUP03, "%d number of interface(s)",iConfigDescriptor.NumInterfaces());
   315 	RDebug::Printf("Product Id=0x%04x, Vendor Id=0x%04x",iPid,iVid);
   336 	OstTraceExt2(TRACE_NORMAL, CUSBTESTDEVICE_CONSTRUCTL_DUP04, "Product Id=0x%04x, Vendor Id=0x%04x",(TUint32)iPid,(TUint32)iVid);
   316 	RDebug::Printf("TotalLength() = %d",iConfigDescriptor.TotalLength());
   337 	OstTrace1(TRACE_NORMAL, CUSBTESTDEVICE_CONSTRUCTL_DUP05, "TotalLength() = %d",iConfigDescriptor.TotalLength());
   317 
   338 
   318 	// The manufacturer string
   339 	// The manufacturer string
   319 	err = iDevice.GetStringDescriptor(iManufacturerStringDesc,iManufacturerStringData,iDeviceDescriptor.ManufacturerIndex());
   340 	err = iDevice.GetStringDescriptor(iManufacturerStringDesc,iManufacturerStringData,iDeviceDescriptor.ManufacturerIndex());
   320 	if(err != KErrNone)
   341 	if(err != KErrNone)
   321 		{
   342 		{
   322 		RDebug::Printf("<Error %d> Getting device (%d) manufacturer string descriptor",err,iHandle);
   343 		OstTraceExt2(TRACE_NORMAL, CUSBTESTDEVICE_CONSTRUCTL_DUP06, "<Error %d> Getting device (%u) manufacturer string descriptor",err,iHandle);
   323 		User::Leave(err);
   344 		User::Leave(err);
   324 		}
   345 		}
   325 	iManufacturerStringDesc->StringData(iManufacturerString);
   346 	iManufacturerStringDesc->StringData(iManufacturerString);
   326 	
   347 	
   327 	// The product string
   348 	// The product string
   328 	err = iDevice.GetStringDescriptor(iProductStringDesc,iProductStringData,iDeviceDescriptor.ProductIndex());
   349 	err = iDevice.GetStringDescriptor(iProductStringDesc,iProductStringData,iDeviceDescriptor.ProductIndex());
   329 	if(err != KErrNone)
   350 	if(err != KErrNone)
   330 		{
   351 		{
   331 		RDebug::Printf("<Error %d> Getting device (%d) product string descriptor",err,iHandle);
   352 		OstTraceExt2(TRACE_NORMAL, CUSBTESTDEVICE_CONSTRUCTL_DUP07, "<Error %d> Getting device (%u) product string descriptor",err,iHandle);
   332 		User::Leave(err);
   353 		User::Leave(err);
   333 		}
   354 		}
   334 	iProductStringDesc->StringData(iProductString);
   355 	iProductStringDesc->StringData(iProductString);
   335 		
   356 		
   336 	// The serial number 
   357 	// The serial number 
   337 	err = iDevice.GetStringDescriptor(iSerialNumberDesc,iSerialNumberStringData,iDeviceDescriptor.SerialNumberIndex());
   358 	err = iDevice.GetStringDescriptor(iSerialNumberDesc,iSerialNumberStringData,iDeviceDescriptor.SerialNumberIndex());
   338 	if(err != KErrNone)
   359 	if(err != KErrNone)
   339 		{
   360 		{
   340 		RDebug::Printf("<Error %d> Getting device (%d) serial number string descriptor",err,iHandle);
   361 		OstTraceExt2(TRACE_NORMAL, CUSBTESTDEVICE_CONSTRUCTL_DUP08, "<Error %d> Getting device (%u) serial number string descriptor",err,iHandle);
   341 		User::Leave(err);
   362 		User::Leave(err);
   342 		}
   363 		}
   343 	iSerialNumberDesc->StringData(iSerialNumber);
   364 	iSerialNumberDesc->StringData(iSerialNumber);
   344 	
   365 	
   345 	// The configuration string
   366 	// The configuration string
   346 	err = iDevice.GetStringDescriptor(iConfigStringDesc,iConfigStringData,iConfigDescriptor.ConfigurationIndex());
   367 	err = iDevice.GetStringDescriptor(iConfigStringDesc,iConfigStringData,iConfigDescriptor.ConfigurationIndex());
   347 	if(err != KErrNone)
   368 	if(err != KErrNone)
   348 		{
   369 		{
   349 		RDebug::Printf("<Error %d> Getting device (%d) configuration string descriptor",err,iHandle);
   370 		OstTraceExt2(TRACE_NORMAL, CUSBTESTDEVICE_CONSTRUCTL_DUP09, "<Error %d> Getting device (%u) configuration string descriptor",err,iHandle);
   350 		User::Leave(err);
   371 		User::Leave(err);
   351 		}
   372 		}
   352 	iConfigStringDesc->StringData(iConfigString);
   373 	iConfigStringDesc->StringData(iConfigString);
   353 	
   374 	
   354 	// Trying to obtain a string descriptor that is not present, expecting a stall	
   375 	// Trying to obtain a string descriptor that is not present, expecting a stall	
   356 	TUsbStringDescriptor* unusedStringDescriptor =  NULL;
   377 	TUsbStringDescriptor* unusedStringDescriptor =  NULL;
   357 	err = iDevice.GetStringDescriptor(unusedStringDescriptor,nonExistentString,KNonExistantStringNumber);
   378 	err = iDevice.GetStringDescriptor(unusedStringDescriptor,nonExistentString,KNonExistantStringNumber);
   358 	if(err != KErrUsbStalled)
   379 	if(err != KErrUsbStalled)
   359 		{
   380 		{
   360 		delete unusedStringDescriptor; //in case 'err ==  KErrNone', in which case this will need freeing
   381 		delete unusedStringDescriptor; //in case 'err ==  KErrNone', in which case this will need freeing
   361 		RDebug::Printf("GetStringDescriptor with nonExistentString didn't return KErrUsbStalled",err,iHandle);
   382 		OstTraceExt2(TRACE_NORMAL, CUSBTESTDEVICE_CONSTRUCTL_DUP10, "GetStringDescriptor with %d Handle %u",err,iHandle);
   362 		User::Leave(err);
   383 		User::Leave(err);
   363 		}
   384 		}
   364 	RDebug::Printf("String not present error(%d)",err);
   385 	OstTrace1(TRACE_NORMAL, CUSBTESTDEVICE_CONSTRUCTL_DUP11, "String not present error(%d)",err);
   365 
   386 
   366 	// Get changes in device state
   387 	// Get changes in device state
   367 	iDevice.QueueDeviceStateChangeNotification(iCurrentState,iStatus); // iCurrentState now holds the current device state
   388 	iDevice.QueueDeviceStateChangeNotification(iCurrentState,iStatus); // iCurrentState now holds the current device state
   368 	SetActive();
   389 	SetActive();
       
   390 	OstTraceFunctionExit1( CUSBTESTDEVICE_CONSTRUCTL_EXIT, this );
   369 	}
   391 	}
   370 	
   392 	
   371 RUsbDevice& CUsbTestDevice::Device()
   393 RUsbDevice& CUsbTestDevice::Device()
   372 	{
   394 	{
       
   395 	OstTraceFunctionEntry1( CUSBTESTDEVICE_DEVICE_ENTRY, this );
       
   396 	OstTraceFunctionExitExt( CUSBTESTDEVICE_DEVICE_EXIT, this, ( TUint )&( iDevice ) );
   373 	return iDevice;
   397 	return iDevice;
   374 	}
   398 	}
   375 	
   399 	
   376 TUint16 CUsbTestDevice::DeviceSpec() const
   400 TUint16 CUsbTestDevice::DeviceSpec() const
   377 	{
   401 	{
       
   402 	OstTraceFunctionEntry1( CUSBTESTDEVICE_DEVICESPEC_ENTRY, this );
       
   403 	OstTraceFunctionExitExt( CUSBTESTDEVICE_DEVICESPEC_EXIT, this, ( TUint16 )( iDeviceSpec ) );
   378 	return iDeviceSpec;
   404 	return iDeviceSpec;
   379 	}
   405 	}
   380 	
   406 	
   381 TUint16 CUsbTestDevice::ProductId() const
   407 TUint16 CUsbTestDevice::ProductId() const
   382 	{
   408 	{
       
   409 	OstTraceFunctionEntry1( CUSBTESTDEVICE_PRODUCTID_ENTRY, this );
       
   410 	OstTraceFunctionExitExt( CUSBTESTDEVICE_PRODUCTID_EXIT, this, ( TUint16 )( iPid ) );
   383 	return iPid;
   411 	return iPid;
   384 	}
   412 	}
   385 	
   413 	
   386 TUint16 CUsbTestDevice::VendorId() const
   414 TUint16 CUsbTestDevice::VendorId() const
   387 	{
   415 	{
       
   416 	OstTraceFunctionEntry1( CUSBTESTDEVICE_VENDORID_ENTRY, this );
       
   417 	OstTraceFunctionExitExt( CUSBTESTDEVICE_VENDORID_EXIT, this, ( TUint16 )( iVid ) );
   388 	return iVid;
   418 	return iVid;
   389 	}
   419 	}
   390 
   420 
   391 const TDesC16& CUsbTestDevice::SerialNumber() const
   421 const TDesC16& CUsbTestDevice::SerialNumber() const
   392 	{
   422 	{
       
   423 	OstTraceFunctionEntry1( CUSBTESTDEVICE_SERIALNUMBER_ENTRY, this );
       
   424 	OstTraceFunctionExitExt( CUSBTESTDEVICE_SERIALNUMBER_EXIT, this, ( TUint )&( iSerialNumber ) );
   393 	return iSerialNumber;
   425 	return iSerialNumber;
   394 	}
   426 	}
   395 
   427 
   396 const TDesC16& CUsbTestDevice::Manufacturer() const
   428 const TDesC16& CUsbTestDevice::Manufacturer() const
   397 	{
   429 	{
       
   430 	OstTraceFunctionEntry1( CUSBTESTDEVICE_MANUFACTURER_ENTRY, this );
       
   431 	OstTraceFunctionExitExt( CUSBTESTDEVICE_MANUFACTURER_EXIT, this, ( TUint )&( iManufacturerString ) );
   398 	return iManufacturerString;
   432 	return iManufacturerString;
   399 	}
   433 	}
   400 	
   434 	
   401 const TDesC16& CUsbTestDevice::Product() const
   435 const TDesC16& CUsbTestDevice::Product() const
   402 	{
   436 	{
       
   437 	OstTraceFunctionEntry1( CUSBTESTDEVICE_PRODUCT_ENTRY, this );
       
   438 	OstTraceFunctionExitExt( CUSBTESTDEVICE_PRODUCT_EXIT, this, ( TUint )&( iProductString ) );
   403 	return iProductString;
   439 	return iProductString;
   404 	}
   440 	}
   405 	
   441 	
   406 const TDesC16& CUsbTestDevice::ConfigurationString() const
   442 const TDesC16& CUsbTestDevice::ConfigurationString() const
   407 	{
   443 	{
       
   444 	OstTraceFunctionEntry1( CUSBTESTDEVICE_CONFIGURATIONSTRING_ENTRY, this );
       
   445 	OstTraceFunctionExitExt( CUSBTESTDEVICE_CONFIGURATIONSTRING_EXIT, this, ( TUint )&( iConfigString ) );
   408 	return iConfigString;
   446 	return iConfigString;
   409 	}
   447 	}
   410 
   448 
   411 const TUsbConfigurationDescriptor& CUsbTestDevice::ConfigurationDescriptor() const
   449 const TUsbConfigurationDescriptor& CUsbTestDevice::ConfigurationDescriptor() const
   412 	{
   450 	{
       
   451 	OstTraceFunctionEntry1( CUSBTESTDEVICE_CONFIGURATIONDESCRIPTOR_ENTRY, this );
       
   452 	OstTraceFunctionExitExt( CUSBTESTDEVICE_CONFIGURATIONDESCRIPTOR_EXIT, this, ( TUint )&( iConfigDescriptor ) );
   413 	return iConfigDescriptor;
   453 	return iConfigDescriptor;
   414 	}
   454 	}
   415 		
   455 		
   416 const TUsbDeviceDescriptor& CUsbTestDevice::DeviceDescriptor() const
   456 const TUsbDeviceDescriptor& CUsbTestDevice::DeviceDescriptor() const
   417 	{
   457 	{
       
   458 	OstTraceFunctionEntry1( CUSBTESTDEVICE_DEVICEDESCRIPTOR_ENTRY, this );
       
   459 	OstTraceFunctionExitExt( CUSBTESTDEVICE_DEVICEDESCRIPTOR_EXIT, this, ( TUint )&( iDeviceDescriptor ) );
   418 	return iDeviceDescriptor;
   460 	return iDeviceDescriptor;
   419 	}
   461 	}
   420 
   462 
   421 void CUsbTestDevice::DoCancel()
   463 void CUsbTestDevice::DoCancel()
   422 	{
   464 	{
   423 	LOG_FUNC
   465     OstTraceFunctionEntry1( CUSBTESTDEVICE_DOCANCEL_ENTRY, this );
   424 
   466 
   425 	iDevice.CancelDeviceStateChangeNotification();
   467 	iDevice.CancelDeviceStateChangeNotification();
       
   468 	OstTraceFunctionExit1( CUSBTESTDEVICE_DOCANCEL_EXIT, this );
   426 	}
   469 	}
   427 
   470 
   428 
   471 
   429 void CUsbTestDevice::RunL()
   472 void CUsbTestDevice::RunL()
   430 	{
   473 	{
   431 	LOG_FUNC
   474     OstTraceFunctionEntry1( CUSBTESTDEVICE_RUNL_ENTRY, this );
   432 
   475 
   433 	TInt completionCode(iStatus.Int());
   476 	TInt completionCode(iStatus.Int());
   434 	RDebug::Printf("CUsbTestDevice::RunL completionCode(%d)",completionCode);
   477 	OstTrace1(TRACE_NORMAL, CUSBTESTDEVICE_RUNL, "CUsbTestDevice::RunL completionCode(%d)",completionCode);
   435 
   478 
   436 	if(completionCode == KErrNone)
   479 	if(completionCode == KErrNone)
   437 		{
   480 		{
   438 		RUsbDevice::TDeviceState newState;
   481 		RUsbDevice::TDeviceState newState;
   439 		iDevice.QueueDeviceStateChangeNotification(newState,iStatus);
   482 		iDevice.QueueDeviceStateChangeNotification(newState,iStatus);
   440 		SetActive();
   483 		SetActive();
   441 		iObserver.DeviceStateChangeL(iCurrentState,newState,completionCode);
   484 		iObserver.DeviceStateChangeL(iCurrentState,newState,completionCode);
   442 		iCurrentState = newState;
   485 		iCurrentState = newState;
   443 		}
   486 		}
       
   487 	OstTraceFunctionExit1( CUSBTESTDEVICE_RUNL_EXIT, this );
   444 	}
   488 	}
   445 
   489 
   446 
   490 
   447 TInt CUsbTestDevice::RunError(TInt aError)
   491 TInt CUsbTestDevice::RunError(TInt aError)
   448 	{
   492 	{
   449 	LOG_FUNC
   493     OstTraceFunctionEntryExt( CUSBTESTDEVICE_RUNERROR_ENTRY, this );
   450 
   494 
   451 	RDebug::Printf("<Error %d>",aError);
   495 	OstTrace1(TRACE_NORMAL, CUSBTESTDEVICE_RUNERROR, "<Error %d>",aError);
       
   496 	OstTraceFunctionExitExt( CUSBTESTDEVICE_RUNERROR_EXIT, this, KErrNone );
   452 	return KErrNone;
   497 	return KErrNone;
   453 	}
   498 	}
   454 
   499 
   455 	}
   500 	}
   456 
   501