usbmgmt/usbmgr/usbman/server/SRC/CUsbDevice.cpp
changeset 49 93c0009bd947
parent 48 21625e5de155
equal deleted inserted replaced
48:21625e5de155 49:93c0009bd947
    22 */
    22 */
    23 #include <cusbclasscontrolleriterator.h>
    23 #include <cusbclasscontrolleriterator.h>
    24 #include <cusbclasscontrollerbase.h>
    24 #include <cusbclasscontrollerbase.h>
    25 #include <cusbclasscontrollerplugin.h>
    25 #include <cusbclasscontrollerplugin.h>
    26 #include <bafl/sysutil.h>
    26 #include <bafl/sysutil.h>
    27 #include <usb/usblogger.h>
       
    28 #include <e32svr.h>
    27 #include <e32svr.h>
    29 #include <e32base.h>
    28 #include <e32base.h>
    30 #include <e32std.h>
    29 #include <e32std.h>
    31 #include <f32file.h>
    30 #include <f32file.h>
    32 #include <barsc.h>
    31 #include <barsc.h>
    45 #include "UsbSettings.h"
    44 #include "UsbSettings.h"
    46 #include "CUsbServer.h"
    45 #include "CUsbServer.h"
    47 #include "UsbUtils.h"
    46 #include "UsbUtils.h"
    48 #include "CUsbDevice.h"
    47 #include "CUsbDevice.h"
    49 #include "CUsbDeviceStateWatcher.h"
    48 #include "CUsbDeviceStateWatcher.h"
       
    49 #include "cusbchargingporttypewatcher.h"
    50 #include "CPersonality.h"
    50 #include "CPersonality.h"
    51 #include "usbmancenrepmanager.h"
    51 #include "usbmancenrepmanager.h"
    52 #include "usbmanprivatecrkeys.h"
    52 #include "usbmanprivatecrkeys.h"
    53 
    53 
    54 #include "OstTraceDefinitions.h"
    54 #include "OstTraceDefinitions.h"
   126 
   126 
   127 	// Free any memory allocated to the list of observers. Note that
   127 	// Free any memory allocated to the list of observers. Note that
   128 	// we don't want to call ResetAndDestroy, because we don't own
   128 	// we don't want to call ResetAndDestroy, because we don't own
   129 	// the observers themselves.
   129 	// the observers themselves.
   130 	iObservers.Reset();
   130 	iObservers.Reset();
       
   131 #ifdef SYMBIAN_USB_BATTERYCHARGING_V1_1	
       
   132 	iChargingObservers.Reset();
       
   133 	delete iChargerTypeWatcher;
       
   134 #endif
   131 
   135 
   132 #ifndef __OVER_DUMMYUSBDI__
   136 #ifndef __OVER_DUMMYUSBDI__
   133 #ifndef __WINS__
   137 #ifndef __WINS__
   134 	OstTrace1( TRACE_NORMAL, CUSBDEVICE_CUSBDEVICE, "CUsbDevice::~CUsbDevice;about to delete device state watcher @ %08x", (TUint32)iDeviceStateWatcher );
   138 	OstTrace1( TRACE_NORMAL, CUSBDEVICE_CUSBDEVICE, "CUsbDevice::~CUsbDevice;about to delete device state watcher @ %08x", (TUint32)iDeviceStateWatcher );
   135 	
   139 	
   244 	OstTrace0( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP5, "CUsbDevice::ConstructL; Got device state" );
   248 	OstTrace0( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP5, "CUsbDevice::ConstructL; Got device state" );
   245 	
   249 	
   246 
   250 
   247 	iDeviceStateWatcher = CUsbDeviceStateWatcher::NewL(*this, iLdd);
   251 	iDeviceStateWatcher = CUsbDeviceStateWatcher::NewL(*this, iLdd);
   248 	iDeviceStateWatcher->Start();
   252 	iDeviceStateWatcher->Start();
       
   253 
       
   254 #ifdef SYMBIAN_USB_BATTERYCHARGING_V1_1	
       
   255 	iChargerTypeWatcher = CUsbChargingPortTypeWatcher::NewL(*this, iLdd);
       
   256 	iChargerTypeWatcher->Start();
       
   257 #endif	
   249 
   258 
   250 	// Get hold of the default serial number in the driver
   259 	// Get hold of the default serial number in the driver
   251 	// This is so it can be put back in place when a device that sets a
   260 	// This is so it can be put back in place when a device that sets a
   252 	// different serial number (through the P&S key) is stopped
   261 	// different serial number (through the P&S key) is stopped
   253 	iDefaultSerialNumber = HBufC16::NewL(KUsbStringDescStringMaxSize);
   262 	iDefaultSerialNumber = HBufC16::NewL(KUsbStringDescStringMaxSize);
  1151 		
  1160 		
  1152 	iCurrentPersonality = personality;
  1161 	iCurrentPersonality = personality;
  1153  	OstTraceFunctionExit0( CUSBDEVICE_SETCURRENTPERSONALITYL_EXIT );
  1162  	OstTraceFunctionExit0( CUSBDEVICE_SETCURRENTPERSONALITYL_EXIT );
  1154  	}
  1163  	}
  1155 	
  1164 	
  1156 void CUsbDevice::ValidatePersonalitiesL()
  1165 void CUsbDevice::ValidatePersonalities()
  1157 /**
  1166 /**
  1158  * Verifies all class controllers associated with each personality are loaded.
  1167  * Verifies all class controllers associated with each personality are loaded.
  1159  * Leave if validation fails.
  1168  * Leave if validation fails.
  1160  */
  1169  */
  1161 	{
  1170 	{
  1162 	OstTraceFunctionEntry0( CUSBDEVICE_VALIDATEPERSONALITIESL_ENTRY );
  1171 	OstTraceFunctionEntry0( CUSBDEVICE_VALIDATEPERSONALITIES_ENTRY );
  1163 
  1172 
  1164 	TInt personalityCount = iSupportedPersonalities.Count();
  1173 	TInt personalityCount = iSupportedPersonalities.Count();
  1165 	for (TInt i = 0; i < personalityCount; i++)
  1174 	for (TInt i = 0; i < personalityCount; i++)
  1166 		{
  1175 		{
  1167 		const RArray<CPersonalityConfigurations::TUsbClasses>& classes = iSupportedPersonalities[i]->SupportedClasses();
  1176 		const RArray<CPersonalityConfigurations::TUsbClasses>& classes = iSupportedPersonalities[i]->SupportedClasses();
  1168 		TInt uidCount = classes.Count();
  1177 		TInt uidCount = classes.Count();
  1169 		for (TInt j = 0; j < uidCount; j++)	
  1178 		for (TInt j = 0; j < uidCount; j++)	
  1170 			{
  1179 			{
  1171 			TInt ccCount = iSupportedClassUids.Count();
  1180 			TInt ccCount = iSupportedClassUids.Count();
  1172 			TInt k;
  1181 			TInt k;
  1173 		    OstTrace1( TRACE_NORMAL, CUSBDEVICE_VALIDATEPERSONALITIESL_DUP1, "CUsbDevice::ValidatePersonalitiesL;iSupportedClassUids Count = %d", ccCount );
  1182 		    OstTrace1( TRACE_NORMAL, CUSBDEVICE_VALIDATEPERSONALITIES_DUP1, "CUsbDevice::ValidatePersonalities;iSupportedClassUids Count = %d", ccCount );
  1174 			for (k = 0; k < ccCount; k++)
  1183 			for (k = 0; k < ccCount; k++)
  1175 				{
  1184 				{
  1176                 OstTraceExt4( TRACE_NORMAL, CUSBDEVICE_VALIDATEPERSONALITIESL_DUP2, "CUsbDevice::ValidatePersonalitiesL;iSupportedClassUids %d %x classes %d %x", k, iSupportedClassUids[k].iUid, j, classes[j].iClassUid.iUid );
  1185                 OstTraceExt4( TRACE_NORMAL, CUSBDEVICE_VALIDATEPERSONALITIES_DUP2, "CUsbDevice::ValidatePersonalities;iSupportedClassUids %d %x classes %d %x", k, iSupportedClassUids[k].iUid, j, classes[j].iClassUid.iUid );
  1177 				if (iSupportedClassUids[k] == classes[j].iClassUid)
  1186 				if (iSupportedClassUids[k] == classes[j].iClassUid)
  1178 					{
  1187 					{
  1179 					break;
  1188 					break;
  1180 					}
  1189 					}
  1181 				}
  1190 				}
  1182 			if (k == ccCount)
  1191 			if (k == ccCount)
  1183 				{
  1192 				{
  1184 				OstTrace0( TRACE_NORMAL, CUSBDEVICE_VALIDATEPERSONALITIESL, "CUsbDevice::ValidatePersonalitiesL;personality validation failed" );
  1193 				OstTrace1( TRACE_FATAL, CUSBDEVICE_VALIDATEPERSONALITIES, "CUsbDevice::ValidatePersonalities; Validation failed, class %x not supported", classes[j].iClassUid.iUid );
  1185 				User::Leave(KErrAbort);
  1194 				// Previously leaves here. But this causes that USB doesn't work.
       
  1195 				// Now this function will only be called in debug version and only shows some information.
       
  1196 				// The behaviour is a little different with before but should be ok.
       
  1197 				// After the device image is verified, this error will never happen at run time.
  1186 				}					
  1198 				}					
  1187 			}	
  1199 			}	
  1188 		}
  1200 		}
  1189 	OstTraceFunctionExit0( CUSBDEVICE_VALIDATEPERSONALITIESL_EXIT );
  1201 	OstTraceFunctionExit0( CUSBDEVICE_VALIDATEPERSONALITIES_EXIT );
  1190 	}
  1202 	}
  1191 /**
  1203 /**
  1192 Converts text string with UIDs to array of Uint
  1204 Converts text string with UIDs to array of Uint
  1193 
  1205 
  1194 If there is an error during the conversion, this function will not clean-up,
  1206 If there is an error during the conversion, this function will not clean-up,
  1385  */
  1397  */
  1386 	{
  1398 	{
  1387 	OstTrace1( TRACE_NORMAL, CUSBDEVICE_MUEPODOREGISTERSTATEOBSERVERL, "CUsbDevice::MuepoDoRegisterStateObserverL;aObserver = 0x%08x", &aObserver );
  1399 	OstTrace1( TRACE_NORMAL, CUSBDEVICE_MUEPODOREGISTERSTATEOBSERVERL, "CUsbDevice::MuepoDoRegisterStateObserverL;aObserver = 0x%08x", &aObserver );
  1388 	RegisterObserverL(aObserver);
  1400 	RegisterObserverL(aObserver);
  1389 	}
  1401 	}
       
  1402 
       
  1403 
       
  1404 #ifdef SYMBIAN_USB_BATTERYCHARGING_V1_1
       
  1405 void CUsbDevice::MuepoDoRegisterChargingObserverL(MUsbChargingNotify& aObserver)
       
  1406 /**
       
  1407  * Inherited from MUsbmanExtensionPluginObserver - Function used by plugins to
       
  1408  * register themselves for notifications of charging changes.
       
  1409  *
       
  1410  * @param aObserver New Observer of the device
       
  1411  */
       
  1412 	{
       
  1413 	OstTrace1( TRACE_NORMAL, CUSBDEVICE_MUEPODOREGISTERCHARGINGOBSERVERL, "CUsbDevice::MuepoDoRegisterChargingObserverL;aObserver = 0x%08x", &aObserver );
       
  1414 	RegisterChargingInfoObserverL(aObserver);
       
  1415 	}
       
  1416 
       
  1417 
       
  1418 void CUsbDevice::RegisterChargingInfoObserverL(MUsbChargingNotify& aObserver)
       
  1419 /**
       
  1420  * Register an observer of charging.
       
  1421  * Presently, the device supports watching state.
       
  1422  *
       
  1423  * @param	aObserver	New Observer of the charging
       
  1424  */
       
  1425 	{
       
  1426 	OstTraceFunctionEntry0( CUSBDEVICE_REGISTERCHARGINGINFOOBSERVERL_ENTRY );
       
  1427 	TInt err = iChargingObservers.Append(&aObserver);
       
  1428 	if(err < 0)
       
  1429 	    {
       
  1430         OstTrace1( TRACE_NORMAL, CUSBDEVICE_REGISTERCHARGINGINFOOBSERVERL, "CUsbDevice::RegisterObserverL;iObservers.Append(&aObserver) with err=%d", err );
       
  1431         User::Leave(err);
       
  1432 	    }
       
  1433 	OstTraceFunctionExit0( CUSBDEVICE_REGISTERCHARGINGINFOOBSERVERL_EXIT );
       
  1434 	}
       
  1435 
       
  1436 
       
  1437 void CUsbDevice::DeRegisterChargingInfoObserver(MUsbChargingNotify& aObserver)
       
  1438 /**
       
  1439  * De-registers an existing charging observer.
       
  1440  *
       
  1441  * @param	aObserver	The existing device observer to be de-registered
       
  1442  */
       
  1443 	{
       
  1444 	OstTraceFunctionEntry0( CUSBDEVICE_DEREGISTERCHARGINGINFOOBSERVERL_ENTRY );
       
  1445 
       
  1446 	TInt index = iChargingObservers.Find(&aObserver);
       
  1447 
       
  1448 	if (index >= 0)
       
  1449 		iObservers.Remove(index);
       
  1450 	OstTraceFunctionExit0( CUSBDEVICE_DEREGISTERCHARGINGINFOOBSERVERL_EXIT );
       
  1451 	}
       
  1452 
       
  1453 
       
  1454 void CUsbDevice::SetChargingPortType(TUsbcChargingPortType aChargingPortType)
       
  1455 	{
       
  1456 	OstTraceFunctionEntry0( CUSBDEVICE_SETCHARGINGPORTTYPE_ENTRY );
       
  1457 	TUint length = iChargingObservers.Count();
       
  1458 
       
  1459 	for (TUint i = 0; i < length; i++)
       
  1460 		{
       
  1461 		iChargingObservers[i]->UsbChargingPortType(aChargingPortType);
       
  1462 		}
       
  1463 	OstTraceFunctionExit0( CUSBDEVICE_SETCHARGINGPORTTYPE_EXIT );
       
  1464 	}
       
  1465 
       
  1466 void CUsbDevice::PeerDeviceMaxPower(TUint aCurrent)
       
  1467 	{
       
  1468 	OstTraceFunctionEntry0( CUSBDEVICE_PEERDEVICEMAXPOWER_ENTRY );
       
  1469 	OstTrace1( TRACE_NORMAL, CUSBDEVICE_PEERDEVICEMAXPOWER_DUP, "CUsbDevice::PeerDeviceMaxPower with aCurrent=%d", aCurrent);
       
  1470 	TUint length = iChargingObservers.Count();
       
  1471 
       
  1472 	for (TUint i = 0; i < length; i++)
       
  1473 		{
       
  1474 		iChargingObservers[i]->PeerDeviceMaxPower(aCurrent);
       
  1475 		}		
       
  1476 	OstTraceFunctionExit0( CUSBDEVICE_PEERDEVICEMAXPOWER_EXIT );
       
  1477 	}
       
  1478 
       
  1479 #endif
       
  1480