usbmgmt/usbmgr/usbman/server/SRC/CUsbDevice.cpp
branchRCL_3
changeset 43 012cc2ee6408
parent 42 f92a4f87e424
child 60 25c602fd1f26
equal deleted inserted replaced
42:f92a4f87e424 43:012cc2ee6408
     1 /*
     1 /*
     2 * Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    18 */
    18 */
    19 
    19 
    20 /**
    20 /**
    21  @file
    21  @file
    22 */
    22 */
       
    23 
       
    24 #include "CUsbDevice.h"
       
    25 #include "CUsbDeviceStateWatcher.h"
    23 #include <cusbclasscontrolleriterator.h>
    26 #include <cusbclasscontrolleriterator.h>
       
    27 #include "MUsbDeviceNotify.h"
       
    28 #include "UsbSettings.h"
       
    29 #include "CUsbServer.h"
    24 #include <cusbclasscontrollerbase.h>
    30 #include <cusbclasscontrollerbase.h>
    25 #include <cusbclasscontrollerplugin.h>
    31 #include <cusbclasscontrollerplugin.h>
       
    32 #include "UsbUtils.h"
    26 #include <cusbmanextensionplugin.h>
    33 #include <cusbmanextensionplugin.h>
       
    34 
       
    35 #ifdef USE_DUMMY_CLASS_CONTROLLER
       
    36 #include "CUsbDummyClassController.h"
       
    37 #endif
       
    38 
    27 #include <bafl/sysutil.h>
    39 #include <bafl/sysutil.h>
    28 #include <usb/usblogger.h>
    40 #include <usb/usblogger.h>
    29 #include <e32svr.h>
    41 #include <e32svr.h>
    30 #include <e32base.h>
    42 #include <e32base.h>
    31 #include <e32std.h>
    43 #include <e32std.h>
       
    44 #include <usbman.rsg>
    32 #include <f32file.h>
    45 #include <f32file.h>
    33 #include <barsc.h>
    46 #include <barsc.h>
    34 #include <barsread.h>
    47 #include <barsread.h>
    35 #include <bautils.h>
    48 #include <bautils.h>
    36 #include <e32property.h> //Publish & Subscribe header
    49 #include <e32property.h> //Publish & Subscribe header
    37 #ifdef USE_DUMMY_CLASS_CONTROLLER
       
    38 #include "CUsbDummyClassController.h"
       
    39 #endif
       
    40 #include "MUsbDeviceNotify.h"
       
    41 #include "UsbSettings.h"
       
    42 #include "CUsbServer.h"
       
    43 #include "UsbUtils.h"
       
    44 #include "CUsbDevice.h"
       
    45 #include "CUsbDeviceStateWatcher.h"
       
    46 #include "CPersonality.h"
    50 #include "CPersonality.h"
    47 #include "usbmancenrepmanager.h"
       
    48 #include "usbmanprivatecrkeys.h"
       
    49 
       
    50 #include "OstTraceDefinitions.h"
       
    51 #ifdef OST_TRACE_COMPILER_IN_USE
       
    52 #include "CUsbDeviceTraces.h"
       
    53 #endif
       
    54 
       
    55 
    51 
    56 _LIT(KUsbLDDName, "eusbc"); //Name used in call to User::LoadLogicalDevice
    52 _LIT(KUsbLDDName, "eusbc"); //Name used in call to User::LoadLogicalDevice
    57 _LIT(KUsbLDDFreeName, "Usbc"); //Name used in call to User::FreeLogicalDevice
    53 _LIT(KUsbLDDFreeName, "Usbc"); //Name used in call to User::FreeLogicalDevice
    58 
    54 
       
    55 #ifdef __FLOG_ACTIVE
       
    56 _LIT8(KLogComponent, "USBSVR");
       
    57 #endif
    59 
    58 
    60 // Panic category only used in debug builds
    59 // Panic category only used in debug builds
    61 #ifdef _DEBUG
    60 #ifdef _DEBUG
    62 _LIT(KUsbDevicePanicCategory, "UsbDevice");
    61 _LIT(KUsbDevicePanicCategory, "UsbDevice");
    63 #endif
    62 #endif
    81  * Constructs a CUsbDevice object.
    80  * Constructs a CUsbDevice object.
    82  *
    81  *
    83  * @return	A new CUsbDevice object
    82  * @return	A new CUsbDevice object
    84  */
    83  */
    85 	{
    84 	{
    86     OstTraceFunctionEntry0( CUSBDEVICE_NEWL_ENTRY );
    85 	LOG_STATIC_FUNC_ENTRY
    87 
    86 
    88 	CUsbDevice* r = new (ELeave) CUsbDevice(aUsbServer);
    87 	CUsbDevice* r = new (ELeave) CUsbDevice(aUsbServer);
    89 	CleanupStack::PushL(r);
    88 	CleanupStack::PushL(r);
    90 	r->ConstructL();
    89 	r->ConstructL();
    91 	CleanupStack::Pop(r);
    90 	CleanupStack::Pop(r);
    92 	OstTraceFunctionExit0( CUSBDEVICE_NEWL_EXIT );
       
    93 	return r;
    91 	return r;
    94 	}
    92 	}
    95 
    93 
    96 
    94 
    97 CUsbDevice::~CUsbDevice()
    95 CUsbDevice::~CUsbDevice()
    98 /**
    96 /**
    99  * Destructor.
    97  * Destructor.
   100  */
    98  */
   101 	{
    99 	{
   102     OstTraceFunctionEntry0( CUSBDEVICE_CUSBDEVICE_DES_ENTRY );
   100 	LOG_FUNC
   103 
   101 
   104 	// Cancel any outstanding asynchronous operation.
   102 	// Cancel any outstanding asynchronous operation.
   105 	Cancel();
   103 	Cancel();
   106 	
   104 	
   107 	delete iUsbClassControllerIterator;
   105 	delete iUsbClassControllerIterator;
   108 	iSupportedClasses.ResetAndDestroy();
   106 	iSupportedClasses.ResetAndDestroy();
   109 	iSupportedPersonalities.ResetAndDestroy();
   107 	iSupportedPersonalities.ResetAndDestroy();
   110 	iSupportedClassUids.Close();
   108 	iSupportedClassUids.Close();
   111 
   109 
   112 	iExtensionPlugins.ResetAndDestroy();
   110 	iExtensionPlugins.ResetAndDestroy();
   113 	
       
   114 	delete iCenRepManager;
       
   115 	
       
   116 	delete  iDeviceConfiguration.iManufacturerName;
       
   117 	delete  iDeviceConfiguration.iProductName;  
       
   118 
   111 
   119 	if(iEcom)
   112 	if(iEcom)
   120 		iEcom->Close();
   113 		iEcom->Close();
   121 	REComSession::FinalClose();
   114 	REComSession::FinalClose();
   122 
   115 
   123 	// Free any memory allocated to the list of observers. Note that
   116 	// Free any memory allocated to the list of observers. Note that
   124 	// we don't want to call ResetAndDestroy, because we don't own
   117 	// we don't want to call ResetAndDestroy, because we don't own
   125 	// the observers themselves.
   118 	// the observers themselves.
   126 	iObservers.Reset();
   119 	iObservers.Reset();
   127 
   120 
   128 #ifndef __OVER_DUMMYUSBDI__
       
   129 #ifndef __WINS__
   121 #ifndef __WINS__
   130 	OstTrace1( TRACE_NORMAL, CUSBDEVICE_CUSBDEVICE, "CUsbDevice::~CUsbDevice;about to delete device state watcher @ %08x", (TUint32)iDeviceStateWatcher );
   122 	LOGTEXT2(_L8("about to delete device state watcher @ %08x"), (TUint32) iDeviceStateWatcher);
   131 	
       
   132 	delete iDeviceStateWatcher;
   123 	delete iDeviceStateWatcher;
   133 	OstTrace0( TRACE_NORMAL, CUSBDEVICE_CUSBDEVICE_DUP1, "CUsbDevice::~CUsbDevice;deleted device state watcher" );
   124 	LOGTEXT(_L8("deleted device state watcher"));
   134 
   125 
   135 	iLdd.Close();
   126 	iLdd.Close();
   136 
   127 
   137 	OstTrace0( TRACE_NORMAL, CUSBDEVICE_CUSBDEVICE_DUP2, "CUsbDevice::~CUsbDevice;Freeing logical device" );
   128 	LOGTEXT(_L8("Freeing logical device"));
   138 	
       
   139 	TInt err = User::FreeLogicalDevice(KUsbLDDFreeName);
   129 	TInt err = User::FreeLogicalDevice(KUsbLDDFreeName);
   140 	//Putting the LOGTEXT2 inside the if statement prevents a compiler
   130 	//Putting the LOGTEXT2 inside the if statement prevents a compiler
   141 	//warning about err being unused in UREL builds.
   131 	//warning about err being unused in UREL builds.
   142 	if(err)
   132 	if(err)
   143 		{
   133 		{
   144         OstTrace1( TRACE_NORMAL, CUSBDEVICE_CUSBDEVICE_DUP3, "CUsbDevice::~CUsbDevice; User::FreeLogicalDevice returned err=%d", err );
   134 		LOGTEXT2(_L8("     User::FreeLogicalDevice returned %d"),err);
   145 		}
   135 		}
   146 #endif
       
   147 #endif	
   136 #endif	
   148 
   137 
   149 	delete iDefaultSerialNumber;
   138 	delete iDefaultSerialNumber;
   150 	OstTraceFunctionExit0( CUSBDEVICE_CUSBDEVICE_DES_EXIT );
       
   151 	}
   139 	}
   152 
   140 
   153 
   141 
   154 CUsbDevice::CUsbDevice(CUsbServer& aUsbServer)
   142 CUsbDevice::CUsbDevice(CUsbServer& aUsbServer)
   155 	: CActive(EPriorityStandard)
   143 	: CActive(EPriorityStandard)
   168 void CUsbDevice::ConstructL()
   156 void CUsbDevice::ConstructL()
   169 /**
   157 /**
   170  * Performs 2nd phase construction of the USB device.
   158  * Performs 2nd phase construction of the USB device.
   171  */
   159  */
   172 	{
   160 	{
   173 	OstTraceFunctionEntry0( CUSBDEVICE_CONSTRUCTL_ENTRY );
   161 	LOG_FUNC
   174 	
   162 	
   175 	iEcom = &(REComSession::OpenL());
   163 	iEcom = &(REComSession::OpenL());
   176 
   164 
   177 	iUsbClassControllerIterator = new(ELeave) CUsbClassControllerIterator(iSupportedClasses);
   165 	iUsbClassControllerIterator = new(ELeave) CUsbClassControllerIterator(iSupportedClasses);
   178 	iCenRepManager = CUsbManCenRepManager::NewL(*this);
   166 
   179 
       
   180 	iDeviceConfiguration.iManufacturerName   = HBufC::NewL(KUsbStringDescStringMaxSize);
       
   181 	iDeviceConfiguration.iProductName        = HBufC::NewL(KUsbStringDescStringMaxSize);
       
   182 #ifndef __OVER_DUMMYUSBDI__	
       
   183 #ifndef __WINS__
   167 #ifndef __WINS__
   184 	OstTrace0( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL, "CUsbDevice::ConstructL; About to load LDD" );
   168 	LOGTEXT(_L8("About to load LDD"));
   185 	
       
   186 	TInt err = User::LoadLogicalDevice(KUsbLDDName);
   169 	TInt err = User::LoadLogicalDevice(KUsbLDDName);
   187 
   170 
   188 	if (err != KErrNone && err != KErrAlreadyExists)
   171 	if (err != KErrNone && err != KErrAlreadyExists)
   189 		{
   172 		{
   190         OstTrace1( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP10, "CUsbDevice::ConstructL;err=%d", err );
   173 		LEAVEL(err);
   191 		User::Leave(err);
   174 		}
   192 		}
   175 
   193 
   176 	LOGTEXT(_L8("About to open LDD"));
   194 	OstTrace0( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP1, "CUsbDevice::ConstructL; About to open LDD" );	
   177 	LEAVEIFERRORL(iLdd.Open(0));
   195 	err = iLdd.Open(0);
   178 	LOGTEXT(_L8("LDD opened"));
   196 	if(err < 0)
       
   197 	    {
       
   198         OstTrace1( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP9, "CUsbDevice::ConstructL;iLdd.Open(0) with error=%d", err );
       
   199         User::Leave(err);
       
   200 	    }
       
   201 	OstTrace0( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP2, "CUsbDevice::ConstructL; LDD opened" );
       
   202 	
       
   203 	
   179 	
   204 	// hide bus from host while interfaces are being set up
   180 	// hide bus from host while interfaces are being set up
   205 	iLdd.DeviceDisconnectFromHost();
   181 	iLdd.DeviceDisconnectFromHost();
   206 
   182 
   207 	// Does the USC support cable detection while powered off? If no, then 
   183 	// Does the USC support cable detection while powered off? If no, then 
   208 	// call PowerUpUdc when RUsb::Start finishes, as is obvious. If yes, we 
   184 	// call PowerUpUdc when RUsb::Start finishes, as is obvious. If yes, we 
   209 	// delay calling PowerUpUdc until both the service state is 'started' and 
   185 	// delay calling PowerUpUdc until both the service state is 'started' and 
   210 	// the device state is not undefined. This is to save power in the UDC 
   186 	// the device state is not undefined. This is to save power in the UDC 
   211 	// when there's no point it being powered.
   187 	// when there's no point it being powered.
   212 	TUsbDeviceCaps devCapsBuf;
   188 	TUsbDeviceCaps devCapsBuf;
   213 	err = iLdd.DeviceCaps(devCapsBuf);
   189 	LEAVEIFERRORL(iLdd.DeviceCaps(devCapsBuf));
   214 	if(err < 0)
       
   215 	    {
       
   216         OstTrace1( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP11, "CUsbDevice::ConstructL;iLdd.DeviceCaps(devCapsBuf) with error=%d", err );
       
   217         User::Leave(err);
       
   218 	    }
       
   219 	
       
   220 	if ( devCapsBuf().iFeatureWord1 & KUsbDevCapsFeatureWord1_CableDetectWithoutPower )
   190 	if ( devCapsBuf().iFeatureWord1 & KUsbDevCapsFeatureWord1_CableDetectWithoutPower )
   221 		{
   191 		{
   222         OstTrace0( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP3, "CUsbDevice::ConstructL: UDC supports cable detect when unpowered" );
   192 		LOGTEXT(_L8("\tUDC supports cable detect when unpowered"));
   223 		iUdcSupportsCableDetectWhenUnpowered = ETrue;
   193 		iUdcSupportsCableDetectWhenUnpowered = ETrue;
   224 		}
   194 		}
   225 	else
   195 	else
   226 		{
   196 		{
   227         OstTrace0( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP4, "CUsbDevice::ConstructL; UDC does not support cable detect when unpowered" );
   197 		LOGTEXT(_L8("\tUDC does not support cable detect when unpowered"));
   228 		}
   198 		}
   229 
   199 
   230 	TUsbcDeviceState deviceState;
   200 	TUsbcDeviceState deviceState;
   231 	err = iLdd.DeviceStatus(deviceState);
   201 	LEAVEIFERRORL(iLdd.DeviceStatus(deviceState));
   232 	if(err < 0)
       
   233 	    {
       
   234         OstTrace1( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP13, "CUsbDevice::ConstructL;iLdd.DeviceStatus(deviceState) with error=%d", err );
       
   235         User::Leave(err);
       
   236 	    }
       
   237 	SetDeviceState(deviceState);
   202 	SetDeviceState(deviceState);
   238 	OstTrace0( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP5, "CUsbDevice::ConstructL; Got device state" );
   203 	LOGTEXT(_L8("Got device state"));
   239 	
       
   240 
   204 
   241 	iDeviceStateWatcher = CUsbDeviceStateWatcher::NewL(*this, iLdd);
   205 	iDeviceStateWatcher = CUsbDeviceStateWatcher::NewL(*this, iLdd);
   242 	iDeviceStateWatcher->Start();
   206 	iDeviceStateWatcher->Start();
   243 
   207 
   244 	// Get hold of the default serial number in the driver
   208 	// Get hold of the default serial number in the driver
   249 	err = iLdd.GetSerialNumberStringDescriptor(serNum);
   213 	err = iLdd.GetSerialNumberStringDescriptor(serNum);
   250 	if (err == KErrNotFound)
   214 	if (err == KErrNotFound)
   251 		{
   215 		{
   252 		delete iDefaultSerialNumber;
   216 		delete iDefaultSerialNumber;
   253 		iDefaultSerialNumber = NULL;
   217 		iDefaultSerialNumber = NULL;
   254 		OstTrace0( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP6, "CUsbDevice::ConstructL; No default serial number" );
   218 		LOGTEXT(_L8("No default serial number"));
   255 		
       
   256 		}
   219 		}
   257 	else
   220 	else
   258 		{
   221 		{
   259         if(err < 0)
   222 		LEAVEIFERRORL(err);
   260             {
   223 #ifdef __FLOG_ACTIVE
   261             OstTrace1( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP12, "CUsbDevice::ConstructL;error=%d", err );
   224 		TBuf8<KUsbStringDescStringMaxSize> narrowString;
   262             User::Leave(err);
   225 		narrowString.Copy(serNum);
   263             }
   226 		LOGTEXT2(_L8("Got default serial number %S"), &narrowString);
   264 #ifdef _DEBUG
   227 #endif //__FLOG_ACTIVE		
   265 		OstTraceExt1( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP7, "CUsbDevice::ConstructL;serNum=%S", serNum );
   228 		}
   266 #endif //_DEBUG  
   229 
   267 		}
   230 	LOGTEXT(_L8("UsbDevice::ConstructL() finished"));
   268 
       
   269 	OstTrace0( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP8, "CUsbDevice::ConstructL; UsbDevice::ConstructL() finished" );
       
   270 	
       
   271 #endif
       
   272 #endif
   231 #endif
   273 	
   232 	
   274 #ifndef __OVER_DUMMYUSBDI__
   233 #ifndef __OVER_DUMMYUSBDI__
   275 	InstantiateExtensionPluginsL();
   234 	InstantiateExtensionPluginsL();
   276 #endif
   235 #endif
   277 	OstTraceFunctionExit0( CUSBDEVICE_CONSTRUCTL_EXIT );
       
   278 	}
   236 	}
   279 
   237 
   280 void CUsbDevice::InstantiateExtensionPluginsL()
   238 void CUsbDevice::InstantiateExtensionPluginsL()
   281 	{
   239 	{
   282     OstTraceFunctionEntry0( CUSBDEVICE_INSTANTIATEEXTENSIONPLUGINSL_ENTRY );
   240 	LOGTEXT(_L8(">>CUsbDevice::InstantiateExtensionPluginsL"));
   283     
       
   284 	const TUid KUidExtensionPluginInterface = TUid::Uid(KUsbmanExtensionPluginInterfaceUid);
   241 	const TUid KUidExtensionPluginInterface = TUid::Uid(KUsbmanExtensionPluginInterfaceUid);
   285 	RImplInfoPtrArray implementations;
   242 	RImplInfoPtrArray implementations;
   286 	const TEComResolverParams noResolverParams;
   243 	const TEComResolverParams noResolverParams;
   287 	REComSession::ListImplementationsL(KUidExtensionPluginInterface, noResolverParams, KRomOnlyResolverUid, implementations);
   244 	REComSession::ListImplementationsL(KUidExtensionPluginInterface, noResolverParams, KRomOnlyResolverUid, implementations);
   288 	CleanupResetAndDestroyPushL(implementations);
   245 	CleanupResetAndDestroyPushL(implementations);
   289 	OstTrace1( TRACE_FLOW, CUSBDEVICE_INSTANTIATEEXTENSIONPLUGINSL, "CUsbDevice::InstantiateExtensionPluginsL;Number of implementations of extension plugin interface: %d", implementations.Count() );
   246 	LOGTEXT2(_L8("Number of implementations of extension plugin interface: %d"), implementations.Count());
   290 	
       
   291 
   247 
   292 	for (TInt i=0; i<implementations.Count(); i++)
   248 	for (TInt i=0; i<implementations.Count(); i++)
   293 		{
   249 		{
   294 		CUsbmanExtensionPlugin* plugin = CUsbmanExtensionPlugin::NewL(implementations[i]->ImplementationUid(), *this);
   250 		CUsbmanExtensionPlugin* plugin = CUsbmanExtensionPlugin::NewL(implementations[i]->ImplementationUid(), *this);
   295 		CleanupStack::PushL(plugin);
   251 		CleanupStack::PushL(plugin);
   296 		iExtensionPlugins.AppendL(plugin); // transfer ownership to iExtensionPlugins
   252 		iExtensionPlugins.AppendL(plugin); // transfer ownership to iExtensionPlugins
   297 		CleanupStack::Pop(plugin);
   253 		CleanupStack::Pop(plugin);
   298 		OstTrace1( TRACE_NORMAL, CUSBDEVICE_INSTANTIATEEXTENSIONPLUGINSL_DUP1, 
   254 		LOGTEXT2(_L8("Added extension plugin with UID 0x%08x"),
   299 		        "CUsbDevice::InstantiateExtensionPluginsL;Added extension plugin with UID 0x%08x", 
   255 			implementations[i]->ImplementationUid());
   300 		        implementations[i]->ImplementationUid().iUid );
       
   301 		
       
   302 		}
   256 		}
   303 
   257 
   304 	CleanupStack::PopAndDestroy(&implementations);
   258 	CleanupStack::PopAndDestroy(&implementations);
   305 	OstTraceFunctionExit0( CUSBDEVICE_INSTANTIATEEXTENSIONPLUGINSL_EXIT );
   259 
       
   260 	LOGTEXT(_L8("<<CUsbDevice::InstantiateExtensionPluginsL"));
   306 	}
   261 	}
   307 
   262 
   308 
   263 
   309 	
   264 	
   310    	
   265    	
   312 /**
   267 /**
   313  * Loads all USB class controllers at startup.
   268  * Loads all USB class controllers at startup.
   314  *
   269  *
   315  */
   270  */
   316 	{
   271 	{
   317 	OstTraceFunctionEntry0( CUSBDEVICE_ENUMERATECLASSCONTROLLERSL_ENTRY );
   272 	LOG_FUNC
   318 	
   273 	
   319 #ifdef USE_DUMMY_CLASS_CONTROLLER
   274 #ifdef USE_DUMMY_CLASS_CONTROLLER
   320 	//create a TLinearOrder to supply the comparison function, Compare(), to be used  
   275 	//create a TLinearOrder to supply the comparison function, Compare(), to be used  
   321 	//to determine the order to add class controllers
   276 	//to determine the order to add class controllers
   322 	TLinearOrder<CUsbClassControllerBase> order(CUsbClassControllerBase::Compare);
   277 	TLinearOrder<CUsbClassControllerBase> order(CUsbClassControllerBase::Compare);
   326 	// make any other class controllers.
   281 	// make any other class controllers.
   327 	for ( TUint ii = 0 ; ii < 3 ; ii++ )
   282 	for ( TUint ii = 0 ; ii < 3 ; ii++ )
   328 		{
   283 		{
   329 		AddClassControllerL(CUsbDummyClassController::NewL(*this, ii), order);	
   284 		AddClassControllerL(CUsbDummyClassController::NewL(*this, ii), order);	
   330 		}
   285 		}
   331 	TInt err = iUsbClassControllerIterator->First();   
   286 	    
   332 	if(err < 0)
   287 	LEAVEIFERRORL(iUsbClassControllerIterator->First());
   333 	    {
       
   334         OstTrace1( TRACE_NORMAL, CUSBDEVICE_ENUMERATECLASSCONTROLLERSL_DUP2, "CUsbDevice::EnumerateClassControllersL;iUsbClassControllerIterator->First() with error=%d", err );
       
   335         User::Leave(err);
       
   336 	    }
       
   337 	    
   288 	    
   338 #else
   289 #else
   339 
   290 
   340 	// Add a class controller statically.
   291 	// Add a class controller statically.
   341 	// The next line shows how to add a class controller, CUsbExampleClassController,
   292 	// The next line shows how to add a class controller, CUsbExampleClassController,
   349 
   300 
   350 	const TEComResolverParams noResolverParams;
   301 	const TEComResolverParams noResolverParams;
   351 	REComSession::ListImplementationsL(KUidUsbPlugIns, noResolverParams, KRomOnlyResolverUid, implementations);
   302 	REComSession::ListImplementationsL(KUidUsbPlugIns, noResolverParams, KRomOnlyResolverUid, implementations);
   352   	CleanupResetAndDestroyPushL(implementations);
   303   	CleanupResetAndDestroyPushL(implementations);
   353   	
   304   	
   354 	OstTrace1( TRACE_NORMAL, CUSBDEVICE_ENUMERATECLASSCONTROLLERSL, "CUsbDevice::EnumerateClassControllersL;Number of implementations to load %d", implementations.Count() );
   305 	LOGTEXT2(_L8("Number of implementations to load  %d"), implementations.Count());
   355 	
   306 	
   356 	for (TInt i=0; i<implementations.Count(); i++)
   307 	for (TInt i=0; i<implementations.Count(); i++)
   357 		{
   308 		{
   358         OstTrace1( TRACE_NORMAL, CUSBDEVICE_ENUMERATECLASSCONTROLLERSL_DUP1, "CUsbDevice::EnumerateClassControllersL;Adding class controller with UID %x", implementations[i]->ImplementationUid().iUid );
   309 		LOGTEXT2(_L8("Adding class controller with UID %x"),
   359         const TUid uid = implementations[i]->ImplementationUid();
   310 			implementations[i]->ImplementationUid());
   360 		TInt err = iSupportedClassUids.Append(uid);
   311 		const TUid uid = implementations[i]->ImplementationUid();
   361 		if(err < 0)
   312 		LEAVEIFERRORL(iSupportedClassUids.Append(uid));
   362 		    {
       
   363             OstTrace1( TRACE_NORMAL, CUSBDEVICE_ENUMERATECLASSCONTROLLERSL_DUP3, "CUsbDevice::EnumerateClassControllersL;iSupportedClassUids.Append(uid) with error=%d", err );
       
   364             User::Leave(err);
       
   365 		    }
       
   366 		}	
   313 		}	
   367 			
   314 			
   368 	CleanupStack::PopAndDestroy(&implementations);
   315 	CleanupStack::PopAndDestroy(&implementations);
   369 	
   316 	
   370 #endif // USE_DUMMY_CLASS_CONTROLLER
   317 #endif // USE_DUMMY_CLASS_CONTROLLER
   371 	OstTraceFunctionExit0( CUSBDEVICE_ENUMERATECLASSCONTROLLERSL_EXIT );
       
   372 	}
   318 	}
   373 
   319 
   374 void CUsbDevice::AddClassControllerL(CUsbClassControllerBase* aClassController, 
   320 void CUsbDevice::AddClassControllerL(CUsbClassControllerBase* aClassController, 
   375 									TLinearOrder<CUsbClassControllerBase> aOrder)
   321 									TLinearOrder<CUsbClassControllerBase> aOrder)
   376 /**
   322 /**
   382  * @param	aClassController	Class to be managed
   328  * @param	aClassController	Class to be managed
   383  * @param   aOrder              Specifies order CUsbClassControllerBase objects are to be
   329  * @param   aOrder              Specifies order CUsbClassControllerBase objects are to be
   384  *                              added
   330  *                              added
   385  */
   331  */
   386 	{
   332 	{
   387 	OstTraceFunctionEntry0( CUSBDEVICE_ADDCLASSCONTROLLERL_ENTRY );
   333 	LOG_FUNC
   388 	
   334 	
   389 	
   335 	
   390 	TInt rc = KErrNone;	
   336 	TInt rc = KErrNone;	
   391 	
   337 	
   392 	if(isPersonalityCfged()) // do not take into account priorities
   338 	if(isPersonalityCfged()) // do not take into account priorities
   401 		
   347 		
   402 	if (rc != KErrNone) 
   348 	if (rc != KErrNone) 
   403 		{
   349 		{
   404 		// Avoid memory leak by deleting class controller if the append fails.
   350 		// Avoid memory leak by deleting class controller if the append fails.
   405 		delete aClassController;
   351 		delete aClassController;
   406 		OstTrace1( TRACE_NORMAL, CUSBDEVICE_ADDCLASSCONTROLLERL, "CUsbDevice::AddClassControllerL;Leave rc=%d", rc );
   352 		LEAVEL(rc);
   407 		User::Leave(rc);
   353 		}
   408 		}
       
   409 	OstTraceFunctionExit0( CUSBDEVICE_ADDCLASSCONTROLLERL_EXIT );
       
   410 	}
   354 	}
   411 
   355 
   412 void CUsbDevice::RegisterObserverL(MUsbDeviceNotify& aObserver)
   356 void CUsbDevice::RegisterObserverL(MUsbDeviceNotify& aObserver)
   413 /**
   357 /**
   414  * Register an observer of the device.
   358  * Register an observer of the device.
   415  * Presently, the device supports watching state.
   359  * Presently, the device supports watching state.
   416  *
   360  *
   417  * @param	aObserver	New Observer of the device
   361  * @param	aObserver	New Observer of the device
   418  */
   362  */
   419 	{
   363 	{
   420 	OstTraceFunctionEntry0( CUSBDEVICE_REGISTEROBSERVERL_ENTRY );
   364 	LOG_FUNC
   421 	TInt err = iObservers.Append(&aObserver);
   365 
   422 	if(err < 0)
   366 	LEAVEIFERRORL(iObservers.Append(&aObserver));
   423 	    {
       
   424         OstTrace1( TRACE_NORMAL, CUSBDEVICE_REGISTEROBSERVERL, "CUsbDevice::RegisterObserverL;iObservers.Append(&aObserver) with err=%d", err );
       
   425         User::Leave(err);
       
   426 	    }
       
   427 	OstTraceFunctionExit0( CUSBDEVICE_REGISTEROBSERVERL_EXIT );
       
   428 	}
   367 	}
   429 
   368 
   430 
   369 
   431 void CUsbDevice::DeRegisterObserver(MUsbDeviceNotify& aObserver)
   370 void CUsbDevice::DeRegisterObserver(MUsbDeviceNotify& aObserver)
   432 /**
   371 /**
   433  * De-registers an existing device observer.
   372  * De-registers an existing device observer.
   434  *
   373  *
   435  * @param	aObserver	The existing device observer to be de-registered
   374  * @param	aObserver	The existing device observer to be de-registered
   436  */
   375  */
   437 	{
   376 	{
   438 	OstTraceFunctionEntry0( CUSBDEVICE_DEREGISTEROBSERVER_ENTRY );
   377 	LOG_FUNC
   439 
   378 
   440 	TInt index = iObservers.Find(&aObserver);
   379 	TInt index = iObservers.Find(&aObserver);
   441 
   380 
   442 	if (index >= 0)
   381 	if (index >= 0)
   443 		iObservers.Remove(index);
   382 		iObservers.Remove(index);
   444 	OstTraceFunctionExit0( CUSBDEVICE_DEREGISTEROBSERVER_EXIT );
       
   445 	}
   383 	}
   446 
   384 
   447 
   385 
   448 void CUsbDevice::StartL()
   386 void CUsbDevice::StartL()
   449 /**
   387 /**
   450  * Start the USB Device and all its associated USB classes.
   388  * Start the USB Device and all its associated USB classes.
   451  * Reports errors and state changes via observer interface.
   389  * Reports errors and state changes via observer interface.
   452  */
   390  */
   453 	{
   391 	{
   454 	OstTraceFunctionEntry0( CUSBDEVICE_STARTL_ENTRY );
   392 	LOG_FUNC
   455 
   393 
   456 	Cancel();
   394 	Cancel();
   457 	SetServiceState(EUsbServiceStarting);
   395 	SetServiceState(EUsbServiceStarting);
   458 
   396 
   459 	TRAPD(err, SetDeviceDescriptorL());
   397 	TRAPD(err, SetDeviceDescriptorL());
   460 	if ( err != KErrNone )
   398 	if ( err != KErrNone )
   461 		{
   399 		{
   462 		SetServiceState(EUsbServiceIdle);	
   400 		SetServiceState(EUsbServiceIdle);
   463 		OstTrace1( TRACE_NORMAL, CUSBDEVICE_STARTL, "CUsbDevice::StartL;Leave with error=%d", err );
   401 		LEAVEL(err);		
   464 		User::Leave(err);		
       
   465 		}
   402 		}
   466 
   403 
   467 	iLastError = KErrNone;
   404 	iLastError = KErrNone;
   468 	StartCurrentClassController();
   405 	StartCurrentClassController();
   469 	OstTraceFunctionExit0( CUSBDEVICE_STARTL_EXIT );
       
   470 	}
   406 	}
   471 
   407 
   472 void CUsbDevice::Stop()
   408 void CUsbDevice::Stop()
   473 /**
   409 /**
   474  * Stop the USB device and all its associated USB classes.
   410  * Stop the USB device and all its associated USB classes.
   475  */
   411  */
   476 	{
   412 	{
   477 	OstTraceFunctionEntry0( CUSBDEVICE_STOP_ENTRY );
   413 	LOG_FUNC
   478 
   414 
   479 	Cancel();
   415 	Cancel();
   480 	SetServiceState(EUsbServiceStopping);
   416 	SetServiceState(EUsbServiceStopping);
   481 	
   417 	
   482 	iLastError = KErrNone;
   418 	iLastError = KErrNone;
   483 	StopCurrentClassController();
   419 	StopCurrentClassController();
   484 	OstTraceFunctionExit0( CUSBDEVICE_STOP_EXIT );
       
   485 	}
   420 	}
   486 
   421 
   487 void CUsbDevice::SetServiceState(TUsbServiceState aState)
   422 void CUsbDevice::SetServiceState(TUsbServiceState aState)
   488 /**
   423 /**
   489  * Change the device's state and report the change to the observers.
   424  * Change the device's state and report the change to the observers.
   490  *
   425  *
   491  * @param	aState	New state that the device is moving to
   426  * @param	aState	New state that the device is moving to
   492  */
   427  */
   493 	{
   428 	{
   494     OstTraceFunctionEntry0( CUSBDEVICE_SETSERVICESTATE_ENTRY );
   429 	LOGTEXT3(_L8("Calling: CUsbDevice::SetServiceState [iServiceState=%d,aState=%d]"),
   495     
   430 		iServiceState, aState);
   496 	OstTraceExt2( TRACE_NORMAL, CUSBDEVICE_SETSERVICESTATE, 
       
   497 	        "CUsbDevice::SetServiceState;iServiceState=%d;aState=%d", iServiceState, aState );
       
   498 	
       
   499 
   431 
   500 	if (iServiceState != aState)
   432 	if (iServiceState != aState)
   501 		{
   433 		{
   502 		// Change state straight away in case any of the clients check it
   434 		// Change state straight away in case any of the clients check it
   503 		TUsbServiceState oldState = iServiceState;
   435 		TUsbServiceState oldState = iServiceState;
   511 			}
   443 			}
   512 
   444 
   513 		if (iServiceState == EUsbServiceIdle)
   445 		if (iServiceState == EUsbServiceIdle)
   514 			iUsbServer.LaunchShutdownTimerIfNoSessions();
   446 			iUsbServer.LaunchShutdownTimerIfNoSessions();
   515 		}
   447 		}
   516 	OstTraceFunctionExit0( CUSBDEVICE_SETSERVICESTATE_EXIT );
   448 	LOGTEXT(_L8("Exiting: CUsbDevice::SetServiceState"));
   517 	}
   449 	}
   518 
   450 
   519 void CUsbDevice::SetDeviceState(TUsbcDeviceState aState)
   451 void CUsbDevice::SetDeviceState(TUsbcDeviceState aState)
   520 /**
   452 /**
   521  * The CUsbDevice::SetDeviceState method
   453  * The CUsbDevice::SetDeviceState method
   524  *
   456  *
   525  * @internalComponent
   457  * @internalComponent
   526  * @param	aState	New state that the device is moving to
   458  * @param	aState	New state that the device is moving to
   527  */
   459  */
   528 	{
   460 	{
   529 	OstTraceFunctionEntry0( CUSBDEVICE_SETDEVICESTATE_ENTRY );
   461 	LOG_FUNC
   530 	OstTraceExt2( TRACE_NORMAL, CUSBDEVICE_SETDEVICESTATE, 
   462 	LOGTEXT3(_L8("\taState = %d, iDeviceState = %d"), aState, iDeviceState);
   531 	        "CUsbDevice::SetDeviceState;aState=%d;iDeviceState=%d", aState, iDeviceState );
       
   532 
   463 
   533 	TUsbDeviceState state;
   464 	TUsbDeviceState state;
   534 	switch (aState)
   465 	switch (aState)
   535 		{
   466 		{
   536 	case EUsbcDeviceStateUndefined:
   467 	case EUsbcDeviceStateUndefined:
   558 		return;
   489 		return;
   559 		}
   490 		}
   560 
   491 
   561 	if (iDeviceState != state)
   492 	if (iDeviceState != state)
   562 		{
   493 		{
   563 #ifndef __OVER_DUMMYUSBDI__
       
   564 #ifndef __WINS__
   494 #ifndef __WINS__
   565 		if (iDeviceState == EUsbDeviceStateUndefined &&
   495 		if (iDeviceState == EUsbDeviceStateUndefined &&
   566 			iUdcSupportsCableDetectWhenUnpowered &&
   496 			iUdcSupportsCableDetectWhenUnpowered &&
   567 			iServiceState == EUsbServiceStarted)
   497 			iServiceState == EUsbServiceStarted)
   568 			{
   498 			{
   570 			// now be attached (if it wasn't before). If the UDC supports
   500 			// now be attached (if it wasn't before). If the UDC supports
   571 			// cable detection when unpowered, NOW is the right time to power
   501 			// cable detection when unpowered, NOW is the right time to power
   572 			// it up (so long as usbman is fully started).
   502 			// it up (so long as usbman is fully started).
   573 			(void)PowerUpAndConnect(); // We don't care about any errors here.
   503 			(void)PowerUpAndConnect(); // We don't care about any errors here.
   574 			}
   504 			}
   575 #endif
   505 #endif // __WINS__
   576 #endif // __OVER_DUMMYUSBDI__
       
   577 		// Change state straight away in case any of the clients check it
   506 		// Change state straight away in case any of the clients check it
   578 		TUsbDeviceState oldState = iDeviceState;
   507 		TUsbDeviceState oldState = iDeviceState;
   579 		iDeviceState = state;
   508 		iDeviceState = state;
   580 		TUint length = iObservers.Count();
   509 		TUint length = iObservers.Count();
   581 
   510 
   582 		for (TUint i = 0; i < length; i++)
   511 		for (TUint i = 0; i < length; i++)
   583 			{
   512 			{
   584 			iObservers[i]->UsbDeviceStateChange(LastError(), oldState, iDeviceState);
   513 			iObservers[i]->UsbDeviceStateChange(LastError(), oldState, iDeviceState);
   585 			}
   514 			}
   586 		}
   515 		}
   587 	OstTraceFunctionExit0( CUSBDEVICE_SETDEVICESTATE_EXIT );
       
   588 	}
   516 	}
   589 
   517 
   590 /**
   518 /**
   591  * Callback called by CDeviceHandler when the USB bus has sucessfully
   519  * Callback called by CDeviceHandler when the USB bus has sucessfully
   592  * completed a ReEnumeration (restarted all services).
   520  * completed a ReEnumeration (restarted all services).
   593  */
   521  */
   594 void CUsbDevice::BusEnumerationCompleted()
   522 void CUsbDevice::BusEnumerationCompleted()
   595 	{
   523 	{
   596 	OstTraceFunctionEntry0( CUSBDEVICE_BUSENUMERATIONCOMPLETED_ENTRY );
   524 	LOG_FUNC
   597 
   525 
   598 	// Has the start been cancelled?
   526 	// Has the start been cancelled?
   599 	if (iServiceState == EUsbServiceStarting)
   527 	if (iServiceState == EUsbServiceStarting)
   600 		{
   528 		{
   601 		SetServiceState(EUsbServiceStarted);
   529 		SetServiceState(EUsbServiceStarted);
   602 		}
   530 		}
   603 	else
   531 	else
   604 		{
   532 		{
   605         OstTrace0( TRACE_NORMAL, CUSBDEVICE_BUSENUMERATIONCOMPLETED, 
   533 		LOGTEXT(_L8("    Start has been cancelled!"));
   606                 "CUsbDevice::BusEnumerationCompleted;    Start has been cancelled!" );
   534 		}
   607 		}
       
   608 	OstTraceFunctionExit0( CUSBDEVICE_BUSENUMERATIONCOMPLETED_EXIT );
       
   609 	}
   535 	}
   610 
   536 
   611 void CUsbDevice::BusEnumerationFailed(TInt aError)
   537 void CUsbDevice::BusEnumerationFailed(TInt aError)
   612 /**
   538 /**
   613  * Callback called by CDeviceHandler when the USB bus has
   539  * Callback called by CDeviceHandler when the USB bus has
   614  * completed an ReEnumeration (Restarted all services) with errors
   540  * completed an ReEnumeration (Restarted all services) with errors
   615  *
   541  *
   616  * @param	aError	Error that has occurred during Re-enumeration
   542  * @param	aError	Error that has occurred during Re-enumeration
   617  */
   543  */
   618 	{
   544 	{
   619 	OstTrace1( TRACE_NORMAL, CUSBDEVICE_BUSENUMERATIONFAILED, "CUsbDevice::BusEnumerationFailed;aError=%d", aError );
   545 	LOGTEXT2(_L8("CUsbDevice::BusEnumerationFailed [aError=%d]"), aError);
   620 	
       
   621 	iLastError = aError;
   546 	iLastError = aError;
   622 
   547 
   623 	if (iServiceState == EUsbServiceStarting)
   548 	if (iServiceState == EUsbServiceStarting)
   624 		{
   549 		{
   625 		SetServiceState(EUsbServiceStopping);
   550 		SetServiceState(EUsbServiceStopping);
   626 		StopCurrentClassController();
   551 		StopCurrentClassController();
   627 		}
   552 		}
   628 	else
   553 	else
   629 		{
   554 		{
   630 		OstTrace0( TRACE_NORMAL, CUSBDEVICE_BUSENUMERATIONFAILED_DUP1, 
   555 		LOGTEXT(_L8("    Start has been cancelled!"));
   631 		        "CUsbDevice::BusEnumerationFailed;    Start has been cancelled!" );		
       
   632 		}
   556 		}
   633 	}
   557 	}
   634 
   558 
   635 
   559 
   636 void CUsbDevice::StartCurrentClassController()
   560 void CUsbDevice::StartCurrentClassController()
   637 /**
   561 /**
   638  * Called numerous times to start all the USB classes.
   562  * Called numerous times to start all the USB classes.
   639  */
   563  */
   640 	{
   564 	{
   641 	OstTraceFunctionEntry0( CUSBDEVICE_STARTCURRENTCLASSCONTROLLER_ENTRY );
   565 	LOG_FUNC
   642 
   566 
   643 	iUsbClassControllerIterator->Current()->Start(iStatus);
   567 	iUsbClassControllerIterator->Current()->Start(iStatus);
   644 	SetActive();
   568 	SetActive();
   645 	OstTraceFunctionExit0( CUSBDEVICE_STARTCURRENTCLASSCONTROLLER_EXIT );
       
   646 	}
   569 	}
   647 
   570 
   648 void CUsbDevice::StopCurrentClassController()
   571 void CUsbDevice::StopCurrentClassController()
   649 /**
   572 /**
   650  * Called numerous times to stop all the USB classes.
   573  * Called numerous times to stop all the USB classes.
   651  */
   574  */
   652 	{
   575 	{
   653 	OstTraceFunctionEntry0( CUSBDEVICE_STOPCURRENTCLASSCONTROLLER_ENTRY );	
   576 	LOG_FUNC
   654 
   577 
   655 	iUsbClassControllerIterator->Current()->Stop(iStatus);
   578 	iUsbClassControllerIterator->Current()->Stop(iStatus);
   656 	SetActive();
   579 	SetActive();
   657 	OstTraceFunctionExit0( CUSBDEVICE_STOPCURRENTCLASSCONTROLLER_EXIT );
       
   658 	}
   580 	}
   659 
   581 
   660 /**
   582 /**
   661 Utility function to power up the UDC and connect the
   583 Utility function to power up the UDC and connect the
   662 device to the host.
   584 device to the host.
   663 */
   585 */
   664 TInt CUsbDevice::PowerUpAndConnect()
   586 TInt CUsbDevice::PowerUpAndConnect()
   665 	{
   587 	{
   666 	OstTraceFunctionEntry0( CUSBDEVICE_POWERUPANDCONNECT_ENTRY );
   588 	LOG_FUNC
   667 	
   589 	LOGTEXT(_L8("\tPowering up UDC..."));
   668 	OstTrace0( TRACE_NORMAL, CUSBDEVICE_POWERUPANDCONNECT, "CUsbDevice::PowerUpAndConnect;Powering up UDC..." );
       
   669 	
       
   670 	TInt res = iLdd.PowerUpUdc();
   590 	TInt res = iLdd.PowerUpUdc();
   671 	OstTrace1( TRACE_NORMAL, CUSBDEVICE_POWERUPANDCONNECT_DUP1, 
   591 	LOGTEXT2(_L8("\tPowerUpUdc res = %d"), res);
   672 	        "CUsbDevice::PowerUpAndConnect;PowerUpUdc res = %d", res );
       
   673 	
       
   674 	res = iLdd.DeviceConnectToHost();
   592 	res = iLdd.DeviceConnectToHost();
   675 	OstTrace1( TRACE_NORMAL, CUSBDEVICE_POWERUPANDCONNECT_DUP2, 
   593 	LOGTEXT2(_L8("\tDeviceConnectToHost res = %d"), res);
   676 	        "CUsbDevice::PowerUpAndConnect;DeviceConnectToHost res = %d", res );
       
   677 	
       
   678 	OstTraceFunctionExit0( CUSBDEVICE_POWERUPANDCONNECT_EXIT );
       
   679 	return res;
   594 	return res;
   680 	}
   595 	}
   681 
   596 
   682 void CUsbDevice::RunL()
   597 void CUsbDevice::RunL()
   683 /**
   598 /**
   684  * Called when starting or stopping a USB class has completed, successfully or
   599  * Called when starting or stopping a USB class has completed, successfully or
   685  * otherwise. Continues with the process of starting or stopping until all
   600  * otherwise. Continues with the process of starting or stopping until all
   686  * classes have been completed.
   601  * classes have been completed.
   687  */
   602  */
   688 	{
   603 	{
   689     OstTraceFunctionEntry0( CUSBDEVICE_RUNL_ENTRY );
   604 	LOGTEXT2(_L8(">>CUsbDevice::RunL [iStatus=%d]"), iStatus.Int());
   690     OstTrace1( TRACE_NORMAL, CUSBDEVICE_RUNL, "CUsbDevice::RunL;iStatus.Int()=%d", iStatus.Int() );
   605 
   691 
   606 	LEAVEIFERRORL(iStatus.Int());
   692     TInt err = iStatus.Int();
       
   693     if(err < 0)
       
   694         {
       
   695         OstTrace1( TRACE_NORMAL, CUSBDEVICE_RUNL_DUP4, "CUsbDevice::RunL;iStatus.Int() with error=%d", err );
       
   696         User::Leave(err);
       
   697         }
       
   698 
   607 
   699 	switch (iServiceState)
   608 	switch (iServiceState)
   700 		{
   609 		{
   701 	case EUsbServiceStarting:
   610 	case EUsbServiceStarting:
   702 		if (iUsbClassControllerIterator->Next() == KErrNotFound)
   611 		if (iUsbClassControllerIterator->Next() == KErrNotFound)
   703 			{
   612 			{
   704 #ifndef __OVER_DUMMYUSBDI__
       
   705 #ifndef __WINS__
   613 #ifndef __WINS__
   706 			if (!iUdcSupportsCableDetectWhenUnpowered || iDeviceState != EUsbDeviceStateUndefined)
   614 			if (!iUdcSupportsCableDetectWhenUnpowered || iDeviceState != EUsbDeviceStateUndefined)
   707 				{
   615 				{
   708 				// We've finished starting the classes. We can just power up the UDC
   616 				// We've finished starting the classes. We can just power up the UDC
   709 				// now: there's no need to re-enumerate, because we soft disconnected
   617 				// now: there's no need to re-enumerate, because we soft disconnected
   710 				// earlier. This will also do a soft connect.
   618 				// earlier. This will also do a soft connect.
   711 				OstTrace0( TRACE_NORMAL, CUSBDEVICE_RUNL_DUP1, "CUsbDevice::RunL;Finished starting classes: powering up UDC" );
   619 				LOGTEXT(_L8("Finished starting classes: powering up UDC"));
   712 				
       
   713 
   620 
   714 				// It isn't an error if this call fails. This will happen, for example,
   621 				// It isn't an error if this call fails. This will happen, for example,
   715 				// in the case where there are no USB classes defined.
   622 				// in the case where there are no USB classes defined.
   716 				(void)PowerUpAndConnect();
   623 				(void)PowerUpAndConnect();
   717 				}
   624 				}
   718 #endif
   625 #endif
   719 #endif
       
   720 			// If we're not running on target, we can just go to "started".
   626 			// If we're not running on target, we can just go to "started".
   721 			SetServiceState(EUsbServiceStarted);
   627 			SetServiceState(EUsbServiceStarted);
   722 			}
   628 			}
   723 		else
   629 		else
   724 			{
   630 			{
   728 
   634 
   729 	case EUsbServiceStopping:
   635 	case EUsbServiceStopping:
   730 		if (iUsbClassControllerIterator->Previous() == KErrNotFound)
   636 		if (iUsbClassControllerIterator->Previous() == KErrNotFound)
   731 			{
   637 			{
   732 			// if stopping classes, hide the USB interface from the host
   638 			// if stopping classes, hide the USB interface from the host
   733 #ifndef __OVER_DUMMYUSBDI__
       
   734 #ifndef __WINS__
   639 #ifndef __WINS__
   735 			iLdd.DeviceDisconnectFromHost();
   640 			iLdd.DeviceDisconnectFromHost();
   736 
   641 
   737 			// Restore the default serial number 
   642 			// Restore the default serial number 
   738 			if (iDefaultSerialNumber)
   643 			if (iDefaultSerialNumber)
   739 				{
   644 				{
   740 				TInt res = iLdd.SetSerialNumberStringDescriptor(*iDefaultSerialNumber);
   645 				TInt res = iLdd.SetSerialNumberStringDescriptor(*iDefaultSerialNumber);
   741 				OstTrace1( TRACE_NORMAL, CUSBDEVICE_RUNL_DUP2, "CUsbDevice::RunL;Restore default serial number res = %d", res );				
   646 				LOGTEXT2(_L8("Restore default serial number res = %d"), res);
   742 				}
   647 				}
   743 			else
   648 			else
   744 				{
   649 				{
   745 				TInt res = iLdd.RemoveSerialNumberStringDescriptor();
   650 				TInt res = iLdd.RemoveSerialNumberStringDescriptor();
   746 				OstTrace1( TRACE_NORMAL, CUSBDEVICE_RUNL_DUP3, "CUsbDevice::RunL;Remove serial number res = %d", res );				
   651 				LOGTEXT2(_L8("Remove serial number res = %d"), res);
   747 				}
   652 				}
   748 
   653 				
   749 #endif				
       
   750 #endif			
   654 #endif			
   751 			SetServiceState(EUsbServiceIdle);
   655 			SetServiceState(EUsbServiceIdle);
   752 			}
   656 			}
   753 		else
   657 		else
   754 			{
   658 			{
   755 			StopCurrentClassController();
   659 			StopCurrentClassController();
   756 			}
   660 			}
   757 		break;
   661 		break;
   758 
   662 
   759 	default:
   663 	default:
   760 
   664 		__ASSERT_DEBUG( EFalse, _USB_PANIC(KUsbDevicePanicCategory, EBadAsynchronousCall) );
   761         OstTrace1( TRACE_FATAL, CUSBDEVICE_RUNL_DUP5, "CUsbDevice::RunL;Panic reason=%d", EBadAsynchronousCall );
       
   762         __ASSERT_DEBUG( EFalse, User::Panic(KUsbDevicePanicCategory, EBadAsynchronousCall) );
       
   763 
       
   764 		break;
   665 		break;
   765 		}
   666 		}
   766 	OstTraceFunctionExit0( CUSBDEVICE_RUNL_EXIT );
   667 	LOGTEXT(_L8("<<CUsbDevice::RunL"));
   767 	}
   668 	}
   768 
   669 
   769 void CUsbDevice::DoCancel()
   670 void CUsbDevice::DoCancel()
   770 /**
   671 /**
   771  * Standard active object cancellation function. If we're starting or stopping
   672  * Standard active object cancellation function. If we're starting or stopping
   772  * a USB class, cancels it. If we're not, then we shouldn't be active and hence
   673  * a USB class, cancels it. If we're not, then we shouldn't be active and hence
   773  * this function being called is a programming error.
   674  * this function being called is a programming error.
   774  */
   675  */
   775 	{
   676 	{
   776 	OstTraceFunctionEntry0( CUSBDEVICE_DOCANCEL_ENTRY );
   677 	LOG_FUNC
   777 
   678 
   778 	switch (iServiceState)
   679 	switch (iServiceState)
   779 		{
   680 		{
   780 	case EUsbServiceStarting:
   681 	case EUsbServiceStarting:
   781 	case EUsbServiceStopping:
   682 	case EUsbServiceStopping:
   782 		iUsbClassControllerIterator->Current()->Cancel();
   683 		iUsbClassControllerIterator->Current()->Cancel();
   783 		break;
   684 		break;
   784 
   685 
   785 	default:
   686 	default:
   786 
   687 		__ASSERT_DEBUG( EFalse, _USB_PANIC(KUsbDevicePanicCategory, EBadAsynchronousCall) );
   787         OstTrace1( TRACE_FATAL, CUSBDEVICE_DOCANCEL, "CUsbDevice::DoCancel;Panic reason=%d", EBadAsynchronousCall );
       
   788         __ASSERT_DEBUG( EFalse, User::Panic(KUsbDevicePanicCategory, EBadAsynchronousCall ) );
       
   789 		break;
   688 		break;
   790 		}
   689 		}
   791 	OstTraceFunctionExit0( CUSBDEVICE_DOCANCEL_EXIT );
       
   792 	}
   690 	}
   793 
   691 
   794 TInt CUsbDevice::RunError(TInt aError)
   692 TInt CUsbDevice::RunError(TInt aError)
   795 /**
   693 /**
   796  * Standard active object RunError function. Handles errors which occur when
   694  * Standard active object RunError function. Handles errors which occur when
   798  *
   696  *
   799  * @param aError The error which occurred
   697  * @param aError The error which occurred
   800  * @return Always KErrNone, to avoid an active scheduler panic
   698  * @return Always KErrNone, to avoid an active scheduler panic
   801  */
   699  */
   802 	{
   700 	{
   803 	OstTrace1( TRACE_NORMAL, CUSBDEVICE_RUNERROR, "CUsbDevice::RunError;aError=%d", aError );
   701 	LOGTEXT2(_L8("CUsbDevice::RunError [aError=%d]"), aError);
   804 	
       
   805 
   702 
   806 	iLastError = aError;
   703 	iLastError = aError;
   807 
   704 
   808 	switch (iServiceState)
   705 	switch (iServiceState)
   809 		{
   706 		{
   831 		else
   728 		else
   832 			StopCurrentClassController();
   729 			StopCurrentClassController();
   833 		break;
   730 		break;
   834 
   731 
   835 	default:
   732 	default:
   836         OstTrace1( TRACE_FATAL, CUSBDEVICE_RUNERROR_DUP1, "CUsbDevice::RunError;Panic reason=%d", EBadAsynchronousCall );
   733 		__ASSERT_DEBUG( EFalse, _USB_PANIC(KUsbDevicePanicCategory, EBadAsynchronousCall) );
   837         __ASSERT_DEBUG( EFalse, User::Panic(KUsbDevicePanicCategory, EBadAsynchronousCall ) );
       
   838 		break;
   734 		break;
   839 		}
   735 		}
   840 
   736 
   841 	return KErrNone;
   737 	return KErrNone;
   842 	}
   738 	}
   848  * which this function returns.
   744  * which this function returns.
   849  *
   745  *
   850  * @return A new iterator
   746  * @return A new iterator
   851  */
   747  */
   852 	{
   748 	{
   853 	OstTraceFunctionEntry0( CUSBDEVICE_UCCNGETCLASSCONTROLLERITERATORL_ENTRY );
   749 	LOG_FUNC
   854 
   750 
   855 	return new (ELeave) CUsbClassControllerIterator(iSupportedClasses);
   751 	return new (ELeave) CUsbClassControllerIterator(iSupportedClasses);
   856 	}
   752 	}
   857 
   753 
   858 void CUsbDevice::UccnError(TInt aError)
   754 void CUsbDevice::UccnError(TInt aError)
   861  * this situation, we should just stop all the classes we can.
   757  * this situation, we should just stop all the classes we can.
   862  *
   758  *
   863  * @param aError The error that's occurred
   759  * @param aError The error that's occurred
   864  */
   760  */
   865 	{
   761 	{
   866 	OstTraceFunctionEntry0( CUSBDEVICE_UCCNERROR_ENTRY );
   762 	LOG_FUNC
   867 
   763 
   868 	RunError(aError);
   764 	RunError(aError);
   869 	OstTraceFunctionExit0( CUSBDEVICE_UCCNERROR_EXIT );
   765 	}
   870 	}
   766 
   871 
   767 
   872 
   768 #ifdef __FLOG_ACTIVE
   873 #ifdef _DEBUG
       
   874 void CUsbDevice::PrintDescriptor(CUsbDevice::TUsbDeviceDescriptor& aDeviceDescriptor)
   769 void CUsbDevice::PrintDescriptor(CUsbDevice::TUsbDeviceDescriptor& aDeviceDescriptor)
   875 	{
   770 	{
   876 	OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR, "CUsbDevice::PrintDescriptor;iLength=%d", aDeviceDescriptor.iLength );
   771 	LOGTEXT2(_L8("\tiLength is %d"), aDeviceDescriptor.iLength);
   877 	OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP1, "CUsbDevice::PrintDescriptor;iDescriptorType=%d", aDeviceDescriptor.iDescriptorType );
   772 	LOGTEXT2(_L8("\tiDescriptorType is %d"), aDeviceDescriptor.iDescriptorType);
   878 	OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP2, "CUsbDevice::PrintDescriptor;iBcdUsb=0x%04x", aDeviceDescriptor.iBcdUsb );
   773 	LOGTEXT2(_L8("\tBcdUsb is: 0x%04x"), aDeviceDescriptor.iBcdUsb);
   879 	OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP3, "CUsbDevice::PrintDescriptor;iDeviceClass=0x%02x", aDeviceDescriptor.iDeviceClass );
   774 	LOGTEXT2(_L8("\tDeviceClass is: 0x%02x"), aDeviceDescriptor.iDeviceClass);
   880 	OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP4, "CUsbDevice::PrintDescriptor;iDeviceSubClass=0x%02x", aDeviceDescriptor.iDeviceSubClass );
   775 	LOGTEXT2(_L8("\tDeviceSubClass is: 0x%02x"), aDeviceDescriptor.iDeviceSubClass);
   881 	OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP5, "CUsbDevice::PrintDescriptor;iDeviceProtocol=0x%02x", aDeviceDescriptor.iDeviceProtocol );
   776 	LOGTEXT2(_L8("\tDeviceProtocol is: 0x%02x"), aDeviceDescriptor.iDeviceProtocol);
   882 	OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP6, "CUsbDevice::PrintDescriptor;iMaxPacketSize=0x%02x", aDeviceDescriptor.iMaxPacketSize );
   777 	LOGTEXT2(_L8("\tiMaxPacketSize is: 0x%02x"), aDeviceDescriptor.iMaxPacketSize);
   883 	
   778 	
   884 	OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP7, "CUsbDevice::PrintDescriptor;iIdVendor=0x%04x", aDeviceDescriptor.iIdVendor );
   779 	LOGTEXT2(_L8("\tVendorId is: 0x%04x"), aDeviceDescriptor.iIdVendor);
   885 	OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP8, "CUsbDevice::PrintDescriptor;iProductId=0x%04x", aDeviceDescriptor.iProductId );
   780 	LOGTEXT2(_L8("\tProductId is: 0x%04x"), aDeviceDescriptor.iIdProduct);
   886 	OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP9, "CUsbDevice::PrintDescriptor;iBcdDevice=0x%04x", aDeviceDescriptor.iBcdDevice );
   781 	LOGTEXT2(_L8("\tBcdDevice is: 0x%04x"), aDeviceDescriptor.iBcdDevice);
   887 	
   782 
   888 	OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP10, "CUsbDevice::PrintDescriptor;iManufacturer=0x%04x", aDeviceDescriptor.iManufacturer );
   783 	LOGTEXT2(_L8("\tiManufacturer is: 0x%04x"), aDeviceDescriptor.iManufacturer);
   889 	OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP11, "CUsbDevice::PrintDescriptor;iSerialNumber=0x%04x", aDeviceDescriptor.iSerialNumber );
   784 	LOGTEXT2(_L8("\tiSerialNumber is: 0x%04x"), aDeviceDescriptor.iSerialNumber);
   890 	OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP12, "CUsbDevice::PrintDescriptor;iNumConfigurations=0x%04x", aDeviceDescriptor.iNumConfigurations );	
   785 	LOGTEXT2(_L8("\tiNumConfigurations is: 0x%04x"), aDeviceDescriptor.iNumConfigurations);
   891 	}
   786 	}
   892 #endif
   787 #endif
   893 //
   788 //
   894 void CUsbDevice::SetDeviceDescriptorL()
   789 void CUsbDevice::SetDeviceDescriptorL()
   895 /**
   790 /**
   896  * Modifies the USB device descriptor.
   791  * Modifies the USB device descriptor.
   897  */
   792  */
   898 	{
   793 	{
   899 	OstTraceFunctionEntry0( CUSBDEVICE_SETDEVICEDESCRIPTORL_ENTRY );
   794 	LOG_FUNC
   900 
   795 
   901 #if !defined(__OVER_DUMMYUSBDI__) && !defined(__WINS__)
   796 #ifndef __WINS__
   902 
   797 
   903 	TInt desSize = 0;
   798 	TInt desSize = 0;
   904 	iLdd.GetDeviceDescriptorSize(desSize);
   799 	iLdd.GetDeviceDescriptorSize(desSize);
   905 	OstTrace1( TRACE_NORMAL, CUSBDEVICE_SETDEVICEDESCRIPTORL, "CUsbDevice::SetDeviceDescriptorL;UDeviceDescriptorSize = %d", desSize );
   800 	LOGTEXT2(_L8("UDeviceDescriptorSize = %d"), desSize);
   906 	HBufC8* deviceBuf = HBufC8::NewLC(desSize);
   801 	HBufC8* deviceBuf = HBufC8::NewLC(desSize);
   907 	TPtr8   devicePtr = deviceBuf->Des();
   802 	TPtr8   devicePtr = deviceBuf->Des();
   908 	devicePtr.SetLength(0);
   803 	devicePtr.SetLength(0);
   909 
   804 
   910 	TInt ret = iLdd.GetDeviceDescriptor(devicePtr);
   805 	TInt ret = iLdd.GetDeviceDescriptor(devicePtr);
   911 
   806 
   912 	if (ret != KErrNone)
   807 	if (ret != KErrNone)
   913 		{
   808 		{
   914 		OstTrace1( TRACE_NORMAL, CUSBDEVICE_SETDEVICEDESCRIPTORL_DUP1, "CUsbDevice::SetDeviceDescriptorL;Unable to fetch device descriptor. Error: %d", ret );
   809 		LOGTEXT2(_L8("Unable to fetch device descriptor. Error: %d"), ret);
   915 		User::Leave(ret);
   810 		LEAVEL(ret);
   916 		}
   811 		}
   917 
   812 
   918 	TUsbDeviceDescriptor* deviceDescriptor = reinterpret_cast<TUsbDeviceDescriptor*>(
   813 	TUsbDeviceDescriptor* deviceDescriptor = reinterpret_cast<TUsbDeviceDescriptor*>(
   919 		const_cast<TUint8*>(devicePtr.Ptr()));
   814 		const_cast<TUint8*>(devicePtr.Ptr()));
   920 
   815 
   924 	// Create an empty descriptor to allow the settings
   819 	// Create an empty descriptor to allow the settings
   925 	// to be read in from the resource file
   820 	// to be read in from the resource file
   926 	TUsbDeviceDescriptor descriptor;
   821 	TUsbDeviceDescriptor descriptor;
   927 	TUsbDeviceDescriptor* deviceDescriptor = &descriptor;
   822 	TUsbDeviceDescriptor* deviceDescriptor = &descriptor;
   928 	
   823 	
   929 #endif // __OVER_DUMMYUSBDI__ && _WINS_
   824 #endif // __WINS__
   930 
   825 
   931 	if (iPersonalityCfged)
   826 	if (iPersonalityCfged)
   932 		{
   827 		{
   933 		SetUsbDeviceSettingsFromPersonalityL(*deviceDescriptor);		
   828 		SetUsbDeviceSettingsFromPersonalityL(*deviceDescriptor);		
   934 		}
   829 		}
   935 	else
   830 	else
   936 		{
   831 		{
   937         OstTrace0( TRACE_NORMAL, CUSBDEVICE_SETDEVICEDESCRIPTORL_DUP3, 
   832 	SetUsbDeviceSettingsL(*deviceDescriptor);
   938                 "CUsbDevice::SetDeviceDescriptorL;USB configuration is not read" );
   833 		}
   939         User::Leave(KErrNotFound);
   834 	
   940 		}
       
   941 	
       
   942 #ifndef __OVER_DUMMYUSBDI__
       
   943 #ifndef __WINS__
   835 #ifndef __WINS__
   944 	ret = iLdd.SetDeviceDescriptor(devicePtr);
   836 	ret = iLdd.SetDeviceDescriptor(devicePtr);
   945 
   837 
   946 	if (ret != KErrNone)
   838 	if (ret != KErrNone)
   947 		{
   839 		{
   948 		OstTrace1( TRACE_NORMAL, CUSBDEVICE_SETDEVICEDESCRIPTORL_DUP2, "CUsbDevice::SetDeviceDescriptorL;Unable to set device descriptor. Error: %d", ret );
   840 		LOGTEXT2(_L8("Unable to set device descriptor. Error: %d"), ret);
   949 		User::Leave(ret);
   841 		LEAVEL(ret);
   950 		}
   842 		}
   951 
   843 
   952 	CleanupStack::PopAndDestroy(deviceBuf);
   844 	CleanupStack::PopAndDestroy(deviceBuf);
   953 
   845 
   954 #endif
   846 #endif // __WINS__
   955 #endif // __OVER_DUMMYUSBDI__
       
   956 	OstTraceFunctionExit0( CUSBDEVICE_SETDEVICEDESCRIPTORL_EXIT );
       
   957 	}
   847 	}
   958 
   848 
   959 void CUsbDevice::SetUsbDeviceSettingsDefaultsL(CUsbDevice::TUsbDeviceDescriptor& aDeviceDescriptor)
   849 void CUsbDevice::SetUsbDeviceSettingsDefaultsL(CUsbDevice::TUsbDeviceDescriptor& aDeviceDescriptor)
   960 /**
   850 /**
   961  * Set the device settings defaults, as per the non-resource
   851  * Set the device settings defaults, as per the non-resource
   966 	{
   856 	{
   967 	aDeviceDescriptor.iDeviceClass		= KUsbDefaultDeviceClass;
   857 	aDeviceDescriptor.iDeviceClass		= KUsbDefaultDeviceClass;
   968 	aDeviceDescriptor.iDeviceSubClass	= KUsbDefaultDeviceSubClass;
   858 	aDeviceDescriptor.iDeviceSubClass	= KUsbDefaultDeviceSubClass;
   969 	aDeviceDescriptor.iDeviceProtocol	= KUsbDefaultDeviceProtocol;
   859 	aDeviceDescriptor.iDeviceProtocol	= KUsbDefaultDeviceProtocol;
   970 	aDeviceDescriptor.iIdVendor			= KUsbDefaultVendorId;
   860 	aDeviceDescriptor.iIdVendor			= KUsbDefaultVendorId;
   971 	aDeviceDescriptor.iProductId		= KUsbDefaultProductId;
   861 	aDeviceDescriptor.iIdProduct		= KUsbDefaultProductId;
   972 	}
   862 	}
   973 
   863 
   974 void CUsbDevice::SetUsbDeviceSettingsFromPersonalityL(CUsbDevice::TUsbDeviceDescriptor& aDeviceDescriptor)
   864 void CUsbDevice::SetUsbDeviceSettingsL(CUsbDevice::TUsbDeviceDescriptor& aDeviceDescriptor)
   975 /**
   865 /**
   976  * Configure the USB device from the current personality.
   866  * Configure the USB device, reading in the settings from a
       
   867  * resource file where possible.
   977  *
   868  *
   978  * @param aDeviceDescriptor The device descriptor for the USB device
   869  * @param aDeviceDescriptor The device descriptor for the USB device
   979  */
   870  */
   980 	{
   871 	{
   981 	OstTraceFunctionEntry0( CUSBDEVICE_SETUSBDEVICESETTINGSFROMPERSONALITYL_ENTRY );
   872 	LOG_FUNC
   982 
   873 
   983 	// First, use the default values
   874 	// First, use the default values
   984 	OstTrace0( TRACE_NORMAL, CUSBDEVICE_SETUSBDEVICESETTINGSFROMPERSONALITYL, "CUsbDevice::SetUsbDeviceSettingsFromPersonalityL;Setting default values for the configuration" );
   875 	LOGTEXT(_L8("Setting default values for the configuration"));
   985 	SetUsbDeviceSettingsDefaultsL(aDeviceDescriptor);
   876 	SetUsbDeviceSettingsDefaultsL(aDeviceDescriptor);
   986 
   877 
   987 	// Now try to get the configuration from the current personality
   878 	// Now try to get the configuration from the resource file
   988     aDeviceDescriptor.iDeviceClass          = iCurrentPersonality->DeviceClass();
   879 	RFs fs;
   989     aDeviceDescriptor.iDeviceSubClass       = iCurrentPersonality->DeviceSubClass();
   880 	LEAVEIFERRORL(fs.Connect());
   990     aDeviceDescriptor.iDeviceProtocol       = iCurrentPersonality->DeviceProtocol();
   881 	CleanupClosePushL(fs);
   991     aDeviceDescriptor.iIdVendor             = iDeviceConfiguration.iVendorId;
   882 
   992     aDeviceDescriptor.iProductId            = iCurrentPersonality->ProductId();
   883 	RResourceFile resource;
   993     aDeviceDescriptor.iBcdDevice            = iCurrentPersonality->BcdDevice();
   884 	TRAPD(err, resource.OpenL(fs, KUsbManagerResource));
   994     aDeviceDescriptor.iNumConfigurations    = iCurrentPersonality->NumConfigurations();	
   885 	LOGTEXT2(_L8("Opened resource file with error %d"), err);
   995 	
   886 
   996 
   887 	if (err != KErrNone)
   997 #ifndef __OVER_DUMMYUSBDI__
   888 		{
       
   889 		LOGTEXT(_L8("Unable to open resource file: using default settings"));
       
   890 		CleanupStack::PopAndDestroy(&fs);
       
   891 		return;
       
   892 		}
       
   893 
       
   894 	CleanupClosePushL(resource);
       
   895 
       
   896 	resource.ConfirmSignatureL(KUsbManagerResourceVersion);
       
   897 
       
   898 	HBufC8* id = resource.AllocReadLC(USB_CONFIG);
       
   899 
       
   900 	// The format of the USB resource structure is:
       
   901 	//
       
   902 	//	STRUCT usb_configuration
       
   903 	//		{
       
   904 	//		WORD	vendorId		= 0x0e22;
       
   905 	//		WORD	productId		= 0x000b;
       
   906 	//		WORD	bcdDevice		= 0x0000;
       
   907 	//		LTEXT	manufacturer	= "Symbian Ltd.";
       
   908 	//		LTEXT	product			= "Symbian OS";
       
   909 	//		}
       
   910 	//
       
   911 	// Note that the resource must be read in this order!
       
   912 	
       
   913 	TResourceReader reader;
       
   914 	reader.SetBuffer(id);
       
   915 
       
   916 	aDeviceDescriptor.iIdVendor = static_cast<TUint16>(reader.ReadUint16());
       
   917 	aDeviceDescriptor.iIdProduct = static_cast<TUint16>(reader.ReadUint16());
       
   918 	aDeviceDescriptor.iBcdDevice = static_cast<TUint16>(reader.ReadUint16());
       
   919 
       
   920 	// Try to read device and manufacturer name from new SysUtil API
       
   921 	TPtrC16 sysUtilModelName;
       
   922 	TPtrC16 sysUtilManuName;
       
   923 	
       
   924 	// This method returns ownership.
       
   925 	CDeviceTypeInformation* deviceInfo = SysUtil::GetDeviceTypeInfoL();
       
   926 	CleanupStack::PushL(deviceInfo);
       
   927 	TInt gotSysUtilModelName = deviceInfo->GetModelName(sysUtilModelName);
       
   928 	TInt gotSysUtilManuName = deviceInfo->GetManufacturerName(sysUtilManuName);
       
   929 	
       
   930 	TPtrC manufacturerString = reader.ReadTPtrC();
       
   931 	TPtrC productString = reader.ReadTPtrC();
       
   932 	
       
   933 	// If we succesfully read the manufacturer or device name from SysUtil API
       
   934 	// then set these results, otherwise use the values defined in resource file
   998 #ifndef __WINS__
   935 #ifndef __WINS__
   999 	TInt err = iLdd.SetManufacturerStringDescriptor(*(iDeviceConfiguration.iManufacturerName));
   936 	if (gotSysUtilManuName == KErrNone)
  1000 	if(err < 0)
   937 		{
  1001 	    {
   938 		LEAVEIFERRORL(iLdd.SetManufacturerStringDescriptor(sysUtilManuName));
  1002         OstTrace1( TRACE_NORMAL, CUSBDEVICE_SETUSBDEVICESETTINGSFROMPERSONALITYL_DUP7, "CUsbDevice::SetUsbDeviceSettingsFromPersonalityL;iLdd.SetManufacturerStringDescriptor(*(iCurrentPersonality->Manufacturer())) with error=%d", err );
   939 		}
  1003         User::Leave(err);
   940 	else
  1004 	    }  
   941 		{
  1005 	err = iLdd.SetProductStringDescriptor(*(iDeviceConfiguration.iProductName));
   942 		LEAVEIFERRORL(iLdd.SetManufacturerStringDescriptor(manufacturerString));
  1006     if(err < 0)
   943 		}
  1007         {
   944 
  1008         OstTrace1( TRACE_NORMAL, CUSBDEVICE_SETUSBDEVICESETTINGSFROMPERSONALITYL_DUP6, "CUsbDevice::SetUsbDeviceSettingsFromPersonalityL;iLdd.SetProductStringDescriptor(*(iCurrentPersonality->Product())) with error=%d", err );
   945 	if (gotSysUtilModelName == KErrNone)
  1009         User::Leave(err);
   946 		{
  1010         }
   947 		LEAVEIFERRORL(iLdd.SetProductStringDescriptor(sysUtilModelName));
  1011 
   948 		}
  1012 
   949 	else
       
   950 		{
       
   951 		LEAVEIFERRORL(iLdd.SetProductStringDescriptor(productString));
       
   952 		}
       
   953 #endif // __WINS__
       
   954 
       
   955 #ifdef __FLOG_ACTIVE
       
   956 	PrintDescriptor(aDeviceDescriptor);	
       
   957 	TBuf8<KUsbStringDescStringMaxSize> narrowString;
       
   958 	narrowString.Copy(manufacturerString);
       
   959 	LOGTEXT2(_L8("Manufacturer is: '%S'"), &narrowString);
       
   960 	narrowString.Copy(productString);
       
   961 	LOGTEXT2(_L8("Product is: '%S'"), &narrowString);
       
   962 #endif // __FLOG_ACTIVE
       
   963 
       
   964 #ifndef __WINS__	
  1013 	//Read the published serial number. The key is the UID KUidUsbmanServer = 0x101FE1DB
   965 	//Read the published serial number. The key is the UID KUidUsbmanServer = 0x101FE1DB
  1014 	TBuf16<KUsbStringDescStringMaxSize> serNum;
   966 	TBuf16<KUsbStringDescStringMaxSize> serNum;
  1015 	TInt r = RProperty::Get(KUidSystemCategory,0x101FE1DB,serNum);
   967 	TInt r = RProperty::Get(KUidSystemCategory,0x101FE1DB,serNum);
  1016 	if(r==KErrNone)
   968 	if(r==KErrNone)
  1017 		{
   969 		{
  1018 #ifdef _DEBUG
   970 #ifdef __FLOG_ACTIVE
  1019 		OstTraceExt1( TRACE_NORMAL, CUSBDEVICE_SETUSBDEVICESETTINGSFROMPERSONALITYL_DUP1, "CUsbDevice::SetUsbDeviceSettingsFromPersonalityL;Setting published SerialNumber: %S", serNum );
   971 		TBuf8<KUsbStringDescStringMaxSize> narrowString;
  1020 #endif//_DEBUG
   972 		narrowString.Copy(serNum);
       
   973 		LOGTEXT2(_L8("Setting published SerialNumber: %S"), &narrowString);
       
   974 #endif // __FLOG_ACTIVE
  1021 		//USB spec doesn't give any constraints on what constitutes a valid serial number.
   975 		//USB spec doesn't give any constraints on what constitutes a valid serial number.
  1022 		//As long as it is a string descriptor it is valid.
   976 		//As long as it is a string descriptor it is valid.
  1023 		err = iLdd.SetSerialNumberStringDescriptor(serNum);	
   977 		LEAVEIFERRORL(iLdd.SetSerialNumberStringDescriptor(serNum));	
  1024 		if(err < 0)
   978 		}
  1025 		    {
   979 #ifdef __FLOG_ACTIVE
  1026             OstTrace1( TRACE_NORMAL, CUSBDEVICE_SETUSBDEVICESETTINGSFROMPERSONALITYL_DUP3, "CUsbDevice::SetUsbDeviceSettingsFromPersonalityL;iLdd.SetSerialNumberStringDescriptor(serNum) with error=%d", err );
       
  1027             User::Leave(err);
       
  1028 		    }
       
  1029 		}
       
  1030 #ifdef _DEBUG
       
  1031 	else
   980 	else
  1032 		{
   981 		{
  1033 		OstTrace0( TRACE_NORMAL, CUSBDEVICE_SETUSBDEVICESETTINGSFROMPERSONALITYL_DUP2, "CUsbDevice::SetUsbDeviceSettingsFromPersonalityL;SerialNumber has not been published" );	
   982 		LOGTEXT(_L8("SerialNumber has not been published"));	
  1034 		}
   983 		}
  1035 #endif // _DEBUG
   984 #endif // __FLOG_ACTIVE
  1036 
   985 #endif // __WINS__
  1037 #endif
   986 
  1038 #endif // __OVER_DUMMYUSBDI__
   987 
  1039 
   988 	CleanupStack::PopAndDestroy(4, &fs); //  deviceInfo, id, resource, fs
  1040 
   989 	}
  1041 #ifdef _DEBUG
   990 
       
   991 void CUsbDevice::SetUsbDeviceSettingsFromPersonalityL(CUsbDevice::TUsbDeviceDescriptor& aDeviceDescriptor)
       
   992 /**
       
   993  * Configure the USB device from the current personality.
       
   994  *
       
   995  * @param aDeviceDescriptor The device descriptor for the USB device
       
   996  */
       
   997 	{
       
   998 	LOG_FUNC
       
   999 
       
  1000 	// First, use the default values
       
  1001 	LOGTEXT(_L8("Setting default values for the configuration"));
       
  1002 	SetUsbDeviceSettingsDefaultsL(aDeviceDescriptor);
       
  1003 
       
  1004 	// Now try to get the configuration from the current personality
       
  1005 	const CUsbDevice::TUsbDeviceDescriptor& deviceDes = iCurrentPersonality->DeviceDescriptor();
       
  1006 	aDeviceDescriptor.iDeviceClass			= deviceDes.iDeviceClass;
       
  1007 	aDeviceDescriptor.iDeviceSubClass		= deviceDes.iDeviceSubClass;
       
  1008 	aDeviceDescriptor.iDeviceProtocol		= deviceDes.iDeviceProtocol;
       
  1009 	aDeviceDescriptor.iIdVendor				= deviceDes.iIdVendor;
       
  1010 	aDeviceDescriptor.iIdProduct			= deviceDes.iIdProduct;
       
  1011 	aDeviceDescriptor.iBcdDevice			= deviceDes.iBcdDevice;
       
  1012 	aDeviceDescriptor.iSerialNumber			= deviceDes.iSerialNumber;
       
  1013 	aDeviceDescriptor.iNumConfigurations	= deviceDes.iNumConfigurations;
       
  1014 
       
  1015 #ifndef __WINS__
       
  1016 	LEAVEIFERRORL(iLdd.SetManufacturerStringDescriptor(*(iCurrentPersonality->Manufacturer())));
       
  1017 	LEAVEIFERRORL(iLdd.SetProductStringDescriptor(*(iCurrentPersonality->Product())));
       
  1018 
       
  1019 	//Read the published serial number. The key is the UID KUidUsbmanServer = 0x101FE1DB
       
  1020 	TBuf16<KUsbStringDescStringMaxSize> serNum;
       
  1021 	TInt r = RProperty::Get(KUidSystemCategory,0x101FE1DB,serNum);
       
  1022 	if(r==KErrNone)
       
  1023 		{
       
  1024 #ifdef __FLOG_ACTIVE
       
  1025 		TBuf8<KUsbStringDescStringMaxSize> narrowString;
       
  1026 		narrowString.Copy(serNum);
       
  1027 		LOGTEXT2(_L8("Setting published SerialNumber: %S"), &narrowString);
       
  1028 #endif // __FLOG_ACTIVE
       
  1029 		//USB spec doesn't give any constraints on what constitutes a valid serial number.
       
  1030 		//As long as it is a string descriptor it is valid.
       
  1031 		LEAVEIFERRORL(iLdd.SetSerialNumberStringDescriptor(serNum));	
       
  1032 		}
       
  1033 #ifdef __FLOG_ACTIVE
       
  1034 	else
       
  1035 		{
       
  1036 		LOGTEXT(_L8("SerialNumber has not been published"));	
       
  1037 		}
       
  1038 #endif // __FLOG_ACTIVE
       
  1039 #endif // __WINS__
       
  1040 
       
  1041 
       
  1042 #ifdef __FLOG_ACTIVE
  1042 	PrintDescriptor(aDeviceDescriptor);		
  1043 	PrintDescriptor(aDeviceDescriptor);		
  1043 
  1044 
  1044 #ifndef __OVER_DUMMYUSBDI__
       
  1045 #ifndef __WINS__
  1045 #ifndef __WINS__
  1046 	TBuf16<KUsbStringDescStringMaxSize> wideString;
  1046 	TBuf16<KUsbStringDescStringMaxSize> wideString;
  1047 	TInt tmp = iLdd.GetConfigurationStringDescriptor(wideString);	
  1047 	TBuf8<KUsbStringDescStringMaxSize> narrowString;
  1048 	if(tmp < 0)
  1048 
  1049 	    {
  1049 	LEAVEIFERRORL(iLdd.GetConfigurationStringDescriptor(wideString));
  1050         OstTrace1( TRACE_NORMAL, CUSBDEVICE_SETUSBDEVICESETTINGSFROMPERSONALITYL_DUP5, "CUsbDevice::SetUsbDeviceSettingsFromPersonalityL;iLdd.GetConfigurationStringDescriptor(wideString) with error=%d", tmp );
  1050 	narrowString.Copy(wideString);
  1051         User::Leave(tmp);
  1051 	LOGTEXT2(_L8("Configuration is: '%S'"), &narrowString);
  1052 	    }
  1052 #endif // __WINS__
  1053 	OstTraceExt1( TRACE_NORMAL, CUSBDEVICE_SETUSBDEVICESETTINGSFROMPERSONALITYL_DUP4, "CUsbDevice::SetUsbDeviceSettingsFromPersonalityL;Configuration is:%S", wideString );
  1053 
  1054 #endif
  1054 #endif // __FLOG_ACTIVE
  1055 #endif // __OVER_DUMMYUSBDI__
       
  1056 
       
  1057 #endif // _DEBUG
       
  1058 	}
  1055 	}
  1059 	
  1056 	
  1060 void CUsbDevice::TryStartL(TInt aPersonalityId)
  1057 void CUsbDevice::TryStartL(TInt aPersonalityId)
  1061 /**
  1058 /**
  1062  * Start all USB classes associated with the personality identified
  1059  * Start all USB classes associated with the personality identified
  1064  * interface.
  1061  * interface.
  1065  *
  1062  *
  1066  * @param aPersonalityId a personality id
  1063  * @param aPersonalityId a personality id
  1067  */
  1064  */
  1068 	{
  1065 	{
  1069 	OstTraceFunctionEntry0( CUSBDEVICE_TRYSTARTL_ENTRY );
  1066 	LOG_FUNC
  1070 	SetCurrentPersonalityL(aPersonalityId);
  1067 	SetCurrentPersonalityL(aPersonalityId);
  1071 	
  1068 	
  1072 	SelectClassControllersL();
  1069 	SelectClassControllersL();
  1073 	SetServiceState(EUsbServiceStarting);
  1070 	SetServiceState(EUsbServiceStarting);
  1074 
  1071 
  1075 	TRAPD(err, SetDeviceDescriptorL());
  1072 	TRAPD(err, SetDeviceDescriptorL());
  1076 	if ( err != KErrNone )
  1073 	if ( err != KErrNone )
  1077 		{
  1074 		{
  1078 		SetServiceState(EUsbServiceIdle);	
  1075 		SetServiceState(EUsbServiceIdle);
  1079 		OstTrace1( TRACE_NORMAL, CUSBDEVICE_TRYSTARTL, "CUsbDevice::TryStartL;leave with error=%d", err );
  1076 		LEAVEL(err);		
  1080 		User::Leave(err);		
       
  1081 		}
  1077 		}
  1082 
  1078 
  1083 	iLastError = KErrNone;
  1079 	iLastError = KErrNone;
  1084 	StartCurrentClassController();
  1080 	StartCurrentClassController();
  1085  	OstTraceFunctionExit0( CUSBDEVICE_TRYSTARTL_EXIT );
       
  1086  	}
  1081  	}
  1087  	
  1082  	
  1088 TInt CUsbDevice::CurrentPersonalityId() const
  1083 TInt CUsbDevice::CurrentPersonalityId() const
  1089 /**
  1084 /**
  1090  * @return the current personality id
  1085  * @return the current personality id
  1091  */
  1086  */
  1092  	{
  1087  	{
  1093 	OstTraceFunctionEntry0( CUSBDEVICE_CURRENTPERSONALITYID_ENTRY );
  1088 	LOG_FUNC
  1094  	return iCurrentPersonality->PersonalityId();
  1089  	return iCurrentPersonality->PersonalityId();
  1095  	}
  1090  	}
  1096  	
  1091  	
  1097 const RPointerArray<CPersonality>& CUsbDevice::Personalities() const
  1092 const RPointerArray<CPersonality>& CUsbDevice::Personalities() const
  1098 /**
  1093 /**
  1099  * @return a const reference to RPointerArray<CPersonality>
  1094  * @return a const reference to RPointerArray<CPersonality>
  1100  */
  1095  */
  1101  	{
  1096  	{
  1102 	OstTraceFunctionEntry0( CUSBDEVICE_PERSONALITIES_ENTRY );
  1097 	LOG_FUNC
  1103  	return iSupportedPersonalities;
  1098  	return iSupportedPersonalities;
  1104  	} 
  1099  	} 
  1105  	
  1100  	
  1106 const CPersonality* CUsbDevice::GetPersonality(TInt aPersonalityId) const
  1101 const CPersonality* CUsbDevice::GetPersonality(TInt aPersonalityId) const
  1107 /**
  1102 /**
  1110  * @param aPeraonalityId a personality id
  1105  * @param aPeraonalityId a personality id
  1111  * @return a const pointer to the CPersonality object whose id is aPersonalityId if found
  1106  * @return a const pointer to the CPersonality object whose id is aPersonalityId if found
  1112  * or 0 otherwise.
  1107  * or 0 otherwise.
  1113  */
  1108  */
  1114 	{
  1109 	{
  1115 	OstTraceFunctionEntry0( CUSBDEVICE_GETPERSONALITY_ENTRY );
  1110 	LOG_FUNC
  1116 	
  1111 	
  1117 	TInt count = iSupportedPersonalities.Count();
  1112 	TInt count = iSupportedPersonalities.Count();
  1118 	for (TInt i = 0; i < count; i++)
  1113 	for (TInt i = 0; i < count; i++)
  1119 		{
  1114 		{
  1120 		if (iSupportedPersonalities[i]->PersonalityId() == aPersonalityId)
  1115 		if (iSupportedPersonalities[i]->PersonalityId() == aPersonalityId)
  1121 			{
  1116 			{
  1122 			OstTraceFunctionExit0( CUSBDEVICE_GETPERSONALITY_EXIT );
       
  1123 			return iSupportedPersonalities[i];
  1117 			return iSupportedPersonalities[i];
  1124 			}
  1118 			}
  1125 		}
  1119 		}
  1126 	
  1120 	
  1127 	OstTraceFunctionExit0( CUSBDEVICE_GETPERSONALITY_EXIT_DUP1 );
       
  1128 	return 0;
  1121 	return 0;
  1129 	}
  1122 	}
  1130 	
  1123 	
  1131 void CUsbDevice::SetCurrentPersonalityL(TInt aPersonalityId)
  1124 void CUsbDevice::SetCurrentPersonalityL(TInt aPersonalityId)
  1132 /**
  1125 /**
  1133  * Sets the current personality to the personality with id aPersonalityId
  1126  * Sets the current personality to the personality with id aPersonalityId
  1134  */
  1127  */
  1135  	{
  1128  	{
  1136 	OstTraceFunctionEntry0( CUSBDEVICE_SETCURRENTPERSONALITYL_ENTRY );
  1129 	LOG_FUNC
  1137 	const CPersonality* personality = GetPersonality(aPersonalityId);
  1130 	const CPersonality* personality = GetPersonality(aPersonalityId);
  1138 	if (!personality)
  1131 	if (!personality)
  1139 		{
  1132 		{
  1140 		OstTrace0( TRACE_NORMAL, CUSBDEVICE_SETCURRENTPERSONALITYL, "CUsbDevice::SetCurrentPersonalityL;Personality id not found" );
  1133 		LOGTEXT(_L8("Personality id not found"));
  1141 		User::Leave(KErrNotFound);
  1134 		LEAVEL(KErrNotFound);
  1142 		}
  1135 		}
  1143 		
  1136 		
  1144 	iCurrentPersonality = personality;
  1137 	iCurrentPersonality = personality;
  1145  	OstTraceFunctionExit0( CUSBDEVICE_SETCURRENTPERSONALITYL_EXIT );
       
  1146  	}
  1138  	}
  1147 	
  1139 	
  1148 void CUsbDevice::ValidatePersonalitiesL()
  1140 void CUsbDevice::ValidatePersonalitiesL()
  1149 /**
  1141 /**
  1150  * Verifies all class controllers associated with each personality are loaded.
  1142  * Verifies all class controllers associated with each personality are loaded.
  1151  * Leave if validation fails.
  1143  * Leave if validation fails.
  1152  */
  1144  */
  1153 	{
  1145 	{
  1154 	OstTraceFunctionEntry0( CUSBDEVICE_VALIDATEPERSONALITIESL_ENTRY );
  1146 	LOG_FUNC
  1155 
  1147 
  1156 	TInt personalityCount = iSupportedPersonalities.Count();
  1148 	TInt personalityCount = iSupportedPersonalities.Count();
  1157 	for (TInt i = 0; i < personalityCount; i++)
  1149 	for (TInt i = 0; i < personalityCount; i++)
  1158 		{
  1150 		{
  1159 		const RArray<CPersonalityConfigurations::TUsbClasses>& classes = iSupportedPersonalities[i]->SupportedClasses();
  1151 		const RArray<TUid>& classUids = iSupportedPersonalities[i]->SupportedClasses();
  1160 		TInt uidCount = classes.Count();
  1152 		TInt uidCount = classUids.Count();
  1161 		for (TInt j = 0; j < uidCount; j++)	
  1153 		for (TInt j = 0; j < uidCount; j++)	
  1162 			{
  1154 			{
  1163 			TInt ccCount = iSupportedClassUids.Count();
  1155 			TInt ccCount = iSupportedClassUids.Count();
  1164 			TInt k;
  1156 			TInt k;
  1165 		    OstTrace1( TRACE_NORMAL, CUSBDEVICE_VALIDATEPERSONALITIESL_DUP1, "CUsbDevice::ValidatePersonalitiesL;iSupportedClassUids Count = %d", ccCount );
       
  1166 			for (k = 0; k < ccCount; k++)
  1157 			for (k = 0; k < ccCount; k++)
  1167 				{
  1158 				{
  1168                 OstTraceExt4( TRACE_NORMAL, CUSBDEVICE_VALIDATEPERSONALITIESL_DUP2, "CUsbDevice::ValidatePersonalitiesL;iSupportedClassUids %d %x classes %d %x", k, iSupportedClassUids[k].iUid, j, classes[j].iClassUid.iUid );
  1159 				if (iSupportedClassUids[k] == classUids[j])
  1169 				if (iSupportedClassUids[k] == classes[j].iClassUid)
       
  1170 					{
  1160 					{
  1171 					break;
  1161 					break;
  1172 					}
  1162 					}
  1173 				}
  1163 				}
  1174 			if (k == ccCount)
  1164 			if (k == ccCount)
  1175 				{
  1165 				{
  1176 				OstTrace0( TRACE_NORMAL, CUSBDEVICE_VALIDATEPERSONALITIESL, "CUsbDevice::ValidatePersonalitiesL;personality validation failed" );
  1166 				LOGTEXT(_L8("personality validation failed"));
  1177 				User::Leave(KErrAbort);
  1167 				LEAVEL(KErrAbort);
  1178 				}					
  1168 				}					
  1179 			}	
  1169 			}	
  1180 		}
  1170 		}
  1181 	OstTraceFunctionExit0( CUSBDEVICE_VALIDATEPERSONALITIESL_EXIT );
       
  1182 	}
  1171 	}
  1183 /**
  1172 /**
  1184 Converts text string with UIDs to array of Uint
  1173 Converts text string with UIDs to array of Uint
  1185 
  1174 
  1186 If there is an error during the conversion, this function will not clean-up,
  1175 If there is an error during the conversion, this function will not clean-up,
  1190 @param aUIDs On return array of UIDs parsed from the input string
  1179 @param aUIDs On return array of UIDs parsed from the input string
  1191 @panic EUidArrayNotEmpty if the RArray passed in is not empty
  1180 @panic EUidArrayNotEmpty if the RArray passed in is not empty
  1192 */
  1181 */
  1193 void CUsbDevice::ConvertUidsL(const TDesC& aStr, RArray<TUint>& aUidArray)	
  1182 void CUsbDevice::ConvertUidsL(const TDesC& aStr, RArray<TUint>& aUidArray)	
  1194 	{
  1183 	{
  1195     OstTraceFunctionEntry0( CUSBDEVICE_CONVERTUIDSL_ENTRY );
       
  1196 	// Function assumes that aUIDs is empty
  1184 	// Function assumes that aUIDs is empty
  1197 #ifdef _DEBUG
  1185 	__ASSERT_DEBUG( aUidArray.Count() == 0, _USB_PANIC(KUsbDevicePanicCategory, EUidArrayNotEmpty) );
  1198     if(aUidArray.Count() != 0)
       
  1199         {
       
  1200         OstTrace1( TRACE_FATAL, CUSBDEVICE_CONVERTUIDSL, "CUsbDevice::ConvertUidsL;Panic reason=%d", EUidArrayNotEmpty );
       
  1201         User::Panic(KUsbDevicePanicCategory, EUidArrayNotEmpty);
       
  1202         }
       
  1203 #endif
       
  1204 
  1186 
  1205 	TLex input(aStr);
  1187 	TLex input(aStr);
  1206 
  1188 
  1207 	// Scan through string to find UIDs
  1189 	// Scan through string to find UIDs
  1208 	// Need to do this at least once, as no UID in the string is an error
  1190 	// Need to do this at least once, as no UID in the string is an error
  1214 			input.Inc();	
  1196 			input.Inc();	
  1215 			}
  1197 			}
  1216 
  1198 
  1217 		// Convert and add to array
  1199 		// Convert and add to array
  1218 		TUint val;
  1200 		TUint val;
  1219 		TInt err = input.Val(val,EHex);
  1201 		LEAVEIFERRORL(input.Val(val,EHex));
  1220 		if(err < 0)
       
  1221 		    {
       
  1222             OstTrace1( TRACE_NORMAL, CUSBDEVICE_CONVERTUIDSL_DUP1, "CUsbDevice::ConvertUidsL;input.Val(val,EHex) with error=%d", err );
       
  1223             User::Leave(err);
       
  1224 		    }
       
  1225 		aUidArray.AppendL(val);
  1202 		aUidArray.AppendL(val);
  1226 		}
  1203 		}
  1227 	while (!input.Eos());	
  1204 	while (!input.Eos());	
  1228 	OstTraceFunctionExit0( CUSBDEVICE_CONVERTUIDSL_EXIT );
       
  1229 	}
  1205 	}
  1230 
  1206 
  1231 void CUsbDevice::ReadPersonalitiesL()
  1207 void CUsbDevice::ReadPersonalitiesL()
  1232     {    
  1208 /**
  1233     OstTraceFunctionEntry0( CUSBDEVICE_READPERSONALITIESL_ENTRY );
  1209  * Reads configured personalities from the resource file
  1234     TPtrC16 sysUtilModelName;
  1210  */
  1235     TPtrC16 sysUtilManuName;
  1211 	{
  1236     
  1212 	LOG_FUNC
  1237     iPersonalityCfged = EFalse;
  1213 	iPersonalityCfged = EFalse;
  1238     
  1214 	// Now try to connect to file server
  1239     iCenRepManager->ReadDeviceConfigurationL(iDeviceConfiguration);
  1215 	RFs fs;
  1240     
  1216 	LEAVEIFERRORL(fs.Connect());
  1241     iCenRepManager->ReadPersonalitiesL(iSupportedPersonalities);
  1217 	CleanupClosePushL(fs);
  1242     
  1218 
  1243     //update info for SetManufacturer & SetProduct
  1219 	TFileName resourceFileName;
  1244     CDeviceTypeInformation* deviceInfo = SysUtil::GetDeviceTypeInfoL();
  1220 	ResourceFileNameL(resourceFileName);
  1245     CleanupStack::PushL(deviceInfo);
  1221 	RResourceFile resource;
  1246     TInt gotSysUtilModelName = deviceInfo->GetModelName(sysUtilModelName);
  1222 	TRAPD(err, resource.OpenL(fs, resourceFileName));
  1247     TInt gotSysUtilManuName = deviceInfo->GetManufacturerName(sysUtilManuName);
  1223 	LOGTEXT2(_L8("Opened resource file with error %d"), err);
  1248     
  1224 
  1249     //To overlap info 
  1225 	if (err != KErrNone)
  1250     if (gotSysUtilManuName == KErrNone)
  1226 		{
  1251         {
  1227 		LOGTEXT(_L8("Unable to open resource file"));
  1252         iDeviceConfiguration.iManufacturerName->Des().Copy(sysUtilManuName); 
  1228 		CleanupStack::PopAndDestroy(&fs);
  1253         }
  1229 		return;
  1254         
  1230 		}
  1255     if (gotSysUtilModelName == KErrNone)
  1231 
  1256         {
  1232 	CleanupClosePushL(resource);
  1257         iDeviceConfiguration.iProductName->Des().Copy(sysUtilModelName);
  1233 
  1258         }
  1234 	TInt resourceVersion = resource.SignatureL();
  1259     CleanupStack::PopAndDestroy(deviceInfo);
  1235 	LOGTEXT2(_L8("Resource file signature is %d"), resourceVersion);
  1260     iPersonalityCfged = ETrue;
  1236 	// Check for the version is valid(EUsbManagerResourceVersionOne, EUsbManagerResourceVersionTwo
  1261     OstTraceFunctionExit0( CUSBDEVICE_READPERSONALITIESL_EXIT );
  1237 	// or EUsbManagerResourceVersionThree).
  1262     }
  1238 	if(resourceVersion > EUsbManagerResourceVersionThree)
       
  1239 		{
       
  1240 		LOGTEXT2(_L8("Version of resource file is valid (>%d)"), EUsbManagerResourceVersionThree);
       
  1241 		User::LeaveIfError(KErrNotSupported);
       
  1242 		}
       
  1243 	
       
  1244 	resource.ConfirmSignatureL(resourceVersion);
       
  1245 
       
  1246 	HBufC8* personalityBuf = 0;
       
  1247 	TRAPD(ret, personalityBuf = resource.AllocReadL(DEVICE_PERSONALITIES));
       
  1248 	// If personalities resource is not found, swallow the error and return
       
  1249 	// as no specified personalities is a valid configuration
       
  1250 	if (ret == KErrNotFound)
       
  1251 		{
       
  1252 		LOGTEXT(_L8("Personalities are not configured"));
       
  1253 		CleanupStack::PopAndDestroy(2, &fs); 
       
  1254 		return;
       
  1255 		}
       
  1256 	// Otherwise leave noisily if the AllocRead fails
       
  1257 	LEAVEIFERRORL(ret);
       
  1258 	CleanupStack::PushL(personalityBuf);
       
  1259 
       
  1260 	// The format of the USB resource structure is:
       
  1261 	//
       
  1262 	// 	STRUCT PERSONALITY
       
  1263 	//		{
       
  1264 	// 		WORD	bcdDeviceClass;
       
  1265 	// 		WORD	bcdDeviceSubClass;
       
  1266 	//		WORD 	protocol;
       
  1267 	//		WORD	numConfigurations;
       
  1268 	//		WORD 	vendorId;
       
  1269 	//		WORD 	productId;
       
  1270 	//		WORD 	bcdDevice;
       
  1271 	//		LTEXT 	manufacturer;
       
  1272 	//		LTEXT 	product;
       
  1273 	//		WORD 	id;					// personality id
       
  1274 	//		LTEXT	class_uids;	
       
  1275 	//		LTEXT 	description;		// personality description
       
  1276 	//     	LTEXT   detailedDescription;  //detailed description. This is in version 2
       
  1277 	//		LONG 	Property;
       
  1278 	//		}
       
  1279 	//
       
  1280 	// Note that the resource must be read in this order!
       
  1281 	
       
  1282 	TResourceReader reader;
       
  1283 	reader.SetBuffer(personalityBuf);
       
  1284 
       
  1285 	TUint16 personalityCount 	= static_cast<TUint16>(reader.ReadUint16());
       
  1286 	
       
  1287 	// Read the manufacturer and device name (product) here from SysUtil class
       
  1288 	TPtrC16 sysUtilModelName;
       
  1289 	TPtrC16 sysUtilManuName;
       
  1290 
       
  1291 	// This method returns ownership.
       
  1292 	CDeviceTypeInformation* deviceInfo = SysUtil::GetDeviceTypeInfoL();
       
  1293 	CleanupStack::PushL(deviceInfo);
       
  1294 	TInt gotSysUtilModelName = deviceInfo->GetModelName(sysUtilModelName);
       
  1295 	TInt gotSysUtilManuName = deviceInfo->GetManufacturerName(sysUtilManuName);
       
  1296 	
       
  1297 	for (TInt idx = 0; idx < personalityCount; idx++)
       
  1298 		{
       
  1299 		// read a personality 
       
  1300 		TUint8 	bDeviceClass 		= static_cast<TUint8>(reader.ReadUint8());
       
  1301 		TUint8 	bDeviceSubClass 	= static_cast<TUint8>(reader.ReadUint8());
       
  1302 		TUint8 	protocol 			= static_cast<TUint8>(reader.ReadUint8());
       
  1303 		TUint8 	numConfigurations	= static_cast<TUint8>(reader.ReadUint8());
       
  1304 		TUint16 vendorId			= static_cast<TUint16>(reader.ReadUint16());
       
  1305 		TUint16 productId			= static_cast<TUint16>(reader.ReadUint16());
       
  1306 		TUint16 bcdDevice			= static_cast<TUint16>(reader.ReadUint16());
       
  1307 		TPtrC	manufacturer		= reader.ReadTPtrC();
       
  1308 		TPtrC	product				= reader.ReadTPtrC();
       
  1309 		TUint16 id					= static_cast<TUint16>(reader.ReadUint16());
       
  1310 		TPtrC	uidsStr				= reader.ReadTPtrC();
       
  1311 		TPtrC 	description			= reader.ReadTPtrC();
       
  1312 		
       
  1313 		RArray<TUint> uids;
       
  1314 		CleanupClosePushL(uids);
       
  1315 		ConvertUidsL(uidsStr, uids);
       
  1316 		// creates a CPersonality object
       
  1317 		CPersonality* personality = CPersonality::NewL();
       
  1318 		CleanupStack::PushL(personality);
       
  1319 
       
  1320 		personality->SetVersion(resourceVersion);
       
  1321 		
       
  1322 		// populates personality object
       
  1323 		personality->SetId(id);
       
  1324 		        
       
  1325 		for (TInt uidIdx = 0; uidIdx < uids.Count(); uidIdx++)
       
  1326 			{
       
  1327 			LEAVEIFERRORL(personality->AddSupportedClasses(TUid::Uid(uids[uidIdx])));
       
  1328 			}
       
  1329 		
       
  1330 		// gets a handle to iDeviceDescriptor of personality
       
  1331 		CUsbDevice::TUsbDeviceDescriptor& dvceDes = personality->DeviceDescriptor();
       
  1332 		if (gotSysUtilManuName == KErrNone)
       
  1333 			{
       
  1334 			personality->SetManufacturer(&sysUtilManuName);
       
  1335 			}
       
  1336 		else
       
  1337 			{
       
  1338 			personality->SetManufacturer(&manufacturer);
       
  1339 			}
       
  1340 			
       
  1341 		if (gotSysUtilModelName == KErrNone)
       
  1342 			{
       
  1343 			personality->SetProduct(&sysUtilModelName);
       
  1344 			}
       
  1345 		else
       
  1346 			{
       
  1347 			personality->SetProduct(&product);
       
  1348 			}
       
  1349 			
       
  1350 		personality->SetDescription(&description);
       
  1351 		dvceDes.iDeviceClass = bDeviceClass;
       
  1352 		dvceDes.iDeviceSubClass = bDeviceSubClass;
       
  1353 		dvceDes.iDeviceProtocol = protocol;
       
  1354 		dvceDes.iIdVendor = vendorId;
       
  1355 		dvceDes.iIdProduct= productId;
       
  1356 		dvceDes.iBcdDevice = bcdDevice;
       
  1357 		dvceDes.iNumConfigurations = numConfigurations;
       
  1358 		
       
  1359 		//detailedDescription is only supported after EUsbManagerResourceVersionTwo
       
  1360 		if(resourceVersion >= EUsbManagerResourceVersionTwo)
       
  1361 			{
       
  1362 			TPtrC   detailedDescription = reader.ReadTPtrC();        
       
  1363 			personality->SetDetailedDescription(&detailedDescription);
       
  1364 #ifdef __FLOG_ACTIVE
       
  1365 			TBuf8<KUsbDescMaxSize_String> narrowLongBuf;
       
  1366 			narrowLongBuf.Copy(detailedDescription);
       
  1367 			LOGTEXT2(_L8("detailed description = '%S'"),        &narrowLongBuf);            
       
  1368 #endif // __FLOG_ACTIVE
       
  1369 			}
       
  1370 
       
  1371 		//Property is only supported after EUsbManagerResourceVersionThree
       
  1372 		if(resourceVersion >= EUsbManagerResourceVersionThree)
       
  1373 			{
       
  1374 			TUint32 property			= static_cast<TUint32>(reader.ReadUint32());
       
  1375 			personality->SetProperty(property);
       
  1376 #ifdef __FLOG_ACTIVE
       
  1377 		LOGTEXT2(_L8("property = %d\n"), 			property);
       
  1378 #endif // __FLOG_ACTIVE
       
  1379 			}
       
  1380 		
       
  1381 		// Append personality to iSupportedPersonalities
       
  1382 		iSupportedPersonalities.AppendL(personality);
       
  1383 		// Now pop off personality
       
  1384 		CleanupStack::Pop(personality);
       
  1385 #ifdef __FLOG_ACTIVE
       
  1386 		// Debugging
       
  1387 		LOGTEXT2(_L8("personalityCount = %d\n"), 	personalityCount);
       
  1388 		LOGTEXT2(_L8("bDeviceClass = %d\n"), 		bDeviceClass);
       
  1389 		LOGTEXT2(_L8("bDeviceSubClass = %d\n"), 	bDeviceSubClass);
       
  1390 		LOGTEXT2(_L8("protocol = %d\n"), 			protocol);
       
  1391 		LOGTEXT2(_L8("numConfigurations = %d\n"), 	numConfigurations);
       
  1392 		LOGTEXT2(_L8("vendorId = %d\n"), 			vendorId);
       
  1393 		LOGTEXT2(_L8("productId = %d\n"), 			productId);
       
  1394 		LOGTEXT2(_L8("bcdDevice = %d\n"), 			bcdDevice);
       
  1395 		TBuf8<KMaxName> narrowBuf;
       
  1396 		narrowBuf.Copy(manufacturer);
       
  1397 		LOGTEXT2(_L8("manufacturer = '%S'"), 		&narrowBuf);
       
  1398 		narrowBuf.Copy(product);
       
  1399 		LOGTEXT2(_L8("product = '%S'"), 			&narrowBuf);
       
  1400 		LOGTEXT2(_L8("id = %d\n"), 					id);
       
  1401 		LOGTEXT(_L8("ClassUids{"));
       
  1402 		for (TInt k = 0; k < uids.Count(); k++)
       
  1403 			{
       
  1404 			LOGTEXT2(_L8("%d"), uids[k]);
       
  1405 			}
       
  1406 		LOGTEXT(_L8("}"));
       
  1407 		narrowBuf.Copy(description);
       
  1408 		LOGTEXT2(_L8("description = '%S'"), 		&narrowBuf);
       
  1409 #endif // __FLOG_ACTIVE
       
  1410 		CleanupStack::PopAndDestroy(&uids);	// close uid array		
       
  1411 		}
       
  1412 		
       
  1413 	CleanupStack::PopAndDestroy(4, &fs); // deviceInfo, personalityBuf, resource, fs
       
  1414 	iPersonalityCfged = ETrue;	
       
  1415 	}
  1263 	
  1416 	
  1264 void CUsbDevice::SelectClassControllersL()
  1417 void CUsbDevice::SelectClassControllersL()
  1265 /**
  1418 /**
  1266  * Selects class controllers for the current personality
  1419  * Selects class controllers for the current personality
  1267  */
  1420  */
  1268 	{
  1421 	{
  1269 	OstTraceFunctionEntry0( CUSBDEVICE_SELECTCLASSCONTROLLERSL_ENTRY );
  1422 	LOG_FUNC
  1270     const RArray<CPersonalityConfigurations::TUsbClasses>& classes = iCurrentPersonality->SupportedClasses();
  1423 
  1271 	RArray<TUid> classUids;
  1424 	CreateClassControllersL(iCurrentPersonality->SupportedClasses());
  1272 	CleanupClosePushL( classUids ); 
       
  1273     TInt classCount = classes.Count();
       
  1274 	for(TInt classIndex = 0; classIndex<classCount; ++classIndex)
       
  1275 	    {
       
  1276         TUid uid = classes[classIndex].iClassUid;
       
  1277         classUids.AppendL(uid);
       
  1278 	    }
       
  1279 	
       
  1280 	CreateClassControllersL(classUids);
       
  1281 	
       
  1282     CleanupStack::PopAndDestroy( &classUids );
       
  1283 	OstTraceFunctionExit0( CUSBDEVICE_SELECTCLASSCONTROLLERSL_EXIT );
       
  1284 	}
  1425 	}
  1285 #ifdef USE_DUMMY_CLASS_CONTROLLER	
  1426 #ifdef USE_DUMMY_CLASS_CONTROLLER	
  1286 void CUsbDevice::CreateClassControllersL(const RArray<TUid>& /* aClassUids*/)
  1427 void CUsbDevice::CreateClassControllersL(const RArray<TUid>& /* aClassUids*/)
  1287 #else 
  1428 #else 
  1288 void CUsbDevice::CreateClassControllersL(const RArray<TUid>& aClassUids)
  1429 void CUsbDevice::CreateClassControllersL(const RArray<TUid>& aClassUids)
  1291  * Creates a class controller object for each class uid
  1432  * Creates a class controller object for each class uid
  1292  *
  1433  *
  1293  * @param aClassUids an array of class uids
  1434  * @param aClassUids an array of class uids
  1294  */
  1435  */
  1295  	{
  1436  	{
  1296 	OstTraceFunctionEntry0( CUSBDEVICE_CREATECLASSCONTROLLERSL_ENTRY );
  1437 	LOG_FUNC
  1297 
  1438 
  1298 #ifndef USE_DUMMY_CLASS_CONTROLLER
  1439 #ifndef USE_DUMMY_CLASS_CONTROLLER
  1299 
  1440 
  1300 	//create a TLinearOrder to supply the comparison function, Compare(), to be used  
  1441 	//create a TLinearOrder to supply the comparison function, Compare(), to be used  
  1301 	//to determine the order to add class controllers
  1442 	//to determine the order to add class controllers
  1303 
  1444 
  1304 	TInt count = aClassUids.Count();
  1445 	TInt count = aClassUids.Count();
  1305 	
  1446 	
  1306 	// destroy any class controller objects in iSupportedClasses and reset it for reuse
  1447 	// destroy any class controller objects in iSupportedClasses and reset it for reuse
  1307 	iSupportedClasses.ResetAndDestroy();
  1448 	iSupportedClasses.ResetAndDestroy();
  1308 	OstTrace1( TRACE_NORMAL, CUSBDEVICE_CREATECLASSCONTROLLERSL, "CUsbDevice::CreateClassControllersL;aClassUids.Count() = %d", count );
  1449 	LOGTEXT2(_L8("aClassUids.Count() = %d\n"), 	count);
  1309 	for (TInt i = 0; i < count; i++)
  1450 	for (TInt i = 0; i < count; i++)
  1310 		{ 
  1451 		{ 
  1311 		CUsbClassControllerPlugIn* plugIn = CUsbClassControllerPlugIn::NewL(aClassUids[i], *this);
  1452 		CUsbClassControllerPlugIn* plugIn = CUsbClassControllerPlugIn::NewL(aClassUids[i], *this);
  1312 		AddClassControllerL(reinterpret_cast<CUsbClassControllerBase*>(plugIn), order);
  1453 		AddClassControllerL(reinterpret_cast<CUsbClassControllerBase*>(plugIn), order);
  1313 		} 
  1454 		} 
  1314 #endif // USE_DUMMY_CLASS_CONTROLLER	
  1455 #endif // USE_DUMMY_CLASS_CONTROLLER	
  1315 	TInt err = iUsbClassControllerIterator->First();	
  1456 
  1316 	if(err < 0)
  1457 	LEAVEIFERRORL(iUsbClassControllerIterator->First());
  1317 	    {
       
  1318         OstTrace1( TRACE_NORMAL, CUSBDEVICE_CREATECLASSCONTROLLERSL_DUP1, "CUsbDevice::CreateClassControllersL;iUsbClassControllerIterator->First() with error=%d", err );
       
  1319         User::Leave(err);
       
  1320 	    }
       
  1321  	}
  1458  	}
  1322 
  1459 
  1323 void CUsbDevice::SetDefaultPersonalityL()
  1460 void CUsbDevice::SetDefaultPersonalityL()
  1324 /**
  1461 /**
  1325  * Sets default personality. Used for Start request.
  1462  * Sets default personality. Used for Start request.
  1326  */
  1463  */
  1327 	{
  1464 	{
  1328 	OstTraceFunctionEntry0( CUSBDEVICE_SETDEFAULTPERSONALITYL_ENTRY );
  1465 	LOG_FUNC
  1329 
  1466 
  1330 	TInt smallestId = iSupportedPersonalities[0]->PersonalityId();
  1467 	TInt smallestId = iSupportedPersonalities[0]->PersonalityId();
  1331  	TInt count = iSupportedPersonalities.Count();
  1468  	TInt count = iSupportedPersonalities.Count();
       
  1469  	
  1332  	for (TInt i = 1; i < count; i++)
  1470  	for (TInt i = 1; i < count; i++)
  1333  		{
  1471  		{
  1334  		if(iSupportedPersonalities[i]->PersonalityId() < smallestId)
  1472  		if(iSupportedPersonalities[i]->PersonalityId() < smallestId)
  1335  			{
  1473  			{
  1336  			smallestId = iSupportedPersonalities[i]->PersonalityId();
  1474  			smallestId = iSupportedPersonalities[i]->PersonalityId();
  1337  			}
  1475  			}
  1338  		}
  1476  		}
  1339     
  1477 
  1340 	SetCurrentPersonalityL(smallestId);
  1478 	SetCurrentPersonalityL(smallestId);
  1341 	SelectClassControllersL();
  1479 	SelectClassControllersL();
  1342 	OstTraceFunctionExit0( CUSBDEVICE_SETDEFAULTPERSONALITYL_EXIT );
       
  1343 	}
  1480 	}
  1344 
  1481 
  1345 void CUsbDevice::LoadFallbackClassControllersL()
  1482 void CUsbDevice::LoadFallbackClassControllersL()
  1346 /**
  1483 /**
  1347  * Load class controllers for fallback situation:
  1484  * Load class controllers for fallback situation:
  1349  * This method inserts all class controllers to 
  1486  * This method inserts all class controllers to 
  1350  * the list from which they will be either all started
  1487  * the list from which they will be either all started
  1351  * or stopped
  1488  * or stopped
  1352  */
  1489  */
  1353  	{
  1490  	{
  1354 	OstTraceFunctionEntry0( CUSBDEVICE_LOADFALLBACKCLASSCONTROLLERSL_ENTRY );
  1491 	LOG_FUNC
  1355  	SetDeviceDescriptorL();
  1492  	SetDeviceDescriptorL();
  1356 	CreateClassControllersL(iSupportedClassUids);
  1493 	CreateClassControllersL(iSupportedClassUids);
  1357  	OstTraceFunctionExit0( CUSBDEVICE_LOADFALLBACKCLASSCONTROLLERSL_EXIT );
       
  1358  	}
  1494  	}
  1359  	
  1495  	
       
  1496 void CUsbDevice::ResourceFileNameL(TFileName& aFileName)
       
  1497 /**
       
  1498  * Gets resource file name
       
  1499  *
       
  1500  * @param aFileName Descriptor to populate with resource file name
       
  1501  */
       
  1502  	{
       
  1503 	LOG_FUNC
       
  1504 
       
  1505 	RFs fs;
       
  1506 	LEAVEIFERRORL(fs.Connect());
       
  1507 	CleanupClosePushL(fs);
       
  1508 
       
  1509 #ifdef __WINS__
       
  1510 	// If we are running in the emulator then read the resource file from system drive.
       
  1511 	// This makes testing with different resource files easier.
       
  1512 	_LIT(KPrivatePath, ":\\Private\\101fe1db\\");
       
  1513 	aFileName.Append(RFs::GetSystemDriveChar()); //get the name of system drive
       
  1514 	aFileName.Append(KPrivatePath);
       
  1515 #else
       
  1516  	const TDriveNumber KResourceDrive = EDriveZ;
       
  1517 
       
  1518 	TDriveUnit driveUnit(KResourceDrive);
       
  1519 	TDriveName drive=driveUnit.Name();
       
  1520 	aFileName.Insert(0, drive);
       
  1521 	// append private path
       
  1522 	TPath privatePath;
       
  1523 	fs.PrivatePath(privatePath);
       
  1524 	aFileName.Append(privatePath);		
       
  1525 #endif //WINS
       
  1526 
       
  1527 	// Find the nearest match of resource file for the chosen locale
       
  1528 	aFileName.Append(_L("usbman.rsc"));
       
  1529 	BaflUtils::NearestLanguageFile(fs, aFileName); // if a match is not found, usbman.rsc will be used
       
  1530 
       
  1531 	CleanupStack::PopAndDestroy(&fs);	// fs no longer needed
       
  1532  	}
       
  1533 
  1360 RDevUsbcClient& CUsbDevice::MuepoDoDevUsbcClient()
  1534 RDevUsbcClient& CUsbDevice::MuepoDoDevUsbcClient()
  1361 /**
  1535 /**
  1362  * Inherited from MUsbmanExtensionPluginObserver - Function used by plugins to
  1536  * Inherited from MUsbmanExtensionPluginObserver - Function used by plugins to
  1363  * retrieve our handle to the LDD
  1537  * retrieve our handle to the LDD
  1364  *
  1538  *
  1374  * register themselves for notifications of device/service state changes.
  1548  * register themselves for notifications of device/service state changes.
  1375  *
  1549  *
  1376  * @param aObserver New Observer of the device
  1550  * @param aObserver New Observer of the device
  1377  */
  1551  */
  1378 	{
  1552 	{
  1379 	OstTrace1( TRACE_NORMAL, CUSBDEVICE_MUEPODOREGISTERSTATEOBSERVERL, "CUsbDevice::MuepoDoRegisterStateObserverL;aObserver = 0x%08x", &aObserver );
  1553 	LOGTEXT2(_L8("CUsbDevice::MuepoDoRegisterStateObserverL aObserver = 0x%08x"),&aObserver);
  1380 	RegisterObserverL(aObserver);
  1554 	RegisterObserverL(aObserver);
  1381 	}
  1555 	}