usbmgmt/usbmgr/usbman/server/SRC/cusbhost.cpp
changeset 54 320d509f1a12
parent 36 1a2a19ee918d
equal deleted inserted replaced
51:eaaed528d5fd 54:320d509f1a12
    13 *
    13 *
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 
    17 
       
    18 #ifdef SYMBIAN_USB_BATTERYCHARGING_V1_1
       
    19 #include <usb/d32usbdescriptors.h>
       
    20 #else
       
    21 #include <d32usbdescriptors.h>
       
    22 #endif
    18 #include <usb/usblogger.h>
    23 #include <usb/usblogger.h>
    19 #include "cusbhost.h"
    24 #include "cusbhost.h"
       
    25 #include "CUsbServer.h"
       
    26 #include "CUsbDevice.h"
       
    27 
    20 #include "OstTraceDefinitions.h"
    28 #include "OstTraceDefinitions.h"
    21 #ifdef OST_TRACE_COMPILER_IN_USE
    29 #ifdef OST_TRACE_COMPILER_IN_USE
    22 #include "cusbhostTraces.h"
    30 #include "cusbhostTraces.h"
    23 #endif
    31 #endif
    24 
    32 
    25 
    33 
    26 CUsbHost* CUsbHost::iInstance = 0;
    34 CUsbHost* CUsbHost::iInstance = 0;
    27 
    35 
    28 CUsbHost* CUsbHost::NewL()
    36 CUsbHost* CUsbHost::NewL(CUsbServer& aServer)
    29 	{
    37 	{
    30 	if(iInstance == 0)
    38 	if(iInstance == 0)
    31 		{
    39 		{
    32 		iInstance = new (ELeave) CUsbHost();		
    40 		iInstance = new (ELeave) CUsbHost(aServer);		
    33 		CleanupStack::PushL(iInstance);		
    41 		CleanupStack::PushL(iInstance);		
    34 		iInstance->ConstructL();		
    42 		iInstance->ConstructL();		
    35 		CleanupStack::Pop(iInstance);
    43 		CleanupStack::Pop(iInstance);
    36 		}	
    44 		}	
    37 	return iInstance;
    45 	return iInstance;
    52 	iObservers.Close();
    60 	iObservers.Close();
    53 	iInstance = 0;
    61 	iInstance = 0;
    54 	OstTraceFunctionExit0( CUSBHOST_CUSBHOST_DES_EXIT );
    62 	OstTraceFunctionExit0( CUSBHOST_CUSBHOST_DES_EXIT );
    55 	}
    63 	}
    56 
    64 
    57 CUsbHost::CUsbHost()
    65 CUsbHost::CUsbHost(CUsbServer& aServer)
       
    66 	: iUsbServer(aServer)
    58 	{
    67 	{
    59     OstTraceFunctionEntry0( CUSBHOST_CUSBHOST_CONS_ENTRY );
    68     OstTraceFunctionEntry0( CUSBHOST_CUSBHOST_CONS_ENTRY );
    60 	OstTraceFunctionExit0( CUSBHOST_CUSBHOST_CONS_EXIT );
    69 	OstTraceFunctionExit0( CUSBHOST_CUSBHOST_CONS_EXIT );
    61 	}
    70 	}
    62 
    71 
   205 	}
   214 	}
   206 
   215 
   207 void CUsbHost::NotifyHostEvent(TUint aWatcherId)
   216 void CUsbHost::NotifyHostEvent(TUint aWatcherId)
   208 	{
   217 	{
   209     OstTraceFunctionEntry0( CUSBHOST_NOTIFYHOSTEVENT_ENTRY );
   218     OstTraceFunctionEntry0( CUSBHOST_NOTIFYHOSTEVENT_ENTRY );
       
   219 #ifdef SYMBIAN_USB_BATTERYCHARGING_V1_1	
       
   220 	ProcessHostEvent(aWatcherId);
       
   221 #endif
   210 
   222 
   211 	if(aWatcherId == EHostEventMonitor)
   223 	if(aWatcherId == EHostEventMonitor)
   212 		{
   224 		{
   213 		OstTrace1( TRACE_NORMAL, CUSBHOST_NOTIFYHOSTEVENT, "CUsbHost::NotifyHostEvent;DeviceId=%d", iHostEventInfo.iDeviceId );
   225 		OstTrace1( TRACE_NORMAL, CUSBHOST_NOTIFYHOSTEVENT, "CUsbHost::NotifyHostEvent;DeviceId=%d", iHostEventInfo.iDeviceId );
   214 		OstTrace1( TRACE_NORMAL, CUSBHOST_NOTIFYHOSTEVENT_DUP1, "CUsbHost::NotifyHostEvent;iEventType=%d", iHostEventInfo.iEventType );
   226 		OstTrace1( TRACE_NORMAL, CUSBHOST_NOTIFYHOSTEVENT_DUP1, "CUsbHost::NotifyHostEvent;iEventType=%d", iHostEventInfo.iEventType );
   263 		{
   275 		{
   264 		iUsbHostStack.DisableDriverLoading();
   276 		iUsbHostStack.DisableDriverLoading();
   265 		}
   277 		}
   266 	OstTraceFunctionExit0( CUSBHOST_DISABLEDRIVERLOADING_EXIT );
   278 	OstTraceFunctionExit0( CUSBHOST_DISABLEDRIVERLOADING_EXIT );
   267 	}
   279 	}
       
   280 
       
   281 #ifdef SYMBIAN_USB_BATTERYCHARGING_V1_1
       
   282 
       
   283 void CUsbHost::ProcessHostEvent(TUint aWatcherId)
       
   284 	{
       
   285 	OstTraceFunctionEntry0( CUSBHOST_PROCESSHOSTEVENT_ENTRY );
       
   286 	TConfigurationDescriptor configDesc;
       
   287 	const TUint KSuspend_Current = 2; //suspend current is 2mA
       
   288 
       
   289 	if(aWatcherId == EHostEventMonitor)
       
   290 		{
       
   291 		// if driver is loaded successful the device enters configed state and we get the max power from configration.
       
   292 		if (iHostEventInfo.iEventType == EDriverLoad 
       
   293 			&& iHostEventInfo.iDriverLoadStatus != EDriverLoadFailure)
       
   294 			{
       
   295 			TInt ret = iUsbHostStack.GetConfigurationDescriptor(iHostEventInfo.iDeviceId, configDesc);
       
   296 			if (ret == KErrNone)
       
   297 				{
       
   298         		TUint currentValue = configDesc.iMaxPower <<1;
       
   299 				iUsbServer.Device().PeerDeviceMaxPower(currentValue);
       
   300 				}
       
   301 			}
       
   302 		// if driver is loaded with failure the device enters suspend state.		
       
   303 		else if (iHostEventInfo.iEventType == EDriverLoad && 
       
   304 			iHostEventInfo.iDriverLoadStatus == EDriverLoadFailure)
       
   305 			{
       
   306 			iUsbServer.Device().PeerDeviceMaxPower(KSuspend_Current);
       
   307 			}
       
   308 		// if a device is unattached .		
       
   309 		else if (iHostEventInfo.iEventType == EDeviceDetachment)
       
   310 			{
       
   311 			iUsbServer.Device().PeerDeviceMaxPower(0);
       
   312 			}
       
   313 		}
       
   314 	OstTraceFunctionExit0( CUSBHOST_PROCESSHOSTEVENT_EXIT );
       
   315 	}
       
   316 #endif
       
   317