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