accessoryservices/remotecontrolfw/server/src/bearermanager.cpp
changeset 74 9d35fd98f273
parent 35 f7565e9c9ce8
equal deleted inserted replaced
69:dc67b94625c5 74:9d35fd98f273
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
   455 
   455 
   456 	LOG1(_L("\tret = %d"), ret);
   456 	LOG1(_L("\tret = %d"), ret);
   457 	return ret;
   457 	return ret;
   458 	}
   458 	}
   459 
   459 
   460 void CBearerManager::ClientTypeSet(TBool aController)
       
   461 	{
       
   462 	LOG_FUNC;
       
   463 	LOG1(_L("\taController = %x"), aController);
       
   464 		
       
   465 	/* When a client (session) has its type set (controller or target) then 
       
   466 	   it will still have a bearer uid of NullUid. In this case we want to 
       
   467 	   update any bearers which now have a controller or target count moving to 1 */
       
   468 	const TUint count = iBearerIfs.Count();
       
   469 	for ( TUint ii = 0 ; ii < count ; ++ii )
       
   470 		{
       
   471 		MRemConBearerInterface* const bearerIf = iBearerIfs[ii].iIf;
       
   472 		MRemConBearerInterfaceV3* const bearerIfV3 = iBearerIfs[ii].iIfV3;
       
   473 
       
   474 		ASSERT_DEBUG(bearerIf);
       
   475 		/* maintain the controller and target count for each bearer 
       
   476 		   tell the bearer if the count has increased to 1
       
   477 		   by doing this in this loop we are sure we only 
       
   478 		   tell the bearer when we need to */
       
   479 		if (aController)
       
   480 			{
       
   481 			iBearerIfs[ii].iControllerCount++;
       
   482 			if (1 == iBearerIfs[ii].iControllerCount)
       
   483 				{
       
   484 				bearerIf->ClientStatus(TBool(iBearerIfs[ii].iControllerCount), TBool(iBearerIfs[ii].iTargetCount));
       
   485 				}
       
   486 			}
       
   487 		else
       
   488 			{
       
   489 			iBearerIfs[ii].iTargetCount++;
       
   490 			if (1 == iBearerIfs[ii].iTargetCount)
       
   491 				{
       
   492 				bearerIf->ClientStatus(TBool(iBearerIfs[ii].iControllerCount), TBool(iBearerIfs[ii].iTargetCount));
       
   493 				}
       
   494 			}
       
   495 		}
       
   496 	}
       
   497 
       
   498 void CBearerManager::TargetClientAvailable(TRemConClientId aId, const TPlayerType& aClientType, const TPlayerSubType& aClientSubType, const TDesC8& aName)
   460 void CBearerManager::TargetClientAvailable(TRemConClientId aId, const TPlayerType& aClientType, const TPlayerSubType& aClientSubType, const TDesC8& aName)
   499 	{
   461 	{
   500 	LOG_FUNC;
   462 	LOG_FUNC;
   501 		
   463 		
   502 	const TUint count = iBearerIfs.Count();
   464 	const TUint count = iBearerIfs.Count();
   503 	for ( TUint ii = 0 ; ii < count ; ++ii )
   465 	for ( TUint ii = 0 ; ii < count ; ++ii )
   504 		{
   466 		{
       
   467 		// maintain the controller and target count for each bearer 
       
   468 		// tell the bearer if the count has increased to 1
       
   469 		// by doing this in this loop we are sure we only 
       
   470 		// tell the bearer when we need to */
       
   471 		MRemConBearerInterface* const bearerIf = iBearerIfs[ii].iIf;
       
   472 		ASSERT_DEBUG(bearerIf);
       
   473 		iBearerIfs[ii].iTargetCount++;
       
   474 		if (1 == iBearerIfs[ii].iTargetCount)
       
   475 			{
       
   476 			bearerIf->ClientStatus(TBool(iBearerIfs[ii].iControllerCount), TBool(iBearerIfs[ii].iTargetCount));
       
   477 			}
       
   478 		
   505 		MRemConBearerInterfaceV3* const bearerIfV3 = iBearerIfs[ii].iIfV3;
   479 		MRemConBearerInterfaceV3* const bearerIfV3 = iBearerIfs[ii].iIfV3;
   506 
       
   507 		if(bearerIfV3)
   480 		if(bearerIfV3)
   508 			{
   481 			{
   509 			bearerIfV3->ClientAvailable(aId, aClientType, aClientSubType, aName);
   482 			bearerIfV3->ClientAvailable(aId, aClientType, aClientSubType, aName);
   510 			}
   483 			}
   511 		}
   484 		}
   512 	}
   485 	}
       
   486 
       
   487 void CBearerManager::TargetFeaturesUpdated(TRemConClientId aId, const TPlayerType& aPlayerType, const TPlayerSubType& aPlayerSubType, const TDesC8& aName)
       
   488     {
       
   489     LOG_FUNC;
       
   490         
       
   491     const TUint count = iBearerIfs.Count();
       
   492     for ( TUint ii = 0 ; ii < count ; ++ii )
       
   493         {
       
   494         MRemConBearerInterfaceV3* const bearerIfV3 = iBearerIfs[ii].iIfV3;
       
   495 
       
   496         if(bearerIfV3)
       
   497             {
       
   498             bearerIfV3->TargetFeaturesUpdated(aId, aPlayerType, aPlayerSubType, aName);
       
   499             }
       
   500         }
       
   501     }
   513 
   502 
   514 void CBearerManager::ControllerClientAvailable()
   503 void CBearerManager::ControllerClientAvailable()
   515 	{
   504 	{
   516 	LOG_FUNC;
   505 	LOG_FUNC;
   517 	
   506 	
   518 	RArray<TUid> supportedInterfaces;
   507 	RArray<TUid> supportedInterfaces;
   519 	TInt err = iServer.ControllerSupportedInterfaces(supportedInterfaces);
   508 	TInt err = iServer.ControllerSupportedInterfaces(supportedInterfaces);
   520 	LOG2(_L("\tGot %d supported interfaces with result %d"), supportedInterfaces.Count(), err);
   509 	LOG2(_L("\tGot %d supported interfaces with result %d"), supportedInterfaces.Count(), err);
   521 	
   510 	
   522 	if(!err)
   511 	const TUint count = iBearerIfs.Count();
   523 		{
   512 	for ( TUint ii = 0 ; ii < count ; ++ii )
   524 		const TUint count = iBearerIfs.Count();
   513 		{
   525 		for ( TUint ii = 0 ; ii < count ; ++ii )
   514 		// maintain the controller and target count for each bearer 
   526 			{
   515 		// tell the bearer if the count has increased to 1
       
   516 		// by doing this in this loop we are sure we only 
       
   517 		// tell the bearer when we need to
       
   518 		MRemConBearerInterface* const bearerIf = iBearerIfs[ii].iIf;
       
   519 		ASSERT_DEBUG(bearerIf);
       
   520 		iBearerIfs[ii].iControllerCount++;
       
   521 		if (1 == iBearerIfs[ii].iControllerCount)
       
   522 			{
       
   523 			bearerIf->ClientStatus(TBool(iBearerIfs[ii].iControllerCount), TBool(iBearerIfs[ii].iTargetCount));
       
   524 			}
       
   525 
       
   526 		if(!err)
       
   527 			{
       
   528 			// If we know what the supported interface are we can tell the bearer
   527 			MRemConBearerInterfaceV3* const bearerIfV3 = iBearerIfs[ii].iIfV3;
   529 			MRemConBearerInterfaceV3* const bearerIfV3 = iBearerIfs[ii].iIfV3;
   528 
   530 
   529 			if(bearerIfV3)
   531 			if(bearerIfV3)
   530 				{
   532 				{
   531 				bearerIfV3->ControllerFeaturesUpdated(supportedInterfaces);
   533 				bearerIfV3->ControllerFeaturesUpdated(supportedInterfaces);
   532 				}
   534 				}
   533 			}
   535 			}
   534 		
   536 		}
   535 		supportedInterfaces.Close();
   537 	
   536 		}
   538 	supportedInterfaces.Close();
   537 	}
   539 	}
   538 
   540 
   539 void CBearerManager::ClientConnectionOriented(TUid aUid)
   541 void CBearerManager::ClientConnectionOriented(TUid aUid)
   540 	{
   542 	{
   541 	LOG_FUNC;
   543 	LOG_FUNC;
   543 	const TUint count = iBearerIfs.Count();
   545 	const TUint count = iBearerIfs.Count();
   544 	for ( TUint ii = 0 ; ii < count ; ++ii )
   546 	for ( TUint ii = 0 ; ii < count ; ++ii )
   545 		{
   547 		{
   546 		MRemConBearerInterface* const bearerIf = iBearerIfs[ii].iIf;
   548 		MRemConBearerInterface* const bearerIf = iBearerIfs[ii].iIf;
   547 		ASSERT_DEBUG(bearerIf);
   549 		ASSERT_DEBUG(bearerIf);
   548 		/* maintain the controller and target count for each bearer 
   550 		// maintain the controller and target count for each bearer 
   549 		   target count won't change for this
   551 		// target count won't change for this
   550 		   Controller won't change if we are the bearer being targetted by the controller
   552 		// Controller won't change if we are the bearer being targetted by the controller
   551 		   it will go down if we're not.
   553 		// it will go down if we're not.
   552 		   Tell the bearer if the controller count has decreased to zero
   554 		// Tell the bearer if the controller count has decreased to zero
   553 		*/
       
   554 		if (aUid != iBearerIfs[ii].iBearerUid)
   555 		if (aUid != iBearerIfs[ii].iBearerUid)
   555 			{
   556 			{
   556 			iBearerIfs[ii].iControllerCount--;
   557 			iBearerIfs[ii].iControllerCount--;
   557 			if (0 == iBearerIfs[ii].iControllerCount)
   558 			if (0 == iBearerIfs[ii].iControllerCount)
   558 				{
   559 				{
   575 		{
   576 		{
   576 		MRemConBearerInterface* const bearerIf = iBearerIfs[ii].iIf;
   577 		MRemConBearerInterface* const bearerIf = iBearerIfs[ii].iIf;
   577 		MRemConBearerInterfaceV3* const bearerIfV3 = iBearerIfs[ii].iIfV3;
   578 		MRemConBearerInterfaceV3* const bearerIfV3 = iBearerIfs[ii].iIfV3;
   578 		ASSERT_DEBUG(bearerIf);
   579 		ASSERT_DEBUG(bearerIf);
   579 
   580 
   580 		/* maintain the controller and target count for each bearer 
   581 		// maintain the controller and target count for each bearer 
   581 		   target count won't change for this
   582 		// target count won't change for this
   582 		   Controller won't change if we were the bearer being targetted by the controller
   583 		// Controller won't change if we were the bearer being targetted by the controller
   583 		   it will go up if we're not.
   584 		// it will go up if we're not.
   584 		   tell the bearer if the controller count has increased to 1 and provide
   585 		// tell the bearer if the controller count has increased to 1 and provide
   585 		   it with the current feature list.	   
   586 		// it with the current feature list.	   
   586 		*/
       
   587 		if (aUid != iBearerIfs[ii].iBearerUid)
   587 		if (aUid != iBearerIfs[ii].iBearerUid)
   588 			{
   588 			{
   589 			iBearerIfs[ii].iControllerCount++;
   589 			iBearerIfs[ii].iControllerCount++;
   590 			if (1 == iBearerIfs[ii].iControllerCount)
   590 			if (1 == iBearerIfs[ii].iControllerCount)
   591 				{
   591 				{
   619 	for ( TUint ii = 0 ; ii < count ; ++ii )
   619 	for ( TUint ii = 0 ; ii < count ; ++ii )
   620 		{
   620 		{
   621 		MRemConBearerInterface* const bearerIf = iBearerIfs[ii].iIf;
   621 		MRemConBearerInterface* const bearerIf = iBearerIfs[ii].iIf;
   622 		MRemConBearerInterfaceV3* const bearerIfV3 = iBearerIfs[ii].iIfV3;
   622 		MRemConBearerInterfaceV3* const bearerIfV3 = iBearerIfs[ii].iIfV3;
   623 		ASSERT_DEBUG(bearerIf);
   623 		ASSERT_DEBUG(bearerIf);
   624 		/* maintain the controller and target count for each bearer 
   624 		// maintain the controller and target count for each bearer 
   625 		   the target count may change for this
   625 		// the target count may change for this
   626 		   Controller won't change if we were the bearer being targetted by the controller
   626 		// Controller won't change if we were the bearer being targetted by the controller
   627 		   it will go up if we're not.
   627 		// it will go up if we're not.
   628 		   
       
   629 		*/
       
   630 		if (aController)
   628 		if (aController)
   631 			{
   629 			{
   632 			/* so if the aUid is not null then the closed session affects only
   630 			// so if the aUid is not null then the closed session affects only
   633 			   the bearer it was pointing at. If the uid is NULL then its affecting
   631 			// the bearer it was pointing at. If the uid is NULL then its affecting
   634 			   all bearers
   632 			// all bearers
   635 			   tell the bearer if controller or target count has reached zero.
   633 			// tell the bearer if controller or target count has reached zero.
   636 			   If there are controllers left then let the bearer know the current
   634 			// If there are controllers left then let the bearer know the current
   637 			   feature set.
   635 			// feature set.
   638 			 */
       
   639 			if ((aUid == iBearerIfs[ii].iBearerUid) || (KNullUid == aUid))
   636 			if ((aUid == iBearerIfs[ii].iBearerUid) || (KNullUid == aUid))
   640 				{
   637 				{
   641 				iBearerIfs[ii].iControllerCount--;
   638 				iBearerIfs[ii].iControllerCount--;
   642 				if (0 == iBearerIfs[ii].iControllerCount)
   639 				if (0 == iBearerIfs[ii].iControllerCount)
   643 					{
   640 					{
   924 	{
   921 	{
   925 	LOG(KNullDesC8());
   922 	LOG(KNullDesC8());
   926 	LOG_FUNC;
   923 	LOG_FUNC;
   927 	
   924 	
   928 	// Just call the handler for removed connections.
   925 	// Just call the handler for removed connections.
   929 	iServer.RemoveConnection(aAddr);
   926 	iServer.RemoveConnection(aAddr, KErrNone);
   930 	}
   927 	}
   931 
   928 
   932 TInt CBearerManager::MrcboDoConnectConfirm(const TRemConAddress& aAddr, TInt aError)
   929 TInt CBearerManager::MrcboDoConnectConfirm(const TRemConAddress& aAddr, TInt aError)
   933 	{
   930 	{
   934 	LOG(KNullDesC8());
   931 	LOG(KNullDesC8());
   956 	iCurrentlyBeingDisconnected.Remove(index);
   953 	iCurrentlyBeingDisconnected.Remove(index);
   957 
   954 
   958 	if ( aError == KErrNone )
   955 	if ( aError == KErrNone )
   959 		{
   956 		{
   960 		// Remove connection and complete notifications.
   957 		// Remove connection and complete notifications.
   961 		iServer.RemoveConnection(aAddr);
   958 		iServer.RemoveConnection(aAddr, aError);
   962 		}
       
   963 
       
   964 	// Complete the specific request(s) that caused a DisconnectRequest on the 
       
   965 	// bearer. Tell all sessions- they remember the address they wanted to 
       
   966 	// connect to, and will filter on the address we give them.
       
   967 	const TUint count = iServer.Sessions().Count();
       
   968 	for ( TUint ii = 0 ; ii < count ; ++ii )
       
   969 		{
       
   970 		ASSERT_DEBUG(iServer.Sessions()[ii]);
       
   971 		iServer.Sessions()[ii]->CompleteDisconnect(aAddr, aError);
       
   972 		}
   959 		}
   973 	}
   960 	}
   974 
   961 
   975 TUint CBearerManager::MrcboDoNewTransactionId()
   962 TUint CBearerManager::MrcboDoNewTransactionId()
   976 	{
   963 	{