bluetoothappprofiles/avrcp/playerinformation/src/playersettings.cpp
changeset 70 f5508c13dfe0
parent 67 16e4b9007960
child 71 083fd884d7dd
equal deleted inserted replaced
67:16e4b9007960 70:f5508c13dfe0
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @publishedAll
       
    19  @released
       
    20 */
       
    21 
       
    22 #include <remconinterfaceselector.h>
       
    23 #include <playerinformationtarget.h>
       
    24 
       
    25 #include "playerapplicationsetting.h"
       
    26 #include "playerinformation.h"
       
    27 #include "playersettingsutils.h"
       
    28 
       
    29 
       
    30 void CPlayerInfoTarget::SendError(TInt aError, TInt aOperationId)
       
    31 	{
       
    32 	TInt error = 0;
       
    33 	RAvrcpIPCError response;
       
    34 	response.iError = aError;
       
    35 	TRAP(error, response.WriteL(iOutBuf));   // Try to send internal error if OOM
       
    36 	if (error == KErrNone)
       
    37 		{
       
    38 		InterfaceSelector().SendUnreliable(TUid::Uid(KRemConPlayerInformationUid),
       
    39 										aOperationId, ERemConResponse, iOutBuf);
       
    40 		}								
       
    41 	}
       
    42 
       
    43 
       
    44 // PDU 0x11
       
    45 void CPlayerInfoTarget::ProcessListPlayerApplicationAttributes(TInt aOperationId)
       
    46 	{
       
    47 	RRemConPlayerListOfAttributes response;
       
    48 	response.iNumberAttributes = iPlayerApplicationSettings.Count();
       
    49 
       
    50 	THashMapIter<TInt, CPlayerApplicationSettings*> iter(iPlayerApplicationSettings);
       
    51 	const TInt* attribute = iter.NextKey();
       
    52 	while ( attribute != NULL )
       
    53 		{
       
    54 		if (response.iAttributes.Append(*attribute) != KErrNone)
       
    55 			{
       
    56 			response.Close();
       
    57 			return SendError(KErrAvrcpMetadataInternalError, aOperationId);   // Try to send internal error if OOM
       
    58 			}
       
    59 		attribute = iter.NextKey();
       
    60 		}
       
    61 
       
    62 	// send the response back to the CT
       
    63 	TInt error = 0;
       
    64 	TRAP(error, response.WriteL(iOutBuf));   // Try to send internal error if OOM
       
    65 	response.Close();
       
    66 	if (error != KErrNone)
       
    67 		{
       
    68 		return SendError(KErrAvrcpMetadataInternalError, aOperationId);
       
    69 		}
       
    70 		
       
    71 	InterfaceSelector().SendUnreliable(TUid::Uid(KRemConPlayerInformationUid),
       
    72 									EListPlayerApplicationSettingAttributes, ERemConResponse, iOutBuf );
       
    73 	}
       
    74 
       
    75 // PDU 0x12
       
    76 void CPlayerInfoTarget::ProcessListPlayerApplicationValues(const TDesC8& aData, TInt aOperationId)
       
    77 	{
       
    78 	TInt error =0;
       
    79 	RDesReadStream readStream;
       
    80 	readStream.Open(aData);
       
    81 	TInt attributeID = 0;
       
    82 	TRAP(error, attributeID = readStream.ReadUint8L());
       
    83 	readStream.Close();
       
    84 	if (error != KErrNone)
       
    85 		{
       
    86 		return SendError(KErrAvrcpMetadataParameterNotFound, aOperationId);  // Nothing in packet
       
    87 		}
       
    88 		
       
    89 	// Send the number of values for this attribute (1 byte),
       
    90 	// followed by the defined values themselves (n x 1byte)
       
    91 	CPlayerApplicationSettings* thisSetting = GetSetting(attributeID);
       
    92 	if (thisSetting == NULL) 
       
    93 		{
       
    94 		// Attribute Id not found
       
    95 		return SendError(KErrAvrcpMetadataInvalidParameter, aOperationId);  
       
    96 		}
       
    97 		
       
    98 	RRemConPlayerListOfAttributes response;
       
    99 	RArray<TUint>* values = thisSetting->GetValues();
       
   100 	TInt numValues = values->Count();
       
   101 	response.iNumberAttributes = numValues;
       
   102 
       
   103 	// Make sure that we always have at least one result to return
       
   104 	// Table 5.18 says that the number of results provided has an
       
   105 	// allowed value of 1-255, so we cannot return zero results.
       
   106 	if (response.iNumberAttributes == 0)
       
   107 		{
       
   108 		return SendError(KErrAvrcpMetadataParameterNotFound, aOperationId);  // No attributes matched
       
   109 		}
       
   110 
       
   111 	for ( TInt i = 0; i < numValues; i++ )
       
   112 		{
       
   113 		TInt value = (*values)[i];
       
   114 		if (response.iAttributes.Append(value) != KErrNone)
       
   115 			{
       
   116 			response.Close();
       
   117 			return SendError(KErrAvrcpMetadataInternalError, aOperationId);   // Try to send internal error if OOM
       
   118 			}
       
   119 		}
       
   120 
       
   121 	// send the response back to the CT
       
   122 	TRAP(error, response.WriteL(iOutBuf));   // Try to send internal error if OOM
       
   123 	response.Close();
       
   124 	if (error != KErrNone)
       
   125 		{
       
   126 		return SendError(KErrAvrcpMetadataInternalError, aOperationId);
       
   127 		}
       
   128 		
       
   129 	InterfaceSelector().SendUnreliable(TUid::Uid(KRemConPlayerInformationUid),
       
   130 									aOperationId, ERemConResponse, iOutBuf );
       
   131 	}
       
   132 
       
   133 // PDU 0x15
       
   134 void CPlayerInfoTarget::ProcessGetPlayerApplicationAttributeText(const TDesC8& aData, TInt aOperationId)
       
   135 	{
       
   136 	TInt error =0;
       
   137 
       
   138 	// If we can't parse the request, then return an error
       
   139 	RRemConPlayerListOfAttributes request;
       
   140 	TRAP(error, request.ReadL(aData));
       
   141 	if (error != KErrNone)
       
   142 		{
       
   143 		request.Close();
       
   144 		return SendError(KErrAvrcpMetadataInvalidCommand, aOperationId);
       
   145 		}
       
   146 		
       
   147 	// Iterate through requested attributes and remove
       
   148 	// those which we don't have any settings for.
       
   149 	for (TInt i = 0; i < request.iNumberAttributes; i++)
       
   150 		{
       
   151 		if (! AttributeSettingExists(request.iAttributes[i]))
       
   152 			{
       
   153 			request.iAttributes.Remove(i);
       
   154 			request.iNumberAttributes--;
       
   155 			i--;
       
   156 			}
       
   157 		}
       
   158 		
       
   159 	// Make sure that we always have at least one result to return
       
   160 	// Table 5.18 says that the number of results provided has an
       
   161 	// allowed value of 1-255, so we cannot return zero results.
       
   162 	RRemConGetPlayerApplicationTextResponse response;
       
   163 	response.iNumberAttributes = request.iNumberAttributes;
       
   164 	if (response.iNumberAttributes == 0)
       
   165 		{
       
   166 		request.Close();
       
   167 		return SendError(KErrAvrcpMetadataInvalidParameter, aOperationId);  // No attributes matched
       
   168 		}
       
   169 
       
   170 	// for every attribute text requested
       
   171 	for (TInt i = 0; i < request.iNumberAttributes; i++)
       
   172 		{
       
   173 		// start with the attribute id requested and the character set
       
   174 		RSettingWithCharset setting;
       
   175 		TInt attId = request.iAttributes[i];
       
   176 		CPlayerApplicationSettings* thisSetting = GetSetting(attId);
       
   177 		setting.iAttributeId = attId;
       
   178 		setting.iCharset = KUtf8MibEnum;
       
   179 		const TPtrC8 text = thisSetting->GetAttributeText();
       
   180 		setting.iStringLen = text.Length();
       
   181 		setting.iString = text.Alloc();
       
   182 		
       
   183 		// If OOM, try to return an internal error.
       
   184 		if (setting.iString == NULL)
       
   185 			{
       
   186 			request.Close();
       
   187 			response.Close();
       
   188 			return SendError(KErrAvrcpMetadataInternalError, aOperationId);
       
   189 			}
       
   190 			
       
   191 		// If OOM, try to return an internal error.
       
   192 		if (response.iAttributes.Append(setting) != KErrNone)
       
   193 			{
       
   194 			setting.Close();
       
   195 			request.Close();
       
   196 			response.Close();
       
   197 			return SendError(KErrAvrcpMetadataInternalError, aOperationId);
       
   198 			}
       
   199 		}
       
   200 	request.Close();
       
   201 	
       
   202 	// Allocate a buffer for the formatted message
       
   203 	RBuf8 messageBuffer;
       
   204 	if ( messageBuffer.Create(response.Size()) != KErrNone )
       
   205 		{
       
   206 		// On OOM drop the message
       
   207 		response.Close();
       
   208 		return;
       
   209 		}
       
   210 		
       
   211 	// send the response back to the CT
       
   212 	TRAP(error, response.WriteL(messageBuffer));   // Try to send internal error if OOM
       
   213 	response.Close();
       
   214 	if (error != KErrNone)
       
   215 		{
       
   216 		messageBuffer.Close();
       
   217 		return SendError(KErrAvrcpMetadataInternalError, aOperationId);
       
   218 		}
       
   219 		
       
   220 	InterfaceSelector().SendUnreliable(TUid::Uid(KRemConPlayerInformationUid),
       
   221 									aOperationId, ERemConResponse, messageBuffer );
       
   222 	
       
   223 	messageBuffer.Close();
       
   224 	}
       
   225 
       
   226 // PDU 0x14
       
   227 void CPlayerInfoTarget::ProcessSetPlayerApplicationValue(const TDesC8& aData, TInt aOperationId)
       
   228 	{
       
   229 	RRemConPlayerAttributeIdsAndValues request;
       
   230 	TInt error = 0;
       
   231 
       
   232 	// If we can't parse the request, then return an error
       
   233 	TRAP(error, request.ReadL(aData));
       
   234 	if (error != KErrNone)
       
   235 		{
       
   236 		request.Close();
       
   237 		return SendError(KErrAvrcpMetadataInvalidCommand, aOperationId);
       
   238 		}
       
   239 		
       
   240 	// Iterate through all the settings we're sent to update and set them
       
   241 	for (TInt i = 0; i < request.iNumberAttributes; i++)
       
   242 		{
       
   243 		if (! AttributeValueCanBeSet(request.iAttributeId[i], request.iAttributeValue[i]))
       
   244 			{
       
   245 			// remove this setting
       
   246 			request.iAttributeId.Remove(i);
       
   247 			request.iAttributeValue.Remove(i);
       
   248 			request.iNumberAttributes--;
       
   249 			i--;
       
   250 			}
       
   251 		}
       
   252 	__ASSERT_DEBUG(request.iAttributeId.Count() == request.iAttributeValue.Count(), PlayerSettingsUtils::Panic(EPlayerSettingsFunnyLengthData));
       
   253 	
       
   254 	// Section 5.7 of the AVRCP specification (page 56) says:
       
   255 	// If CT sent a PDU with nonexistent PDU ID or a PDU containing
       
   256 	// only one parameter with nonexistent parameter ID, TG shall return
       
   257 	// REJECTED response with Error Status Code. If CT sent a PDU with
       
   258 	// multiple parameters where at least one ID is existent and the
       
   259 	// others are nonexistent, TG shall proceed with the existent ID and
       
   260 	// ignore the non-existent IDs.
       
   261 	//
       
   262 	// This means we return REJECTED if we have nothing to set
       
   263 	if (request.iNumberAttributes == 0)
       
   264 		{
       
   265 		request.Close();
       
   266 		return SendError(KErrAvrcpMetadataInvalidParameter, aOperationId);
       
   267 		}
       
   268 		
       
   269 	// If an application setting notifier has been requested then notify it
       
   270 	// If the notification succeeds, then set all the values
       
   271 
       
   272 	TRAP(error, iApplicationSettingNotifier.MpasnSetPlayerApplicationValueL(request.iAttributeId, request.iAttributeValue));
       
   273 	if ( error == KErrNone )
       
   274 		{
       
   275 		for (TInt i = 0; i < request.iNumberAttributes; i++)
       
   276 			{
       
   277 			CPlayerApplicationSettings* thisSetting = GetSetting(request.iAttributeId[i]);
       
   278 			thisSetting->SetCurrentValue(request.iAttributeValue[i]);
       
   279 			}
       
   280 		}
       
   281 	else
       
   282 		{
       
   283 		// Return an AVRCP internal error via RemCon. See section 5.7.1 of specification.
       
   284 		request.Close();
       
   285 		return SendError(KErrAvrcpMetadataInternalError, aOperationId);
       
   286 		}
       
   287 		
       
   288 	request.Close();
       
   289      // Send a notification if one has been registered
       
   290      if ( KErrNotFound != iPendingNotificationEventList.Find( ERegisterNotificationPlayerApplicationSettingChanged ))
       
   291           {
       
   292            SendNotificationResponse( ERegisterNotificationPlayerApplicationSettingChanged, ERemConNotifyResponseChanged );
       
   293           }
       
   294        
       
   295 		
       
   296 	// SendError KErrNone is used to send a valid response
       
   297 	SendError(KErrNone, aOperationId);
       
   298 	}
       
   299 
       
   300 // PDU 0x13
       
   301 void CPlayerInfoTarget::ProcessGetCurrentPlayerApplicationValue(const TDesC8& aData, TInt aOperationId)
       
   302 	{
       
   303 	TInt error = 0;
       
   304 
       
   305 	// If we can't parse the request, then return an error
       
   306 	RRemConPlayerListOfAttributes request;
       
   307 	TRAP(error, request.ReadL(aData));
       
   308 	if (error != KErrNone)
       
   309 		{
       
   310 		request.Close();
       
   311 		return SendError(KErrAvrcpMetadataInvalidCommand, aOperationId);
       
   312 		}
       
   313 		
       
   314 	// Look through requested attributes, and assemble a response
       
   315 	// for those which we posess. If none are found, return an error
       
   316 	RRemConPlayerAttributeIdsAndValues response;
       
   317 	response.iNumberAttributes = 0;
       
   318 	request.iAttributes.Sort();
       
   319 	
       
   320 	for (TInt i = 0; i < request.iNumberAttributes; i++)
       
   321 		{
       
   322 		TInt attToSend = request.iAttributes[i];
       
   323 		if (AttributeSettingExists(attToSend))
       
   324 			{
       
   325 			TInt ret1 = response.iAttributeId.Append(attToSend);
       
   326 			TInt ret2 = response.iAttributeValue.Append(GetSetting(attToSend)->GetCurrentValue());
       
   327 			if (ret1 != KErrNone || ret2 != KErrNone)
       
   328 				{
       
   329 				request.Close();
       
   330 				response.Close();
       
   331 				return SendError(KErrAvrcpMetadataInternalError, aOperationId);   // Try to send internal error if OOM
       
   332 				}
       
   333 			response.iNumberAttributes++;
       
   334 			}
       
   335 		}
       
   336 	request.Close();
       
   337 		
       
   338 	// Make sure that we always have at least one result to return
       
   339 	// Table 5.18 says that the number of results provided has an
       
   340 	// allowed value of 1-255, so we cannot return zero results.
       
   341 	if (response.iNumberAttributes == 0)
       
   342 		{
       
   343 		response.Close();
       
   344 		return SendError(KErrAvrcpMetadataInvalidParameter, aOperationId);  // No attributes matched
       
   345 		}
       
   346 		
       
   347 	// send the response back to the CT
       
   348 	TRAP(error, response.WriteL(iOutBuf));   // Try to send internal error if OOM
       
   349 	response.Close();
       
   350 	if (error != KErrNone)
       
   351 		{
       
   352 		return SendError(KErrAvrcpMetadataInternalError, aOperationId);
       
   353 		}
       
   354 		
       
   355 	InterfaceSelector().SendUnreliable(TUid::Uid(KRemConPlayerInformationUid),
       
   356 									aOperationId, ERemConResponse, iOutBuf );
       
   357 	}
       
   358 
       
   359 // PDU 0x16
       
   360 void CPlayerInfoTarget::ProcessGetPlayerApplicationValueText(const TDesC8& aData, TInt aOperationId)
       
   361 	{
       
   362 	RDesReadStream readStream;
       
   363 	readStream.Open(aData);
       
   364 
       
   365 	TInt error = 0;
       
   366 	TInt reqAttribute = 0;
       
   367 	
       
   368 	// Read the attribute id
       
   369 	TRAP(error, reqAttribute = readStream.ReadUint8L());
       
   370 	if (error != KErrNone)
       
   371 		{
       
   372 		readStream.Close();
       
   373 		return SendError(KErrAvrcpMetadataParameterNotFound, aOperationId);  // Nothing in packet
       
   374 		}
       
   375 		
       
   376 	// If we don't have settings for this attribute, return an error
       
   377 	CPlayerApplicationSettings* thisSetting = GetSetting(reqAttribute);
       
   378 	if (thisSetting == NULL)
       
   379 		{
       
   380 		readStream.Close();
       
   381 		return SendError(KErrAvrcpMetadataInvalidParameter, aOperationId);  // Attribute not found
       
   382 		}
       
   383 		
       
   384 	// Read the number of PAS values
       
   385 	TInt numSettings = 0;
       
   386 	TRAP(error, numSettings = readStream.ReadUint8L());
       
   387 	if (error != KErrNone)
       
   388 		{
       
   389 		readStream.Close();
       
   390 		return SendError(KErrAvrcpMetadataParameterNotFound, aOperationId);  // Nothing in packet
       
   391 		}
       
   392 	
       
   393 	RArray<TInt> valueTextsRequested;
       
   394 	for (TInt i = 0; i < numSettings; i++)
       
   395 		{
       
   396 		TInt requestedValueText = 0;
       
   397 		TRAP(error, requestedValueText = readStream.ReadUint8L());
       
   398 		if (error == KErrNone)
       
   399 			{
       
   400 			if (valueTextsRequested.Append(requestedValueText) != KErrNone)
       
   401 				{
       
   402 				readStream.Close();
       
   403 				return SendError(KErrAvrcpMetadataInternalError, aOperationId);   // Try to send internal error if OOM
       
   404 				}
       
   405 			}
       
   406 		}
       
   407 	
       
   408 	readStream.Close();
       
   409 	
       
   410 	// format the response in a RRemConGetPlayerApplicationTextResponse
       
   411 	RRemConGetPlayerApplicationTextResponse response;
       
   412 	response.iNumberAttributes = 0;
       
   413 
       
   414 	// for every attribute text requested
       
   415 	RPointerArray<HBufC8>* textValues = thisSetting->GetValuesTexts();
       
   416 	RArray<TUint>* values = thisSetting->GetValues();
       
   417 	TInt numRequested = valueTextsRequested.Count();
       
   418 	for (TInt i = 0; i < numRequested; i++)
       
   419 		{
       
   420 		// start with the attribute id requested and the character set
       
   421 		RSettingWithCharset setting;
       
   422 		TInt valueToSend = valueTextsRequested[i];
       
   423 		setting.iAttributeId = valueToSend;
       
   424 		setting.iCharset = KUtf8MibEnum;
       
   425 
       
   426 		// text length followed by the text
       
   427 		TInt found = values->Find(valueToSend);
       
   428 		if (found != KErrNotFound)
       
   429 			{
       
   430 			HBufC8* text = (*textValues)[found];
       
   431 			setting.iStringLen = text->Length();
       
   432 			setting.iString = text->Alloc();
       
   433 			
       
   434 			// If OOM, try to return an internal error.
       
   435 			if (setting.iString == NULL)
       
   436 				{
       
   437 				response.Close();
       
   438 				valueTextsRequested.Close();
       
   439 				return SendError(KErrAvrcpMetadataInternalError, aOperationId);
       
   440 				}
       
   441 				
       
   442 			// If OOM, try to return an internal error. Of course, this could fail too
       
   443 			if (response.iAttributes.Append(setting) != KErrNone)
       
   444 				{
       
   445 				response.Close();
       
   446 				setting.Close();
       
   447 				valueTextsRequested.Close();
       
   448 				return SendError(KErrAvrcpMetadataInternalError, aOperationId);
       
   449 				}
       
   450 				
       
   451 			response.iNumberAttributes++;
       
   452 			}
       
   453 		}
       
   454 	valueTextsRequested.Close();
       
   455 	
       
   456 	// Make sure that we always have at least one result to return
       
   457 	// Table 5.18 says that the number of results provided has an
       
   458 	// allowed value of 1-255, so we cannot return zero results.
       
   459 	if (response.iNumberAttributes == 0)
       
   460 		{
       
   461 		response.Close();
       
   462 		return SendError(KErrAvrcpMetadataInvalidParameter, aOperationId);
       
   463 		}
       
   464 		
       
   465 	// Allocate a buffer for the formatted message
       
   466 	RBuf8 messageBuffer;
       
   467 	if ( messageBuffer.Create(response.Size()) != KErrNone )
       
   468 		{
       
   469 		// On OOM drop the message
       
   470 		response.Close();
       
   471 		return;
       
   472 		}
       
   473 		
       
   474 	// send the response back to the CT
       
   475 	TRAP(error, response.WriteL(messageBuffer));   // Try to send internal error if OOM
       
   476 	response.Close();
       
   477 	if (error != KErrNone)
       
   478 		{
       
   479 		messageBuffer.Close();
       
   480 		return SendError(KErrAvrcpMetadataInternalError, aOperationId);
       
   481 		}
       
   482 		
       
   483 	InterfaceSelector().SendUnreliable(TUid::Uid(KRemConPlayerInformationUid),
       
   484 									aOperationId, ERemConResponse, messageBuffer );
       
   485 	messageBuffer.Close();
       
   486 	}
       
   487 
       
   488 TBool CPlayerInfoTarget::AttributeSettingExists(TUint anAttributeID)
       
   489 	{
       
   490 	if (GetSetting(anAttributeID) == NULL)
       
   491 		{
       
   492 		return EFalse;
       
   493 		}
       
   494 	else
       
   495 		{
       
   496 		return ETrue;
       
   497 		}
       
   498 	}
       
   499 
       
   500 TBool CPlayerInfoTarget::IsValidAttributeValue(TUint anAttributeID, TUint anAttributeValue)
       
   501 	{
       
   502 	// As defined in Appendix F of the AVRCP specification, page 81
       
   503 	// Attribute 0x01 - range 0x01 to 0x02
       
   504 	// Attribute 0x02 - range 0x01 to 0x04
       
   505 	// Attribute 0x03 - range 0x01 to 0x03
       
   506 	// Attribute 0x04 - range 0x01 to 0x03
       
   507 	// Attribute 0x05 - 0x7f -- invalid; reserved for future use
       
   508 	// Attribute 0x80 - 0xff -- vendor dependent
       
   509 	if (anAttributeID >= 0x80 && anAttributeID <= 0xff && anAttributeValue <= 0xff )
       
   510 		{
       
   511 		return ETrue;
       
   512 		}
       
   513 		
       
   514 	if (anAttributeID == 0x01 && anAttributeValue >= 0x01 && anAttributeValue <= 0x02)
       
   515 		{
       
   516 		return ETrue;
       
   517 		}
       
   518 		
       
   519 	if (anAttributeID == 0x02 && anAttributeValue >= 0x01 && anAttributeValue <= 0x04)
       
   520 		{
       
   521 		return ETrue;
       
   522 		}
       
   523 		
       
   524 	if ((anAttributeID == 0x03 || anAttributeID == 0x04)
       
   525 		&& anAttributeValue >= 0x01 && anAttributeValue <= 0x03)
       
   526 		{
       
   527 		return ETrue;
       
   528 		}
       
   529 		
       
   530 	// Everything else is invalid, as defined by the specification
       
   531 	return EFalse;
       
   532 	}
       
   533 
       
   534 // Check that anAttributeValue is in the valid value list for anAttributeID
       
   535 TBool CPlayerInfoTarget::AttributeValueCanBeSet(TUint anAttributeID, TUint anAttributeValue)
       
   536 	{
       
   537 	CPlayerApplicationSettings* thisSetting = GetSetting(anAttributeID);
       
   538 	if (thisSetting == NULL)
       
   539 		{
       
   540 		return EFalse;
       
   541 		}
       
   542 		
       
   543 	RArray<TUint>* values = thisSetting->GetValues();
       
   544 	if (values == NULL)
       
   545 		{
       
   546 		return EFalse;
       
   547 		}
       
   548 		
       
   549 	if (values->Find(anAttributeValue) == KErrNotFound)
       
   550 		{
       
   551 		return EFalse;
       
   552 		}
       
   553 		
       
   554 	// This attribute id and value has been already defined by the RSS
       
   555 	// file, and checked that it conforms to the specification when the
       
   556 	// RSS file was loaded. Now allow this value to be set over the air.
       
   557 	return ETrue;
       
   558 	}
       
   559 
       
   560 CPlayerApplicationSettings* CPlayerInfoTarget::GetSetting(TUint anAttributeID)
       
   561 	{
       
   562 	// Will return NULL if anAttributeID is not found
       
   563 	CPlayerApplicationSettings** settings = iPlayerApplicationSettings.Find(anAttributeID);
       
   564 	if (settings == NULL)
       
   565 		{
       
   566 		return NULL;
       
   567 		}
       
   568 		
       
   569 	return *settings;
       
   570 	}
       
   571 
       
   572 
       
   573 // from MPlayerApplicationSettingsObserver
       
   574 // exported function wrapper for internal pure virtual
       
   575 EXPORT_C void MPlayerApplicationSettingsObserver::DefineAttributeL(TUint aAttributeID,
       
   576 																	TDesC8& aAttributeText,
       
   577 																	RArray<TUint>& aValues,
       
   578 																	RArray<TPtrC8>& aValueTexts,
       
   579 																	TUint aInitialValue)
       
   580 	{
       
   581 	DoDefineAttributeL(aAttributeID, aAttributeText, aValues, aValueTexts, aInitialValue);
       
   582 	}
       
   583 
       
   584 EXPORT_C void MPlayerApplicationSettingsObserver::SetAttributeL(TUint aAttributeID, TUint aValue)
       
   585 	{
       
   586 	DoSetAttributeL(aAttributeID, aValue );
       
   587 	}
       
   588 
       
   589 void CPlayerInfoTarget::DoDefineAttributeL(TUint aAttributeID,
       
   590 											TDesC8& aAttributeText,
       
   591 											RArray<TUint>& aValues,
       
   592 											RArray<TPtrC8>& aValueTexts,
       
   593 											TUint aInitialValue)
       
   594 	{
       
   595 	//Check Length of the player application setting attribute string is 1-255
       
   596 	if(aAttributeText.Length() > KMaxPlayerApplicationSettingsValue || 
       
   597 			aAttributeText.Length() < KMinPlayerApplicationSettingsValue )
       
   598 		{
       
   599 		User::Leave(KErrNotSupported);
       
   600 		}
       
   601 	
       
   602 	//Check the number of player application setting values is 1-255
       
   603 	if(aValues.Count() > KMaxPlayerApplicationSettingsValue || 
       
   604 			aValues.Count() < KMinPlayerApplicationSettingsValue )
       
   605 		{
       
   606 		User::Leave(KErrNotSupported);
       
   607 		}	
       
   608 	
       
   609 	//Check the numbers of player application setting values and 
       
   610 	//player application setting value texts are equal
       
   611 	if(aValues.Count() != aValueTexts.Count())
       
   612 		{
       
   613 		User::Leave(KErrNotSupported);
       
   614 		}
       
   615 	
       
   616 	//Check Length of the player application setting value string is 1-255
       
   617 	for(TInt i = 0; i < aValueTexts.Count(); i++ )
       
   618 		{
       
   619 		if(aValueTexts[i].Length() > KMaxPlayerApplicationSettingsValue ||
       
   620 				aValueTexts[i].Length() < KMinPlayerApplicationSettingsValue )
       
   621 			{
       
   622 			User::Leave (KErrNotSupported);
       
   623 			}			
       
   624 		}
       
   625 
       
   626 	for (TInt i = 0; i < aValues.Count(); i++)
       
   627 		{
       
   628 		// The user cannot define certain attribute ids or values; see Appendix F
       
   629 		if ( ! IsValidAttributeValue(aAttributeID, aValues[i]))
       
   630 			{
       
   631 			User::Leave(KErrNotSupported);
       
   632 			}
       
   633 		}
       
   634 	
       
   635 	// Check the initial value, too
       
   636 	if ( ! IsValidAttributeValue(aAttributeID, aInitialValue))
       
   637 		{
       
   638 		User::Leave(KErrNotSupported);
       
   639 		}
       
   640 		
       
   641 	// check that aInitialValue is in aValues
       
   642 	if (aValues.Find(aInitialValue) == KErrNotFound)
       
   643 		{
       
   644 		User::Leave(KErrNotSupported);
       
   645 		}
       
   646 		
       
   647 	// create a new TPlayerApplicationSettings
       
   648 	CPlayerApplicationSettings* newSetting = CPlayerApplicationSettings::NewL(aAttributeID, aAttributeText, aValues, aValueTexts, aInitialValue);
       
   649 	CleanupStack::PushL(newSetting);
       
   650 	
       
   651 	// Backup the settings of aAttributeID if they exist, return NULL if the attribute ID cannot be found
       
   652 	CPlayerApplicationSettings* backupSetting = GetSetting(aAttributeID); 
       
   653 	
       
   654 	// and save it 
       
   655 	iPlayerApplicationSettings.InsertL(aAttributeID, newSetting);
       
   656 	
       
   657 	//Delete backupSetting, as the InsertL will replace the old objects by the provided objects 
       
   658 	delete backupSetting;
       
   659 	
       
   660 	CleanupStack::Pop(newSetting);
       
   661 	}
       
   662 
       
   663 void CPlayerInfoTarget::DoSetAttributeL(TUint aAttributeID, TUint aValue)
       
   664 	{
       
   665 	// Will return NULL if the attribute ID cannot be found
       
   666 	CPlayerApplicationSettings* setting = GetSetting(aAttributeID);
       
   667 	if (setting == NULL)
       
   668 		{
       
   669 		User::Leave(KErrNotFound);
       
   670 		}
       
   671 		
       
   672 	if ( ! IsValidAttributeValue(aAttributeID, aValue))
       
   673 		{
       
   674 		User::Leave(KErrNotSupported);
       
   675 		}
       
   676 		
       
   677 	setting->SetCurrentValue(aValue);
       
   678 	
       
   679 	if ( KErrNotFound != iPendingNotificationEventList.Find( ERegisterNotificationPlayerApplicationSettingChanged ))
       
   680 		{
       
   681 		// send response
       
   682 		SendNotificationResponse( ERegisterNotificationPlayerApplicationSettingChanged, ERemConNotifyResponseChanged );
       
   683 		}
       
   684 	}
       
   685