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