kerneltest/e32test/usbho/t_otgdi/src/t_otgdi_fdfactor.cpp
changeset 259 57b9594f5772
parent 0 a41df078684a
child 257 3e88ff8f41d5
equal deleted inserted replaced
247:d8d70de2bd36 259:57b9594f5772
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2008-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".
    17  @file 
    17  @file 
    18  @internalComponent
    18  @internalComponent
    19 */
    19 */
    20 
    20 
    21 #include "t_otgdi_fdfactor.h"
    21 #include "t_otgdi_fdfactor.h"
       
    22 #include "OstTraceDefinitions.h"
       
    23 #ifdef OST_TRACE_COMPILER_IN_USE
       
    24 #include "t_otgdi_fdfactorTraces.h"
       
    25 #endif
    22 #include <Usb.h>
    26 #include <Usb.h>
    23 
    27 
    24 #define LOG_FUNC
    28 #define LOG_FUNC
    25 
    29 
    26 CActorFDF* CActorFDF::NewL(MUsbBusObserver& aObserver)
    30 CActorFDF* CActorFDF::NewL(MUsbBusObserver& aObserver)
    46 	CActiveScheduler::Add(this);
    50 	CActiveScheduler::Add(this);
    47 	
    51 	
    48 	TInt err(iDriver.Open());
    52 	TInt err(iDriver.Open());
    49 	if (err != KErrNone)
    53 	if (err != KErrNone)
    50 		{
    54 		{
    51 		RDebug::Print(_L("<Error %d> Unable to open driver channel"),err);
    55 		OstTrace1(TRACE_NORMAL, CACTORFDF_CONSTRUCTL, "<Error %d> Unable to open driver channel",err);
    52 		User::Leave(err);
    56 		User::Leave(err);
    53 		}		
    57 		}		
    54 	
    58 	
    55 	err = iDriver.StartHost();
    59 	err = iDriver.StartHost();
    56 	if (err != KErrNone)
    60 	if (err != KErrNone)
    57 		{
    61 		{
    58 		// Test case did not run successfully
    62 		// Test case did not run successfully
    59 		RDebug::Print(_L("<Error %d> USB Host stack not starting"),err);		
    63 		OstTrace1(TRACE_NORMAL, CACTORFDF_CONSTRUCTL_DUP01, "<Error %d> USB Host stack not starting",err);		
    60 		}
    64 		}
    61 	}
    65 	}
    62 
    66 
    63 
    67 
    64 CActorFDF::~CActorFDF()
    68 CActorFDF::~CActorFDF()
    90 	}
    94 	}
    91 	
    95 	
    92 void CActorFDF::Monitor()
    96 void CActorFDF::Monitor()
    93 	{
    97 	{
    94 	LOG_FUNC
    98 	LOG_FUNC
    95 	RDebug::Print(_L("Monitoring Bus Events"));
    99 	OstTrace0(TRACE_NORMAL, CACTORFDF_MONITOR, "Monitoring Bus Events");
    96 	iDriver.WaitForBusEvent(iBusEvent,iStatus);
   100 	iDriver.WaitForBusEvent(iBusEvent,iStatus);
    97 	SetActive();
   101 	SetActive();
    98 	}
   102 	}
    99 	
   103 	
   100 	
   104 	
   108 	{
   112 	{
   109 	LOG_FUNC
   113 	LOG_FUNC
   110 
   114 
   111 	// Obtain completion code
   115 	// Obtain completion code
   112 	TInt completionCode(iStatus.Int());
   116 	TInt completionCode(iStatus.Int());
   113 	RDebug::Print(_L("Completion code  : %d"),completionCode);
   117 	OstTrace1(TRACE_NORMAL, CACTORFDF_RUNL, "Completion code  : %d",completionCode);
   114 	
   118 	
   115 	 if (completionCode == KErrNone)
   119 	 if (completionCode == KErrNone)
   116 		{
   120 		{
   117 		if (iBusEvent.iEventType == RUsbHubDriver::TBusEvent::EDeviceAttached)
   121 		if (iBusEvent.iEventType == RUsbHubDriver::TBusEvent::EDeviceAttached)
   118 			{
   122 			{
   119 			// Device Attached
   123 			// Device Attached
   120 			RDebug::Print(_L("Usb device attached: %d"),iBusEvent.iDeviceHandle);
   124 			OstTrace1(TRACE_NORMAL, CACTORFDF_RUNL_DUP01, "Usb device attached: %d",iBusEvent.iDeviceHandle);
   121 			
   125 			
   122 			// Create the test device object
   126 			// Create the test device object
   123 			iDevices.InsertL(iBusEvent.iDeviceHandle,CUsbTestDevice::NewL(iDriver,iBusEvent.iDeviceHandle,iObserver));
   127 			iDevices.InsertL(iBusEvent.iDeviceHandle,CUsbTestDevice::NewL(iDriver,iBusEvent.iDeviceHandle,iObserver));
   124 			
   128 			
   125 			// Notify observer
   129 			// Notify observer
   127 			
   131 			
   128 			// Suspend the newly attached device in preparation for role swap
   132 			// Suspend the newly attached device in preparation for role swap
   129 			CUsbTestDevice* newDevice = iDevices.FindL(iBusEvent.iDeviceHandle);
   133 			CUsbTestDevice* newDevice = iDevices.FindL(iBusEvent.iDeviceHandle);
   130 			if(newDevice)
   134 			if(newDevice)
   131 				{
   135 				{
   132 				RDebug::Print(_L("Suspending device %d"),iBusEvent.iDeviceHandle);
   136 				OstTrace1(TRACE_NORMAL, CACTORFDF_RUNL_DUP02, "Suspending device %d",iBusEvent.iDeviceHandle);
   133 				TInt err = newDevice->Suspend();
   137 				TInt err = newDevice->Suspend();
   134 				if(err)
   138 				if(err)
   135 					{
   139 					{
   136 					RDebug::Print(_L("Suspending device %d returned error %d"), iBusEvent.iDeviceHandle, err);
   140 					OstTraceExt2(TRACE_NORMAL, CACTORFDF_RUNL_DUP03, "Suspending device %d returned error %d", (TInt)iBusEvent.iDeviceHandle, err);
   137 					}
   141 					}
   138 				}
   142 				}
   139 			else
   143 			else
   140 				{
   144 				{
   141 				RDebug::Print(_L("Can't find newly attached device %d"),iBusEvent.iDeviceHandle);
   145 				OstTrace1(TRACE_NORMAL, CACTORFDF_RUNL_DUP04, "Can't find newly attached device %d",iBusEvent.iDeviceHandle);
   142 				}
   146 				}
   143 
   147 
   144 			}
   148 			}
   145 		else if (iBusEvent.iEventType == RUsbHubDriver::TBusEvent::EDeviceRemoved)
   149 		else if (iBusEvent.iEventType == RUsbHubDriver::TBusEvent::EDeviceRemoved)
   146 			{
   150 			{
   147 			// Device Removed
   151 			// Device Removed
   148 			RDebug::Print(_L("Usb device removed: %d"),iBusEvent.iDeviceHandle);
   152 			OstTrace1(TRACE_NORMAL, CACTORFDF_RUNL_DUP05, "Usb device removed: %d",iBusEvent.iDeviceHandle);
   149 			
   153 			
   150 			// Notify observer
   154 			// Notify observer
   151 			iObserver.DeviceRemovedL(iBusEvent.iDeviceHandle);
   155 			iObserver.DeviceRemovedL(iBusEvent.iDeviceHandle);
   152 			
   156 			
   153 			// Destroy the device for the handle and remove from the map
   157 			// Destroy the device for the handle and remove from the map
   154 			delete iDevices.FindL(iBusEvent.iDeviceHandle);
   158 			delete iDevices.FindL(iBusEvent.iDeviceHandle);
   155 			iDevices.Remove(iBusEvent.iDeviceHandle);
   159 			iDevices.Remove(iBusEvent.iDeviceHandle);
   156 			}
   160 			}
   157 		else
   161 		else
   158 			{
   162 			{
   159 			RDebug::Print(_L("<Warning> Bus event %d occured, still monitoring, reason = %d"),iBusEvent.iEventType, iBusEvent.iReason);
   163 			OstTraceExt2(TRACE_NORMAL, CACTORFDF_RUNL_DUP06, "<Warning> Bus event %d occured, still monitoring, reason = %d",iBusEvent.iEventType, iBusEvent.iReason);
   160 			}
   164 			}
   161 		}
   165 		}
   162 	else
   166 	else
   163 		{
   167 		{
   164 		RDebug::Print(_L("<Error %d> Bus event %d"),completionCode,iBusEvent.iEventType);
   168 		OstTraceExt2(TRACE_NORMAL, CACTORFDF_RUNL_DUP07, "<Error %d> Bus event %d",completionCode,iBusEvent.iEventType);
   165 		iObserver.BusErrorL(completionCode);
   169 		iObserver.BusErrorL(completionCode);
   166 		}
   170 		}
   167 	Monitor();	//	Requeue for notification of further bus events
   171 	Monitor();	//	Requeue for notification of further bus events
   168 	}
   172 	}
   169 	
   173 	
   170 
   174 
   171 TInt CActorFDF::RunError(TInt aError)
   175 TInt CActorFDF::RunError(TInt aError)
   172 	{
   176 	{
   173 	LOG_FUNC
   177 	LOG_FUNC
   174 	RDebug::Print(_L("<Error %d> CActorFDF::RunError"),aError);
   178 	OstTrace1(TRACE_NORMAL, CACTORFDF_RUNERROR, "<Error %d> CActorFDF::RunError",aError);
   175 	return KErrNone;
   179 	return KErrNone;
   176 	}
   180 	}
   177 	
   181 	
   178 	
   182 	
   179 	
   183 	
   220 	User::LeaveIfError(iDevice.Open(iDriver,iHandle));
   224 	User::LeaveIfError(iDevice.Open(iDriver,iHandle));
   221 
   225 
   222 	TInt err(iDevice.GetDeviceDescriptor(iDeviceDescriptor));
   226 	TInt err(iDevice.GetDeviceDescriptor(iDeviceDescriptor));
   223 	if (err != KErrNone)
   227 	if (err != KErrNone)
   224 		{
   228 		{
   225 		RDebug::Print(_L("<Error %d> Getting device (%d) descriptor"),err,iHandle);
   229 		OstTraceExt2(TRACE_NORMAL, CUSBTESTDEVICE_CONSTRUCTL, "<Error %d> Getting device (%d) descriptor",err,(TInt)iHandle);
   226 		User::Leave(err);
   230 		User::Leave(err);
   227 		}
   231 		}
   228 	
   232 	
   229 	err = iDevice.GetConfigurationDescriptor(iConfigDescriptor);
   233 	err = iDevice.GetConfigurationDescriptor(iConfigDescriptor);
   230 	if (err != KErrNone)
   234 	if (err != KErrNone)
   231 		{
   235 		{
   232 		RDebug::Print(_L("<Error %d> Getting device (%d) configuration descriptor"),err,iHandle);
   236 		OstTraceExt2(TRACE_NORMAL, CUSBTESTDEVICE_CONSTRUCTL_DUP01, "<Error %d> Getting device (%d) configuration descriptor",err,(TInt)iHandle);
   233 		User::Leave(err);
   237 		User::Leave(err);
   234 		}
   238 		}
   235 
   239 
   236 	iDeviceSpec = iDeviceDescriptor.USBBcd();
   240 	iDeviceSpec = iDeviceDescriptor.USBBcd();
   237 	iPid = iDeviceDescriptor.ProductId();
   241 	iPid = iDeviceDescriptor.ProductId();
   238 	iVid = iDeviceDescriptor.VendorId();
   242 	iVid = iDeviceDescriptor.VendorId();
   239 	
   243 	
   240 	RDebug::Print(_L("%dmA configuration maximum power consumption"),iConfigDescriptor.MaxPower()*2);
   244 	OstTrace1(TRACE_NORMAL, CUSBTESTDEVICE_CONSTRUCTL_DUP02, "%dmA configuration maximum power consumption",iConfigDescriptor.MaxPower()*2);
   241 	RDebug::Print(_L("%d number of interface(s)"),iConfigDescriptor.NumInterfaces());
   245 	OstTrace1(TRACE_NORMAL, CUSBTESTDEVICE_CONSTRUCTL_DUP03, "%d number of interface(s)",iConfigDescriptor.NumInterfaces());
   242 	RDebug::Print(_L("Vendor Id=0x%04x, Product Id=0x%04x"),iVid,iPid);
   246 	OstTraceExt2(TRACE_NORMAL, CUSBTESTDEVICE_CONSTRUCTL_DUP04, "Vendor Id=0x%04x, Product Id=0x%04x",iVid,iPid);
   243 	RDebug::Print(_L("TotalLength() = %d"),iConfigDescriptor.TotalLength());
   247 	OstTrace1(TRACE_NORMAL, CUSBTESTDEVICE_CONSTRUCTL_DUP05, "TotalLength() = %d",iConfigDescriptor.TotalLength());
   244 
   248 
   245 	// Get changes in device state
   249 	// Get changes in device state
   246 	iDevice.QueueDeviceStateChangeNotification(iCurrentState,iStatus); // iCurrentState now holds the current device state
   250 	iDevice.QueueDeviceStateChangeNotification(iCurrentState,iStatus); // iCurrentState now holds the current device state
   247 	SetActive();
   251 	SetActive();
   248 	}
   252 	}
   295 
   299 
   296 	TInt completionCode(iStatus.Int());
   300 	TInt completionCode(iStatus.Int());
   297 	
   301 	
   298 	if ( completionCode != KErrCancel )
   302 	if ( completionCode != KErrCancel )
   299 		{
   303 		{
   300 		RDebug::Print(_L("CUsbTestDevice::RunL completionCode(%d)"),completionCode);
   304 		OstTrace1(TRACE_NORMAL, CUSBTESTDEVICE_RUNL, "CUsbTestDevice::RunL completionCode(%d)",completionCode);
   301 		}
   305 		}
   302 	
   306 	
   303 	if(completionCode == KErrNone)
   307 	if(completionCode == KErrNone)
   304 		{
   308 		{
   305 		RUsbDevice::TDeviceState newState;
   309 		RUsbDevice::TDeviceState newState;
   313 
   317 
   314 TInt CUsbTestDevice::RunError(TInt aError)
   318 TInt CUsbTestDevice::RunError(TInt aError)
   315 	{
   319 	{
   316 	LOG_FUNC
   320 	LOG_FUNC
   317 
   321 
   318 	RDebug::Print(_L("<Error %d>"),aError);
   322 	OstTrace1(TRACE_NORMAL, CUSBTESTDEVICE_RUNERROR, "<Error %d>",aError);
   319 	return KErrNone;
   323 	return KErrNone;
   320 	}
   324 	}
   321 
   325 
   322 CFdfTOtgdiWatcher* CFdfTOtgdiWatcher::NewL()
   326 CFdfTOtgdiWatcher* CFdfTOtgdiWatcher::NewL()
   323 	{
   327 	{
   331 void CFdfTOtgdiWatcher::DoCancel()
   335 void CFdfTOtgdiWatcher::DoCancel()
   332 	{
   336 	{
   333 	TInt err=iTotgdiProcess.RendezvousCancel(iStatus);
   337 	TInt err=iTotgdiProcess.RendezvousCancel(iStatus);
   334 	if(err)
   338 	if(err)
   335 		{
   339 		{
   336 		RDebug::Print(_L("Cancelling Rendezvous completed with %d"),err);
   340 		OstTrace1(TRACE_NORMAL, CFDFTOTGDIWATCHER_DOCANCEL, "Cancelling Rendezvous completed with %d",err);
   337 		}
   341 		}
   338 	}
   342 	}
   339 	
   343 	
   340 void CFdfTOtgdiWatcher::RunL()
   344 void CFdfTOtgdiWatcher::RunL()
   341 	{
   345 	{
   342 	//	The t_otgdi process has signalled its rendezvous
   346 	//	The t_otgdi process has signalled its rendezvous
   343 	//	Time to stop the active scheduler, tidy up and go away
   347 	//	Time to stop the active scheduler, tidy up and go away
   344 	RDebug::Print(_L("Rendezvous signalled from t_otgdi"));
   348 	OstTrace0(TRACE_NORMAL, CFDFTOTGDIWATCHER_RUNL, "Rendezvous signalled from t_otgdi");
   345 	CActiveScheduler::Stop();
   349 	CActiveScheduler::Stop();
   346 	}
   350 	}
   347 	
   351 	
   348 void CFdfTOtgdiWatcher::ConstructL()
   352 void CFdfTOtgdiWatcher::ConstructL()
   349 	{
   353 	{
   357 	
   361 	
   358 	TInt err=iTotgdiProcess.Open(totgdiProcessName);
   362 	TInt err=iTotgdiProcess.Open(totgdiProcessName);
   359 	
   363 	
   360 	if(err)
   364 	if(err)
   361 		{
   365 		{
   362 		RDebug::Print(_L("Couldn't open process handle to t_otgdi.exe"));
   366 		OstTrace0(TRACE_NORMAL, CFDFTOTGDIWATCHER_CONSTRUCTL, "Couldn't open process handle to t_otgdi.exe");
   363 		}
   367 		}
   364 	User::LeaveIfError(err);
   368 	User::LeaveIfError(err);
   365 
   369 
   366 	iTotgdiProcess.Rendezvous(iStatus);
   370 	iTotgdiProcess.Rendezvous(iStatus);
   367 
   371 
   368 	SetActive();
   372 	SetActive();
   369 	}
   373 	}
   370 	
   374 	
   371 TInt CFdfTOtgdiWatcher::FindTOtgdiProcessName(TFullName& aProcessName)
   375 TInt CFdfTOtgdiWatcher::FindTOtgdiProcessName(TFullName& aProcessName)
   372 	{
   376 	{
   373 	RDebug::Print(_L("Into FindTOtgdiProcessName"));
   377 	OstTrace0(TRACE_NORMAL, CFDFTOTGDIWATCHER_FINDTOTGDIPROCESSNAME, "Into FindTOtgdiProcessName");
   374 	TInt successCode = KErrNotFound;
   378 	TInt successCode = KErrNotFound;
   375 	TFindProcess fp;
   379 	TFindProcess fp;
   376 	fp.Find(_L("t_otgdi.exe*"));	//	Process name match pattern
   380 	fp.Find(_L("t_otgdi.exe*"));	//	Process name match pattern
   377 	while(fp.Next(aProcessName)==KErrNone)
   381 	while(fp.Next(aProcessName)==KErrNone)
   378 		{
   382 		{
   379 		RDebug::Print(_L("FDFActor Found process %S"),&aProcessName);
   383 		OstTraceExt1(TRACE_NORMAL, CFDFTOTGDIWATCHER_FINDTOTGDIPROCESSNAME_DUP01, "FDFActor Found process %S",aProcessName);
   380 		successCode = KErrNone;
   384 		successCode = KErrNone;
   381 		}
   385 		}
   382 	return successCode;
   386 	return successCode;
   383 	}
   387 	}
   384 	
   388 	
   387 	{
   391 	{
   388 	}
   392 	}
   389 	
   393 	
   390 CFdfTOtgdiWatcher::~CFdfTOtgdiWatcher()
   394 CFdfTOtgdiWatcher::~CFdfTOtgdiWatcher()
   391 	{
   395 	{
   392 	RDebug::Print(_L("About to call CFdfTOtgdiWatcher::Cancel"));
   396 	OstTrace0(TRACE_NORMAL, CFDFTOTGDIWATCHER_DCFDFTOTGDIWATCHER, "About to call CFdfTOtgdiWatcher::Cancel");
   393 	Cancel();
   397 	Cancel();
   394 	RDebug::Print(_L("About to call iTotgdiProcess.Close"));
   398 	OstTrace0(TRACE_NORMAL, CFDFTOTGDIWATCHER_DCFDFTOTGDIWATCHER_DUP01, "About to call iTotgdiProcess.Close");
   395 	iTotgdiProcess.Close();
   399 	iTotgdiProcess.Close();
   396 	}
   400 	}
   397 
   401