bluetoothappprofiles/avrcp/remconbeareravrcp/src/avrcpplayerinfomanager.cpp
branchRCL_3
changeset 56 9386f31cc85b
parent 55 613943a21004
equal deleted inserted replaced
55:613943a21004 56:9386f31cc85b
     1 // Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2008-2009 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".
   131 	ASSERT_BULK_THREAD;
   131 	ASSERT_BULK_THREAD;
   132 	delete iUidWatcher;
   132 	delete iUidWatcher;
   133 	iUidWatcher = NULL;
   133 	iUidWatcher = NULL;
   134 	}
   134 	}
   135 
   135 
   136 // Helper function for ClientAvailable and TargetFeaturesUpdated
   136 void CAvrcpPlayerInfoManager::ClientAvailable(const TRemConClientId& aId, TPlayerType aClientType, TPlayerSubType aClientSubType, const TDesC8& aName)
   137 TInt CAvrcpPlayerInfoManager::SetItemDetails(TAvrcpMediaPlayerItem& aItem, TPlayerType aPlayerType, TPlayerSubType aPlayerSubType, const TDesC8& aName)
       
   138 	{
       
   139 	aItem.iPlayerType = aPlayerType;
       
   140 	aItem.iPlayerSubType = aPlayerSubType;
       
   141 	aItem.iName.Set(aName);
       
   142 	aItem.iFeatureBitmask = TPlayerFeatureBitmask();
       
   143 	return SetPlayerFeatures(aItem.iId, aItem.iFeatureBitmask, aItem.iSdpFeatures, aItem.iAbsoluteVolumeSupport);
       
   144 	}
       
   145 
       
   146 // Helper function for ClientAvailable and TargetFeaturesUpdated
       
   147 void CAvrcpPlayerInfoManager::UpdateSdpRecord(const TAvrcpMediaPlayerItem& aItem)
       
   148 	{
       
   149 	// Update SDP record, if this fails we carry on, it's non-fatal
       
   150 	TInt sdpErr = KErrNone;
       
   151 	if(!iTargetRecord)
       
   152 		{
       
   153 		TRAP(sdpErr, AvrcpSdpUtils::CreateServiceRecordL(iSdpDatabase, iTargetRecord, ETrue, 
       
   154 					(aItem.iSdpFeatures & AvrcpSdp::EBrowsing) ? AvrcpSdp::KAvrcpProfileVersion14 : AvrcpSdp::KAvrcpProfileVersion13));
       
   155 		}
       
   156 	if(sdpErr == KErrNone)
       
   157 		{
       
   158 		TRAP_IGNORE(UpdateTgServiceRecordL());
       
   159 		}
       
   160 	}
       
   161 
       
   162 void CAvrcpPlayerInfoManager::ClientAvailable(const TRemConClientId& aId, TPlayerType aPlayerType, TPlayerSubType aPlayerSubType, const TDesC8& aName)
       
   163 	{
   137 	{
   164 	LOG_FUNC;
   138 	LOG_FUNC;
   165 	ASSERT_CONTROL_THREAD;
   139 	ASSERT_CONTROL_THREAD;
   166 	iLock.Wait();
   140 	iLock.Wait();
   167 	// Add this to our client list, using any holes in the client id array
   141 	// Add this to our client list, using any holes in the client id array
   174 		return;
   148 		return;
   175 		}
   149 		}
   176 	
   150 	
   177 	TAvrcpMediaPlayerItem& item = iPlayers[index];
   151 	TAvrcpMediaPlayerItem& item = iPlayers[index];
   178 	item.iId = aId;
   152 	item.iId = aId;
       
   153 	item.iPlayerType = aClientType;
       
   154 	item.iPlayerSubType = aClientSubType;
       
   155 	item.iName.Set(aName);
   179 	item.iBulkClientAvailable = EFalse;
   156 	item.iBulkClientAvailable = EFalse;
   180 	item.iUidCounter = 0;
   157 	item.iUidCounter = 0;
   181 	item.iLastUpdatedUidCounter = 0;
   158 	item.iLastUpdatedUidCounter = 0;
   182 	item.iPlaybackStatus = MPlayerEventsObserver::EStopped;
   159 	item.iPlaybackStatus = MPlayerEventsObserver::EStopped;
   183 	TInt err = SetItemDetails(item, aPlayerType, aPlayerSubType, aName);
   160 	item.iFeatureBitmask = TPlayerFeatureBitmask();
       
   161 	TInt err = SetPlayerFeatures(aId, item.iFeatureBitmask, item.iSdpFeatures, item.iAbsoluteVolumeSupport);
   184 
   162 
   185 	// Release lock before calling out of player info manager in case
   163 	// Release lock before calling out of player info manager in case
   186 	// anyone needs to call back in - we're finished updating the
   164 	// anyone needs to call back in - we're finished updating the
   187 	// info now.
   165 	// info now.
   188 	iLock.Signal();
   166 	iLock.Signal();
   189 
   167 
   190 	if(!err)
   168 	if(!err)
   191 		{
   169 		{
   192 		TRAP(err, iPlayStatusWatcher->StartWatchingPlayerL(aId));
   170 		TRAP(err, iPlayStatusWatcher->StartWatchingPlayerL(aId));
       
   171 	
   193 		if(!err)
   172 		if(!err)
   194 			{
   173 			{
   195 			UpdateSdpRecord(item);
   174 			// Update SDP record, if this fails we carry on, it's non-fatal
   196 		     for(TInt i = 0; i<iObservers.Count(); i++)
   175 			TInt sdpErr = KErrNone;
       
   176 			if(!iTargetRecord)
   197 				{
   177 				{
   198 				iObservers[i]->MpcoAvailablePlayersChanged();
   178 				TRAP(sdpErr, AvrcpSdpUtils::CreateServiceRecordL(iSdpDatabase, 
       
   179 						iTargetRecord, 
       
   180 						ETrue, 
       
   181 						(item.iSdpFeatures & AvrcpSdp::EBrowsing) ? 
       
   182 						AvrcpSdp::KAvrcpProfileVersion14 : 
       
   183 						AvrcpSdp::KAvrcpProfileVersion13));
   199 				}
   184 				}
   200 			}
   185 			
   201 		  else    
   186 			if(sdpErr == KErrNone)
   202 			{
   187 				{
   203 			iLock.Wait();
   188 				TRAP_IGNORE(UpdateTgServiceRecordL());
   204 			iPlayers[index].iId = KNullClientId;
   189 				}
   205 			iLock.Signal();
   190 			}
   206 			}
   191 		}
       
   192 
       
   193 	if(!err)
       
   194 		{
       
   195 		for(TInt i = 0; i<iObservers.Count(); i++)
       
   196 			{
       
   197 			iObservers[i]->MpcoAvailablePlayersChanged();
       
   198 			}
       
   199 		}
       
   200 	else	
       
   201 		{
       
   202 		iLock.Wait();
       
   203 		iPlayers[index].iId = KNullClientId;
       
   204 		iLock.Signal();
   207 		}
   205 		}
   208 	}
   206 	}
   209 
   207 
   210 void CAvrcpPlayerInfoManager::ClientNotAvailable(const TRemConClientId& aId)
   208 void CAvrcpPlayerInfoManager::ClientNotAvailable(const TRemConClientId& aId)
   211 	{
   209 	{
   301 		}
   299 		}
   302 
   300 
   303 	AvrcpSdpUtils::UpdateProtocolDescriptorListL(iSdpDatabase, iControllerRecord, avctpVersion);
   301 	AvrcpSdpUtils::UpdateProtocolDescriptorListL(iSdpDatabase, iControllerRecord, avctpVersion);
   304 	AvrcpSdpUtils::UpdateProfileDescriptorListL(iSdpDatabase, iControllerRecord, avrcpVersion);
   302 	AvrcpSdpUtils::UpdateProfileDescriptorListL(iSdpDatabase, iControllerRecord, avrcpVersion);
   305 	AvrcpSdpUtils::UpdateSupportedFeaturesL(iSdpDatabase, iControllerRecord, AvrcpSdp::ERemoteControl, AvrcpSdp::KAvrcpBaseCtFeatures);
   303 	AvrcpSdpUtils::UpdateSupportedFeaturesL(iSdpDatabase, iControllerRecord, AvrcpSdp::ERemoteControl, AvrcpSdp::KAvrcpBaseCtFeatures);
   306 	}
       
   307 
       
   308 void CAvrcpPlayerInfoManager::TargetFeaturesUpdated(const TRemConClientId& aId, TPlayerType aPlayerType, TPlayerSubType aPlayerSubType, const TDesC8& aName)
       
   309 	{
       
   310 	LOG_FUNC;
       
   311 	ASSERT_CONTROL_THREAD;
       
   312 	iLock.Wait();
       
   313 	// Find this client in our client list
       
   314 	TInt index = iPlayers.Find(aId, PlayerCompare);
       
   315 	if(index < 0)
       
   316 		{
       
   317 		// Couldn't find client in client list, maybe we removed it after an earlier failure
       
   318 		iLock.Signal();
       
   319 		return;
       
   320 		}
       
   321 
       
   322 	TAvrcpMediaPlayerItem& item = iPlayers[index];
       
   323 	TInt err = SetItemDetails(item, aPlayerType, aPlayerSubType, aName);
       
   324 
       
   325 	// Release lock before calling out of player info manager in case
       
   326 	// anyone needs to call back in - we're finished updating the
       
   327 	// info now.
       
   328 	iLock.Signal();
       
   329 
       
   330 	if(!err)
       
   331 		{
       
   332 		UpdateSdpRecord(item);
       
   333 		}
       
   334 	else    
       
   335 		{
       
   336 		// There was an error updating the features so remove this client from the client list
       
   337 		iLock.Wait();
       
   338 		iPlayers[index].iId = KNullClientId;
       
   339 		iLock.Signal();
       
   340 		}
       
   341 
       
   342 	for(TInt i = 0; i<iObservers.Count(); i++)
       
   343 		{
       
   344 		iObservers[i]->MpcoAvailablePlayersChanged();
       
   345 		}
       
   346 	}
   304 	}
   347 
   305 
   348 MIncomingCommandHandler& CAvrcpPlayerInfoManager::InternalCommandHandler()
   306 MIncomingCommandHandler& CAvrcpPlayerInfoManager::InternalCommandHandler()
   349 	{
   307 	{
   350 	LOG_FUNC
   308 	LOG_FUNC