persistentstorage/centralrepository/common/inc/setting.inl
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2004-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 using namespace NCentralRepositoryConstants;
       
    17 
       
    18 inline TServerSetting::TServerSetting()
       
    19 	: iKey(0),
       
    20 	  iMeta(0),
       
    21 	  iAccessPolicy(0)
       
    22 	{
       
    23 	Mem::FillZ(&iValue, sizeof(iValue));
       
    24 	}
       
    25 
       
    26 inline TServerSetting::TServerSetting(const TUint32 aKey)
       
    27 	: iKey(aKey),
       
    28 	  iMeta(0),
       
    29 	  iAccessPolicy(0)
       
    30 	{
       
    31 	Mem::FillZ(&iValue, sizeof(iValue));
       
    32 	}
       
    33 
       
    34 /** Ensures this setting has the same type and value of source. Where EString types
       
    35 are involved, safely removes previously-owned string, and deep copies string taken
       
    36 from source.
       
    37 Does not require source and destination type to match. Callers must check if important.
       
    38 @return	KErrNone if successful or KErrNoMemory if no memory available for copying any string.
       
    39 @post If error code is not KErrNone, object is guaranteed to be in its original state.
       
    40 */
       
    41 inline TInt TServerSetting::ReplaceTypeAndValue(const TServerSetting& source)
       
    42 	{
       
    43 	ASSERT(IsDeleted());
       
    44 	
       
    45 	if (source.IsStr())
       
    46 		{
       
    47 		const HBufC8* sourceBuf = source.GetStrValue();
       
    48 		HBufC8* buf = sourceBuf ? sourceBuf->Alloc() : NULL;
       
    49 		if (sourceBuf && !buf)
       
    50 			{
       
    51 			return KErrNoMemory;
       
    52 			}
       
    53 		
       
    54 		ResetValue();
       
    55 		SetType(EString);
       
    56 		iValue.s = buf;
       
    57 		}
       
    58 	else if (source.IsReal())
       
    59 		{
       
    60 		if(!source.iValue.r)
       
    61 			{
       
    62 			return KErrCorrupt;
       
    63 			}
       
    64 		
       
    65 		TReal* temp = new TReal(source.GetRealValue());
       
    66 		if (temp == NULL)
       
    67 			{
       
    68 			return KErrNoMemory;
       
    69 			}
       
    70 		
       
    71 		ResetValue();
       
    72 		SetType(EReal);
       
    73 		iValue.r = temp;
       
    74 		}
       
    75 	else
       
    76 		{
       
    77 		ResetValue();
       
    78 		SetType(source.Type());
       
    79 		if (source.IsInt())
       
    80 			{
       
    81 			iValue.i = source.GetIntValue();
       
    82 			}
       
    83 		}
       
    84 	
       
    85 	return KErrNone;
       
    86 	}
       
    87 
       
    88 /** Replaces the contents of this setting with those of source, safely cleaning up previously-
       
    89 owned string, and making a deep copy of source string if of string type.
       
    90 Does not require source and destination type to match. Callers must check if important.
       
    91 @return	KErrNone if successful or KErrNoMemory if no memory available for copying any string.
       
    92 @post If error code is not KErrNone, object is guaranteed to be in its original state.
       
    93 */
       
    94 inline TInt TServerSetting::Replace(const TServerSetting& aSetting)
       
    95 	{
       
    96 	if (aSetting.IsStr())
       
    97 		{
       
    98 		const HBufC8* sourceBuf = aSetting.GetStrValue();
       
    99 		HBufC8* targetBuf = sourceBuf ? sourceBuf->Alloc() : NULL;
       
   100 		if (sourceBuf && !targetBuf)
       
   101 			{
       
   102 			return KErrNoMemory;
       
   103 			}
       
   104 		Reset();
       
   105 		*this = aSetting;
       
   106 		iValue.s = targetBuf;
       
   107 		}
       
   108 	else if (aSetting.IsReal())
       
   109 		{
       
   110 		TReal* temp = new TReal(aSetting.GetRealValue());
       
   111 		if(temp == NULL)
       
   112 			{
       
   113 			return KErrNoMemory;
       
   114 			}
       
   115 
       
   116 		Reset();
       
   117 		*this = aSetting;
       
   118 		iValue.r = temp;
       
   119 		temp = NULL;
       
   120 		}
       
   121 	else
       
   122 		{
       
   123 		Reset();
       
   124 		*this = aSetting;
       
   125 		}
       
   126 	return KErrNone;
       
   127 	}
       
   128 
       
   129 /** Transfer ownership of the contents of this setting with those of source, safely cleaning up previously-
       
   130 owned string, and making a deep copy of source string if of string type.
       
   131 Does not require source and destination type to match. Callers must check if important.
       
   132 @return	KErrNone if successful or KErrNoMemory if no memory available for copying any string.
       
   133 @post If error code is not KErrNone, object is guaranteed to be in its original state.
       
   134 */
       
   135 inline TInt TServerSetting::Transfer(TServerSetting& aSetting)
       
   136 	{
       
   137 	Reset();
       
   138 	*this = aSetting;
       
   139 	
       
   140 	Mem::FillZ(&aSetting.iValue, sizeof(aSetting.iValue));
       
   141 	aSetting.SetType(EDeleted);
       
   142 
       
   143 	return KErrNone;
       
   144 	}
       
   145 
       
   146 
       
   147 inline TUint32 TServerSetting::Key() const
       
   148 	{
       
   149 	return iKey;
       
   150 	}
       
   151 
       
   152 inline void TServerSetting::SetKey(TUint32 aKey)
       
   153 	{
       
   154 	iKey = aKey;
       
   155 	}
       
   156 
       
   157 inline TUint32 TServerSetting::Meta() const
       
   158 	{
       
   159 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
       
   160 	return iMeta & ~KMetaInternal;
       
   161 #else
       
   162 	return iMeta & ~KMetaType;
       
   163 #endif	
       
   164 	}
       
   165 
       
   166 inline void TServerSetting::SetMeta(const TUint32 aMeta)
       
   167 	{
       
   168 	iMeta = (iMeta & KMetaType) | (aMeta & ~KMetaType);
       
   169 	}
       
   170 	
       
   171 inline TUint32 TServerSetting::Type() const
       
   172 	{
       
   173 	return iMeta & KMetaType;
       
   174 	}
       
   175 
       
   176 inline void TServerSetting::SetType(const TUint32 aType)
       
   177 	{
       
   178 	iMeta = (iMeta & ~KMetaType) | (aType & KMetaType);
       
   179 	}
       
   180 	
       
   181 inline TInt TServerSetting::GetIntValue() const
       
   182 	{
       
   183 	return iValue.i;
       
   184 	}
       
   185 
       
   186 inline const TReal& TServerSetting::GetRealValue() const
       
   187 	{
       
   188 	return *(iValue.r);
       
   189 	}
       
   190 
       
   191 inline const HBufC8* TServerSetting::GetStrValue() const
       
   192 	{
       
   193 	return iValue.s;
       
   194 	}
       
   195 
       
   196 inline void TServerSetting::SetIntValue(TInt aVal)
       
   197 	{
       
   198 	SetType(EInt);
       
   199 	iValue.i = aVal;
       
   200 	}
       
   201 
       
   202 inline void TServerSetting::SetRealValue(const TReal* aVal)
       
   203 	{
       
   204 	ASSERT(aVal);
       
   205 	SetType(EReal);
       
   206 	iValue.r = const_cast<TReal*>(aVal);
       
   207 	}
       
   208 
       
   209 
       
   210 inline void TServerSetting::SetStrValue(const HBufC8* aVal)
       
   211 	{
       
   212 	SetType(EString);
       
   213 	if(aVal && !aVal->Length())
       
   214 		{
       
   215 		delete aVal;
       
   216 		iValue.s = NULL;
       
   217 		}
       
   218 	else
       
   219 		{
       
   220 		iValue.s = const_cast<HBufC8*>(aVal);
       
   221 		}
       
   222 	}
       
   223 
       
   224 inline void TServerSetting::SetDeleted()
       
   225 	{
       
   226 	SetType(EDeleted);
       
   227 	}
       
   228 
       
   229 inline TInt TServerSetting::CopyValue(TInt aVal)
       
   230 	{
       
   231 	Reset();
       
   232 	SetIntValue(aVal);
       
   233 	return KErrNone;
       
   234 	}
       
   235 	
       
   236 inline TInt TServerSetting::CopyValue(const TReal& aVal)
       
   237 	{
       
   238 	Reset();
       
   239 	TReal* temp=new TReal(aVal);
       
   240 	if (!temp)
       
   241 		return KErrNoMemory;
       
   242 	SetRealValue(temp);
       
   243 	return KErrNone;	
       
   244 	}
       
   245 	
       
   246 inline TInt TServerSetting::CopyValue(const TDesC8& aVal)
       
   247 	{
       
   248 	Reset();
       
   249 	if (aVal.Length())
       
   250 		{
       
   251 		HBufC8* temp=aVal.Alloc();
       
   252 		if (!temp)
       
   253 			return KErrNoMemory;
       
   254 		SetStrValue(temp);
       
   255 		}
       
   256 	else
       
   257 		{
       
   258 		SetStrValue(NULL);
       
   259 		}
       
   260 	return KErrNone;
       
   261 	}
       
   262 	
       
   263 inline void TServerSetting::CopyValueL(TInt aVal)
       
   264 	{
       
   265 	User::LeaveIfError(CopyValue(aVal));
       
   266 	}
       
   267 
       
   268 inline void TServerSetting::CopyValueL(const TReal& aVal)
       
   269 	{
       
   270 	User::LeaveIfError(CopyValue(aVal));
       
   271 	}
       
   272 
       
   273 inline void TServerSetting::CopyValueL(const TDesC8& aVal)
       
   274 	{
       
   275 	User::LeaveIfError(CopyValue(aVal));
       
   276 	}
       
   277 
       
   278 inline TInt TServerSetting::AssignValueTo(TInt& aVal) const
       
   279 	{
       
   280 	return IsInt() ? (aVal=iValue.i, KErrNone) : KErrArgument;
       
   281 	}
       
   282 
       
   283 inline TInt TServerSetting::AssignValueTo(TReal& aVal) const
       
   284 	{
       
   285 	return IsReal() ? 
       
   286 		(iValue.r ? (aVal=*(iValue.r), KErrNone) : KErrCorrupt)
       
   287 		: KErrArgument;
       
   288 	}
       
   289 
       
   290 inline TInt TServerSetting::AssignValueTo(TDes8& aVal) const
       
   291 	{
       
   292 	return IsStr() ?
       
   293 		(iValue.s ? (aVal=iValue.s->Des(), KErrNone) : (aVal=KNullDesC8, KErrNone))
       
   294 		: KErrArgument;
       
   295 	}
       
   296 
       
   297 inline TInt TServerSetting::AssignValueFrom(TInt aVal)
       
   298 	{
       
   299 	return IsInt() ? (iValue.i=aVal, KErrNone) : KErrArgument;
       
   300 	}
       
   301 
       
   302 inline TInt TServerSetting::AssignValueFrom(const TReal& aVal)
       
   303 	{
       
   304 	if(!IsReal())
       
   305 		{
       
   306 		return KErrArgument;
       
   307 		}
       
   308 	TReal* temp = new TReal(aVal);
       
   309 	if (!temp)
       
   310 		return KErrNoMemory;
       
   311 	delete iValue.r;
       
   312 	iValue.r = temp;
       
   313 	temp = NULL;
       
   314 	return KErrNone;
       
   315 	}
       
   316 
       
   317 inline TInt TServerSetting::AssignValueFrom(const TDesC8& aVal)
       
   318 	{
       
   319 	if(!IsStr())
       
   320 		return KErrArgument;
       
   321 	
       
   322 	if(aVal.Length())
       
   323 		{
       
   324 		HBufC8* buf = aVal.Alloc();
       
   325 		if (!buf)
       
   326 			return KErrNoMemory;
       
   327 		delete iValue.s;
       
   328 		iValue.s = buf;
       
   329 		}
       
   330 	else
       
   331 		{
       
   332 		delete iValue.s;
       
   333 		iValue.s = NULL;
       
   334 		}
       
   335 	return KErrNone;
       
   336 	}
       
   337 	
       
   338 inline void TServerSetting::Reset()
       
   339 	{
       
   340 	ResetValue();
       
   341 	iAccessPolicy = NULL;
       
   342 	}
       
   343 
       
   344 inline void TServerSetting::ResetValue()
       
   345 	{
       
   346 	if(IsStr())
       
   347 		{
       
   348 		if(iValue.s)
       
   349 			{
       
   350 			delete iValue.s;
       
   351 			}
       
   352 		}
       
   353 	if(IsReal())
       
   354 		{
       
   355 		ASSERT(iValue.r);
       
   356 		delete iValue.r;
       
   357 		}
       
   358 	iValue.i = 0;
       
   359 	}
       
   360 
       
   361 inline void TServerSetting::PushL() const
       
   362 	{
       
   363 	if(IsStr() && iValue.s)
       
   364 		{
       
   365 		CleanupStack::PushL(iValue.s);
       
   366 		}
       
   367 	else if(IsReal())
       
   368 		{
       
   369 		CleanupStack::PushL(iValue.r);
       
   370 		}
       
   371 	}
       
   372 
       
   373 inline void TServerSetting::Pop() const
       
   374 	{
       
   375 	if(IsStr() && iValue.s)
       
   376 		{
       
   377 		CleanupStack::Pop(iValue.s);
       
   378 		}
       
   379 	else if(IsReal())
       
   380 		{
       
   381 		CleanupStack::Pop(iValue.r);
       
   382 		}
       
   383 	}
       
   384 
       
   385 inline void TServerSetting::PopAndDestroy() const
       
   386 	{
       
   387 	if(IsStr() && iValue.s)
       
   388 		{
       
   389 		CleanupStack::PopAndDestroy(iValue.s);
       
   390 		}
       
   391 	else if(IsReal())
       
   392 		{
       
   393 		CleanupStack::PopAndDestroy(iValue.r);
       
   394 		}
       
   395 	}
       
   396 
       
   397 inline TInt TServerSetting::operator==(const TServerSetting& aSetting) const
       
   398 	{
       
   399 	return	aSetting.IsInt() && *this==aSetting.iValue.i ||
       
   400 		aSetting.IsReal() && aSetting.iValue.r && *this==*(aSetting.iValue.r) ||
       
   401 		aSetting.IsStr() && !aSetting.iValue.s && !iValue.s ||
       
   402 		aSetting.IsStr() && aSetting.iValue.s && *this==aSetting.iValue.s->Des();
       
   403 	}
       
   404 
       
   405 inline TInt TServerSetting::operator==(TInt aVal) const
       
   406 	{
       
   407 	return IsInt() && iValue.i==aVal;
       
   408 	}
       
   409 
       
   410 inline TInt TServerSetting::operator==(const TReal& aVal) const
       
   411 	{
       
   412 	return IsReal() && iValue.r && *(iValue.r)==aVal;
       
   413 	}
       
   414 
       
   415 inline TInt TServerSetting::operator==(const TDesC8& aVal) const
       
   416 	{
       
   417 	return IsStr() && iValue.s && iValue.s->Des()==aVal;
       
   418 	}
       
   419 
       
   420 inline TSettingsAccessPolicy* TServerSetting::AccessPolicy() const
       
   421 	{
       
   422 	return iAccessPolicy;
       
   423 	}
       
   424 
       
   425 inline void TServerSetting::SetAccessPolicy(TSettingsAccessPolicy* aPolicy)
       
   426 	{
       
   427 	iAccessPolicy = aPolicy;
       
   428 	}
       
   429 
       
   430 //inline const RArray<TSecurityPolicy>& TServerSetting::GetReadAccessPolicy()
       
   431 inline const TSecurityPolicy* TServerSetting::GetReadAccessPolicy() const
       
   432 	{
       
   433 	return iAccessPolicy ? iAccessPolicy->GetReadAccessPolicy() : NULL;
       
   434 	}
       
   435 
       
   436 //inline const RArray<TSecurityPolicy>& TServerSetting::GetWriteAccessPolicy()
       
   437 inline const TSecurityPolicy* TServerSetting::GetWriteAccessPolicy() const 
       
   438 	{
       
   439 	return iAccessPolicy ? iAccessPolicy->GetWriteAccessPolicy() : NULL;
       
   440 	}
       
   441 
       
   442 inline TBool TServerSetting::HasAccessPolicy() const
       
   443 	{
       
   444 	return NULL != iAccessPolicy;
       
   445 	}
       
   446 
       
   447 inline void TServerSetting::ExternalizeMetaL(RWriteStream& aStream) const
       
   448 	{
       
   449 	//Historically, CRE file stores type and meta information seperately for 
       
   450 	//TServerSetting. To save memory, this has been changed for the 
       
   451 	//in-memory representation but we must store and retrieve the meta in the
       
   452 	//same way for compatibility with existing backup and cre files.
       
   453 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
       
   454 	aStream << (Meta() | (iMeta & KMetaIndividual)) ;
       
   455 #else	
       
   456 	aStream << Meta(); 	
       
   457 #endif	
       
   458 	TUint32 type = Type();
       
   459 	TUint8 temp = static_cast<TUint8>(type >> 28) ;
       
   460 	aStream << temp ;
       
   461 	}
       
   462 
       
   463 inline void TServerSetting::ExternalizeL(RWriteStream& aStream) const
       
   464 	{
       
   465 	aStream << iKey ;
       
   466 	ExternalizeMetaL(aStream);
       
   467 	switch (Type())
       
   468 		{
       
   469 		case EInt:
       
   470 			{
       
   471 			TInt32 integerValue = iValue.i ;
       
   472 			aStream << integerValue ;
       
   473 			break ;
       
   474 			}		
       
   475 		case EReal :
       
   476 			ASSERT(iValue.r);
       
   477 			aStream << *(iValue.r) ;
       
   478 			break ;
       
   479 			
       
   480 		case EString :
       
   481 			if(iValue.s)
       
   482 				{
       
   483 				aStream << *(iValue.s) ;
       
   484 				}
       
   485 			else
       
   486 				{
       
   487 				aStream << KNullDesC8 ;
       
   488 				}
       
   489 			break ;
       
   490 			
       
   491 		case EDeleted :
       
   492 			// Deleted settings should never be in a settings list being made
       
   493 			// persistent. Hence, fail assert if attempting to externalize them:
       
   494 			ASSERT(EFalse);
       
   495 			break ;
       
   496 		}	
       
   497 	}
       
   498 
       
   499 
       
   500 inline void TServerSetting::InternalizeMetaL(RReadStream& aStream)
       
   501 	{
       
   502 	//Historically, CRE file stores type and meta information seperately for 
       
   503 	//TServerSetting. To save memory, this has been changed for the 
       
   504 	//in-memory representation but we must store and retrieve the meta in the
       
   505 	//same way for compatibility with existing backup and cre files.
       
   506 	TUint32 meta;
       
   507 	aStream >> meta;
       
   508 	SetMeta(meta) ;
       
   509 	
       
   510 	TUint8 temp ;
       
   511 	aStream >> temp ;
       
   512 	TUint32 type = (static_cast<TUint32>(temp)) << 28;
       
   513 	SetType(type);
       
   514 	}
       
   515 
       
   516 inline void TServerSetting::InternalizeL(RReadStream& aStream) 
       
   517 {
       
   518 	aStream >> iKey ;
       
   519 	InternalizeMetaL(aStream);
       
   520 	switch (Type())
       
   521 		{
       
   522 		case EInt:
       
   523 			{
       
   524 			TInt32 integerValue;
       
   525 			aStream >> integerValue ;
       
   526 			iValue.i = integerValue ;
       
   527 			break ;
       
   528 			}			
       
   529 		case EReal:
       
   530 			iValue.r = new(ELeave)TReal;
       
   531 			aStream >> *(iValue.r);
       
   532 			break ;
       
   533 			
       
   534 		case EString :
       
   535 			{
       
   536 			HBufC8* string = HBufC8::NewL (aStream, KMaxBinaryLength) ;
       
   537 			if(string->Length())
       
   538 				{
       
   539 				iValue.s =	string;	
       
   540 				}
       
   541 			else
       
   542 				{
       
   543 				delete string;
       
   544 				iValue.s = NULL;
       
   545 				}
       
   546 			break ;
       
   547 			}
       
   548 
       
   549 		case EDeleted :
       
   550 			// Deleted settings should never be in a persistent settings list.
       
   551 			// Hence, fail assert if attempting to internalize them:
       
   552 			ASSERT(EFalse);
       
   553 			break ;
       
   554 		}	
       
   555 	}
       
   556 
       
   557 inline TBool TServerSetting::IsType(const TInt&) const
       
   558 	{ 
       
   559 	return Type() == EInt; 
       
   560 	}
       
   561 	
       
   562 inline TBool TServerSetting::IsType(const TReal&) const
       
   563 	{ 
       
   564 	return Type() == EReal; 
       
   565 	}
       
   566 	
       
   567 inline TBool TServerSetting::IsType(const TDesC8&) const
       
   568 	{ 
       
   569 	return Type() == EString; 
       
   570 	}
       
   571 
       
   572 inline TBool TServerSetting::IsType(const TDesC16&) const
       
   573 	{ 
       
   574 	return Type() == EString; 
       
   575 	}
       
   576 
       
   577 inline TBool TServerSetting::IsInt() const
       
   578 	{
       
   579 	return (iMeta & KMetaType) == EInt;
       
   580 	}
       
   581 	
       
   582 inline TBool TServerSetting::IsReal() const
       
   583 	{
       
   584 	return (iMeta & KMetaType) == EReal;
       
   585 	}
       
   586 	
       
   587 inline TBool TServerSetting::IsStr() const
       
   588 	{
       
   589 	return (iMeta & KMetaType) == EString;
       
   590 	}
       
   591 	
       
   592 inline TBool TServerSetting::IsDeleted() const
       
   593 	{
       
   594 	return (iMeta & KMetaType) == EDeleted;
       
   595 	}
       
   596 
       
   597 inline TSettingsAccessPolicy::TSettingsAccessPolicy(TSecurityPolicy& aReadPolicy,
       
   598 													TSecurityPolicy& aWritePolicy,
       
   599 													TUint32 aLowKey, TUint32 aHighKey,
       
   600 													TUint32 aKeyMask)
       
   601 	{
       
   602 	iLowKey = aLowKey; 
       
   603 	iHighKey = aHighKey;
       
   604 	iKeyMask = aKeyMask;
       
   605 	iReadAccessPolicy.Set(aReadPolicy.Package());
       
   606 	iWriteAccessPolicy.Set(aWritePolicy.Package());
       
   607 	}
       
   608 
       
   609 inline TSettingsAccessPolicy::TSettingsAccessPolicy(TSecurityPolicy& aReadPolicy,
       
   610 													TSecurityPolicy& aWritePolicy,
       
   611 													TUint32 aKey)
       
   612 	{
       
   613 	iLowKey = aKey; 
       
   614 	iHighKey = 0;
       
   615 	iKeyMask = 0;
       
   616 	iReadAccessPolicy.Set(aReadPolicy.Package());
       
   617 	iWriteAccessPolicy.Set(aWritePolicy.Package());
       
   618 	}
       
   619 
       
   620 inline TSettingsAccessPolicy::TSettingsAccessPolicy(TUint32 key)
       
   621 	{
       
   622 	iLowKey = key; 
       
   623 	iHighKey = 0;
       
   624 	iKeyMask = 0;
       
   625 	}
       
   626 		
       
   627 inline TSettingsAccessPolicy::TSettingsAccessPolicy()
       
   628 	{
       
   629 	iLowKey = 0; 
       
   630 	iHighKey = 0;
       
   631 	iKeyMask = 0;
       
   632 	}
       
   633 	
       
   634 inline TBool TSettingsAccessPolicy::IsInRange(TUint32 aKey) const
       
   635 	{
       
   636 	if((iLowKey<=aKey)&&(aKey<=iHighKey))
       
   637 		return ETrue;
       
   638 	else if((0 != iKeyMask)&&((iKeyMask&aKey)==iLowKey))
       
   639 		return ETrue;
       
   640 		
       
   641 	return EFalse;
       
   642 	}
       
   643 
       
   644 inline void TSettingsAccessPolicy::ExternalizeL(RWriteStream& aStream) const
       
   645 {
       
   646 	aStream << iLowKey ;
       
   647 	aStream << iHighKey ;
       
   648 	aStream << iKeyMask ;
       
   649 	
       
   650 	// Externalize TSecurityPolicy objects as descriptors
       
   651 	aStream << (iReadAccessPolicy.Package()) ;
       
   652 	aStream << (iWriteAccessPolicy.Package()) ;
       
   653 }
       
   654 
       
   655 inline void TSettingsAccessPolicy::InternalizeL(RReadStream& aStream) 
       
   656 {
       
   657 	aStream >> iLowKey ;
       
   658 	aStream >> iHighKey ;
       
   659 	aStream >> iKeyMask ;
       
   660 	
       
   661 	// Internalize TSecurityPolicy objects as descriptors and then use them
       
   662 	// to set the actual TSecurityPolicy member data.
       
   663 	HBufC8* securityPolicyPackage ;
       
   664 	securityPolicyPackage = HBufC8::NewLC(aStream, 10000);
       
   665 	iReadAccessPolicy.Set(securityPolicyPackage->Des()) ;
       
   666 	CleanupStack::PopAndDestroy(securityPolicyPackage) ;
       
   667 	
       
   668 	securityPolicyPackage = HBufC8::NewLC(aStream, 10000);
       
   669 	iWriteAccessPolicy.Set(securityPolicyPackage->Des()) ;
       
   670 	CleanupStack::PopAndDestroy(securityPolicyPackage) ;
       
   671 
       
   672 	}
       
   673 
       
   674 inline TUint32 TSettingsAccessPolicy::LowKey() const
       
   675 	{
       
   676 	return iLowKey;
       
   677 	}
       
   678 inline TUint32 TSettingsAccessPolicy::HighKey() const
       
   679 	{
       
   680 	return iHighKey;
       
   681 	}
       
   682 inline TUint32 TSettingsAccessPolicy::KeyMask() const
       
   683 	{
       
   684 	return iKeyMask;
       
   685 	}
       
   686 
       
   687 /**
       
   688 @internalTechnology
       
   689 It is responsility of client to check the key,
       
   690 this simply returns the TSecurityPolicy - it is set to EAlwaysFail if uninitialised
       
   691 */
       
   692 inline const TSecurityPolicy* TSettingsAccessPolicy::GetReadAccessPolicy() const
       
   693 	{
       
   694 	return &iReadAccessPolicy;
       
   695 	}
       
   696 	
       
   697 
       
   698 /**
       
   699 @internalTechnology
       
   700 It is responsility of client to check the key,
       
   701 this simply returns the TSecurityPolicy - it is set to EAlwaysFail if uninitialised
       
   702 */	
       
   703 inline const TSecurityPolicy* TSettingsAccessPolicy::GetWriteAccessPolicy() const
       
   704 	{
       
   705 	return &iWriteAccessPolicy;
       
   706 	}
       
   707 	
       
   708 inline TSettingsDefaultMeta::TSettingsDefaultMeta(TUint32 aValue, TUint32 aLowKey,
       
   709 												  TUint32 aHighKey, TUint32 aKeyMask)
       
   710 	{
       
   711 	iLowKey = aLowKey; 
       
   712 	iHighKey = aHighKey;
       
   713 	iKeyMask = aKeyMask;
       
   714 	iDefaultMetaData = aValue;
       
   715 	}
       
   716 
       
   717 inline TSettingsDefaultMeta::TSettingsDefaultMeta()
       
   718 	{
       
   719 	iLowKey = 0; 
       
   720 	iHighKey = 0;
       
   721 	iKeyMask = 0;
       
   722 	iDefaultMetaData = 0;
       
   723 	}
       
   724 
       
   725 inline TUint32 TSettingsDefaultMeta::LowKey() const
       
   726 	{
       
   727 	return iLowKey;
       
   728 	}
       
   729 	
       
   730 inline TUint32 TSettingsDefaultMeta::HighKey() const
       
   731 	{
       
   732 	return iHighKey;
       
   733 	}
       
   734 	
       
   735 inline TUint32 TSettingsDefaultMeta::KeyMask() const
       
   736 	{
       
   737 	return iKeyMask;
       
   738 	}
       
   739 	
       
   740 inline TBool TSettingsDefaultMeta::IsInRange(TUint32 aKey) const
       
   741 	{
       
   742 	if((iLowKey<=aKey)&&(aKey<=iHighKey))
       
   743 		return ETrue;
       
   744 	else if((0 != iKeyMask)&&((iKeyMask&aKey)==iLowKey))
       
   745 		return ETrue;
       
   746 		
       
   747 	return EFalse;
       
   748 	}
       
   749 
       
   750 inline void TSettingsDefaultMeta::ExternalizeL(RWriteStream& aStream) const
       
   751 	{
       
   752 	aStream << iLowKey ;
       
   753 	aStream << iHighKey ;
       
   754 	aStream << iKeyMask ;
       
   755 	aStream << iDefaultMetaData ;
       
   756 	}
       
   757 
       
   758 inline void TSettingsDefaultMeta::InternalizeL(RReadStream& aStream)
       
   759 	{
       
   760 	aStream >> iLowKey ;
       
   761 	aStream >> iHighKey ;
       
   762 	aStream >> iKeyMask ;
       
   763 	aStream >> iDefaultMetaData;
       
   764 	}
       
   765 
       
   766 inline TSettingSingleMeta::TSettingSingleMeta(TUint32 aKey, TUint32 aMeta) : iKey(aKey), iMeta(aMeta)
       
   767 	{
       
   768 	}
       
   769 
       
   770 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
       
   771 inline void TServerSetting::SetIndividualMeta(TBool aIndividualSettingMeta)
       
   772 	{
       
   773 	if (aIndividualSettingMeta)
       
   774 		iMeta|= KMetaIndividual;
       
   775 	else
       
   776 		iMeta&=~KMetaIndividual;
       
   777 	}
       
   778 	
       
   779 //NEW: Copy the value only from a source, already validate the type
       
   780 inline TInt TServerSetting::CopyTypeValue(const TServerSetting& source)
       
   781 	{
       
   782 
       
   783 	if (source.IsStr())
       
   784 		{
       
   785 		const HBufC8* sourceBuf = source.GetStrValue();
       
   786 		HBufC8* buf = sourceBuf ? sourceBuf->Alloc() : NULL;
       
   787 		if (sourceBuf && !buf)
       
   788 			{
       
   789 			return KErrNoMemory;
       
   790 			}
       
   791 		ResetValue();			
       
   792 		SetType(EString);		
       
   793 		iValue.s = buf;
       
   794 		}
       
   795 	else if (source.IsReal())
       
   796 		{
       
   797 		if(!source.iValue.r)
       
   798 			{
       
   799 			return KErrCorrupt;
       
   800 			}
       
   801 		
       
   802 		TReal* temp = new TReal(source.GetRealValue());
       
   803 		if (temp == NULL)
       
   804 			{
       
   805 			return KErrNoMemory;
       
   806 			}
       
   807 		ResetValue();	
       
   808 		SetType(EReal);		
       
   809 		iValue.r = temp;
       
   810 		}
       
   811 	else
       
   812 		{
       
   813 		SetType(source.Type());		
       
   814 		if (source.IsInt())
       
   815 			{
       
   816 			iValue.i = source.GetIntValue();
       
   817 			}
       
   818 		}
       
   819 	
       
   820 	return KErrNone;
       
   821 	}
       
   822 #endif