usbmgmt/usbmgr/usbman/server/SRC/CUsbDevice.cpp
changeset 25 4ddb65515edd
parent 0 c9bc50fca66e
child 26 f3a1ae528dee
equal deleted inserted replaced
14:4285b54b0d2c 25:4ddb65515edd
   116 	// Free any memory allocated to the list of observers. Note that
   116 	// Free any memory allocated to the list of observers. Note that
   117 	// 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
   118 	// the observers themselves.
   118 	// the observers themselves.
   119 	iObservers.Reset();
   119 	iObservers.Reset();
   120 
   120 
       
   121 #ifndef __OVER_DUMMYUSBDI__
   121 #ifndef __WINS__
   122 #ifndef __WINS__
   122 	LOGTEXT2(_L8("about to delete device state watcher @ %08x"), (TUint32) iDeviceStateWatcher);
   123 	LOGTEXT2(_L8("about to delete device state watcher @ %08x"), (TUint32) iDeviceStateWatcher);
   123 	delete iDeviceStateWatcher;
   124 	delete iDeviceStateWatcher;
   124 	LOGTEXT(_L8("deleted device state watcher"));
   125 	LOGTEXT(_L8("deleted device state watcher"));
   125 
   126 
   131 	//warning about err being unused in UREL builds.
   132 	//warning about err being unused in UREL builds.
   132 	if(err)
   133 	if(err)
   133 		{
   134 		{
   134 		LOGTEXT2(_L8("     User::FreeLogicalDevice returned %d"),err);
   135 		LOGTEXT2(_L8("     User::FreeLogicalDevice returned %d"),err);
   135 		}
   136 		}
       
   137 #endif
   136 #endif	
   138 #endif	
   137 
   139 
   138 	delete iDefaultSerialNumber;
   140 	delete iDefaultSerialNumber;
   139 	}
   141 	}
   140 
   142 
   162 	
   164 	
   163 	iEcom = &(REComSession::OpenL());
   165 	iEcom = &(REComSession::OpenL());
   164 
   166 
   165 	iUsbClassControllerIterator = new(ELeave) CUsbClassControllerIterator(iSupportedClasses);
   167 	iUsbClassControllerIterator = new(ELeave) CUsbClassControllerIterator(iSupportedClasses);
   166 
   168 
       
   169 #ifndef __OVER_DUMMYUSBDI__
   167 #ifndef __WINS__
   170 #ifndef __WINS__
   168 	LOGTEXT(_L8("About to load LDD"));
   171 	LOGTEXT(_L8("About to load LDD"));
   169 	TInt err = User::LoadLogicalDevice(KUsbLDDName);
   172 	TInt err = User::LoadLogicalDevice(KUsbLDDName);
   170 
   173 
   171 	if (err != KErrNone && err != KErrAlreadyExists)
   174 	if (err != KErrNone && err != KErrAlreadyExists)
   226 		LOGTEXT2(_L8("Got default serial number %S"), &narrowString);
   229 		LOGTEXT2(_L8("Got default serial number %S"), &narrowString);
   227 #endif //__FLOG_ACTIVE		
   230 #endif //__FLOG_ACTIVE		
   228 		}
   231 		}
   229 
   232 
   230 	LOGTEXT(_L8("UsbDevice::ConstructL() finished"));
   233 	LOGTEXT(_L8("UsbDevice::ConstructL() finished"));
       
   234 #endif
   231 #endif
   235 #endif
   232 	
   236 	
   233 #ifndef __OVER_DUMMYUSBDI__
   237 #ifndef __OVER_DUMMYUSBDI__
   234 	InstantiateExtensionPluginsL();
   238 	InstantiateExtensionPluginsL();
   235 #endif
   239 #endif
   489 		return;
   493 		return;
   490 		}
   494 		}
   491 
   495 
   492 	if (iDeviceState != state)
   496 	if (iDeviceState != state)
   493 		{
   497 		{
       
   498 #ifndef __OVER_DUMMYUSBDI__
   494 #ifndef __WINS__
   499 #ifndef __WINS__
   495 		if (iDeviceState == EUsbDeviceStateUndefined &&
   500 		if (iDeviceState == EUsbDeviceStateUndefined &&
   496 			iUdcSupportsCableDetectWhenUnpowered &&
   501 			iUdcSupportsCableDetectWhenUnpowered &&
   497 			iServiceState == EUsbServiceStarted)
   502 			iServiceState == EUsbServiceStarted)
   498 			{
   503 			{
   500 			// now be attached (if it wasn't before). If the UDC supports
   505 			// now be attached (if it wasn't before). If the UDC supports
   501 			// cable detection when unpowered, NOW is the right time to power
   506 			// cable detection when unpowered, NOW is the right time to power
   502 			// it up (so long as usbman is fully started).
   507 			// it up (so long as usbman is fully started).
   503 			(void)PowerUpAndConnect(); // We don't care about any errors here.
   508 			(void)PowerUpAndConnect(); // We don't care about any errors here.
   504 			}
   509 			}
   505 #endif // __WINS__
   510 #endif
       
   511 #endif // __OVER_DUMMYUSBDI__
   506 		// Change state straight away in case any of the clients check it
   512 		// Change state straight away in case any of the clients check it
   507 		TUsbDeviceState oldState = iDeviceState;
   513 		TUsbDeviceState oldState = iDeviceState;
   508 		iDeviceState = state;
   514 		iDeviceState = state;
   509 		TUint length = iObservers.Count();
   515 		TUint length = iObservers.Count();
   510 
   516 
   608 	switch (iServiceState)
   614 	switch (iServiceState)
   609 		{
   615 		{
   610 	case EUsbServiceStarting:
   616 	case EUsbServiceStarting:
   611 		if (iUsbClassControllerIterator->Next() == KErrNotFound)
   617 		if (iUsbClassControllerIterator->Next() == KErrNotFound)
   612 			{
   618 			{
       
   619 #ifndef __OVER_DUMMYUSBDI__
   613 #ifndef __WINS__
   620 #ifndef __WINS__
   614 			if (!iUdcSupportsCableDetectWhenUnpowered || iDeviceState != EUsbDeviceStateUndefined)
   621 			if (!iUdcSupportsCableDetectWhenUnpowered || iDeviceState != EUsbDeviceStateUndefined)
   615 				{
   622 				{
   616 				// We've finished starting the classes. We can just power up the UDC
   623 				// We've finished starting the classes. We can just power up the UDC
   617 				// now: there's no need to re-enumerate, because we soft disconnected
   624 				// now: there's no need to re-enumerate, because we soft disconnected
   621 				// It isn't an error if this call fails. This will happen, for example,
   628 				// It isn't an error if this call fails. This will happen, for example,
   622 				// in the case where there are no USB classes defined.
   629 				// in the case where there are no USB classes defined.
   623 				(void)PowerUpAndConnect();
   630 				(void)PowerUpAndConnect();
   624 				}
   631 				}
   625 #endif
   632 #endif
       
   633 #endif
   626 			// If we're not running on target, we can just go to "started".
   634 			// If we're not running on target, we can just go to "started".
   627 			SetServiceState(EUsbServiceStarted);
   635 			SetServiceState(EUsbServiceStarted);
   628 			}
   636 			}
   629 		else
   637 		else
   630 			{
   638 			{
   634 
   642 
   635 	case EUsbServiceStopping:
   643 	case EUsbServiceStopping:
   636 		if (iUsbClassControllerIterator->Previous() == KErrNotFound)
   644 		if (iUsbClassControllerIterator->Previous() == KErrNotFound)
   637 			{
   645 			{
   638 			// if stopping classes, hide the USB interface from the host
   646 			// if stopping classes, hide the USB interface from the host
       
   647 #ifndef __OVER_DUMMYUSBDI__
   639 #ifndef __WINS__
   648 #ifndef __WINS__
   640 			iLdd.DeviceDisconnectFromHost();
   649 			iLdd.DeviceDisconnectFromHost();
   641 
   650 
   642 			// Restore the default serial number 
   651 			// Restore the default serial number 
   643 			if (iDefaultSerialNumber)
   652 			if (iDefaultSerialNumber)
   648 			else
   657 			else
   649 				{
   658 				{
   650 				TInt res = iLdd.RemoveSerialNumberStringDescriptor();
   659 				TInt res = iLdd.RemoveSerialNumberStringDescriptor();
   651 				LOGTEXT2(_L8("Remove serial number res = %d"), res);
   660 				LOGTEXT2(_L8("Remove serial number res = %d"), res);
   652 				}
   661 				}
   653 				
   662 
       
   663 #endif				
   654 #endif			
   664 #endif			
   655 			SetServiceState(EUsbServiceIdle);
   665 			SetServiceState(EUsbServiceIdle);
   656 			}
   666 			}
   657 		else
   667 		else
   658 			{
   668 			{
   791  * Modifies the USB device descriptor.
   801  * Modifies the USB device descriptor.
   792  */
   802  */
   793 	{
   803 	{
   794 	LOG_FUNC
   804 	LOG_FUNC
   795 
   805 
   796 #ifndef __WINS__
   806 #if !defined(__OVER_DUMMYUSBDI__) && !defined(__WINS__)
   797 
   807 
   798 	TInt desSize = 0;
   808 	TInt desSize = 0;
   799 	iLdd.GetDeviceDescriptorSize(desSize);
   809 	iLdd.GetDeviceDescriptorSize(desSize);
   800 	LOGTEXT2(_L8("UDeviceDescriptorSize = %d"), desSize);
   810 	LOGTEXT2(_L8("UDeviceDescriptorSize = %d"), desSize);
   801 	HBufC8* deviceBuf = HBufC8::NewLC(desSize);
   811 	HBufC8* deviceBuf = HBufC8::NewLC(desSize);
   819 	// Create an empty descriptor to allow the settings
   829 	// Create an empty descriptor to allow the settings
   820 	// to be read in from the resource file
   830 	// to be read in from the resource file
   821 	TUsbDeviceDescriptor descriptor;
   831 	TUsbDeviceDescriptor descriptor;
   822 	TUsbDeviceDescriptor* deviceDescriptor = &descriptor;
   832 	TUsbDeviceDescriptor* deviceDescriptor = &descriptor;
   823 	
   833 	
   824 #endif // __WINS__
   834 #endif // __OVER_DUMMYUSBDI__ && _WINS_
   825 
   835 
   826 	if (iPersonalityCfged)
   836 	if (iPersonalityCfged)
   827 		{
   837 		{
   828 		SetUsbDeviceSettingsFromPersonalityL(*deviceDescriptor);		
   838 		SetUsbDeviceSettingsFromPersonalityL(*deviceDescriptor);		
   829 		}
   839 		}
   830 	else
   840 	else
   831 		{
   841 		{
   832 	SetUsbDeviceSettingsL(*deviceDescriptor);
   842 	SetUsbDeviceSettingsL(*deviceDescriptor);
   833 		}
   843 		}
   834 	
   844 	
       
   845 #ifndef __OVER_DUMMYUSBDI__
   835 #ifndef __WINS__
   846 #ifndef __WINS__
   836 	ret = iLdd.SetDeviceDescriptor(devicePtr);
   847 	ret = iLdd.SetDeviceDescriptor(devicePtr);
   837 
   848 
   838 	if (ret != KErrNone)
   849 	if (ret != KErrNone)
   839 		{
   850 		{
   841 		LEAVEL(ret);
   852 		LEAVEL(ret);
   842 		}
   853 		}
   843 
   854 
   844 	CleanupStack::PopAndDestroy(deviceBuf);
   855 	CleanupStack::PopAndDestroy(deviceBuf);
   845 
   856 
   846 #endif // __WINS__
   857 #endif
       
   858 #endif // __OVER_DUMMYUSBDI__
   847 	}
   859 	}
   848 
   860 
   849 void CUsbDevice::SetUsbDeviceSettingsDefaultsL(CUsbDevice::TUsbDeviceDescriptor& aDeviceDescriptor)
   861 void CUsbDevice::SetUsbDeviceSettingsDefaultsL(CUsbDevice::TUsbDeviceDescriptor& aDeviceDescriptor)
   850 /**
   862 /**
   851  * Set the device settings defaults, as per the non-resource
   863  * Set the device settings defaults, as per the non-resource
   930 	TPtrC manufacturerString = reader.ReadTPtrC();
   942 	TPtrC manufacturerString = reader.ReadTPtrC();
   931 	TPtrC productString = reader.ReadTPtrC();
   943 	TPtrC productString = reader.ReadTPtrC();
   932 	
   944 	
   933 	// If we succesfully read the manufacturer or device name from SysUtil API
   945 	// 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
   946 	// then set these results, otherwise use the values defined in resource file
       
   947 #ifndef __OVER_DUMMYUSBDI__
   935 #ifndef __WINS__
   948 #ifndef __WINS__
   936 	if (gotSysUtilManuName == KErrNone)
   949 	if (gotSysUtilManuName == KErrNone)
   937 		{
   950 		{
   938 		LEAVEIFERRORL(iLdd.SetManufacturerStringDescriptor(sysUtilManuName));
   951 		LEAVEIFERRORL(iLdd.SetManufacturerStringDescriptor(sysUtilManuName));
   939 		}
   952 		}
   948 		}
   961 		}
   949 	else
   962 	else
   950 		{
   963 		{
   951 		LEAVEIFERRORL(iLdd.SetProductStringDescriptor(productString));
   964 		LEAVEIFERRORL(iLdd.SetProductStringDescriptor(productString));
   952 		}
   965 		}
   953 #endif // __WINS__
   966 		
       
   967 #endif
       
   968 #endif // __OVER_DUMMYUSBDI__
   954 
   969 
   955 #ifdef __FLOG_ACTIVE
   970 #ifdef __FLOG_ACTIVE
   956 	PrintDescriptor(aDeviceDescriptor);	
   971 	PrintDescriptor(aDeviceDescriptor);	
   957 	TBuf8<KUsbStringDescStringMaxSize> narrowString;
   972 	TBuf8<KUsbStringDescStringMaxSize> narrowString;
   958 	narrowString.Copy(manufacturerString);
   973 	narrowString.Copy(manufacturerString);
   959 	LOGTEXT2(_L8("Manufacturer is: '%S'"), &narrowString);
   974 	LOGTEXT2(_L8("Manufacturer is: '%S'"), &narrowString);
   960 	narrowString.Copy(productString);
   975 	narrowString.Copy(productString);
   961 	LOGTEXT2(_L8("Product is: '%S'"), &narrowString);
   976 	LOGTEXT2(_L8("Product is: '%S'"), &narrowString);
   962 #endif // __FLOG_ACTIVE
   977 #endif // __FLOG_ACTIVE
   963 
   978 
       
   979 #ifndef __OVER_DUMMYUSBDI__
   964 #ifndef __WINS__	
   980 #ifndef __WINS__	
   965 	//Read the published serial number. The key is the UID KUidUsbmanServer = 0x101FE1DB
   981 	//Read the published serial number. The key is the UID KUidUsbmanServer = 0x101FE1DB
   966 	TBuf16<KUsbStringDescStringMaxSize> serNum;
   982 	TBuf16<KUsbStringDescStringMaxSize> serNum;
   967 	TInt r = RProperty::Get(KUidSystemCategory,0x101FE1DB,serNum);
   983 	TInt r = RProperty::Get(KUidSystemCategory,0x101FE1DB,serNum);
   968 	if(r==KErrNone)
   984 	if(r==KErrNone)
   980 	else
   996 	else
   981 		{
   997 		{
   982 		LOGTEXT(_L8("SerialNumber has not been published"));	
   998 		LOGTEXT(_L8("SerialNumber has not been published"));	
   983 		}
   999 		}
   984 #endif // __FLOG_ACTIVE
  1000 #endif // __FLOG_ACTIVE
   985 #endif // __WINS__
  1001 
       
  1002 #endif
       
  1003 #endif // __OVER_DUMMYUSBDI__
   986 
  1004 
   987 
  1005 
   988 	CleanupStack::PopAndDestroy(4, &fs); //  deviceInfo, id, resource, fs
  1006 	CleanupStack::PopAndDestroy(4, &fs); //  deviceInfo, id, resource, fs
   989 	}
  1007 	}
   990 
  1008 
  1010 	aDeviceDescriptor.iIdProduct			= deviceDes.iIdProduct;
  1028 	aDeviceDescriptor.iIdProduct			= deviceDes.iIdProduct;
  1011 	aDeviceDescriptor.iBcdDevice			= deviceDes.iBcdDevice;
  1029 	aDeviceDescriptor.iBcdDevice			= deviceDes.iBcdDevice;
  1012 	aDeviceDescriptor.iSerialNumber			= deviceDes.iSerialNumber;
  1030 	aDeviceDescriptor.iSerialNumber			= deviceDes.iSerialNumber;
  1013 	aDeviceDescriptor.iNumConfigurations	= deviceDes.iNumConfigurations;
  1031 	aDeviceDescriptor.iNumConfigurations	= deviceDes.iNumConfigurations;
  1014 
  1032 
       
  1033 #ifndef __OVER_DUMMYUSBDI__
  1015 #ifndef __WINS__
  1034 #ifndef __WINS__
  1016 	LEAVEIFERRORL(iLdd.SetManufacturerStringDescriptor(*(iCurrentPersonality->Manufacturer())));
  1035 	LEAVEIFERRORL(iLdd.SetManufacturerStringDescriptor(*(iCurrentPersonality->Manufacturer())));
  1017 	LEAVEIFERRORL(iLdd.SetProductStringDescriptor(*(iCurrentPersonality->Product())));
  1036 	LEAVEIFERRORL(iLdd.SetProductStringDescriptor(*(iCurrentPersonality->Product())));
  1018 
  1037 
  1019 	//Read the published serial number. The key is the UID KUidUsbmanServer = 0x101FE1DB
  1038 	//Read the published serial number. The key is the UID KUidUsbmanServer = 0x101FE1DB
  1034 	else
  1053 	else
  1035 		{
  1054 		{
  1036 		LOGTEXT(_L8("SerialNumber has not been published"));	
  1055 		LOGTEXT(_L8("SerialNumber has not been published"));	
  1037 		}
  1056 		}
  1038 #endif // __FLOG_ACTIVE
  1057 #endif // __FLOG_ACTIVE
  1039 #endif // __WINS__
  1058 
       
  1059 #endif
       
  1060 #endif // __OVER_DUMMYUSBDI__
  1040 
  1061 
  1041 
  1062 
  1042 #ifdef __FLOG_ACTIVE
  1063 #ifdef __FLOG_ACTIVE
  1043 	PrintDescriptor(aDeviceDescriptor);		
  1064 	PrintDescriptor(aDeviceDescriptor);		
  1044 
  1065 
       
  1066 #ifndef __OVER_DUMMYUSBDI__
  1045 #ifndef __WINS__
  1067 #ifndef __WINS__
  1046 	TBuf16<KUsbStringDescStringMaxSize> wideString;
  1068 	TBuf16<KUsbStringDescStringMaxSize> wideString;
  1047 	TBuf8<KUsbStringDescStringMaxSize> narrowString;
  1069 	TBuf8<KUsbStringDescStringMaxSize> narrowString;
  1048 
  1070 
  1049 	LEAVEIFERRORL(iLdd.GetConfigurationStringDescriptor(wideString));
  1071 	LEAVEIFERRORL(iLdd.GetConfigurationStringDescriptor(wideString));
  1050 	narrowString.Copy(wideString);
  1072 	narrowString.Copy(wideString);
  1051 	LOGTEXT2(_L8("Configuration is: '%S'"), &narrowString);
  1073 	LOGTEXT2(_L8("Configuration is: '%S'"), &narrowString);
  1052 #endif // __WINS__
  1074 #endif
       
  1075 #endif // __OVER_DUMMYUSBDI__
  1053 
  1076 
  1054 #endif // __FLOG_ACTIVE
  1077 #endif // __FLOG_ACTIVE
  1055 	}
  1078 	}
  1056 	
  1079 	
  1057 void CUsbDevice::TryStartL(TInt aPersonalityId)
  1080 void CUsbDevice::TryStartL(TInt aPersonalityId)