usbmgmt/usbmgr/usbman/server/SRC/CUsbSession.cpp
branchRCL_3
changeset 15 f92a4f87e424
parent 6 96e575696901
child 16 012cc2ee6408
equal deleted inserted replaced
14:d3e8e7d462dd 15:f92a4f87e424
     1 /*
     1 /*
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 1997-2010 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  @file
    20  @file
    21 */
    21 */
    22 
    22 
       
    23 #include <usbstates.h>
       
    24 #include <usberrors.h>
       
    25 #include <usb/usbshared.h>
    23 #include <usb/usblogger.h>
    26 #include <usb/usblogger.h>
       
    27 
    24 #include "CUsbSession.h"
    28 #include "CUsbSession.h"
    25 #include "CUsbDevice.h"
    29 #include "CUsbDevice.h"
    26 #include "CUsbServer.h"
    30 #include "CUsbServer.h"
    27 
    31 
    28 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
    32 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
    29 #include "CUsbOtg.h"
    33 #include "CUsbOtg.h"
    30 #include "cusbhost.h"
    34 #include "cusbhost.h"
    31 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
    35 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
    32 
    36 
    33 #include <usbstates.h>
       
    34 #include <usberrors.h>
       
    35 
       
    36 #include <usb/usbshared.h>
       
    37 #include "CPersonality.h"
    37 #include "CPersonality.h"
    38 #include "rusb.h"
    38 #include "rusb.h"
    39 #include "UsbSettings.h"
    39 #include "UsbSettings.h"
    40 
    40 #include "OstTraceDefinitions.h"
    41 #ifdef __FLOG_ACTIVE
    41 #ifdef OST_TRACE_COMPILER_IN_USE
    42 _LIT8(KLogComponent, "USBSVR");
    42 #include "CUsbSessionTraces.h"
    43 #endif
    43 #endif
       
    44 
       
    45 
    44 
    46 
    45 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
    47 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
    46 CUsbSession* CUsbSession::iCtlSession = NULL;
    48 CUsbSession* CUsbSession::iCtlSession = NULL;
    47 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
    49 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
    48 
    50 
    54  *
    56  *
    55  * @return	A new CUsbSession object
    57  * @return	A new CUsbSession object
    56  */
    58  */
    57 CUsbSession* CUsbSession::NewL(CUsbServer* aServer)
    59 CUsbSession* CUsbSession::NewL(CUsbServer* aServer)
    58 	{
    60 	{
    59 	LOG_STATIC_FUNC_ENTRY
    61 	OstTraceFunctionEntry0( CUSBSESSION_NEWL_ENTRY );
    60 
    62 
    61 	//this class has moved away from standard NewL() semantics
    63 	//this class has moved away from standard NewL() semantics
    62 	//and now uses the virtual CSession2::CreateL() function
    64 	//and now uses the virtual CSession2::CreateL() function
    63 	//[instead of ConstructL()] which is called by CServer2
    65 	//[instead of ConstructL()] which is called by CServer2
    64 	//and finalises the construction of the session
    66 	//and finalises the construction of the session
    73  * @param	aServer	Service the session will be a member of
    75  * @param	aServer	Service the session will be a member of
    74  */
    76  */
    75 CUsbSession::CUsbSession(CUsbServer* aServer)
    77 CUsbSession::CUsbSession(CUsbServer* aServer)
    76 	: iUsbServer(aServer)
    78 	: iUsbServer(aServer)
    77 	{
    79 	{
    78 	LOG_FUNC
    80 	OstTraceFunctionEntry0( CUSBSESSION_CUSBSESSION_CONS_ENTRY );
    79 
    81 
    80 	iUsbServer->IncrementSessionCount();
    82 	iUsbServer->IncrementSessionCount();
       
    83 	OstTraceFunctionExit0( CUSBSESSION_CUSBSESSION_CONS_EXIT );
    81 	}
    84 	}
    82 
    85 
    83 
    86 
    84 /**
    87 /**
    85  * Destructor.
    88  * Destructor.
    86  */
    89  */
    87 CUsbSession::~CUsbSession()
    90 CUsbSession::~CUsbSession()
    88 	{
    91 	{
    89 	LOG_FUNC
    92 	OstTraceFunctionEntry0( CUSBSESSION_CUSBSESSION_DES_ENTRY );
    90 
    93 
    91 	LOGTEXT2(_L8("About to Device().DeRegisterObserver(%08x"),this);
    94 	OstTrace1( TRACE_NORMAL, CUSBSESSION_CUSBSESSION, "CUsbSession::~CUsbSession;About to Device().DeRegisterObserver(%08x)", this );
    92 	iUsbServer->Device().DeRegisterObserver(*this);
    95 	iUsbServer->Device().DeRegisterObserver(*this);
    93 
    96 
    94 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
    97 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
    95 #ifndef __OVER_DUMMYUSBDI__
    98 #ifndef __OVER_DUMMYUSBDI__
    96 	LOGTEXT2(_L8("About to Otg().DeRegisterObserver(%08x"),this);
    99 	OstTrace1( TRACE_NORMAL, CUSBSESSION_CUSBSESSION_DUP1, "CUsbSession::~CUsbSession;About to Otg().DeRegisterObserver(%08x)", this );
    97 	iUsbServer->Otg().DeRegisterObserver(*this);
   100 	iUsbServer->Otg().DeRegisterObserver(*this);
    98 #endif
   101 #endif
    99 
   102 
   100 	LOGTEXT2(_L8("About to Host().DeRegisterObserver(%08x"),this);
   103 	OstTrace1( TRACE_NORMAL, CUSBSESSION_CUSBSESSION_DUP2, "CUsbSession::~CUsbSession;About to Host().DeRegisterObserver(%08x)", this );
   101 	iUsbServer->Host().DeregisterObserver(*this);
   104 	iUsbServer->Host().DeregisterObserver(*this);
   102 
   105 
   103 	if ( iCtlSession && (iCtlSession == this) )
   106 	if ( iCtlSession && (iCtlSession == this) )
   104 		{
   107 		{
   105 		iCtlSession = NULL;
   108 		iCtlSession = NULL;
   106 		}
   109 		}
   107 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
   110 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
   108 
   111 
   109 	LOGTEXT(_L8("About to iUsbServer->DecrementSessionCount()"));
   112 	OstTrace0( TRACE_NORMAL, CUSBSESSION_CUSBSESSION_DUP3, "CUsbSession::~CUsbSession;About to iUsbServer->DecrementSessionCount()" );
   110 	iUsbServer->DecrementSessionCount();
   113 	iUsbServer->DecrementSessionCount();
       
   114 	OstTraceFunctionExit0( CUSBSESSION_CUSBSESSION_DES_EXIT );
   111 	}
   115 	}
   112 
   116 
   113 
   117 
   114 /**
   118 /**
   115  * Called when a message is received from the client.
   119  * Called when a message is received from the client.
   116  *
   120  *
   117  * @param	aMessage	Message received from the client
   121  * @param	aMessage	Message received from the client
   118  */
   122  */
   119 void CUsbSession::ServiceL(const RMessage2& aMessage)
   123 void CUsbSession::ServiceL(const RMessage2& aMessage)
   120 	{
   124 	{
   121 	LOG_FUNC
   125 	OstTraceFunctionEntry0( CUSBSESSION_SERVICEL_ENTRY );
   122 
   126 
   123 	DispatchMessageL(aMessage);
   127 	DispatchMessageL(aMessage);
       
   128 	OstTraceFunctionExit0( CUSBSESSION_SERVICEL_EXIT );
   124 	}
   129 	}
   125 
   130 
   126 /**
   131 /**
   127  * Handles 2nd Phase Construction.  Implementation of the virtual method defined in CSession2 and called from
   132  * Handles 2nd Phase Construction.  Implementation of the virtual method defined in CSession2 and called from
   128  * CServer2::DoConnectL() which executes when the client makes a connection request through CServer2::Connect().  If
   133  * CServer2::DoConnectL() which executes when the client makes a connection request through CServer2::Connect().  If
   129  * a Leave occurs at any point the CUsbSession object is cleaned up in CServer2::DoConnect().
   134  * a Leave occurs at any point the CUsbSession object is cleaned up in CServer2::DoConnect().
   130  */
   135  */
   131 void CUsbSession::CreateL()
   136 void CUsbSession::CreateL()
   132 	{
   137 	{
   133 	LOG_FUNC
   138 	OstTraceFunctionEntry0( CUSBSESSION_CREATEL_ENTRY );
   134 
   139 
   135 	// This code originally existed in the typical non-virtual ConstructL() method.
   140 	// This code originally existed in the typical non-virtual ConstructL() method.
   136 	// However it was moved to this method for minor optimisation reasons [three less
   141 	// However it was moved to this method for minor optimisation reasons [three less
   137 	// function calls and several lines less code in the NewL() method].
   142 	// function calls and several lines less code in the NewL() method].
   138 
   143 
   139 	iPersonalityCfged = iUsbServer->Device().isPersonalityCfged();
   144 	iPersonalityCfged = iUsbServer->Device().isPersonalityCfged();
   140 
   145 
   141     LOGTEXT(_L8("Registering Device Observer\n"));
   146     OstTrace0( TRACE_NORMAL, CUSBSESSION_CREATEL, "CUsbSession::CreateL;Registering Device Observer" );
   142 	iUsbServer->Device().RegisterObserverL(*this);
   147 	iUsbServer->Device().RegisterObserverL(*this);
   143 
   148 
   144 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
   149 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
   145 #ifndef __OVER_DUMMYUSBDI__
   150 #ifndef __OVER_DUMMYUSBDI__
   146 	LOGTEXT(_L8("Registering OTG Observer\n"));
   151 	OstTrace0( TRACE_NORMAL, CUSBSESSION_CREATEL_DUP1, "CUsbSession::CreateL;Registering OTG Observer" );
   147 	iUsbServer->Otg().RegisterObserverL(*this);
   152 	iUsbServer->Otg().RegisterObserverL(*this);
   148 #endif
   153 #endif
   149 
   154 
   150 	LOGTEXT(_L8("Registering HOST Observer\n"));
   155 	OstTrace0( TRACE_NORMAL, CUSBSESSION_CREATEL_DUP2, "CUsbSession::CreateL;Registering HOST Observer" );
   151 	iUsbServer->Host().RegisterObserverL(*this);
   156 	iUsbServer->Host().RegisterObserverL(*this);
   152 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
   157 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
       
   158 	OstTraceFunctionExit0( CUSBSESSION_CREATEL_EXIT );
   153 	}
   159 	}
   154 
   160 
   155 /**
   161 /**
   156  * Called by CUsbDevice when the service state changes.
   162  * Called by CUsbDevice when the service state changes.
   157  * CUsbSession is an observer of the device.
   163  * CUsbSession is an observer of the device.
   161  * @param	aNewState	The device's new and current service state
   167  * @param	aNewState	The device's new and current service state
   162  */
   168  */
   163 void CUsbSession::UsbServiceStateChange(TInt aLastError, TUsbServiceState aOldState,
   169 void CUsbSession::UsbServiceStateChange(TInt aLastError, TUsbServiceState aOldState,
   164 										TUsbServiceState aNewState)
   170 										TUsbServiceState aNewState)
   165 	{
   171 	{
   166 	LOG_FUNC
   172 	OstTraceFunctionEntry0( CUSBSESSION_USBSERVICESTATECHANGE_ENTRY );
   167 	LOGTEXT3(_L8("    aOldState=0x%X, aNewState=0x%X"), aOldState, aNewState);
   173 	OstTraceExt2( TRACE_NORMAL, CUSBSESSION_USBSERVICESTATECHANGE, "CUsbSession::UsbServiceStateChange;aOldState=0x%X, aNewState=0x%X", aOldState, aNewState );
   168 	(void) aOldState; // a-void build warning in UREL
   174 	(void) aOldState; // a-void build warning in UREL
   169 
   175 
   170 	// Note that it's possible to have both a start and a stop outstanding!
   176 	// Note that it's possible to have both a start and a stop outstanding!
   171 
   177 
   172 	if (iStartOutstanding)
   178 	if (iStartOutstanding)
   186 		TPckg<TUint32> pckg(aNewState);
   192 		TPckg<TUint32> pckg(aNewState);
   187 		iServiceObserverOutstanding = EFalse;
   193 		iServiceObserverOutstanding = EFalse;
   188 		const TInt err = iServiceObserverMessage.Write(0, pckg);
   194 		const TInt err = iServiceObserverMessage.Write(0, pckg);
   189 		iServiceObserverMessage.Complete(err);
   195 		iServiceObserverMessage.Complete(err);
   190 		}
   196 		}
       
   197 	OstTraceFunctionExit0( CUSBSESSION_USBSERVICESTATECHANGE_EXIT );
   191 	}
   198 	}
   192 
   199 
   193 /**
   200 /**
   194  * Handles a state change while a start request is currently outstanding.
   201  * Handles a state change while a start request is currently outstanding.
   195  *
   202  *
   197  * @param aNewState The state we've moved to
   204  * @param aNewState The state we've moved to
   198  */
   205  */
   199 void CUsbSession::HandleServiceStateChangeWhileStarting(TInt aLastError,
   206 void CUsbSession::HandleServiceStateChangeWhileStarting(TInt aLastError,
   200 												 TUsbServiceState aNewState)
   207 												 TUsbServiceState aNewState)
   201 	{
   208 	{
   202 	LOG_FUNC
   209 	OstTraceFunctionEntry0( CUSBSESSION_HANDLESERVICESTATECHANGEWHILESTARTING_ENTRY );
   203 
   210 
   204 	switch (aNewState)
   211 	switch (aNewState)
   205 		{
   212 		{
   206 	case EUsbServiceStarted:
   213 	case EUsbServiceStarted:
   207 		LOGTEXT(_L8("    Completing Start successfully"));
   214 		OstTrace0( TRACE_NORMAL, CUSBSESSION_HANDLESERVICESTATECHANGEWHILESTARTING, "CUsbSession::HandleServiceStateChangeWhileStarting    Completing Start successfully" );
   208 
   215 
   209 		// If the user has tried to cancel the start, they're too late!
   216 		// If the user has tried to cancel the start, they're too late!
   210 		if (iCancelOutstanding)
   217 		if (iCancelOutstanding)
   211 			{
   218 			{
   212 			LOGTEXT(_L8("    Completing cancel request with KErrNone"));
   219 			OstTrace0( TRACE_NORMAL, CUSBSESSION_HANDLESERVICESTATECHANGEWHILESTARTING_DUP1, "CUsbSession::HandleServiceStateChangeWhileStarting    Completing cancel request with KErrNone" );
   213 			iCancelOutstanding = EFalse;
   220 			iCancelOutstanding = EFalse;
   214 			iCancelMessage.Complete(KErrNone);
   221 			iCancelMessage.Complete(KErrNone);
   215 			}
   222 			}
   216 
   223 
   217 		iStartMessage.Complete(KErrNone);
   224 		iStartMessage.Complete(KErrNone);
   218 		iStartOutstanding = EFalse;
   225 		iStartOutstanding = EFalse;
   219 		break;
   226 		break;
   220 
   227 
   221 	case EUsbServiceIdle:
   228 	case EUsbServiceIdle:
   222 		LOGTEXT2(_L8("    Completing Start with error=%d"), aLastError);
   229 		OstTrace1( TRACE_NORMAL, CUSBSESSION_HANDLESERVICESTATECHANGEWHILESTARTING_DUP2, "CUsbSession::HandleServiceStateChangeWhileStarting;    Completing Start with error=%d", aLastError );
   223 
   230 
   224 		// If there hasn't actually been an error, but we're in an unexpected
   231 		// If there hasn't actually been an error, but we're in an unexpected
   225 		// state now, that means that this client cancelled the request, or
   232 		// state now, that means that this client cancelled the request, or
   226 		// another client stopped the service.
   233 		// another client stopped the service.
   227 		if (aLastError == KErrNone)
   234 		if (aLastError == KErrNone)
   228 			{
   235 			{
   229 			// If there's a cancel outstanding, then that message succeeded, but
   236 			// If there's a cancel outstanding, then that message succeeded, but
   230 			// the start message should be completed with KErrCancel.
   237 			// the start message should be completed with KErrCancel.
   231 			if (iCancelOutstanding)
   238 			if (iCancelOutstanding)
   232 				{
   239 				{
   233 				LOGTEXT(_L8("    Completing original message with KErrCancel"));
   240 				OstTrace0( TRACE_NORMAL, CUSBSESSION_HANDLESERVICESTATECHANGEWHILESTARTING_DUP3, "CUsbSession::HandleServiceStateChangeWhileStarting    Completing original message with KErrCancel" );
   234 				iCancelOutstanding = EFalse;
   241 				iCancelOutstanding = EFalse;
   235 				iCancelMessage.Complete(KErrNone);
   242 				iCancelMessage.Complete(KErrNone);
   236 				iStartMessage.Complete(KErrCancel);
   243 				iStartMessage.Complete(KErrCancel);
   237 				}
   244 				}
   238 			else
   245 			else
   256 		break;
   263 		break;
   257 
   264 
   258 	default:
   265 	default:
   259 		break;
   266 		break;
   260 		}
   267 		}
       
   268 	OstTraceFunctionExit0( CUSBSESSION_HANDLESERVICESTATECHANGEWHILESTARTING_EXIT );
   261 	}
   269 	}
   262 
   270 
   263 /**
   271 /**
   264  * Handles a state change while a stop request is currently outstanding.
   272  * Handles a state change while a stop request is currently outstanding.
   265  *
   273  *
   267  * @param aNewState The state we've moved to
   275  * @param aNewState The state we've moved to
   268  */
   276  */
   269 void CUsbSession::HandleServiceStateChangeWhileStopping(TInt aLastError,
   277 void CUsbSession::HandleServiceStateChangeWhileStopping(TInt aLastError,
   270 												 TUsbServiceState aNewState)
   278 												 TUsbServiceState aNewState)
   271 	{
   279 	{
   272 	LOG_FUNC
   280 	OstTraceFunctionEntry0( CUSBSESSION_HANDLESERVICESTATECHANGEWHILESTOPPING_ENTRY );
   273 
   281 
   274 	switch (aNewState)
   282 	switch (aNewState)
   275 		{
   283 		{
   276 	case EUsbServiceStarted:
   284 	case EUsbServiceStarted:
   277 		LOGTEXT2(_L8("    Completing Stop with error=%d"), aLastError);
   285 		OstTrace1( TRACE_NORMAL, CUSBSESSION_HANDLESERVICESTATECHANGEWHILESTOPPING, "CUsbSession::HandleServiceStateChangeWhileStopping;    Completing Stop with error=%d", aLastError );
   278 
   286 
   279 		// If there hasn't actually been an error, but we're in an unexpected
   287 		// If there hasn't actually been an error, but we're in an unexpected
   280 		// state now, that means that this client cancelled the request, or
   288 		// state now, that means that this client cancelled the request, or
   281 		// another client has started the service.
   289 		// another client has started the service.
   282 		if (aLastError == KErrNone)
   290 		if (aLastError == KErrNone)
   283 			{
   291 			{
   284 			// If there's a cancel outstanding, then that message succeeded, but
   292 			// If there's a cancel outstanding, then that message succeeded, but
   285 			// the stop message should be completed with KErrCancel.
   293 			// the stop message should be completed with KErrCancel.
   286 			if (iCancelOutstanding)
   294 			if (iCancelOutstanding)
   287 				{
   295 				{
   288 				LOGTEXT(_L8("    Completing original message with KErrCancel"));
   296 				OstTrace0( TRACE_NORMAL, CUSBSESSION_HANDLESERVICESTATECHANGEWHILESTOPPING_DUP1, "CUsbSession::HandleServiceStateChangeWhileStopping;    Completing original message with KErrCancel" );
   289 				iCancelOutstanding = EFalse;
   297 				iCancelOutstanding = EFalse;
   290 				iCancelMessage.Complete(KErrNone);
   298 				iCancelMessage.Complete(KErrNone);
   291 				iStopMessage.Complete(KErrCancel);
   299 				iStopMessage.Complete(KErrCancel);
   292 				}
   300 				}
   293 			else
   301 			else
   309 
   317 
   310 		iStopOutstanding = EFalse;
   318 		iStopOutstanding = EFalse;
   311 		break;
   319 		break;
   312 
   320 
   313 	case EUsbServiceIdle:
   321 	case EUsbServiceIdle:
   314 		LOGTEXT(_L8("    Completing Stop with KErrNone"));
   322 		OstTrace0( TRACE_NORMAL, CUSBSESSION_HANDLESERVICESTATECHANGEWHILESTOPPING_DUP2, "CUsbSession::HandleServiceStateChangeWhileStopping    Completing Stop with KErrNone" );
   315 
   323 
   316 		// If the user has tried to cancel the stop, they're too late!
   324 		// If the user has tried to cancel the stop, they're too late!
   317 		if (iCancelOutstanding)
   325 		if (iCancelOutstanding)
   318 			{
   326 			{
   319 			LOGTEXT(_L8("    Completing cancel request with KErrNone"));
   327 			OstTrace0( TRACE_NORMAL, CUSBSESSION_HANDLESERVICESTATECHANGEWHILESTOPPING_DUP3, "CUsbSession::HandleServiceStateChangeWhileStopping    Completing cancel request with KErrNone" );
   320 			iCancelOutstanding = EFalse;
   328 			iCancelOutstanding = EFalse;
   321 			iCancelMessage.Complete(KErrNone);
   329 			iCancelMessage.Complete(KErrNone);
   322 			}
   330 			}
   323 
   331 
   324 		iStopMessage.Complete(KErrNone);
   332 		iStopMessage.Complete(KErrNone);
   326 		break;
   334 		break;
   327 
   335 
   328 	default:
   336 	default:
   329 		break;
   337 		break;
   330 		}
   338 		}
       
   339 	OstTraceFunctionExit0( CUSBSESSION_HANDLESERVICESTATECHANGEWHILESTOPPING_EXIT );
   331 	}
   340 	}
   332 
   341 
   333 /**
   342 /**
   334  * Called by CUsbDevice when it state change. CUsbSession is an observer of
   343  * Called by CUsbDevice when it state change. CUsbSession is an observer of
   335  * the device. If the client has an Observer outstanding then complete it,
   344  * the device. If the client has an Observer outstanding then complete it,
   341  * @param	aNewState	The device's new and current state
   350  * @param	aNewState	The device's new and current state
   342  */
   351  */
   343 void CUsbSession::UsbDeviceStateChange(TInt /*aLastError*/, TUsbDeviceState /*aOldState*/,
   352 void CUsbSession::UsbDeviceStateChange(TInt /*aLastError*/, TUsbDeviceState /*aOldState*/,
   344 									   TUsbDeviceState aNewState)
   353 									   TUsbDeviceState aNewState)
   345 	{
   354 	{
   346 	LOG_FUNC
   355 	OstTraceFunctionEntry0( CUSBSESSION_USBDEVICESTATECHANGE_ENTRY );
   347 
   356 
   348 	// can we bypass the queue?
   357 	// can we bypass the queue?
   349  	if ((iDeviceObserverOutstanding) && (iDevStateQueueHead == iDevStateQueueTail))
   358  	if ((iDeviceObserverOutstanding) && (iDevStateQueueHead == iDevStateQueueTail))
   350 		{
   359 		{
   351 		if ((iDeviceObserverMessage.Int0() & aNewState) ||
   360 		if ((iDeviceObserverMessage.Int0() & aNewState) ||
   382  			while (queuePtr != iDevStateQueueHead)
   391  			while (queuePtr != iDevStateQueueHead)
   383  				{
   392  				{
   384  				if (aNewState == iDeviceStateQueue[queuePtr])
   393  				if (aNewState == iDeviceStateQueue[queuePtr])
   385  					{
   394  					{
   386  					// Event is already queued; discard the duplicate and in-between events
   395  					// Event is already queued; discard the duplicate and in-between events
   387  					LOGTEXT3(_L8("--- collapsing queue head (%d, %d)"),
   396  					OstTraceExt2( TRACE_NORMAL, CUSBSESSION_USBDEVICESTATECHANGE, "CUsbSession::UsbDeviceStateChange;--- collapsing queue head (%d, %d)", iDevStateQueueHead, ((queuePtr + 1) % KDeviceStatesQueueSize) );
   388 						iDevStateQueueHead,
   397 
   389 						(queuePtr + 1) % KDeviceStatesQueueSize);
       
   390 
   398 
   391  					// queue head moved to position following the match
   399  					// queue head moved to position following the match
   392  					iDevStateQueueHead = (queuePtr + 1) % KDeviceStatesQueueSize;
   400  					iDevStateQueueHead = (queuePtr + 1) % KDeviceStatesQueueSize;
   393  					addToQueue = EFalse;
   401  					addToQueue = EFalse;
   394  					break;
   402  					break;
   403  		if (addToQueue)
   411  		if (addToQueue)
   404  			{
   412  			{
   405  			// add event to head of queue
   413  			// add event to head of queue
   406  			iDeviceStateQueue[iDevStateQueueHead] = aNewState;
   414  			iDeviceStateQueue[iDevStateQueueHead] = aNewState;
   407  			iDevStateQueueHead = (iDevStateQueueHead + 1) % KDeviceStatesQueueSize;
   415  			iDevStateQueueHead = (iDevStateQueueHead + 1) % KDeviceStatesQueueSize;
   408  			LOGTEXT3(_L8("+++ addqueue (%d, %d)"), iDevStateQueueHead,
   416  			OstTraceExt2( TRACE_NORMAL, CUSBSESSION_USBDEVICESTATECHANGE_DUP1, "CUsbSession::UsbDeviceStateChange;+++ addqueue (%d, %d)", iDevStateQueueHead, iDevStateQueueTail );
   409 				iDevStateQueueTail);
       
   410  			}
   417  			}
   411 
   418 
   412  		// UsbDeviceDequeueEvent() will read from queue when RegisterObserver()
   419  		// UsbDeviceDequeueEvent() will read from queue when RegisterObserver()
   413 		// is next called.
   420 		// is next called.
   414 		}
   421 		}
       
   422 	OstTraceFunctionExit0( CUSBSESSION_USBDEVICESTATECHANGE_EXIT );
   415 	}
   423 	}
   416 
   424 
   417 /**
   425 /**
   418  * Dequeues an event and completes the observer's request with it.
   426  * Dequeues an event and completes the observer's request with it.
   419  */
   427  */
   420 void CUsbSession::UsbDeviceDequeueEvent()
   428 void CUsbSession::UsbDeviceDequeueEvent()
   421  	{
   429  	{
   422 	LOG_FUNC
   430 	OstTraceFunctionEntry0( CUSBSESSION_USBDEVICEDEQUEUEEVENT_ENTRY );
   423 
   431 
   424  	// Work our way through the queue, until we reach the end
   432  	// Work our way through the queue, until we reach the end
   425  	// OR we find an event the current observer wants.
   433  	// OR we find an event the current observer wants.
   426  	while ((iDeviceObserverOutstanding) && (iDevStateQueueHead != iDevStateQueueTail))
   434  	while ((iDeviceObserverOutstanding) && (iDevStateQueueHead != iDevStateQueueTail))
   427  		{
   435  		{
   438  			{
   446  			{
   439  			TPckg<TUint32> pckg(newState);
   447  			TPckg<TUint32> pckg(newState);
   440 
   448 
   441  			iNotifiedDevState = newState;
   449  			iNotifiedDevState = newState;
   442 
   450 
   443  			LOGTEXT3(_L8(">>> dequeued event #%d (0x%x)"), iDevStateQueueTail, newState);
   451  			OstTraceExt2( TRACE_NORMAL, CUSBSESSION_USBDEVICEDEQUEUEEVENT, "CUsbSession::UsbDeviceDequeueEvent;dequeued event #%d (0x%x)", iDevStateQueueTail, newState );
   444 
   452 
   445   			iDeviceObserverOutstanding = EFalse;
   453   			iDeviceObserverOutstanding = EFalse;
   446 			const TInt err = iDeviceObserverMessage.Write(1, pckg);
   454 			const TInt err = iDeviceObserverMessage.Write(1, pckg);
   447  			iDeviceObserverMessage.Complete(err);
   455  			iDeviceObserverMessage.Complete(err);
   448  			break;
   456  			break;
   449    			}
   457    			}
   450    		}
   458    		}
       
   459    	OstTraceFunctionExit0( CUSBSESSION_USBDEVICEDEQUEUEEVENT_EXIT );
   451    	}
   460    	}
   452 
   461 
   453 /**
   462 /**
   454  * Handles the request (in the form of a the message) received from the client
   463  * Handles the request (in the form of a the message) received from the client
   455  *
   464  *
   456  * @internalComponent
   465  * @internalComponent
   457  * @param	aMessage	The received message
   466  * @param	aMessage	The received message
   458  */
   467  */
   459 void CUsbSession::DispatchMessageL(const RMessage2& aMessage)
   468 void CUsbSession::DispatchMessageL(const RMessage2& aMessage)
   460 	{
   469 	{
   461 	LOG_FUNC
   470 	OstTraceFunctionEntry0( CUSBSESSION_DISPATCHMESSAGEL_ENTRY );
   462 
   471 
   463 	TBool complete = ETrue;
   472 	TBool complete = ETrue;
   464 	TInt ret = KErrNone;
   473 	TInt ret = KErrNone;
   465 
   474 
   466 	LOGTEXT2(_L8("CUsbSession::DispatchMessageL(): func# %d"), aMessage.Function());
   475 	OstTrace1( TRACE_NORMAL, CUSBSESSION_DISPATCHMESSAGEL, "CUsbSession::DispatchMessageL;func#=%d", aMessage.Function() );
   467 
   476 
   468 	switch (aMessage.Function())
   477 	switch (aMessage.Function())
   469 		{
   478 		{
   470 	case EUsbStart:
   479 	case EUsbStart:
   471 		ret = StartDeviceL(aMessage, complete);
   480 		ret = StartDeviceL(aMessage, complete);
   516 		ret = GetPersonalityIds(aMessage);
   525 		ret = GetPersonalityIds(aMessage);
   517 		break;
   526 		break;
   518 	case EUsbGetDescription:
   527 	case EUsbGetDescription:
   519 		ret = GetDescription(aMessage);
   528 		ret = GetDescription(aMessage);
   520 		break;
   529 		break;
   521 	case EUsbGetDetailedDescription:
       
   522 		ret = GetDetailedDescription(aMessage);
       
   523 		break;
       
   524 	case EUsbGetPersonalityProperty:
   530 	case EUsbGetPersonalityProperty:
   525 		ret = GetPersonalityProperty(aMessage);
   531 		ret = GetPersonalityProperty(aMessage);
   526 		break;
   532 		break;
   527 	case EUsbClassSupported:
   533 	case EUsbClassSupported:
   528 		ret = ClassSupported(aMessage);
   534 		ret = ClassSupported(aMessage);
   530 
   536 
   531 #ifdef _DEBUG
   537 #ifdef _DEBUG
   532 	// Heap failure debug APIs.
   538 	// Heap failure debug APIs.
   533 
   539 
   534 	case EUsbDbgMarkHeap:
   540 	case EUsbDbgMarkHeap:
   535 		LOGTEXT(_L8("Marking heap"));
   541 		OstTrace0( TRACE_NORMAL, CUSBSESSION_DISPATCHMESSAGEL_DUP1, "CUsbSession::DispatchMessageL;Marking heap" );
   536 		__UHEAP_MARK;
   542 		__UHEAP_MARK;
   537 		break;
   543 		break;
   538 	case EUsbDbgCheckHeap:
   544 	case EUsbDbgCheckHeap:
   539 		LOGTEXT2(_L8("Checking heap (expecting %d cells)"), aMessage.Int0());
   545 		OstTrace1( TRACE_NORMAL, CUSBSESSION_DISPATCHMESSAGEL_DUP2, "CUsbSession::DispatchMessageL;Checking heap (expecting %d cells)", aMessage.Int0() );
   540 		__UHEAP_CHECK(aMessage.Int0());
   546 		__UHEAP_CHECK(aMessage.Int0());
   541 		break;
   547 		break;
   542 	case EUsbDbgMarkEnd:
   548 	case EUsbDbgMarkEnd:
   543 		LOGTEXT2(_L8("End of marking heap (expecting %d cells)"), aMessage.Int0());
   549 		OstTrace1( TRACE_NORMAL, CUSBSESSION_DISPATCHMESSAGEL_DUP3, "CUsbSession::DispatchMessageL;End of marking heap (expecting %d cells)", aMessage.Int0() );
   544 		__UHEAP_MARKENDC(aMessage.Int0());
   550 		__UHEAP_MARKENDC(aMessage.Int0());
   545 		break;
   551 		break;
   546 	case EUsbDbgFailNext:
   552 	case EUsbDbgFailNext:
   547 		{
   553 		{
   548 		LOGTEXT2(_L8("Simulating failure after %d allocation(s)"), aMessage.Int0());
   554 		OstTrace1( TRACE_NORMAL, CUSBSESSION_DISPATCHMESSAGEL_DUP4, "CUsbSession::DispatchMessageL;Simulating failure after %d allocation(s)", aMessage.Int0() );
   549 		if (aMessage.Int0() == 0)
   555 		if (aMessage.Int0() == 0)
   550 			__UHEAP_RESET;
   556 			__UHEAP_RESET;
   551 		else
   557 		else
   552 			__UHEAP_FAILNEXT(aMessage.Int0());
   558 			__UHEAP_FAILNEXT(aMessage.Int0());
   553 		}
   559 		}
   554 		break;
   560 		break;
   555 	case EUsbDbgAlloc:
   561 	case EUsbDbgAlloc:
   556 		{
   562 		{
   557 		ret = KErrNone;
   563 		ret = KErrNone;
   558 #ifdef _DEBUG
   564 #ifdef _DEBUG
   559 		LOGTEXT(_L8("\tallocate on the heap"));
   565 		OstTrace0( TRACE_NORMAL, CUSBSESSION_DISPATCHMESSAGEL_DUP5, "CUsbSession::DispatchMessageL;allocate on the heap" );
   560 		TInt* x = NULL;
   566 		TInt* x = NULL;
   561 		TRAP(ret, x = new(ELeave) TInt);
   567 		TRAP(ret, x = new(ELeave) TInt);
   562 		delete x;
   568 		delete x;
   563 #endif // _DEBUG
   569 #endif // _DEBUG
   564 		}
   570 		}
   644 		ret = KErrNotSupported;
   650 		ret = KErrNotSupported;
   645 		break;
   651 		break;
   646 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
   652 #endif // SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
   647 
   653 
   648 	default:
   654 	default:
   649 		LOGTEXT2(_L8("Illegal IPC argument(%d) - Panicking Client..."), aMessage.Function());
   655 		OstTrace1( TRACE_NORMAL, CUSBSESSION_DISPATCHMESSAGEL_DUP6, "CUsbSession::DispatchMessageL;Illegal IPC argument(%d) - Panicking Client...", aMessage.Function() );
   650 		aMessage.Panic(KUsbCliPncCat, EUsbPanicIllegalIPC);
   656 		aMessage.Panic(KUsbCliPncCat, EUsbPanicIllegalIPC);
   651 		complete = EFalse;
   657 		complete = EFalse;
   652 		break;
   658 		break;
   653 		}
   659 		}
   654 
   660 
   655 	if (complete)
   661 	if (complete)
   656 		aMessage.Complete(ret);
   662 		aMessage.Complete(ret);
       
   663 	OstTraceFunctionExit0( CUSBSESSION_DISPATCHMESSAGEL_EXIT );
   657 	}
   664 	}
   658 
   665 
   659 
   666 
   660 /**
   667 /**
   661  * Client request to start the device.
   668  * Client request to start the device.
   664  * @param	aComplete	Whether the request is complete or not
   671  * @param	aComplete	Whether the request is complete or not
   665  * @return	Any error that occurred or KErrNone
   672  * @return	Any error that occurred or KErrNone
   666  */
   673  */
   667 TInt CUsbSession::StartDeviceL(const RMessage2& aMessage, TBool& aComplete)
   674 TInt CUsbSession::StartDeviceL(const RMessage2& aMessage, TBool& aComplete)
   668 	{
   675 	{
   669 	LOG_FUNC
   676 	OstTraceFunctionEntry0( CUSBSESSION_STARTDEVICEL_ENTRY );
   670 
   677 
   671 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
   678 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
   672 	// Only 'control' session is allowed to start USB support
   679 	// Only 'control' session is allowed to start USB support
   673 	if ( !iSessionCtlMode )
   680 	if ( !iSessionCtlMode )
   674 		{
   681 		{
       
   682 		OstTraceFunctionExit0( CUSBSESSION_STARTDEVICEL_EXIT );
   675 		return KErrAccessDenied;
   683 		return KErrAccessDenied;
   676 		}
   684 		}
   677 #endif
   685 #endif
   678 
   686 
   679 	if (iStartOutstanding)
   687 	if (iStartOutstanding)
   703 		aComplete = EFalse;
   711 		aComplete = EFalse;
   704 		iStartMessage = aMessage;
   712 		iStartMessage = aMessage;
   705 		iStartOutstanding = ETrue;
   713 		iStartOutstanding = ETrue;
   706 		}
   714 		}
   707 
   715 
       
   716 	OstTraceFunctionExit0( CUSBSESSION_STARTDEVICEL_EXIT_DUP1 );
   708 	return KErrNone;
   717 	return KErrNone;
   709 
   718 
   710 #else
   719 #else
   711 	// pretend that the server is in Started state
   720 	// pretend that the server is in Started state
   712 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
   721 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
   713 	iUsbServer->Host().StartL();
   722 	iUsbServer->Host().StartL();
   714 #endif
   723 #endif
   715 	iStartOutstanding = EFalse;
   724 	iStartOutstanding = EFalse;
   716 	aMessage.IsNull();
   725 	aMessage.IsNull();
   717 	aComplete = ETrue;
   726 	aComplete = ETrue;
       
   727 	OstTraceFunctionExit0( CUSBSESSION_STARTDEVICEL_EXIT_DUP2 );
   718 	return KErrNone;
   728 	return KErrNone;
   719 
   729 
   720 #endif
   730 #endif
   721 	}
   731 	}
   722 
   732 
   727  * @param	aComplete	Whether the request is complete or not
   737  * @param	aComplete	Whether the request is complete or not
   728  * @return	Any error that occurred or KErrNone
   738  * @return	Any error that occurred or KErrNone
   729  */
   739  */
   730 TInt CUsbSession::StopDeviceL(const RMessage2& aMessage, TBool& aComplete)
   740 TInt CUsbSession::StopDeviceL(const RMessage2& aMessage, TBool& aComplete)
   731     {
   741     {
   732 	LOG_FUNC
   742 	OstTraceFunctionEntry0( CUSBSESSION_STOPDEVICEL_ENTRY );
   733 
   743 
   734 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
   744 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
   735 	// Only 'control' session is allowed to stop USB support
   745 	// Only 'control' session is allowed to stop USB support
   736 	if ( !iSessionCtlMode )
   746 	if ( !iSessionCtlMode )
   737 		{
   747 		{
       
   748 		OstTraceFunctionExit0( CUSBSESSION_STOPDEVICEL_EXIT );
   738 		return KErrAccessDenied;
   749 		return KErrAccessDenied;
   739 		}
   750 		}
   740 #endif
   751 #endif
   741 
   752 
   742 	if (iStopOutstanding)
   753 	if (iStopOutstanding)
   743 		{
   754 		{
       
   755 		OstTraceFunctionExit0( CUSBSESSION_STOPDEVICEL_EXIT_DUP1 );
   744 		return KErrInUse;
   756 		return KErrInUse;
   745 		}
   757 		}
   746 
   758 
   747 #ifndef __OVER_DUMMYUSBDI__
   759 #ifndef __OVER_DUMMYUSBDI__
   748 
   760 
   758 		aComplete = EFalse;
   770 		aComplete = EFalse;
   759 		iStopMessage = aMessage;
   771 		iStopMessage = aMessage;
   760 		iStopOutstanding = ETrue;
   772 		iStopOutstanding = ETrue;
   761 		}
   773 		}
   762 
   774 
       
   775 	OstTraceFunctionExit0( CUSBSESSION_STOPDEVICEL_EXIT_DUP2 );
   763 	return KErrNone;
   776 	return KErrNone;
   764 
   777 
   765 #else
   778 #else
   766 	// pretend that the server is in Started state
   779 	// pretend that the server is in Started state
   767 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
   780 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
   768 	iUsbServer->Host().Stop();
   781 	iUsbServer->Host().Stop();
   769 #endif
   782 #endif
   770 	aComplete = ETrue;
   783 	aComplete = ETrue;
   771 	aMessage.IsNull();
   784 	aMessage.IsNull();
   772 	iStopOutstanding = EFalse;
   785 	iStopOutstanding = EFalse;
       
   786 	OstTraceFunctionExit0( CUSBSESSION_STOPDEVICEL_EXIT_DUP3 );
   773 	return KErrNone;
   787 	return KErrNone;
   774 
   788 
   775 #endif
   789 #endif
   776     }
   790     }
   777 
   791 
   784  * @param aComplete Whether the message is complete or not
   798  * @param aComplete Whether the message is complete or not
   785  * @return Always KErrNone
   799  * @return Always KErrNone
   786  */
   800  */
   787 TInt CUsbSession::StartCancel(const RMessage2& aMessage, TBool& aComplete)
   801 TInt CUsbSession::StartCancel(const RMessage2& aMessage, TBool& aComplete)
   788 	{
   802 	{
   789 	LOG_FUNC
   803 	OstTraceFunctionEntry0( CUSBSESSION_STARTCANCEL_ENTRY );
   790 
   804 
   791 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
   805 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
   792 	// Only 'control' session is allowed to cancel outstaning start request
   806 	// Only 'control' session is allowed to cancel outstaning start request
   793 	if ( !iSessionCtlMode )
   807 	if ( !iSessionCtlMode )
   794 		{
   808 		{
       
   809 		OstTraceFunctionExit0( CUSBSESSION_STARTCANCEL_EXIT );
   795 		return KErrAccessDenied;
   810 		return KErrAccessDenied;
   796 		}
   811 		}
   797 #endif
   812 #endif
   798 
   813 
   799 	if (!iStartOutstanding)
   814 	if (!iStartOutstanding)
   809 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
   824 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
   810 		iUsbServer->Host().Stop();
   825 		iUsbServer->Host().Stop();
   811 #endif
   826 #endif
   812 		}
   827 		}
   813 
   828 
       
   829 	OstTraceFunctionExit0( CUSBSESSION_STARTCANCEL_EXIT_DUP1 );
   814 	return KErrNone;
   830 	return KErrNone;
   815 	}
   831 	}
   816 
   832 
   817 /**
   833 /**
   818  * Cancel the pending stop operation. Note that this can just be implemented as
   834  * Cancel the pending stop operation. Note that this can just be implemented as
   823  * @param aComplete Whether the message is complete or not
   839  * @param aComplete Whether the message is complete or not
   824  * @return KErrNone on success, otherwise standard error codes
   840  * @return KErrNone on success, otherwise standard error codes
   825  */
   841  */
   826 TInt CUsbSession::StopCancel(const RMessage2& aMessage, TBool& aComplete)
   842 TInt CUsbSession::StopCancel(const RMessage2& aMessage, TBool& aComplete)
   827 	{
   843 	{
   828 	LOG_FUNC
   844 	OstTraceFunctionEntry0( CUSBSESSION_STOPCANCEL_ENTRY );
   829 
       
   830 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
   845 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
   831 	// Only 'control' session is allowed to cancel outstaning stop request
   846 	// Only 'control' session is allowed to cancel outstaning stop request
   832 	if ( !iSessionCtlMode )
   847 	if ( !iSessionCtlMode )
   833 		{
   848 		{
       
   849 		OstTraceFunctionExit0( CUSBSESSION_STOPCANCEL_EXIT );
   834 		return KErrAccessDenied;
   850 		return KErrAccessDenied;
   835 		}
   851 		}
   836 #endif
   852 #endif
   837 
   853 
   838 	if (!iStopOutstanding)
   854 	if (!iStopOutstanding)
   839 		{
   855 		{
       
   856 		OstTraceFunctionExit0( CUSBSESSION_STOPCANCEL_EXIT_DUP1 );
   840 		return KErrNone;
   857 		return KErrNone;
   841 		}
   858 		}
   842 
   859 
   843 	aComplete = EFalse;
   860 	aComplete = EFalse;
   844 	iCancelMessage = aMessage;
   861 	iCancelMessage = aMessage;
   848 	TRAPD(errHost,iUsbServer->Host().StartL());
   865 	TRAPD(errHost,iUsbServer->Host().StartL());
   849 	if (errHost != KErrNone)
   866 	if (errHost != KErrNone)
   850 		return errHost;
   867 		return errHost;
   851 #endif
   868 #endif
   852 	TRAPD(err, iUsbServer->Device().StartL());
   869 	TRAPD(err, iUsbServer->Device().StartL());
       
   870 	OstTraceFunctionExit0( CUSBSESSION_STOPCANCEL_EXIT_DUP2 );
   853 	return err;
   871 	return err;
   854 	}
   872 	}
   855 
   873 
   856 /**
   874 /**
   857  * Client request to observe the device (for state changes).
   875  * Client request to observe the device (for state changes).
   863  *
   881  *
   864  * @return	Any error that occurred or KErrNone
   882  * @return	Any error that occurred or KErrNone
   865  */
   883  */
   866 TInt CUsbSession::RegisterDeviceObserver(const RMessage2& aMessage, TBool& aComplete)
   884 TInt CUsbSession::RegisterDeviceObserver(const RMessage2& aMessage, TBool& aComplete)
   867 	{
   885 	{
   868 	LOG_FUNC
   886 	OstTraceFunctionEntry0( CUSBSESSION_REGISTERDEVICEOBSERVER_ENTRY );
   869 
   887 
   870 	if (iDeviceObserverOutstanding)
   888 	if (iDeviceObserverOutstanding)
   871 		{
   889 		{
       
   890 		OstTraceFunctionExit0( CUSBSESSION_REGISTERDEVICEOBSERVER_EXIT );
   872 		return KErrInUse;
   891 		return KErrInUse;
   873 		}
   892 		}
   874 
   893 
   875 	iDeviceObserverMessage = aMessage;
   894 	iDeviceObserverMessage = aMessage;
   876 	iDeviceObserverOutstanding = ETrue;
   895 	iDeviceObserverOutstanding = ETrue;
   878 
   897 
   879  	if (iObserverQueueEvents == EFalse)
   898  	if (iObserverQueueEvents == EFalse)
   880 	 	{
   899 	 	{
   881  		// This is the first observer after c'tor or DeregisterObserver(),
   900  		// This is the first observer after c'tor or DeregisterObserver(),
   882  		// so zap the device event queue.
   901  		// so zap the device event queue.
   883  		LOGTEXT(_L8("    Reset Device Event Queue"));
   902  		OstTrace0( TRACE_NORMAL, CUSBSESSION_REGISTERDEVICEOBSERVER, "CUsbSession::RegisterDeviceObserver    Reset Device Event Queue" );
   884  		iDevStateQueueHead = 0;
   903  		iDevStateQueueHead = 0;
   885  		iDevStateQueueTail = 0;
   904  		iDevStateQueueTail = 0;
   886  		iObserverQueueEvents = ETrue;
   905  		iObserverQueueEvents = ETrue;
   887 	 	}
   906 	 	}
   888  	else if (iDevStateQueueHead != iDevStateQueueTail)
   907  	else if (iDevStateQueueHead != iDevStateQueueTail)
   889 	 	{
   908 	 	{
   890  		// event(s) queued, we can de-queue one now
   909  		// event(s) queued, we can de-queue one now
   891  		UsbDeviceDequeueEvent();
   910  		UsbDeviceDequeueEvent();
   892 	 	}
   911 	 	}
   893 
   912 
       
   913 	OstTraceFunctionExit0( CUSBSESSION_REGISTERDEVICEOBSERVER_EXIT_DUP1 );
   894 	return KErrNone;
   914 	return KErrNone;
   895 	}
   915 	}
   896 
   916 
   897 /**
   917 /**
   898  * Client request to observe the service (for state changes)
   918  * Client request to observe the service (for state changes)
   904  *
   924  *
   905  * @return	Any error that occurred or KErrNone
   925  * @return	Any error that occurred or KErrNone
   906  */
   926  */
   907 TInt CUsbSession::RegisterServiceObserver(const RMessage2& aMessage, TBool& aComplete)
   927 TInt CUsbSession::RegisterServiceObserver(const RMessage2& aMessage, TBool& aComplete)
   908 	{
   928 	{
   909 	LOG_FUNC
   929 	OstTraceFunctionEntry0( CUSBSESSION_REGISTERSERVICEOBSERVER_ENTRY );
   910 
   930 
   911 	if (iServiceObserverOutstanding)
   931 	if (iServiceObserverOutstanding)
   912 		{
   932 		{
       
   933 		OstTraceFunctionExit0( CUSBSESSION_REGISTERSERVICEOBSERVER_EXIT );
   913 		return KErrInUse;
   934 		return KErrInUse;
   914 		}
   935 		}
   915 
   936 
   916 	iServiceObserverMessage = aMessage;
   937 	iServiceObserverMessage = aMessage;
   917 	iServiceObserverOutstanding = ETrue;
   938 	iServiceObserverOutstanding = ETrue;
   918 	aComplete = EFalse;
   939 	aComplete = EFalse;
       
   940 	OstTraceFunctionExit0( CUSBSESSION_REGISTERSERVICEOBSERVER_EXIT_DUP1 );
   919 	return KErrNone;
   941 	return KErrNone;
   920 	}
   942 	}
   921 
   943 
   922 
   944 
   923 /**
   945 /**
   929  *
   951  *
   930  * @return	Any errors that occurred or KErrNone
   952  * @return	Any errors that occurred or KErrNone
   931  */
   953  */
   932 TInt CUsbSession::GetCurrentServiceState(const RMessage2& aMessage)
   954 TInt CUsbSession::GetCurrentServiceState(const RMessage2& aMessage)
   933 	{
   955 	{
   934 	LOG_FUNC
   956 	OstTraceFunctionEntry0( CUSBSESSION_GETCURRENTSERVICESTATE_ENTRY );
   935 
   957 
   936 	TUsbServiceState state = iUsbServer->Device().ServiceState();
   958 	TUsbServiceState state = iUsbServer->Device().ServiceState();
   937 	LOGTEXT2(_L8("\tstate = %d"), state);
   959 	OstTrace1( TRACE_NORMAL, CUSBSESSION_GETCURRENTSERVICESTATE, "CUsbSession::GetCurrentServiceState;state=%d", state );
   938 	TPckg<TUint32> pckg(state);
   960 	TPckg<TUint32> pckg(state);
   939 	return aMessage.Write(0, pckg);
   961 	return aMessage.Write(0, pckg);
   940 	}
   962 	}
   941 
   963 
   942 /**
   964 /**
   948  *
   970  *
   949  * @return	Any errors that occurred or KErrNone
   971  * @return	Any errors that occurred or KErrNone
   950  */
   972  */
   951 TInt CUsbSession::GetCurrentDeviceState(const RMessage2& aMessage)
   973 TInt CUsbSession::GetCurrentDeviceState(const RMessage2& aMessage)
   952 	{
   974 	{
   953 	LOG_FUNC
   975 	OstTraceFunctionEntry0( CUSBSESSION_GETCURRENTDEVICESTATE_ENTRY );
   954 
   976 
   955 	TUsbDeviceState state = iUsbServer->Device().DeviceState();
   977 	TUsbDeviceState state = iUsbServer->Device().DeviceState();
   956 	LOGTEXT2(_L8("\tstate = %d"), state);
   978 	OstTrace1( TRACE_NORMAL, CUSBSESSION_GETCURRENTDEVICESTATE, "CUsbSession::GetCurrentDeviceState;state=%d", state );
   957 	TPckg<TUint32> pckg(state);
   979 	TPckg<TUint32> pckg(state);
   958 	return aMessage.Write(0, pckg);
   980 	return aMessage.Write(0, pckg);
   959 	}
   981 	}
   960 
   982 
   961 
   983 
   966  *
   988  *
   967  * @return Always KErrNone
   989  * @return Always KErrNone
   968  */
   990  */
   969 TInt CUsbSession::DeRegisterDeviceObserver()
   991 TInt CUsbSession::DeRegisterDeviceObserver()
   970 	{
   992 	{
   971 	LOG_FUNC
   993 	OstTraceFunctionEntry0( CUSBSESSION_DEREGISTERDEVICEOBSERVER_ENTRY );
   972 
   994 
   973 	if (!iDeviceObserverOutstanding)
   995 	if (!iDeviceObserverOutstanding)
   974 		{
   996 		{
       
   997 		OstTraceFunctionExit0( CUSBSESSION_DEREGISTERDEVICEOBSERVER_EXIT );
   975 		return KErrNone;
   998 		return KErrNone;
   976 		}
   999 		}
   977 
  1000 
   978 	iDeviceObserverOutstanding = EFalse;
  1001 	iDeviceObserverOutstanding = EFalse;
   979 	iDeviceObserverMessage.Complete(KErrCancel);
  1002 	iDeviceObserverMessage.Complete(KErrCancel);
   980 
  1003 
   981 	// client doesn't need events queuing any more
  1004 	// client doesn't need events queuing any more
   982  	iObserverQueueEvents = EFalse;
  1005  	iObserverQueueEvents = EFalse;
   983 
  1006 
       
  1007 	OstTraceFunctionExit0( CUSBSESSION_DEREGISTERDEVICEOBSERVER_EXIT_DUP1 );
   984 	return KErrNone;
  1008 	return KErrNone;
   985 	}
  1009 	}
   986 
  1010 
   987 /**
  1011 /**
   988  * Deregister the client as an observer of service state changes. Note that we don't
  1012  * Deregister the client as an observer of service state changes. Note that we don't
   991  *
  1015  *
   992  * @return Always KErrNone
  1016  * @return Always KErrNone
   993  */
  1017  */
   994 TInt CUsbSession::DeRegisterServiceObserver()
  1018 TInt CUsbSession::DeRegisterServiceObserver()
   995 	{
  1019 	{
   996 	LOG_FUNC
  1020 	OstTraceFunctionEntry0( CUSBSESSION_DEREGISTERSERVICEOBSERVER_ENTRY );
   997 
  1021 
   998 	if (!iServiceObserverOutstanding)
  1022 	if (!iServiceObserverOutstanding)
   999 		{
  1023 		{
       
  1024 		OstTraceFunctionExit0( CUSBSESSION_DEREGISTERSERVICEOBSERVER_EXIT );
  1000 		return KErrNone;
  1025 		return KErrNone;
  1001 		}
  1026 		}
  1002 
  1027 
  1003 	iServiceObserverOutstanding = EFalse;
  1028 	iServiceObserverOutstanding = EFalse;
  1004 	iServiceObserverMessage.Complete(KErrCancel);
  1029 	iServiceObserverMessage.Complete(KErrCancel);
       
  1030 	OstTraceFunctionExit0( CUSBSESSION_DEREGISTERSERVICEOBSERVER_EXIT_DUP1 );
  1005 	return KErrNone;
  1031 	return KErrNone;
  1006 	}
  1032 	}
  1007 
  1033 
  1008 /**
  1034 /**
  1009  * Try starting the USB device.
  1035  * Try starting the USB device.
  1013  * @param	aComplete	set to true to complete the request
  1039  * @param	aComplete	set to true to complete the request
  1014  * @return	Any error that occurred or KErrNone
  1040  * @return	Any error that occurred or KErrNone
  1015  */
  1041  */
  1016 TInt CUsbSession::TryStartDeviceL(const RMessage2& aMessage, TBool& aComplete)
  1042 TInt CUsbSession::TryStartDeviceL(const RMessage2& aMessage, TBool& aComplete)
  1017 	{
  1043 	{
  1018 	LOG_FUNC
  1044 	OstTraceFunctionEntry0( CUSBSESSION_TRYSTARTDEVICEL_ENTRY );
  1019 
  1045 
  1020 #ifndef __OVER_DUMMYUSBDI__
  1046 #ifndef __OVER_DUMMYUSBDI__
  1021 
  1047 
  1022 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
  1048 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
  1023 	// Only 'control' session is allowed to start USB support
  1049 	// Only 'control' session is allowed to start USB support
  1024 	if ( !iSessionCtlMode )
  1050 	if ( !iSessionCtlMode )
  1025 		{
  1051 		{
       
  1052 		OstTraceFunctionExit0( CUSBSESSION_TRYSTARTDEVICEL_EXIT );
  1026 		return KErrAccessDenied;
  1053 		return KErrAccessDenied;
  1027 		}
  1054 		}
  1028 #endif
  1055 #endif
  1029 
  1056 
  1030 	if (!iPersonalityCfged)
  1057 	if (!iPersonalityCfged)
  1031 	{
  1058 	{
       
  1059 	OstTraceFunctionExit0( CUSBSESSION_TRYSTARTDEVICEL_EXIT_DUP1 );
  1032 	return KErrNotSupported;
  1060 	return KErrNotSupported;
  1033 	}
  1061 	}
  1034 
  1062 
  1035 	if (iStartOutstanding || iStopOutstanding)
  1063 	if (iStartOutstanding || iStopOutstanding)
  1036 		{
  1064 		{
       
  1065 		OstTraceFunctionExit0( CUSBSESSION_TRYSTARTDEVICEL_EXIT_DUP2 );
  1037 		return KErrServerBusy;
  1066 		return KErrServerBusy;
  1038 		}
  1067 		}
  1039 
  1068 
  1040 	// Obtains the curent service state
  1069 	// Obtains the curent service state
  1041 	TUsbServiceState state = iUsbServer->Device().ServiceState();
  1070 	TUsbServiceState state = iUsbServer->Device().ServiceState();
  1068 		}
  1097 		}
  1069 	else if (state == EUsbServiceStarting || state == EUsbServiceStarted)
  1098 	else if (state == EUsbServiceStarting || state == EUsbServiceStarted)
  1070 		{
  1099 		{
  1071 		if (aMessage.Int0() != iUsbServer->Device().CurrentPersonalityId())
  1100 		if (aMessage.Int0() != iUsbServer->Device().CurrentPersonalityId())
  1072 			{
  1101 			{
       
  1102 			OstTraceFunctionExit0( CUSBSESSION_TRYSTARTDEVICEL_EXIT_DUP3 );
  1073 			return KErrAbort;
  1103 			return KErrAbort;
  1074 			}
  1104 			}
  1075 
  1105 
  1076 		if (state == EUsbServiceStarting)
  1106 		if (state == EUsbServiceStarting)
  1077 			{
  1107 			{
  1080 			iStartOutstanding = ETrue;
  1110 			iStartOutstanding = ETrue;
  1081 			}
  1111 			}
  1082 		}
  1112 		}
  1083 	else if (state == EUsbServiceStopping)
  1113 	else if (state == EUsbServiceStopping)
  1084 		{
  1114 		{
       
  1115 		OstTraceFunctionExit0( CUSBSESSION_TRYSTARTDEVICEL_EXIT_DUP4 );
  1085 		return KErrServerBusy;
  1116 		return KErrServerBusy;
  1086 		}
  1117 		}
  1087 
  1118 
       
  1119 	OstTraceFunctionExit0( CUSBSESSION_TRYSTARTDEVICEL_EXIT_DUP5 );
  1088 	return KErrNone;
  1120 	return KErrNone;
  1089 
  1121 
  1090 #else
  1122 #else
  1091 	// pretend that the server is in Started state
  1123 	// pretend that the server is in Started state
  1092 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
  1124 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
  1093 	iUsbServer->Host().StartL();
  1125 	iUsbServer->Host().StartL();
  1094 #endif
  1126 #endif
  1095 	iStartOutstanding = EFalse;
  1127 	iStartOutstanding = EFalse;
  1096 	aMessage.IsNull();
  1128 	aMessage.IsNull();
  1097 	aComplete = ETrue;
  1129 	aComplete = ETrue;
       
  1130 	OstTraceFunctionExit0( CUSBSESSION_TRYSTARTDEVICEL_EXIT_DUP6 );
  1098 	return KErrNone;
  1131 	return KErrNone;
  1099 #endif
  1132 #endif
  1100 	}
  1133 	}
  1101 
  1134 
  1102 /**
  1135 /**
  1107  * @param	aComplete	Whether the request is complete or not
  1140  * @param	aComplete	Whether the request is complete or not
  1108  * @return	Any error that occurred or KErrNone
  1141  * @return	Any error that occurred or KErrNone
  1109  */
  1142  */
  1110 TInt CUsbSession::TryStopDeviceL(const RMessage2& aMessage, TBool& aComplete)
  1143 TInt CUsbSession::TryStopDeviceL(const RMessage2& aMessage, TBool& aComplete)
  1111 	{
  1144 	{
  1112 	LOG_FUNC
  1145 	OstTraceFunctionEntry0( CUSBSESSION_TRYSTOPDEVICEL_ENTRY );
  1113 
  1146 
  1114 #ifndef __OVER_DUMMYUSBDI__
  1147 #ifndef __OVER_DUMMYUSBDI__
  1115 
  1148 
  1116 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
  1149 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
  1117 	// Only 'control' session is allowed to stop USB support
  1150 	// Only 'control' session is allowed to stop USB support
  1118 	if ( !iSessionCtlMode )
  1151 	if ( !iSessionCtlMode )
  1119 		{
  1152 		{
       
  1153 		OstTraceFunctionExit0( CUSBSESSION_TRYSTOPDEVICEL_EXIT );
  1120 		return KErrAccessDenied;
  1154 		return KErrAccessDenied;
  1121 		}
  1155 		}
  1122 #endif
  1156 #endif
  1123 
  1157 
  1124 	if (!iPersonalityCfged)
  1158 	if (!iPersonalityCfged)
  1125 		{
  1159 		{
       
  1160 		OstTraceFunctionExit0( CUSBSESSION_TRYSTOPDEVICEL_EXIT_DUP1 );
  1126 		return KErrNotSupported;
  1161 		return KErrNotSupported;
  1127 		}
  1162 		}
  1128 
  1163 
  1129 	if (iStartOutstanding || iStopOutstanding)
  1164 	if (iStartOutstanding || iStopOutstanding)
  1130 		{
  1165 		{
       
  1166 		OstTraceFunctionExit0( CUSBSESSION_TRYSTOPDEVICEL_EXIT_DUP2 );
  1131 		return KErrServerBusy;
  1167 		return KErrServerBusy;
  1132 		}
  1168 		}
  1133 
  1169 
  1134 	// Obtains the curent service state
  1170 	// Obtains the curent service state
  1135 	TUsbServiceState state = iUsbServer->Device().ServiceState();
  1171 	TUsbServiceState state = iUsbServer->Device().ServiceState();
  1155 		iStopMessage = aMessage;
  1191 		iStopMessage = aMessage;
  1156 		iStopOutstanding = ETrue;
  1192 		iStopOutstanding = ETrue;
  1157 		}
  1193 		}
  1158 	else if (state == EUsbServiceStarting)
  1194 	else if (state == EUsbServiceStarting)
  1159 		{
  1195 		{
       
  1196 		OstTraceFunctionExit0( CUSBSESSION_TRYSTOPDEVICEL_EXIT_DUP3 );
  1160 		return KErrServerBusy;
  1197 		return KErrServerBusy;
  1161 		}
  1198 		}
  1162 	else if (state == EUsbServiceStopping)
  1199 	else if (state == EUsbServiceStopping)
  1163 		{
  1200 		{
  1164 		aComplete = EFalse;
  1201 		aComplete = EFalse;
  1165 		iStopMessage = aMessage;
  1202 		iStopMessage = aMessage;
  1166 		iStopOutstanding = ETrue;
  1203 		iStopOutstanding = ETrue;
  1167 		}
  1204 		}
  1168 
  1205 
       
  1206 	OstTraceFunctionExit0( CUSBSESSION_TRYSTOPDEVICEL_EXIT_DUP4 );
  1169 	return KErrNone;
  1207 	return KErrNone;
  1170 
  1208 
  1171 #else
  1209 #else
  1172 	// pretend that the server is in Started state
  1210 	// pretend that the server is in Started state
  1173 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
  1211 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
  1174 	iUsbServer->Host().Stop();
  1212 	iUsbServer->Host().Stop();
  1175 #endif
  1213 #endif
  1176 	aMessage.IsNull();
  1214 	aMessage.IsNull();
  1177 	aComplete = ETrue;
  1215 	aComplete = ETrue;
  1178 	iStopOutstanding = EFalse;
  1216 	iStopOutstanding = EFalse;
       
  1217 	OstTraceFunctionExit0( CUSBSESSION_TRYSTOPDEVICEL_EXIT_DUP5 );
  1179 	return KErrNone;
  1218 	return KErrNone;
  1180 #endif
  1219 #endif
  1181 	}
  1220 	}
  1182 
  1221 
  1183 /**
  1222 /**
  1188  * @param	aMessage	Message received from the client
  1227  * @param	aMessage	Message received from the client
  1189  * @return	KErrCancel
  1228  * @return	KErrCancel
  1190  */
  1229  */
  1191 TInt CUsbSession::CancelInterest(const RMessage2& aMessage)
  1230 TInt CUsbSession::CancelInterest(const RMessage2& aMessage)
  1192 	{
  1231 	{
  1193 	LOG_FUNC
  1232 	OstTraceFunctionEntry0( CUSBSESSION_CANCELINTEREST_ENTRY );
  1194 
  1233 
  1195 	if (!iPersonalityCfged)
  1234 	if (!iPersonalityCfged)
  1196 		{
  1235 		{
       
  1236 		OstTraceFunctionExit0( CUSBSESSION_CANCELINTEREST_EXIT );
  1197 		return KErrNotSupported;
  1237 		return KErrNotSupported;
  1198 		}
  1238 		}
  1199 
  1239 
  1200 	TUsbMessages toBeCancelledMsg = static_cast<TUsbMessages>(aMessage.Int0());
  1240 	TUsbMessages toBeCancelledMsg = static_cast<TUsbMessages>(aMessage.Int0());
  1201 	if (toBeCancelledMsg == EUsbStart || toBeCancelledMsg == EUsbTryStart)
  1241 	if (toBeCancelledMsg == EUsbStart || toBeCancelledMsg == EUsbTryStart)
  1213 			iStopMessage.Complete(KErrNone);
  1253 			iStopMessage.Complete(KErrNone);
  1214 			iStopOutstanding = EFalse;
  1254 			iStopOutstanding = EFalse;
  1215 			}
  1255 			}
  1216 		}
  1256 		}
  1217 
  1257 
       
  1258 	OstTraceFunctionExit0( CUSBSESSION_CANCELINTEREST_EXIT_DUP1 );
  1218 	return KErrCancel;
  1259 	return KErrCancel;
  1219 	}
  1260 	}
  1220 
  1261 
  1221 /**
  1262 /**
  1222  * Gets the current personality id.
  1263  * Gets the current personality id.
  1225  * @param	aMessage	Message received from the client
  1266  * @param	aMessage	Message received from the client
  1226  * @return	Any error that occurred or KErrNone
  1267  * @return	Any error that occurred or KErrNone
  1227  */
  1268  */
  1228 TInt CUsbSession::GetCurrentPersonalityId(const RMessage2& aMessage)
  1269 TInt CUsbSession::GetCurrentPersonalityId(const RMessage2& aMessage)
  1229 	{
  1270 	{
  1230 	LOG_FUNC
  1271 	OstTraceFunctionEntry0( CUSBSESSION_GETCURRENTPERSONALITYID_ENTRY );
  1231 
  1272 
  1232 	if (!iPersonalityCfged)
  1273 	if (!iPersonalityCfged)
  1233 		{
  1274 		{
       
  1275 		OstTraceFunctionExit0( CUSBSESSION_GETCURRENTPERSONALITYID_EXIT );
  1234 		return KErrNotSupported;
  1276 		return KErrNotSupported;
  1235 		}
  1277 		}
  1236 
  1278 
  1237 	TInt currentPersonalityId = iUsbServer->Device().CurrentPersonalityId();
  1279 	TInt currentPersonalityId = iUsbServer->Device().CurrentPersonalityId();
  1238 	LOGTEXT2(_L8("\tcurrentPersonalityId = %d"), currentPersonalityId);
  1280 	OstTrace1( TRACE_NORMAL, CUSBSESSION_GETCURRENTPERSONALITYID, "CUsbSession::GetCurrentPersonalityId;currentPersonalityId=%d", currentPersonalityId );
  1239 	TPckgC<TInt> pckg(currentPersonalityId);
  1281 	TPckgC<TInt> pckg(currentPersonalityId);
  1240 	return aMessage.Write(0, pckg);
  1282 	return aMessage.Write(0, pckg);
  1241 	}
  1283 	}
  1242 
  1284 
  1243 /**
  1285 /**
  1249  *          KErrNotSupported if personality is not configured
  1291  *          KErrNotSupported if personality is not configured
  1250  * 			return code from RMessage2.Write()
  1292  * 			return code from RMessage2.Write()
  1251  */
  1293  */
  1252 TInt CUsbSession::GetSupportedClasses(const RMessage2& aMessage)
  1294 TInt CUsbSession::GetSupportedClasses(const RMessage2& aMessage)
  1253 	{
  1295 	{
  1254 	LOG_FUNC
  1296 	OstTraceFunctionEntry0( CUSBSESSION_GETSUPPORTEDCLASSES_ENTRY );
  1255 
  1297 
  1256 	if (!iPersonalityCfged)
  1298 	if (!iPersonalityCfged)
  1257 		{
  1299 		{
       
  1300 		OstTraceFunctionExit0( CUSBSESSION_GETSUPPORTEDCLASSES_EXIT );
  1258 		return KErrNotSupported;
  1301 		return KErrNotSupported;
  1259 		}
  1302 		}
  1260 
  1303 
  1261 	// +1 for the size of actual class uid count
  1304 	// +1 for the size of actual class uid count
  1262 	TInt32 classUids[KUsbMaxSupportedClasses + 1];
  1305 	TInt32 classUids[KUsbMaxSupportedClasses + 1];
  1264 	// Gets all class uids for the given personality
  1307 	// Gets all class uids for the given personality
  1265 	const RPointerArray<CPersonality>&  personalities = iUsbServer->Device().Personalities();
  1308 	const RPointerArray<CPersonality>&  personalities = iUsbServer->Device().Personalities();
  1266 	TInt personalityCount = personalities.Count();
  1309 	TInt personalityCount = personalities.Count();
  1267 	for (TInt i = 0; i < personalityCount; i++)
  1310 	for (TInt i = 0; i < personalityCount; i++)
  1268 		{
  1311 		{
  1269 		__ASSERT_ALWAYS(personalities[i] != NULL, _USB_PANIC(KUsbSvrPncCat, ENullPersonalityPointer));
  1312 		if(personalities[i] == NULL)
       
  1313 		    {
       
  1314             OstTrace1( TRACE_NORMAL, CUSBSESSION_GETSUPPORTEDCLASSES, "CUsbSession::GetSupportedClasses;ENullPersonalityPointer=%d", ENullPersonalityPointer );
       
  1315             User::Panic(KUsbSvrPncCat, ENullPersonalityPointer);
       
  1316 		    }
  1270 		if (aMessage.Int0() == personalities[i]->PersonalityId())
  1317 		if (aMessage.Int0() == personalities[i]->PersonalityId())
  1271 			{
  1318 			{
  1272 			classUids[0] = personalities[i]->SupportedClasses().Count();
  1319 			classUids[0] = personalities[i]->SupportedClasses().Count();
  1273 			for (TInt j = 1; j <= classUids[0]; j++)
  1320 			for (TInt j = 1; j <= classUids[0]; j++)
  1274 				{
  1321 				{
  1275 				if (j < KUsbMaxSupportedClasses + 1)
  1322 				if (j < KUsbMaxSupportedClasses + 1)
  1276 					{
  1323 					{
  1277 					classUids[j] = personalities[i]->SupportedClasses()[j - 1].iUid;
  1324 					classUids[j] = personalities[i]->SupportedClasses()[j - 1].iClassUid.iUid;
  1278 					LOGTEXT3(_L8("\tclassUids[%d] = %d"), j, classUids[j]);
  1325 					OstTrace1( TRACE_NORMAL, CUSBSESSION_GETSUPPORTEDCLASSES_DUP1, "CUsbSession::GetSupportedClasses;classUids[%d] = ", j );
       
  1326 					OstTrace1( TRACE_NORMAL, CUSBSESSION_GETSUPPORTEDCLASSES_DUP2, "%d", classUids[j] );					
  1279 					}
  1327 					}
  1280 				else
  1328 				else
  1281 					{
  1329 					{
       
  1330 					OstTraceFunctionExit0( CUSBSESSION_GETSUPPORTEDCLASSES_EXIT_DUP1 );
  1282 					return KErrTooBig;
  1331 					return KErrTooBig;
  1283 					}
  1332 					}
  1284 				}
  1333 				}
  1285 			break;
  1334 			break;
  1286 			}
  1335 			}
  1287 		}
  1336 		}
  1288 
  1337 
  1289 	if (classUids[0] == 0)
  1338 	if (classUids[0] == 0)
  1290 		{
  1339 		{
  1291 		// No supported classes are found
  1340 		// No supported classes are found
       
  1341 		OstTraceFunctionExit0( CUSBSESSION_GETSUPPORTEDCLASSES_EXIT_DUP2 );
  1292 		return KErrNotSupported;
  1342 		return KErrNotSupported;
  1293 		}
  1343 		}
  1294 
  1344 
  1295 	TInt ret;
  1345 	TInt ret;
  1296 	HBufC8* buf = NULL;
  1346 	HBufC8* buf = NULL;
  1301 		ptr8.Copy(reinterpret_cast<TUint8*>(classUids), (classUids[0] + 1)*sizeof(TInt32));
  1351 		ptr8.Copy(reinterpret_cast<TUint8*>(classUids), (classUids[0] + 1)*sizeof(TInt32));
  1302 		ret = aMessage.Write(1, ptr8);
  1352 		ret = aMessage.Write(1, ptr8);
  1303 		}
  1353 		}
  1304 
  1354 
  1305 	delete buf;
  1355 	delete buf;
       
  1356 	OstTraceFunctionExit0( CUSBSESSION_GETSUPPORTEDCLASSES_EXIT_DUP3 );
  1306 	return ret;
  1357 	return ret;
  1307 	}
  1358 	}
  1308 
  1359 
  1309 /**
  1360 /**
  1310  * Gets all personality ids.
  1361  * Gets all personality ids.
  1313  * @param	aMessage	Message received from the client
  1364  * @param	aMessage	Message received from the client
  1314  * @return	Any error that occurred or KErrNone
  1365  * @return	Any error that occurred or KErrNone
  1315  */
  1366  */
  1316 TInt CUsbSession::GetPersonalityIds(const RMessage2& aMessage)
  1367 TInt CUsbSession::GetPersonalityIds(const RMessage2& aMessage)
  1317 	{
  1368 	{
  1318 	LOG_FUNC
  1369 	OstTraceFunctionEntry0( CUSBSESSION_GETPERSONALITYIDS_ENTRY );
  1319 
  1370 
  1320 	if (!iPersonalityCfged)
  1371 	if (!iPersonalityCfged)
  1321 		{
  1372 		{
       
  1373 		OstTraceFunctionExit0( CUSBSESSION_GETPERSONALITYIDS_EXIT );
  1322 		return KErrNotSupported;
  1374 		return KErrNotSupported;
  1323 		}
  1375 		}
  1324 
  1376 
  1325 	// +1 for the size of actual personality id count
  1377 	// +1 for the size of actual personality id count
  1326 	TInt personalityIds[KUsbMaxSupportedPersonalities + 1];
  1378 	TInt personalityIds[KUsbMaxSupportedPersonalities + 1];
  1327 
  1379 
  1328 	const RPointerArray<CPersonality>&  personalities = iUsbServer->Device().Personalities();
  1380 	const RPointerArray<CPersonality>&  personalities = iUsbServer->Device().Personalities();
  1329 	TInt personalityCount = personalities.Count();
  1381 	TInt personalityCount = personalities.Count();
  1330 	for (TInt i = 0; i < personalityCount; ++i)
  1382 	for (TInt i = 0; i < personalityCount; ++i)
  1331 		{
  1383 		{
  1332 		__ASSERT_ALWAYS(personalities[i] != NULL, _USB_PANIC(KUsbSvrPncCat, ENullPersonalityPointer));
  1384         if(personalities[i] == NULL)
       
  1385             {
       
  1386             OstTrace1( TRACE_NORMAL, CUSBSESSION_GETPERSONALITYIDS, "CUsbSession::GetPersonalityIds;Panic reason=%d", ENullPersonalityPointer );
       
  1387             User::Panic(KUsbSvrPncCat, ENullPersonalityPointer);
       
  1388             }
  1333 		personalityIds[i + 1] = personalities[i]->PersonalityId();
  1389 		personalityIds[i + 1] = personalities[i]->PersonalityId();
  1334 		}
  1390 		}
  1335 	personalityIds[0] = personalityCount;
  1391 	personalityIds[0] = personalityCount;
  1336 
  1392 
  1337 	TInt ret;
  1393 	TInt ret;
  1343 		ptr8.Copy(reinterpret_cast<TUint8*>(personalityIds), (personalityCount + 1)*sizeof(TInt));
  1399 		ptr8.Copy(reinterpret_cast<TUint8*>(personalityIds), (personalityCount + 1)*sizeof(TInt));
  1344 		ret = aMessage.Write(0, ptr8);
  1400 		ret = aMessage.Write(0, ptr8);
  1345 		}
  1401 		}
  1346 
  1402 
  1347 	delete buf;
  1403 	delete buf;
       
  1404 	OstTraceFunctionExit0( CUSBSESSION_GETPERSONALITYIDS_EXIT_DUP1 );
  1348 	return ret;
  1405 	return ret;
  1349 	}
  1406 	}
  1350 
  1407 
  1351 /**
  1408 /**
  1352  * Gets personality description
  1409  * Gets personality description
  1355  * @param	aMessage	Message received from the client
  1412  * @param	aMessage	Message received from the client
  1356  * @return	Any error that occurred or KErrNone
  1413  * @return	Any error that occurred or KErrNone
  1357  */
  1414  */
  1358 TInt CUsbSession::GetDescription(const RMessage2& aMessage)
  1415 TInt CUsbSession::GetDescription(const RMessage2& aMessage)
  1359 	{
  1416 	{
  1360 	LOG_FUNC
  1417 	OstTraceFunctionEntry0( CUSBSESSION_GETDESCRIPTION_ENTRY );
  1361 
  1418 
  1362 	if (!iPersonalityCfged)
  1419 	if (!iPersonalityCfged)
  1363 		{
  1420 		{
       
  1421 		OstTraceFunctionExit0( CUSBSESSION_GETDESCRIPTION_EXIT );
  1364 		return KErrNotSupported;
  1422 		return KErrNotSupported;
  1365 		}
  1423 		}
  1366 
  1424 
  1367 	TInt personalityId = aMessage.Int0();
  1425 	TInt personalityId = aMessage.Int0();
  1368 	const CPersonality* personality = iUsbServer->Device().GetPersonality(personalityId);
  1426 	const CPersonality* personality = iUsbServer->Device().GetPersonality(personalityId);
  1370 		{
  1428 		{
  1371 		return aMessage.Write(1, *(personality->Description()));
  1429 		return aMessage.Write(1, *(personality->Description()));
  1372 		}
  1430 		}
  1373 
  1431 
  1374 	// We should never reach here
  1432 	// We should never reach here
       
  1433 	OstTraceFunctionExit0( CUSBSESSION_GETDESCRIPTION_EXIT_DUP1 );
  1375 	return KErrNotSupported;
  1434 	return KErrNotSupported;
  1376 	}
  1435 	}
  1377 
  1436 
  1378 /**
  1437 
  1379  * Gets personality detailed description
  1438 /**
       
  1439  * Gets personality property
  1380  *
  1440  *
  1381  * @internalComponent
  1441  * @internalComponent
  1382  * @param   aMessage    Message received from the client
  1442  * @param   aMessage    Message received from the client
  1383  * @return  Any error that occurred or KErrNone
  1443  * @return  Any error that occurred or KErrNone
  1384  */
  1444  */
  1385 TInt CUsbSession::GetDetailedDescription(const RMessage2& aMessage)
       
  1386 	{
       
  1387 	LOG_FUNC
       
  1388 
       
  1389  	if (!iPersonalityCfged)
       
  1390 		{
       
  1391 		return KErrNotSupported;
       
  1392 		}
       
  1393 
       
  1394 	TInt personalityId = aMessage.Int0();
       
  1395 	const CPersonality* personality = iUsbServer->Device().GetPersonality(personalityId);
       
  1396     	if (personality)
       
  1397         	{
       
  1398         	if(personality->Version() < EUsbManagerResourceVersionTwo)
       
  1399             		{
       
  1400             		return KErrNotFound;
       
  1401             		}
       
  1402 		return aMessage.Write(1, *(personality->DetailedDescription()));
       
  1403 		}
       
  1404 
       
  1405 	// We should never reach here
       
  1406 	return KErrNotSupported;
       
  1407 	}
       
  1408 
       
  1409 /**
       
  1410  * Gets personality property
       
  1411  *
       
  1412  * @internalComponent
       
  1413  * @param   aMessage    Message received from the client
       
  1414  * @return  Any error that occurred or KErrNone
       
  1415  */
       
  1416 TInt CUsbSession::GetPersonalityProperty(const RMessage2& aMessage)
  1445 TInt CUsbSession::GetPersonalityProperty(const RMessage2& aMessage)
  1417 	{
  1446 	{
  1418 		LOG_FUNC
  1447 		OstTraceFunctionEntry0( CUSBSESSION_GETPERSONALITYPROPERTY_ENTRY );
  1419 
  1448 
  1420 		if (!iPersonalityCfged)
  1449 		if (!iPersonalityCfged)
  1421 			{
  1450 			{
       
  1451 			OstTraceFunctionExit0( CUSBSESSION_GETPERSONALITYPROPERTY_EXIT );
  1422 			return KErrNotSupported;
  1452 			return KErrNotSupported;
  1423 			}
  1453 			}
  1424 
  1454 
  1425 		TInt personalityId = aMessage.Int0();
  1455 		TInt personalityId = aMessage.Int0();
  1426 		const CPersonality* personality = iUsbServer->Device().GetPersonality(personalityId);
  1456 		const CPersonality* personality = iUsbServer->Device().GetPersonality(personalityId);
  1427 		if (personality)
  1457 		if (personality)
  1428 			{
  1458 			{
  1429 			if(personality->Version() < EUsbManagerResourceVersionThree)
       
  1430 				{
       
  1431 				return KErrNotFound;
       
  1432 				}
       
  1433 			TPckg<TUint32> pckg(personality->Property());
  1459 			TPckg<TUint32> pckg(personality->Property());
  1434 			return aMessage.Write(1, pckg);
  1460 			return aMessage.Write(1, pckg);
  1435 			}
  1461 			}
  1436 
  1462 
       
  1463 		OstTraceFunctionExit0( CUSBSESSION_GETPERSONALITYPROPERTY_EXIT_DUP2 );
  1437 		return KErrNotSupported;
  1464 		return KErrNotSupported;
  1438 	}
  1465 	}
  1439 
  1466 
  1440 /**
  1467 /**
  1441  * Checks if a given class is supported by a personality.
  1468  * Checks if a given class is supported by a personality.
  1444  * @param	aMessage	Message received from the client
  1471  * @param	aMessage	Message received from the client
  1445  * @return	Any error that occurred or KErrNone
  1472  * @return	Any error that occurred or KErrNone
  1446  */
  1473  */
  1447 TInt CUsbSession::ClassSupported(const RMessage2& aMessage)
  1474 TInt CUsbSession::ClassSupported(const RMessage2& aMessage)
  1448 	{
  1475 	{
  1449 	LOG_FUNC
  1476 	OstTraceFunctionEntry0( CUSBSESSION_CLASSSUPPORTED_ENTRY );
  1450 
       
  1451 	if (!iPersonalityCfged)
  1477 	if (!iPersonalityCfged)
  1452 		{
  1478 		{
       
  1479 		OstTraceFunctionExit0( CUSBSESSION_CLASSSUPPORTED_EXIT );
  1453 		return KErrNotSupported;
  1480 		return KErrNotSupported;
  1454 		}
  1481 		}
  1455 
  1482 
  1456 	TBool isSupported = EFalse;
  1483 	TBool isSupported = EFalse;
  1457 	TInt personalityId = aMessage.Int0();
  1484 	TInt personalityId = aMessage.Int0();
  1458 	TUid classUid = TUid::Uid(aMessage.Int1());
  1485 	TUid classUid = TUid::Uid(aMessage.Int1());
  1459 	const CPersonality* personality = iUsbServer->Device().GetPersonality(personalityId);
  1486 	const CPersonality* personality = iUsbServer->Device().GetPersonality(personalityId);
  1460 	if (personality)
  1487 	if (personality)
  1461 		{
  1488 		{
  1462 		isSupported = (personality->ClassSupported(classUid) != KErrNotFound);
  1489 		isSupported = personality->ClassSupported(classUid);
  1463 		TPckg<TBool> pkg2(isSupported);
  1490 		TPckg<TBool> pkg2(isSupported);
  1464 		return aMessage.Write(2, pkg2);
  1491 		return aMessage.Write(2, pkg2);
  1465 		}
  1492 		}
  1466 
  1493 
  1467 	// We should never reach here
  1494 	// We should never reach here
       
  1495 	OstTraceFunctionExit0( CUSBSESSION_CLASSSUPPORTED_EXIT_DUP1 );
  1468 	return KErrNotSupported;
  1496 	return KErrNotSupported;
  1469 	}
  1497 	}
  1470 
  1498 
  1471 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
  1499 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
  1472 /**
  1500 /**
  1476  * @param	aMessage	Message received from the client
  1504  * @param	aMessage	Message received from the client
  1477  * @return	Any error that occurred or KErrNone
  1505  * @return	Any error that occurred or KErrNone
  1478  */
  1506  */
  1479 TInt CUsbSession::SetCtlSessionMode(const RMessage2& aMessage)
  1507 TInt CUsbSession::SetCtlSessionMode(const RMessage2& aMessage)
  1480 	{
  1508 	{
  1481 	LOG_FUNC
  1509 	OstTraceFunctionEntry0( CUSBSESSION_SETCTLSESSIONMODE_ENTRY );
  1482 
  1510 
  1483 	TInt ret = KErrNone;
  1511 	TInt ret = KErrNone;
  1484 
  1512 
  1485 	TBool value = (TBool)aMessage.Int0();
  1513 	TBool value = (TBool)aMessage.Int0();
  1486 	LOGTEXT2(_L8("\tSetting = %d"), static_cast<TInt>(value));
  1514 	OstTrace1( TRACE_NORMAL, CUSBSESSION_SETCTLSESSIONMODE, "CUsbSession::SetCtlSessionMode;Setting = %d", static_cast<TInt>(value) );
  1487 
  1515 
  1488 	// Verify if this is the same session which set the value before
  1516 	// Verify if this is the same session which set the value before
  1489 	if ( iCtlSession && (iCtlSession != this) )
  1517 	if ( iCtlSession && (iCtlSession != this) )
  1490 		{
  1518 		{
  1491 		ret = KErrAccessDenied;
  1519 		ret = KErrAccessDenied;
  1503 			{
  1531 			{
  1504 			iCtlSession = NULL;
  1532 			iCtlSession = NULL;
  1505 			}
  1533 			}
  1506 		}
  1534 		}
  1507 
  1535 
       
  1536 	OstTraceFunctionExit0( CUSBSESSION_SETCTLSESSIONMODE_EXIT );
  1508 	return ret;
  1537 	return ret;
  1509 	}
  1538 	}
  1510 
  1539 
  1511 /**
  1540 /**
  1512  * Asserts a request to drive VBus.
  1541  * Asserts a request to drive VBus.
  1515  * @return	If control mode flag is not set returns KErrAccessDenied
  1544  * @return	If control mode flag is not set returns KErrAccessDenied
  1516  * 			An error code for all other cases
  1545  * 			An error code for all other cases
  1517  */
  1546  */
  1518 TInt CUsbSession::BusRequest()
  1547 TInt CUsbSession::BusRequest()
  1519 	{
  1548 	{
  1520 	LOG_FUNC
  1549 	OstTraceFunctionEntry0( CUSBSESSION_BUSREQUEST_ENTRY );
  1521 
  1550 
  1522 	TInt ret = KErrNone;
  1551 	TInt ret = KErrNone;
  1523 	if ( iSessionCtlMode )
  1552 	if ( iSessionCtlMode )
  1524 		{
  1553 		{
  1525 		ret = iUsbServer->Otg().BusRequest();
  1554 		ret = iUsbServer->Otg().BusRequest();
  1527 	else
  1556 	else
  1528 		{
  1557 		{
  1529 		ret = KErrAccessDenied;
  1558 		ret = KErrAccessDenied;
  1530 		}
  1559 		}
  1531 
  1560 
       
  1561 	OstTraceFunctionExit0( CUSBSESSION_BUSREQUEST_EXIT );
  1532 	return ret;
  1562 	return ret;
  1533 	}
  1563 	}
  1534 
  1564 
  1535 /**
  1565 /**
  1536  * Asserts a request to raise VBUS but assumes this is after B-Device
  1566  * Asserts a request to raise VBUS but assumes this is after B-Device
  1541  * @return	If control mode flag is not set returns KErrAccessDenied
  1571  * @return	If control mode flag is not set returns KErrAccessDenied
  1542  * 			Any error that occurred or KErrNone for all other cases
  1572  * 			Any error that occurred or KErrNone for all other cases
  1543  */
  1573  */
  1544 TInt CUsbSession::BusRespondSrp()
  1574 TInt CUsbSession::BusRespondSrp()
  1545 	{
  1575 	{
  1546 	LOG_FUNC
  1576 	OstTraceFunctionEntry0( CUSBSESSION_BUSRESPONDSRP_ENTRY );
  1547 
  1577 
  1548 	TInt ret = KErrNone;
  1578 	TInt ret = KErrNone;
  1549 	if ( iSessionCtlMode )
  1579 	if ( iSessionCtlMode )
  1550 		{
  1580 		{
  1551 		ret = iUsbServer->Otg().BusRespondSrp();
  1581 		ret = iUsbServer->Otg().BusRespondSrp();
  1553 	else
  1583 	else
  1554 		{
  1584 		{
  1555 		ret = KErrAccessDenied;
  1585 		ret = KErrAccessDenied;
  1556 		}
  1586 		}
  1557 
  1587 
       
  1588 	OstTraceFunctionExit0( CUSBSESSION_BUSRESPONDSRP_EXIT );
  1558 	return ret;
  1589 	return ret;
  1559 	}
  1590 	}
  1560 
  1591 
  1561 /**
  1592 /**
  1562  * Clears a possible VBUS error condition (VBUS inexplicably low after
  1593  * Clears a possible VBUS error condition (VBUS inexplicably low after
  1566  * @return	If control mode flag is not set returns KErrAccessDenied
  1597  * @return	If control mode flag is not set returns KErrAccessDenied
  1567  * 			Any error that occurred or KErrNone for all other cases
  1598  * 			Any error that occurred or KErrNone for all other cases
  1568  */
  1599  */
  1569 TInt CUsbSession::BusClearError()
  1600 TInt CUsbSession::BusClearError()
  1570 	{
  1601 	{
  1571 	LOG_FUNC
  1602 	OstTraceFunctionEntry0( CUSBSESSION_BUSCLEARERROR_ENTRY );
  1572 
  1603 
  1573 	TInt ret = KErrNone;
  1604 	TInt ret = KErrNone;
  1574 	if ( iSessionCtlMode )
  1605 	if ( iSessionCtlMode )
  1575 		{
  1606 		{
  1576 		ret = iUsbServer->Otg().BusClearError();
  1607 		ret = iUsbServer->Otg().BusClearError();
  1578 	else
  1609 	else
  1579 		{
  1610 		{
  1580 		ret = KErrAccessDenied;
  1611 		ret = KErrAccessDenied;
  1581 		}
  1612 		}
  1582 
  1613 
       
  1614 	OstTraceFunctionExit0( CUSBSESSION_BUSCLEARERROR_EXIT );
  1583 	return ret;
  1615 	return ret;
  1584 	}
  1616 	}
  1585 
  1617 
  1586 /**
  1618 /**
  1587  * Drops VBus.
  1619  * Drops VBus.
  1590  * @return	If control mode flag is not set returns KErrAccessDenied
  1622  * @return	If control mode flag is not set returns KErrAccessDenied
  1591  * 			Any error that occurred or KErrNone for all other cases
  1623  * 			Any error that occurred or KErrNone for all other cases
  1592  */
  1624  */
  1593 TInt CUsbSession::BusDrop()
  1625 TInt CUsbSession::BusDrop()
  1594 	{
  1626 	{
  1595 	LOG_FUNC
  1627 	OstTraceFunctionEntry0( CUSBSESSION_BUSDROP_ENTRY );
  1596 
  1628 
  1597 	TInt ret = KErrNone;
  1629 	TInt ret = KErrNone;
  1598 	if ( iSessionCtlMode )
  1630 	if ( iSessionCtlMode )
  1599 		{
  1631 		{
  1600 		ret = iUsbServer->Otg().BusDrop();
  1632 		ret = iUsbServer->Otg().BusDrop();
  1602 	else
  1634 	else
  1603 		{
  1635 		{
  1604 		ret = KErrAccessDenied;
  1636 		ret = KErrAccessDenied;
  1605 		}
  1637 		}
  1606 
  1638 
       
  1639 	OstTraceFunctionExit0( CUSBSESSION_BUSDROP_EXIT );
  1607 	return ret;
  1640 	return ret;
  1608 	}
  1641 	}
  1609 
  1642 
  1610 /**
  1643 /**
  1611  * Enables loading of Function Drivers.
  1644  * Enables loading of Function Drivers.
  1614  * @return	If control mode flag is not set returns KErrAccessDenied
  1647  * @return	If control mode flag is not set returns KErrAccessDenied
  1615  * 			Any error that occurred or KErrNone for all other cases
  1648  * 			Any error that occurred or KErrNone for all other cases
  1616  */
  1649  */
  1617 TInt CUsbSession::EnableFunctionDriverLoading()
  1650 TInt CUsbSession::EnableFunctionDriverLoading()
  1618 	{
  1651 	{
  1619 	LOG_FUNC
  1652 	OstTraceFunctionEntry0( CUSBSESSION_ENABLEFUNCTIONDRIVERLOADING_ENTRY );
  1620 
  1653 
  1621 	TInt ret = KErrNone;
  1654 	TInt ret = KErrNone;
  1622 	if ( iSessionCtlMode )
  1655 	if ( iSessionCtlMode )
  1623 		{
  1656 		{
  1624 		ret = iUsbServer->Host().EnableDriverLoading();
  1657 		ret = iUsbServer->Host().EnableDriverLoading();
  1626 	else
  1659 	else
  1627 		{
  1660 		{
  1628 		ret = KErrAccessDenied;
  1661 		ret = KErrAccessDenied;
  1629 		}
  1662 		}
  1630 
  1663 
       
  1664 	OstTraceFunctionExit0( CUSBSESSION_ENABLEFUNCTIONDRIVERLOADING_EXIT );
  1631 	return ret;
  1665 	return ret;
  1632 	}
  1666 	}
  1633 
  1667 
  1634 /**
  1668 /**
  1635  * Disables loading of Function Drivers.
  1669  * Disables loading of Function Drivers.
  1638  * @return	If control mode flag is not set returns KErrAccessDenied
  1672  * @return	If control mode flag is not set returns KErrAccessDenied
  1639  * 			KErrNone for all other cases
  1673  * 			KErrNone for all other cases
  1640  */
  1674  */
  1641 TInt CUsbSession::DisableFunctionDriverLoading()
  1675 TInt CUsbSession::DisableFunctionDriverLoading()
  1642 	{
  1676 	{
  1643 	LOG_FUNC
  1677 	OstTraceFunctionEntry0( CUSBSESSION_DISABLEFUNCTIONDRIVERLOADING_ENTRY );
  1644 
  1678 
  1645 	TInt ret = KErrNone;
  1679 	TInt ret = KErrNone;
  1646 	if ( iSessionCtlMode )
  1680 	if ( iSessionCtlMode )
  1647 		{
  1681 		{
  1648 		iUsbServer->Host().DisableDriverLoading();
  1682 		iUsbServer->Host().DisableDriverLoading();
  1650 	else
  1684 	else
  1651 		{
  1685 		{
  1652 		ret = KErrAccessDenied;
  1686 		ret = KErrAccessDenied;
  1653 		}
  1687 		}
  1654 
  1688 
       
  1689 	OstTraceFunctionExit0( CUSBSESSION_DISABLEFUNCTIONDRIVERLOADING_EXIT );
  1655 	return ret;
  1690 	return ret;
  1656 	}
  1691 	}
  1657 
  1692 
  1658 /**
  1693 /**
  1659  * Requests an array of language identifiers supported by connected device.
  1694  * Requests an array of language identifiers supported by connected device.
  1662  * @param	aMessage	Message received from the client
  1697  * @param	aMessage	Message received from the client
  1663  * @return	Any error that occurred or KErrNone
  1698  * @return	Any error that occurred or KErrNone
  1664  */
  1699  */
  1665 TInt CUsbSession::GetSupportedLanguages(const RMessage2& aMessage)
  1700 TInt CUsbSession::GetSupportedLanguages(const RMessage2& aMessage)
  1666 	{
  1701 	{
  1667 	LOG_FUNC
  1702 	OstTraceFunctionEntry0( CUSBSESSION_GETSUPPORTEDLANGUAGES_ENTRY );
  1668 	TRAPD(err, GetSupportedLanguagesL(aMessage));
  1703 	TRAPD(err, GetSupportedLanguagesL(aMessage));
       
  1704 	OstTraceFunctionExit0( CUSBSESSION_GETSUPPORTEDLANGUAGES_EXIT );
  1669 	return err;
  1705 	return err;
  1670 	}
  1706 	}
  1671 
  1707 
  1672 /**
  1708 /**
  1673  * Requests an array of language identifiers supported by connected device.
  1709  * Requests an array of language identifiers supported by connected device.
  1676  * @param	aMessage	Message received from the client
  1712  * @param	aMessage	Message received from the client
  1677  * @return	Any error that occurred or KErrNone
  1713  * @return	Any error that occurred or KErrNone
  1678  */
  1714  */
  1679 TInt CUsbSession::GetSupportedLanguagesL(const RMessage2& aMessage)
  1715 TInt CUsbSession::GetSupportedLanguagesL(const RMessage2& aMessage)
  1680 	{
  1716 	{
  1681 	LOG_FUNC
  1717 	OstTraceFunctionEntry0( CUSBSESSION_GETSUPPORTEDLANGUAGESL_ENTRY );
  1682 
       
  1683 
  1718 
  1684 	const TUint deviceId = aMessage.Int0();
  1719 	const TUint deviceId = aMessage.Int0();
  1685 	LOGTEXT2(_L8("\tdeviceId = %d"), deviceId);
  1720 	OstTrace1( TRACE_NORMAL, CUSBSESSION_GETSUPPORTEDLANGUAGESL, "CUsbSession::GetSupportedLanguagesL;deviceId=%d", deviceId );
  1686 
  1721 
  1687 	RArray<TUint> langIds;
  1722 	RArray<TUint> langIds;
  1688 	CleanupClosePushL(langIds);
  1723 	CleanupClosePushL(langIds);
  1689 	TInt ret = iUsbServer->Host().GetSupportedLanguages(deviceId,langIds);
  1724 	TInt ret = iUsbServer->Host().GetSupportedLanguages(deviceId,langIds);
  1690 
  1725 
  1691 	if (ret == KErrNone)
  1726 	if (ret == KErrNone)
  1692 		{
  1727 		{
  1693 		const TUint count = langIds.Count();
  1728 		const TUint count = langIds.Count();
  1694 		LOGTEXT2(_L8("\tcount = %d"), count);
  1729 		OstTrace1( TRACE_NORMAL, CUSBSESSION_GETSUPPORTEDLANGUAGESL_DUP1, "CUsbSession::GetSupportedLanguagesL;count=%d", count );
  1695 
  1730 
  1696 		// Set error code if there is no languages or there are too many
  1731 		// Set error code if there is no languages or there are too many
  1697 		if ( count == 0 )
  1732 		if ( count == 0 )
  1698 			{
  1733 			{
  1699 			ret = KErrNotSupported;
  1734 			ret = KErrNotSupported;
  1715 
  1750 
  1716 			// Save all received language Ids
  1751 			// Save all received language Ids
  1717 			for ( TUint ii = 0 ; ii < count; ++ii )
  1752 			for ( TUint ii = 0 ; ii < count; ++ii )
  1718 				{
  1753 				{
  1719 				buf.Append((TUint8*)&(langIds[ii]), sizeof(TUint));
  1754 				buf.Append((TUint8*)&(langIds[ii]), sizeof(TUint));
  1720 				LOGTEXT3(_L8("Append langID[%d] = %d"),ii,langIds[ii]);
  1755 				OstTraceExt2( TRACE_NORMAL, CUSBSESSION_GETSUPPORTEDLANGUAGESL_DUP2, "CUsbSession::GetSupportedLanguagesL;Append langID[%d] = %d", ii, langIds[ii] );
  1721 				}
  1756 				}
  1722 
  1757 
  1723 			// Write back to the client.
  1758 			// Write back to the client.
  1724 			ret = aMessage.Write(1, buf);
  1759 			ret = aMessage.Write(1, buf);
  1725 			CleanupStack::PopAndDestroy(&buf);
  1760 			CleanupStack::PopAndDestroy(&buf);
  1726 			}
  1761 			}
  1727 		}
  1762 		}
  1728 
  1763 
  1729 	CleanupStack::PopAndDestroy();
  1764 	CleanupStack::PopAndDestroy();
  1730 
  1765 
       
  1766 	OstTraceFunctionExit0( CUSBSESSION_GETSUPPORTEDLANGUAGESL_EXIT );
  1731 	return ret;
  1767 	return ret;
  1732 	}
  1768 	}
  1733 
  1769 
  1734 /**
  1770 /**
  1735  * Requests a manufacturer string descriptor of connected device.
  1771  * Requests a manufacturer string descriptor of connected device.
  1738  * @param	aMessage	Message received from the client
  1774  * @param	aMessage	Message received from the client
  1739  * @return	Any error that occurred or KErrNone
  1775  * @return	Any error that occurred or KErrNone
  1740  */
  1776  */
  1741 TInt CUsbSession::GetManufacturerStringDescriptor(const RMessage2& aMessage)
  1777 TInt CUsbSession::GetManufacturerStringDescriptor(const RMessage2& aMessage)
  1742 	{
  1778 	{
  1743 	LOG_FUNC
  1779 	OstTraceFunctionEntry0( CUSBSESSION_GETMANUFACTURERSTRINGDESCRIPTOR_ENTRY );
  1744 
  1780 
  1745 	const TUint deviceId = aMessage.Int0();
  1781 	const TUint deviceId = aMessage.Int0();
  1746 	const TUint langId = aMessage.Int1();
  1782 	const TUint langId = aMessage.Int1();
  1747 	LOGTEXT3(_L8("\tdeviceId = %d, langId = %d"), deviceId, langId);
  1783 	OstTraceExt2( TRACE_NORMAL, CUSBSESSION_GETMANUFACTURERSTRINGDESCRIPTOR, "CUsbSession::GetManufacturerStringDescriptor;langId=%d;deviceId=%d", langId, deviceId );
  1748 
  1784 
  1749 	TName string;
  1785 	TName string;
  1750 	TInt ret = iUsbServer->Host().GetManufacturerStringDescriptor(deviceId,langId,string);
  1786 	TInt ret = iUsbServer->Host().GetManufacturerStringDescriptor(deviceId,langId,string);
  1751 	if (ret == KErrNone)
  1787 	if (ret == KErrNone)
  1752 		{
  1788 		{
  1753 		LOGTEXT2(_L("\tstring = \"%S\""), &string);
  1789 		OstTraceExt1( TRACE_NORMAL, CUSBSESSION_GETMANUFACTURERSTRINGDESCRIPTOR_DUP1, "CUsbSession::GetManufacturerStringDescriptor;string = \"%S\"", string );
  1754 		ret = aMessage.Write(2, string);
  1790 		ret = aMessage.Write(2, string);
  1755 		}
  1791 		}
  1756 
  1792 
       
  1793 	OstTraceFunctionExit0( CUSBSESSION_GETMANUFACTURERSTRINGDESCRIPTOR_EXIT );
  1757 	return ret;
  1794 	return ret;
  1758 	}
  1795 	}
  1759 
  1796 
  1760 /**
  1797 /**
  1761  * Requests a product string descriptor of connected device.
  1798  * Requests a product string descriptor of connected device.
  1764  * @param	aMessage	Message received from the client
  1801  * @param	aMessage	Message received from the client
  1765  * @return	Any error that occurred or KErrNone
  1802  * @return	Any error that occurred or KErrNone
  1766  */
  1803  */
  1767 TInt CUsbSession::GetProductStringDescriptor(const RMessage2& aMessage)
  1804 TInt CUsbSession::GetProductStringDescriptor(const RMessage2& aMessage)
  1768 	{
  1805 	{
  1769 	LOG_FUNC
  1806 	OstTraceFunctionEntry0( CUSBSESSION_GETPRODUCTSTRINGDESCRIPTOR_ENTRY );
  1770 
  1807 
  1771 	const TUint deviceId = aMessage.Int0();
  1808 	const TUint deviceId = aMessage.Int0();
  1772 	const TUint langId = aMessage.Int1();
  1809 	const TUint langId = aMessage.Int1();
  1773 	LOGTEXT3(_L8("\tdeviceId = %d, langId = %d"), deviceId, langId);
  1810 	OstTraceExt2( TRACE_NORMAL, CUSBSESSION_GETPRODUCTSTRINGDESCRIPTOR, "CUsbSession::GetProductStringDescriptor;deviceId=%d;langId=%d", deviceId, langId );
  1774 
  1811 
  1775 	TName string;
  1812 	TName string;
  1776 	TInt ret = iUsbServer->Host().GetProductStringDescriptor(deviceId,langId,string);
  1813 	TInt ret = iUsbServer->Host().GetProductStringDescriptor(deviceId,langId,string);
  1777 	if (ret == KErrNone)
  1814 	if (ret == KErrNone)
  1778 		{
  1815 		{
  1779 		LOGTEXT2(_L("\tstring = \"%S\""), &string);
  1816 		OstTraceExt1( TRACE_NORMAL, CUSBSESSION_GETPRODUCTSTRINGDESCRIPTOR_DUP1, "CUsbSession::GetProductStringDescriptor;string = \"%S\"", string );
  1780 		ret = aMessage.Write(2, string);
  1817 		ret = aMessage.Write(2, string);
  1781 		}
  1818 		}
  1782 
  1819 
       
  1820 	OstTraceFunctionExit0( CUSBSESSION_GETPRODUCTSTRINGDESCRIPTOR_EXIT );
  1783 	return ret;
  1821 	return ret;
  1784 	}
  1822 	}
  1785 
  1823 
  1786 /**
  1824 /**
  1787  * Requests a OTG descriptor of connected device.
  1825  * Requests a OTG descriptor of connected device.
  1790  * @param	aMessage	Message received from the client
  1828  * @param	aMessage	Message received from the client
  1791  * @return	Any error that occurred or KErrNone
  1829  * @return	Any error that occurred or KErrNone
  1792  */
  1830  */
  1793 TInt CUsbSession::GetOtgDescriptor(const RMessage2& aMessage)
  1831 TInt CUsbSession::GetOtgDescriptor(const RMessage2& aMessage)
  1794 	{
  1832 	{
  1795 	LOG_FUNC
  1833 	OstTraceFunctionEntry0( CUSBSESSION_GETOTGDESCRIPTOR_ENTRY );
  1796 
  1834 
  1797 	const TUint deviceId = aMessage.Int0();
  1835 	const TUint deviceId = aMessage.Int0();
  1798 	LOGTEXT2(_L8("\tdeviceId = %d"), deviceId);
  1836 	OstTrace1( TRACE_NORMAL, CUSBSESSION_GETOTGDESCRIPTOR, "CUsbSession::GetOtgDescriptor;deviceId=%d", deviceId );
  1799 
  1837 
  1800     TOtgDescriptor otgDescriptor;
  1838     TOtgDescriptor otgDescriptor;
  1801 	TInt ret = iUsbServer->Host().GetOtgDescriptor(deviceId, otgDescriptor);
  1839 	TInt ret = iUsbServer->Host().GetOtgDescriptor(deviceId, otgDescriptor);
  1802 	if (ret == KErrNone)
  1840 	if (ret == KErrNone)
  1803 		{
  1841 		{
  1804 		TPckg<TOtgDescriptor> buf(otgDescriptor);
  1842 		TPckg<TOtgDescriptor> buf(otgDescriptor);
  1805 		ret = aMessage.Write(1, buf);
  1843 		ret = aMessage.Write(1, buf);
  1806 		}
  1844 		}
  1807 
  1845 
       
  1846 	OstTraceFunctionExit0( CUSBSESSION_GETOTGDESCRIPTOR_EXIT );
  1808 	return ret;
  1847 	return ret;
  1809 	}
  1848 	}
  1810 
  1849 
  1811 /**
  1850 /**
  1812  * Client request to observe the host (for state changes).
  1851  * Client request to observe the host (for state changes).
  1820  *
  1859  *
  1821  * @return	Any error that occurred or KErrNone
  1860  * @return	Any error that occurred or KErrNone
  1822  */
  1861  */
  1823 TInt CUsbSession::RegisterHostObserver(const RMessage2& aMessage, TBool& aComplete)
  1862 TInt CUsbSession::RegisterHostObserver(const RMessage2& aMessage, TBool& aComplete)
  1824 	{
  1863 	{
  1825 	LOG_FUNC
  1864 	OstTraceFunctionEntry0( CUSBSESSION_REGISTERHOSTOBSERVER_ENTRY );
  1826 
  1865 
  1827 	if (iHostEventObserverOutstanding)
  1866 	if (iHostEventObserverOutstanding)
  1828 		{
  1867 		{
       
  1868 		OstTraceFunctionExit0( CUSBSESSION_REGISTERHOSTOBSERVER_EXIT );
  1829 		return KErrInUse;
  1869 		return KErrInUse;
  1830 		}
  1870 		}
  1831 
  1871 
  1832 	iHostEventObserverMessage = aMessage;
  1872 	iHostEventObserverMessage = aMessage;
  1833 	iHostEventObserverOutstanding = ETrue;
  1873 	iHostEventObserverOutstanding = ETrue;
  1835 
  1875 
  1836  	if (iHostEventObserverQueueEvents == EFalse)
  1876  	if (iHostEventObserverQueueEvents == EFalse)
  1837 	 	{
  1877 	 	{
  1838  		// This is the first observer after c'tor or DeregisterObserver(),
  1878  		// This is the first observer after c'tor or DeregisterObserver(),
  1839  		// so zap the device event queue.
  1879  		// so zap the device event queue.
  1840  		LOGTEXT(_L8("    Reset OTG Host State Queue"));
  1880  		OstTrace0( TRACE_NORMAL, CUSBSESSION_REGISTERHOSTOBSERVER, "CUsbSession::RegisterHostObserver;    Reset OTG Host State Queue" );
  1841  		iHostEventQueueHead = 0;
  1881  		iHostEventQueueHead = 0;
  1842  		iHostEventQueueTail = 0;
  1882  		iHostEventQueueTail = 0;
  1843  		iHostEventObserverQueueEvents = ETrue;
  1883  		iHostEventObserverQueueEvents = ETrue;
  1844 	 	}
  1884 	 	}
  1845  	else if (iHostEventQueueHead != iHostEventQueueTail)
  1885  	else if (iHostEventQueueHead != iHostEventQueueTail)
  1846 	 	{
  1886 	 	{
  1847  		// event(s) queued, we can de-queue one now
  1887  		// event(s) queued, we can de-queue one now
  1848  		UsbHostEventDequeue();
  1888  		UsbHostEventDequeue();
  1849 	 	}
  1889 	 	}
  1850 
  1890 
       
  1891 	OstTraceFunctionExit0( CUSBSESSION_REGISTERHOSTOBSERVER_EXIT_DUP1 );
  1851 	return KErrNone;
  1892 	return KErrNone;
  1852 	}
  1893 	}
  1853 
  1894 
  1854 /**
  1895 /**
  1855  * Deregister the client as an observer of host state changes.
  1896  * Deregister the client as an observer of host state changes.
  1857  * @internalComponent
  1898  * @internalComponent
  1858  * @return Always KErrNone
  1899  * @return Always KErrNone
  1859  */
  1900  */
  1860 TInt CUsbSession::DeRegisterHostObserver()
  1901 TInt CUsbSession::DeRegisterHostObserver()
  1861 	{
  1902 	{
  1862 	LOG_FUNC
  1903 	OstTraceFunctionEntry0( CUSBSESSION_DEREGISTERHOSTOBSERVER_ENTRY );
  1863 
       
  1864 
  1904 
  1865 	if (!iHostEventObserverQueueEvents)
  1905 	if (!iHostEventObserverQueueEvents)
  1866 		{
  1906 		{
  1867 		//Never register
  1907 		//Never register
  1868 		LOGTEXT(_L8("iHostEventObserverQueueEvents is FALSE!"));
  1908 		OstTrace0( TRACE_NORMAL, CUSBSESSION_DEREGISTERHOSTOBSERVER, "CUsbSession::DeRegisterHostObserver;iHostEventObserverQueueEvents is FALSE!" );
       
  1909 		OstTraceFunctionExit0( CUSBSESSION_DEREGISTERHOSTOBSERVER_EXIT );
  1869 		return KErrNone;
  1910 		return KErrNone;
  1870 		}
  1911 		}
  1871 
  1912 
  1872 	if (iHostEventObserverOutstanding)
  1913 	if (iHostEventObserverOutstanding)
  1873 		{
  1914 		{
  1874 		iHostEventObserverOutstanding = EFalse;
  1915 		iHostEventObserverOutstanding = EFalse;
  1875 		iHostEventObserverMessage.Complete(KErrCancel);
  1916 		iHostEventObserverMessage.Complete(KErrCancel);
  1876 		LOGTEXT(_L8("iHostEventObserverMessage.Complete(KErrCancel);"));
  1917 		OstTrace0( TRACE_NORMAL, CUSBSESSION_DEREGISTERHOSTOBSERVER_DUP1, "CUsbSession::DeRegisterHostObserver;iHostEventObserverMessage.Complete(KErrCancel);" );
  1877 		}
  1918 		}
  1878 
  1919 
  1879 	// client doesn't need events queuing any more
  1920 	// client doesn't need events queuing any more
  1880  	iHostEventObserverQueueEvents = EFalse;
  1921  	iHostEventObserverQueueEvents = EFalse;
  1881 	//Reset OTG Host State Queue
  1922 	//Reset OTG Host State Queue
  1882 	iHostEventQueueHead = 0;
  1923 	iHostEventQueueHead = 0;
  1883 	iHostEventQueueTail = 0;
  1924 	iHostEventQueueTail = 0;
  1884 
  1925 
       
  1926 	OstTraceFunctionExit0( CUSBSESSION_DEREGISTERHOSTOBSERVER_EXIT_DUP1 );
  1885 	return KErrNone;	
  1927 	return KErrNone;	
  1886 	}
  1928 	}
  1887 
  1929 
  1888 /**
  1930 /**
  1889  * Client request to observe both OTG and HOST (for events and errors).
  1931  * Client request to observe both OTG and HOST (for events and errors).
  1897  *
  1939  *
  1898  * @return	Any error that occurred or KErrNone
  1940  * @return	Any error that occurred or KErrNone
  1899  */
  1941  */
  1900 TInt CUsbSession::RegisterMsgObserver(const RMessage2& aMessage, TBool& aComplete)
  1942 TInt CUsbSession::RegisterMsgObserver(const RMessage2& aMessage, TBool& aComplete)
  1901 	{
  1943 	{
  1902 	LOG_FUNC
  1944 	OstTraceFunctionEntry0( CUSBSESSION_REGISTERMSGOBSERVER_ENTRY );
  1903 
  1945 
  1904 	if (iMsgObserverOutstanding)
  1946 	if (iMsgObserverOutstanding)
  1905 		{
  1947 		{
       
  1948 		OstTraceFunctionExit0( CUSBSESSION_REGISTERMSGOBSERVER_EXIT );
  1906 		return KErrInUse;
  1949 		return KErrInUse;
  1907 		}
  1950 		}
  1908 
  1951 
  1909 	iMsgObserverMessage = aMessage;
  1952 	iMsgObserverMessage = aMessage;
  1910 	iMsgObserverOutstanding = ETrue;
  1953 	iMsgObserverOutstanding = ETrue;
  1912 
  1955 
  1913  	if (iMsgObserverQueueEvents == EFalse)
  1956  	if (iMsgObserverQueueEvents == EFalse)
  1914 	 	{
  1957 	 	{
  1915  		// This is the first observer after c'tor or DeregisterObserver(),
  1958  		// This is the first observer after c'tor or DeregisterObserver(),
  1916  		// so zap the device event queue.
  1959  		// so zap the device event queue.
  1917  		LOGTEXT(_L8("    Reset OTG Message Queue"));
  1960  		OstTrace0( TRACE_NORMAL, CUSBSESSION_REGISTERMSGOBSERVER, "CUsbSession::RegisterMsgObserver;    Reset OTG Message Queue" );
  1918  		iMsgQueueHead = 0;
  1961  		iMsgQueueHead = 0;
  1919  		iMsgQueueTail = 0;
  1962  		iMsgQueueTail = 0;
  1920  		iMsgObserverQueueEvents = ETrue;
  1963  		iMsgObserverQueueEvents = ETrue;
  1921 	 	}
  1964 	 	}
  1922  	else if (iMsgQueueHead != iMsgQueueTail)
  1965  	else if (iMsgQueueHead != iMsgQueueTail)
  1923 	 	{
  1966 	 	{
  1924  		// event(s) queued, we can de-queue one now
  1967  		// event(s) queued, we can de-queue one now
  1925  		UsbMsgDequeue();
  1968  		UsbMsgDequeue();
  1926 	 	}
  1969 	 	}
  1927 
  1970 
       
  1971 	OstTraceFunctionExit0( CUSBSESSION_REGISTERMSGOBSERVER_EXIT_DUP1 );
  1928 	return KErrNone;
  1972 	return KErrNone;
  1929 	}
  1973 	}
  1930 
  1974 
  1931 /**
  1975 /**
  1932  * Deregister the client as an observer of OTG/HOST events and errors.
  1976  * Deregister the client as an observer of OTG/HOST events and errors.
  1934  * @internalComponent
  1978  * @internalComponent
  1935  * @return Always KErrNone
  1979  * @return Always KErrNone
  1936  */
  1980  */
  1937 TInt CUsbSession::DeRegisterMsgObserver()
  1981 TInt CUsbSession::DeRegisterMsgObserver()
  1938 	{
  1982 	{
  1939 	LOG_FUNC
  1983 	OstTraceFunctionEntry0( CUSBSESSION_DEREGISTERMSGOBSERVER_ENTRY );
  1940 
  1984 
  1941 	if (!iMsgObserverOutstanding)
  1985 	if (!iMsgObserverOutstanding)
  1942 		{
  1986 		{
       
  1987 		OstTraceFunctionExit0( CUSBSESSION_DEREGISTERMSGOBSERVER_EXIT );
  1943 		return KErrNone;
  1988 		return KErrNone;
  1944 		}
  1989 		}
  1945 
  1990 
  1946 	iMsgObserverOutstanding = EFalse;
  1991 	iMsgObserverOutstanding = EFalse;
  1947 	iMsgObserverMessage.Complete(KErrCancel);
  1992 	iMsgObserverMessage.Complete(KErrCancel);
  1948 
  1993 
  1949 	// client doesn't need events queuing any more
  1994 	// client doesn't need events queuing any more
  1950  	iMsgObserverQueueEvents = EFalse;
  1995  	iMsgObserverQueueEvents = EFalse;
  1951 
  1996 
       
  1997 	OstTraceFunctionExit0( CUSBSESSION_DEREGISTERMSGOBSERVER_EXIT_DUP1 );
  1952 	return KErrNone;
  1998 	return KErrNone;
  1953 	}
  1999 	}
  1954 
  2000 
  1955 
  2001 
  1956 
  2002 
  1960  * @internalComponent
  2006  * @internalComponent
  1961  * @param aMessage The new OTG Message
  2007  * @param aMessage The new OTG Message
  1962  */
  2008  */
  1963 void CUsbSession::UsbOtgHostMessage(TInt aMessage)
  2009 void CUsbSession::UsbOtgHostMessage(TInt aMessage)
  1964 	{
  2010 	{
  1965 	LOG_FUNC
  2011 	OstTraceFunctionEntry0( CUSBSESSION_USBOTGHOSTMESSAGE_ENTRY );
  1966 
  2012 
  1967 	// can we bypass the queue?
  2013 	// can we bypass the queue?
  1968  	if ((iMsgObserverOutstanding) && (iMsgQueueHead == iMsgQueueTail))
  2014  	if ((iMsgObserverOutstanding) && (iMsgQueueHead == iMsgQueueTail))
  1969 		{
  2015 		{
  1970 		TPckg<TInt> pckg(aMessage);
  2016 		TPckg<TInt> pckg(aMessage);
  1978 	else if (iMsgObserverQueueEvents)
  2024 	else if (iMsgObserverQueueEvents)
  1979 		{
  2025 		{
  1980 		// add event to head of queue
  2026 		// add event to head of queue
  1981 		iMsgQueue[iMsgQueueHead] = aMessage;
  2027 		iMsgQueue[iMsgQueueHead] = aMessage;
  1982 		iMsgQueueHead = (iMsgQueueHead + 1) % KOtgHostMessageQueueSize;
  2028 		iMsgQueueHead = (iMsgQueueHead + 1) % KOtgHostMessageQueueSize;
  1983 		LOGTEXT3(_L8("+++ CUsbSession::UsbOtgMessage() addqueue (%d, %d)"), iMsgQueueHead,
  2029 		OstTraceExt2( TRACE_NORMAL, CUSBSESSION_USBOTGHOSTMESSAGE, "CUsbSession::UsbOtgHostMessage; addqueue (%d, %d)", iMsgQueueHead, iMsgQueueTail );
  1984 			iMsgQueueTail);
       
  1985 
  2030 
  1986  		// UsbMsgDequeueEvent() will read from queue when RegisterMsgObserver()
  2031  		// UsbMsgDequeueEvent() will read from queue when RegisterMsgObserver()
  1987 		// is next called.
  2032 		// is next called.
  1988 		}
  2033 		}
       
  2034 	OstTraceFunctionExit0( CUSBSESSION_USBOTGHOSTMESSAGE_EXIT );
  1989 	}
  2035 	}
  1990 
  2036 
  1991 /**
  2037 /**
  1992  * Called by CUsbHost when it state change. CUsbSession is an observer of
  2038  * Called by CUsbHost when it state change. CUsbSession is an observer of
  1993  * the device. If the client has an Observer outstanding then complete it,
  2039  * the device. If the client has an Observer outstanding then complete it,
  1997  * @param	aDevInfo	The information about the device being attached or detached
  2043  * @param	aDevInfo	The information about the device being attached or detached
  1998  * 						along with the status of Function Driver loading
  2044  * 						along with the status of Function Driver loading
  1999  */
  2045  */
  2000 void CUsbSession::UsbHostEvent(TDeviceEventInformation& aDevInfo)
  2046 void CUsbSession::UsbHostEvent(TDeviceEventInformation& aDevInfo)
  2001 	{
  2047 	{
  2002 	LOG_FUNC
  2048 	OstTraceFunctionEntry0( CUSBSESSION_USBHOSTEVENT_ENTRY );
  2003 
  2049 
  2004 	// can we bypass the queue?
  2050 	// can we bypass the queue?
  2005  	if ((iHostEventObserverOutstanding) && (iHostEventQueueHead == iHostEventQueueTail))
  2051  	if ((iHostEventObserverOutstanding) && (iHostEventQueueHead == iHostEventQueueTail))
  2006 		{
  2052 		{
  2007 		iNotifiedHostState = aDevInfo;
  2053 		iNotifiedHostState = aDevInfo;
  2008 		iHostEventObserverOutstanding = EFalse;
  2054 		iHostEventObserverOutstanding = EFalse;
  2009 
  2055 
  2010 		LOGTEXT(_L8("CUsbSession::UsbHostEvent() detected outstanding request"));
  2056 		OstTrace0( TRACE_NORMAL, CUSBSESSION_USBHOSTEVENT, "CUsbSession::UsbHostEvent detected outstanding request" );
  2011 
  2057 
  2012 		TPckg<TDeviceEventInformation> info(aDevInfo);
  2058 		TPckg<TDeviceEventInformation> info(aDevInfo);
  2013 		const TInt err = iHostEventObserverMessage.Write(0, info);
  2059 		const TInt err = iHostEventObserverMessage.Write(0, info);
  2014 		iHostEventObserverMessage.Complete(err);
  2060 		iHostEventObserverMessage.Complete(err);
  2015 		LOGTEXT2(_L8("CUsbSession::UsbHostEvent() detects outstanding request: request is compeleted with %d"), err);
  2061 		OstTrace1( TRACE_NORMAL, CUSBSESSION_USBHOSTEVENT_DUP1, "CUsbSession::UsbHostEvent; detects outstanding request: request is compeleted with %d", err );
  2016 		}
  2062 		}
  2017 	else if (iHostEventObserverQueueEvents)
  2063 	else if (iHostEventObserverQueueEvents)
  2018 		{
  2064 		{
  2019 		// add dev info to head of queue
  2065 		// add dev info to head of queue
  2020 		iHostStateQueue[iHostEventQueueHead] = aDevInfo;
  2066 		iHostStateQueue[iHostEventQueueHead] = aDevInfo;
  2021 		iHostEventQueueHead = (iHostEventQueueHead + 1) % KDeviceStatesQueueSize;
  2067 		iHostEventQueueHead = (iHostEventQueueHead + 1) % KDeviceStatesQueueSize;
  2022 		LOGTEXT3(_L8("+++ CUsbSession::UsbHostEvent() addqueue (%d, %d)"), iHostEventQueueHead,
  2068 		OstTraceExt2( TRACE_NORMAL, CUSBSESSION_USBHOSTEVENT_DUP2, "CUsbSession::UsbHostEvent; addqueue (%d, %d)", iHostEventQueueHead, iHostEventQueueTail );
  2023 			iHostEventQueueTail);
       
  2024 
  2069 
  2025  		// UsbHostStateDequeueEvent() will read from queue when RegisterHostObserver()
  2070  		// UsbHostStateDequeueEvent() will read from queue when RegisterHostObserver()
  2026 		// is next called.
  2071 		// is next called.
  2027 		}
  2072 		}
       
  2073 	OstTraceFunctionExit0( CUSBSESSION_USBHOSTEVENT_EXIT );
  2028 	}
  2074 	}
  2029 
  2075 
  2030 /**
  2076 /**
  2031  * Dequeues an event and completes the observer's request with it.
  2077  * Dequeues an event and completes the observer's request with it.
  2032  */
  2078  */
  2033 void CUsbSession::UsbMsgDequeue()
  2079 void CUsbSession::UsbMsgDequeue()
  2034  	{
  2080  	{
  2035 	LOG_FUNC
  2081 	OstTraceFunctionEntry0( CUSBSESSION_USBMSGDEQUEUE_ENTRY );
  2036 
  2082 
  2037 	// Work our way through the queue, until we reach the end
  2083 	// Work our way through the queue, until we reach the end
  2038  	// OR we find an event the current observer wants.
  2084  	// OR we find an event the current observer wants.
  2039  	if ((iMsgObserverOutstanding) && (iMsgQueueHead != iMsgQueueTail))
  2085  	if ((iMsgObserverOutstanding) && (iMsgQueueHead != iMsgQueueTail))
  2040  		{
  2086  		{
  2044  		iMsgQueueTail = (iMsgQueueTail + 1) % KOtgHostMessageQueueSize;
  2090  		iMsgQueueTail = (iMsgQueueTail + 1) % KOtgHostMessageQueueSize;
  2045 
  2091 
  2046  		TPckg<TUint32> pckg(newMsg);
  2092  		TPckg<TUint32> pckg(newMsg);
  2047  		iNotifiedMsg = newMsg;
  2093  		iNotifiedMsg = newMsg;
  2048 
  2094 
  2049  		LOGTEXT3(_L8(">>> dequeued event #%d (0x%x)"), iMsgQueueTail, newMsg);
  2095  		OstTraceExt2( TRACE_NORMAL, CUSBSESSION_USBMSGDEQUEUE, "CUsbSession::UsbMsgDequeue;dequeued event #%d (0x%x)", iMsgQueueTail, newMsg );
  2050 
  2096 
  2051 		iMsgObserverOutstanding = EFalse;
  2097 		iMsgObserverOutstanding = EFalse;
  2052 		const TInt err = iMsgObserverMessage.Write(0, pckg);
  2098 		const TInt err = iMsgObserverMessage.Write(0, pckg);
  2053 		iMsgObserverMessage.Complete(err);
  2099 		iMsgObserverMessage.Complete(err);
  2054    		}
  2100    		}
       
  2101   	OstTraceFunctionExit0( CUSBSESSION_USBMSGDEQUEUE_EXIT );
  2055   	}
  2102   	}
  2056 
  2103 
  2057 /**
  2104 /**
  2058  * Dequeues an event and completes the observer's request with it.
  2105  * Dequeues an event and completes the observer's request with it.
  2059  */
  2106  */
  2060 void CUsbSession::UsbHostEventDequeue()
  2107 void CUsbSession::UsbHostEventDequeue()
  2061  	{
  2108  	{
  2062 	LOG_FUNC
  2109 	OstTraceFunctionEntry0( CUSBSESSION_USBHOSTEVENTDEQUEUE_ENTRY );
  2063 
  2110 
  2064 	// Work our way through the queue, until we reach the end
  2111 	// Work our way through the queue, until we reach the end
  2065  	// OR we find an event the current observer wants.
  2112  	// OR we find an event the current observer wants.
  2066  	if ((iHostEventObserverOutstanding) && (iHostEventQueueHead != iHostEventQueueTail))
  2113  	if ((iHostEventObserverOutstanding) && (iHostEventQueueHead != iHostEventQueueTail))
  2067  		{
  2114  		{
  2071 		iNotifiedHostState = newDevInfo;
  2118 		iNotifiedHostState = newDevInfo;
  2072 
  2119 
  2073  		// advance tail towards the head
  2120  		// advance tail towards the head
  2074  		iHostEventQueueTail = (iHostEventQueueTail + 1) % KDeviceStatesQueueSize;
  2121  		iHostEventQueueTail = (iHostEventQueueTail + 1) % KDeviceStatesQueueSize;
  2075 
  2122 
  2076 		LOGTEXT3(_L8(">>> CUsbSession::UsbHostStateDequeueEvent() dequeued event #%d (0x%x)"), iHostEventQueueTail, newDevInfo.iEventType);
  2123 		OstTraceExt2( TRACE_NORMAL, CUSBSESSION_USBHOSTEVENTDEQUEUE, "CUsbSession::UsbHostEventDequeue; dequeued event #%d (0x%x)", iHostEventQueueTail, newDevInfo.iEventType );
  2077 
  2124 
  2078 		TPckg<TDeviceEventInformation> info(newDevInfo);
  2125 		TPckg<TDeviceEventInformation> info(newDevInfo);
  2079 		iHostEventObserverOutstanding = EFalse;
  2126 		iHostEventObserverOutstanding = EFalse;
  2080 		const TInt err = iHostEventObserverMessage.Write(0, info);
  2127 		const TInt err = iHostEventObserverMessage.Write(0, info);
  2081 		iHostEventObserverMessage.Complete(err);
  2128 		iHostEventObserverMessage.Complete(err);
  2082 
  2129 
  2083 		LOGTEXT2(_L8("CUsbSession::UsbHostStateDequeueEvent() detects outstanding request: request is compeleted with %d"), err);
  2130 		OstTrace1( TRACE_NORMAL, CUSBSESSION_USBHOSTEVENTDEQUEUE_DUP1, "CUsbSession::UsbHostStateDequeueEvent() detects outstanding request: request is compeleted with %d", err );
  2084    		}
  2131    		}
       
  2132    	OstTraceFunctionExit0( CUSBSESSION_USBHOSTEVENTDEQUEUE_EXIT );
  2085    	}
  2133    	}
  2086 
  2134 
  2087 TInt CUsbSession::RequestSession()
  2135 TInt CUsbSession::RequestSession()
  2088 	{
  2136 	{
  2089 	return DoRequestSession();
  2137 	return DoRequestSession();