datacommsserver/esockserver/csock/cs_parameterfamily.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2007-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 // Implementation for RParameterFamily and RParameterFamilyBundle classes
       
    15 // 
       
    16 //
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21  @internalTechnology
       
    22 */
       
    23 
       
    24 #include <comms-infras/es_parameterfamily.h>
       
    25 #include <comms-infras/es_parameterbundle.h>
       
    26 #include <es_sock.h>
       
    27 
       
    28 
       
    29 #ifdef _DEBUG
       
    30 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module
       
    31 // (if it could happen through user error then you should give it an explicit, documented, category + code)
       
    32 _LIT(KSpecAssert_ESockCSckCSPrmtF, "ESockCSckCSPrmtF");
       
    33 #endif
       
    34 
       
    35 
       
    36 
       
    37 using namespace Meta;
       
    38 
       
    39 EXPORT_C void RParameterFamily::CreateL(RParameterFamilyBundle& aBundle, TUint32 aFamilyId)
       
    40 /** Creates a new parameter set family. This class is used as a container for a number of parameter
       
    41     sets that make up a family. It is a specific instantiatable class and therefore creates
       
    42 	an instance of CParameterFamily without using ECOM.
       
    43 
       
    44 @param aBundle Family container (bundle) that this family is to be added to
       
    45 @exception KErrInUse if the container has already been prepared for use, KErrArgument if
       
    46 aBundle is invalid, or another system-wide error code
       
    47 */
       
    48 	{
       
    49 	if(iContainer)
       
    50 		{
       
    51 		User::Leave(KErrInUse);
       
    52 		}
       
    53 	CParameterBundleBase* bundle = aBundle.iBundle;
       
    54 	if(!bundle)
       
    55 		{
       
    56 		User::Leave(KErrArgument);
       
    57 		}
       
    58 	iContainer = CParameterSetContainer::NewL(*bundle,aFamilyId);
       
    59 	}
       
    60 
       
    61 EXPORT_C void RParameterFamily::LoadL(RParameterFamilyBundle& aBundle, TPtrC8& aBuffer)
       
    62 	{
       
    63 	if(iContainer)
       
    64 		{
       
    65 		User::Leave(KErrInUse);
       
    66 		}
       
    67 	CParameterBundleBase* bundle = aBundle.iBundle;
       
    68 	if(!bundle)
       
    69 		{
       
    70 		User::Leave(KErrArgument);
       
    71 		}
       
    72 	iContainer = CParameterSetContainer::LoadL(*bundle,aBuffer);
       
    73 	}
       
    74 
       
    75 
       
    76 
       
    77 
       
    78 
       
    79 EXPORT_C void RParameterFamily::Destroy()
       
    80 /** Sub-connection parameter family destructor. It cleans up the arrays deleting all
       
    81     the parameter sets it owns
       
    82 */
       
    83 	{
       
    84 	delete iContainer;
       
    85 	iContainer = NULL;
       
    86 	}
       
    87 
       
    88 
       
    89 /**
       
    90 Adds a parameter set to a sub-connection parameter set family.
       
    91 
       
    92 @param aExtensionSet Parameter Set to be added to the family (family takes ownership)
       
    93 @param aType The type of the set (requested, acceptable or granted)
       
    94 @exception leaves with KErrNoMemory in out of memory conditions, or KErrNotReady if the parameter
       
    95 family hasn't been prepared with LoadL or CreateL, or KErrArgument if aSet is invalid
       
    96 */
       
    97 EXPORT_C void RParameterFamily::AddParameterSetL(XParameterSetBase* aSet, TParameterSetType aType)
       
    98 	{
       
    99 	User::LeaveIfError(AddParameterSet(aSet, aType));
       
   100 	}
       
   101 
       
   102 /**
       
   103 Adds a parameter set to a sub-connection parameter set family.
       
   104 
       
   105 @param aExtensionSet Parameter Set to be added to the family (family takes ownership)
       
   106 @param aType The type of the set (requested, acceptable or granted)
       
   107 @returns Returns KErrNoMemory in out of memory conditions, or KErrNotReady if the parameter
       
   108 family hasn't been prepared with LoadL or CreateL, or KErrArgument if aSet is invalid
       
   109 */
       
   110 EXPORT_C TInt RParameterFamily::AddParameterSet(XParameterSetBase* aSet, TParameterSetType aType)
       
   111 	{
       
   112 	if (!aSet)
       
   113 		{
       
   114 		return KErrArgument;
       
   115 		}
       
   116 
       
   117 	if (IsNull())
       
   118 		{
       
   119 		return KErrNotReady;
       
   120 		}
       
   121 	
       
   122 	TInt index = aType;
       
   123 	for( ; index < iContainer->CountParameterSets() ; index += ENumValues)
       
   124 		{
       
   125 		if (iContainer->GetParameterSet(index) == NULL)
       
   126 			{
       
   127 			return iContainer->ReplaceParameterSet(index, aSet);
       
   128 			}
       
   129 		}
       
   130 
       
   131 	// if we've got here we have to expand the array as there's no null slots to use
       
   132 	TInt err;
       
   133 	err = iContainer->GrowToFit(index + 1);
       
   134 	if (err == KErrNone)
       
   135 		{
       
   136 		err = iContainer->ReplaceParameterSet(index, aSet);
       
   137 		}
       
   138 	return err;
       
   139 	}
       
   140 
       
   141 
       
   142 EXPORT_C XParameterSetBase* RParameterFamily::GetParameterSetAtIndex(TUint aIndex, TParameterSetType aType)
       
   143 	{
       
   144 	XParameterSetBase* result = NULL;
       
   145 	if(iContainer)
       
   146 		{
       
   147 		TInt index = (aIndex * ENumValues) + aType;
       
   148 		if(index < iContainer->CountParameterSets())
       
   149 			{
       
   150 			result = iContainer->GetParameterSet(index);
       
   151 			}
       
   152 		}
       
   153 	return result;
       
   154 	}
       
   155 
       
   156 
       
   157 EXPORT_C TInt RParameterFamily::CountParameterSets()
       
   158 	{
       
   159 	return (iContainer?iContainer->CountParameterSets():0);
       
   160 	}
       
   161 
       
   162 // returns the size (number of elements needed to span from the first element of type aType to
       
   163 //  the last such element with a value)
       
   164 EXPORT_C TInt RParameterFamily::CountParameterSets(TParameterSetType aType)
       
   165 	{
       
   166 	// work out the allocated size of the array for this type
       
   167 	TInt size = ((iContainer?iContainer->CountParameterSets():0) + (ENumValues-aType-1)) / 3;
       
   168 
       
   169 	for(TInt i=size-1; i>=0; --i)
       
   170 		{
       
   171 		TInt index = (i * ENumValues) + aType;
       
   172 		XParameterSetBase* ps = iContainer->GetParameterSet(index);
       
   173 		if(ps)
       
   174 			{
       
   175 			return size;
       
   176 			}
       
   177 		}
       
   178 	return 0;
       
   179 	}
       
   180 
       
   181 
       
   182 EXPORT_C XParameterSetBase* RParameterFamily::FindParameterSet(STypeId aSetId, TParameterSetType aType)
       
   183 	{
       
   184 	TInt index = aType;
       
   185 	for( ; index < (iContainer?iContainer->CountParameterSets():0) ; index += ENumValues)
       
   186 		{
       
   187 		XParameterSetBase* thisSet = iContainer->GetParameterSet(index);
       
   188 		if(thisSet && thisSet->IsTypeOf(aSetId))
       
   189 			{
       
   190 			return thisSet;
       
   191 			}
       
   192 		}
       
   193 	return NULL; // not found
       
   194 	}
       
   195 
       
   196 
       
   197 
       
   198 /**
       
   199 Removes a parameter set from a parameter set family.
       
   200 
       
   201 @param aSetToRemove Parameter Set to be removed from the family returning ownership to the calling method
       
   202 @param aType The type of the set (requested, acceptable or granted)
       
   203 @return Returns with KErrNotFound if set is not found, or KErrNotReady if the parameter
       
   204 family hasn't been prepared with LoadL or CreateL
       
   205 */
       
   206 EXPORT_C TInt RParameterFamily::RemoveParameterSet(XParameterSetBase* aSetToRemove, TParameterSetType aType)
       
   207 	{
       
   208 	if (IsNull())
       
   209 		{
       
   210 		return KErrNotReady;
       
   211 		}
       
   212 
       
   213 	TInt index = aType;
       
   214 	for( ; index < iContainer->CountParameterSets() ; index += ENumValues)
       
   215 		{
       
   216 		if(iContainer->GetParameterSet(index) == aSetToRemove)
       
   217 			{
       
   218 			XParameterSetBase* ps = iContainer->RemoveParameterSet(index);
       
   219 			ASSERT(ps && ps == aSetToRemove);
       
   220 			(void)ps; // avoid unused variable warning in urel
       
   221 			return KErrNone;
       
   222 			}
       
   223 		}
       
   224 
       
   225 	return KErrNotFound;
       
   226 	}
       
   227 
       
   228 
       
   229 /**
       
   230 Removes a parameter set from a parameter set family and deletes it
       
   231 
       
   232 @param aSetToRemove Parameter Set to be removed from the family 
       
   233 @param aType The type of the set (requested, acceptable or granted)
       
   234 @return Returns with KErrNotFound if set is not found, or KErrNotReady if the parameter
       
   235 family hasn't been prepared with LoadL or CreateL
       
   236 */
       
   237 EXPORT_C TInt RParameterFamily::RemoveAndDestroyParameterSet(XParameterSetBase* aSetToRemove, TParameterSetType aType)
       
   238 	{
       
   239 	TInt err = RemoveParameterSet(aSetToRemove, aType);
       
   240 	if (err == KErrNone)
       
   241 		{
       
   242 		delete aSetToRemove;
       
   243 		}
       
   244 	return err;
       
   245 	}
       
   246 
       
   247 
       
   248 
       
   249 EXPORT_C TUint RParameterFamily::Length() const
       
   250 /** Calculates the length of buffer required to serialise this parameter family.
       
   251 
       
   252 @return Length of buffer required.
       
   253 */
       
   254 	{
       
   255 	return iContainer ? iContainer->Length() : 0;
       
   256 	}
       
   257 
       
   258 
       
   259 EXPORT_C TInt RParameterFamily::Store(TDes8& aDes) const
       
   260 /** Instructs this sub-connection family to create a serialised version of itself
       
   261     and append it to the buffer that has been passed.
       
   262 
       
   263 @param aDes Buffer to append the serialised object to
       
   264 @return KErrNone if successful, otherwise system wide error (e.g. KErrOverflow if the descriptor is too small)
       
   265 If unsuccessful, there is no guarantee as to the buffer or data stored in it.
       
   266 */
       
   267 	{
       
   268 	return iContainer ? iContainer->Store(aDes) : KErrNotReady;
       
   269 	}
       
   270 
       
   271 
       
   272 EXPORT_C void RParameterFamily::ClearAllParameters(TParameterSetType aType)
       
   273 /** Clears (removes and deletes) all parameter sets with the type specified
       
   274 
       
   275 @param aType The type of the set to be deleted(requested, acceptable or granted)
       
   276 */
       
   277 	{
       
   278 	TInt index = aType;
       
   279 	for( ; index < iContainer->CountParameterSets() ; index += ENumValues)
       
   280 		{
       
   281 		TRAP_IGNORE(iContainer->ReplaceParameterSetL(index,NULL));
       
   282 		}
       
   283 	}
       
   284 
       
   285 
       
   286 EXPORT_C void RParameterFamily::DeleteParameterSetL(TInt aIndex)
       
   287 	{
       
   288     User::LeaveIfError(DeleteParameterSet(aIndex));
       
   289 	}
       
   290 
       
   291 EXPORT_C TInt RParameterFamily::DeleteParameterSet(TInt aIndex)
       
   292 	{
       
   293 	if(iContainer)
       
   294 		{
       
   295 		return iContainer->DeleteParameterSet(aIndex);
       
   296 		}
       
   297 	else
       
   298 		{
       
   299 		return KErrNotReady;
       
   300 		}
       
   301 	}
       
   302 
       
   303 EXPORT_C TInt RParameterFamily::ClearParameterSetPointer(TInt aIndex, TParameterSetType aType)
       
   304 	{
       
   305 	if(iContainer)
       
   306 		{
       
   307 		iContainer->ClearParameterSetPointer(aIndex * ENumValues + aType);
       
   308 		return KErrNone;
       
   309 		}
       
   310 	else
       
   311 		return KErrNotReady;
       
   312 	}
       
   313 
       
   314 EXPORT_C TUint32 RParameterFamily::Id() const
       
   315 /**
       
   316 Fetch the identity of the sub-connection parameter family
       
   317 */
       
   318 	{
       
   319 	return (iContainer == NULL) ? 0 : iContainer->Id();
       
   320 	}
       
   321 
       
   322 EXPORT_C RParameterFamily RParameterFamilyBundle::CreateFamilyL(TUint32 aFamilyId)
       
   323 	{
       
   324 	if(iBundle == NULL)
       
   325 		{
       
   326 		User::Leave(KErrNotReady);
       
   327 		}
       
   328 	RParameterFamily newFamily;
       
   329 	newFamily.CreateL(*this,aFamilyId);
       
   330 	return newFamily;
       
   331 	}
       
   332 
       
   333 
       
   334 EXPORT_C RParameterFamily RParameterFamilyBundle::GetFamilyAtIndex(TUint aIndex)
       
   335 	{
       
   336 	RParameterFamily result;
       
   337 	if(iBundle != NULL)
       
   338 		{
       
   339 		CParameterSetContainer* psc = iBundle->GetParamSetContainer(aIndex);
       
   340 		if(psc != NULL)
       
   341 			{
       
   342 			result.iContainer = psc;
       
   343 			}
       
   344 		}
       
   345 	return result;
       
   346 	}
       
   347 
       
   348 EXPORT_C RParameterFamily RParameterFamilyBundle::FindFamily(TUint32 aFamilyId)
       
   349 /** Search the sub-connection parameter bundle for a parameter family
       
   350 
       
   351 @param aFamilyId Id of the family to match against
       
   352 @return Matching family or NULL pointer if not found
       
   353 */
       
   354 	{
       
   355 	RParameterFamily result;
       
   356 	if(iBundle != NULL)
       
   357 		{
       
   358 		CParameterSetContainer* psc = iBundle->FindParamSetContainer(aFamilyId);
       
   359 		if(psc != NULL)
       
   360 			{
       
   361 			result.iContainer = psc;
       
   362 			}
       
   363 		}
       
   364 	return result;
       
   365 	}
       
   366 
       
   367 
       
   368 EXPORT_C void RParameterFamilyBundle::ClearAllParameters(RParameterFamily::TParameterSetType aType)
       
   369 /** Clears (removes and deletes) all parameter sets with the type specified (delegated to the families)
       
   370 
       
   371 @param aType The type of the set to be deleted(requested, acceptable or granted)
       
   372 */
       
   373 	{
       
   374 	if(iBundle == NULL)
       
   375 		{
       
   376 		return;
       
   377 		}
       
   378 
       
   379 	TUint length = iBundle->CountParamSetContainers();
       
   380 	RParameterFamily pf;
       
   381 	for (TUint i = 0; i < length; ++i)
       
   382 		{
       
   383 		pf.iContainer = iBundle->GetParamSetContainer(i);
       
   384 		pf.ClearAllParameters(aType);
       
   385 		}
       
   386 	}
       
   387 
       
   388 EXPORT_C TInt RParameterFamilyBundle::CountParameterFamilies() const
       
   389 	{
       
   390 	return iBundle->CountParamSetContainers();
       
   391 	}
       
   392 
       
   393 EXPORT_C TInt RParameterFamilyBundle::DeleteFamilyAtIndex(TInt aIndex)
       
   394 	{
       
   395 	if (aIndex < iBundle->CountParamSetContainers())
       
   396 		{
       
   397 		CParameterSetContainer* aFamily = iBundle->GetParamSetContainer (aIndex);
       
   398 		delete aFamily;
       
   399 		RemoveFamilyAtIndex (aIndex);
       
   400 		return KErrNone;
       
   401 		}
       
   402 
       
   403 	return KErrNotFound;
       
   404 	}
       
   405 
       
   406 EXPORT_C void RParameterFamilyBundle::RemoveFamilyAtIndex(TInt aIndex)
       
   407 	{
       
   408 	__ASSERT_DEBUG (aIndex < iBundle->CountParamSetContainers (), User::Invariant());
       
   409 	iBundle->RemoveParamSetContainer(aIndex);
       
   410 	}
       
   411 
       
   412 RParameterFamilyBundle& RParameterFamilyBundle::operator=(const RParameterFamilyBundle& /*aBundle*/)
       
   413 /** Assignment operator
       
   414 */
       
   415 	{
       
   416 	__ASSERT_DEBUG(EFalse, User::Panic(KSpecAssert_ESockCSckCSPrmtF, 1));//can be Unreachable in future
       
   417 	return *this;
       
   418 	}
       
   419 
       
   420 
       
   421 
       
   422 RParameterFamilyBundle::RParameterFamilyBundle(const RParameterFamilyBundle& /*aBundle*/)
       
   423 /** Copy Constructor
       
   424 */
       
   425 	{
       
   426 	__ASSERT_DEBUG(EFalse, User::Panic(KSpecAssert_ESockCSckCSPrmtF, 2));//can be Unreachable in future
       
   427 	}
       
   428 
       
   429 
       
   430 EXPORT_C /* static */ void RParameterFamilyBundleC::CreateL()
       
   431 	{
       
   432 	iBundle = CGenericParameterBundle::NewL();
       
   433 	}
       
   434 
       
   435 EXPORT_C /* static */ void RParameterFamilyBundleC::LoadL(TDesC8& aDes)
       
   436 /** Creates a new parameter family bundle from a buffer containing the serialised object.
       
   437 
       
   438 @param aDes Buffer containing the serialised object information
       
   439 @return a pointer to a parameter family bundle if successful, otherwise leaves with system error code.
       
   440 */
       
   441 	{
       
   442 	iBundle = CGenericParameterBundle::LoadL(aDes);
       
   443 	}
       
   444 	
       
   445 EXPORT_C TInt RParameterFamilyBundleC::Load(const TDesC8& aDes)
       
   446 	{
       
   447 	return iBundle->Load(aDes);
       
   448 	}
       
   449 
       
   450 EXPORT_C void RParameterFamilyBundleC::Destroy()
       
   451 /** Sub-connection parameter bundle destructor, clear up the families
       
   452 */
       
   453 	{
       
   454 	delete iBundle;
       
   455 	iBundle=NULL;
       
   456 	}
       
   457 
       
   458 
       
   459 EXPORT_C TUint RParameterFamilyBundleC::Length() const
       
   460 /** Calculates the length of buffer required to serialise this parameter set bundle.
       
   461 
       
   462 @return Length of buffer required.
       
   463 */
       
   464 	{
       
   465 	return iBundle ? iBundle->Length() : 0;
       
   466 	}
       
   467 
       
   468 
       
   469 EXPORT_C TInt RParameterFamilyBundleC::Store(TDes8& aDes) const
       
   470 /** Instructs this parameter family bundle to create a serilised version of itself
       
   471     and append it to the buffer that has been passed.
       
   472 
       
   473 @param aDes Buffer to append the serialised object to
       
   474 @return KErrNone if successful, otherwise system wide error (e.g. EKrrOverflow if the descriptor is too small)
       
   475 If unsuccessful, there is no guarantee as to the buffer or data stored in it.
       
   476 */
       
   477 	{
       
   478 	return iBundle ? iBundle->Store(aDes) : KErrNotReady;
       
   479 	}
       
   480 
       
   481 
       
   482 EXPORT_C const RParameterFamily RParameterFamilyBundleC::GetFamilyAtIndex(TUint aIndex) const
       
   483 	{
       
   484 	RParameterFamily result;
       
   485 	if(iBundle != NULL)
       
   486 		{
       
   487 		CParameterSetContainer* psc = iBundle->GetParamSetContainer(aIndex);
       
   488 		if(psc != NULL)
       
   489 			{
       
   490 			result.iContainer = psc;
       
   491 			}
       
   492 		}
       
   493 	return result;
       
   494 	}
       
   495 
       
   496 EXPORT_C const RParameterFamily RParameterFamilyBundleC::FindFamily(TUint32 aFamilyId) const
       
   497 /** Search the sub-connection parameter bundle for a parameter family
       
   498 
       
   499 @param aFamilyId Id of the family to match against
       
   500 @return Matching family or NULL pointer if not found
       
   501 */
       
   502 	{
       
   503 	RParameterFamily result;
       
   504 	if(iBundle != NULL)
       
   505 		{
       
   506 		CParameterSetContainer* psc = iBundle->FindParamSetContainer(aFamilyId);
       
   507 		if(psc != NULL)
       
   508 			{
       
   509 			result.iContainer = psc;
       
   510 			}
       
   511 		}
       
   512 	return result;
       
   513 	}
       
   514 
       
   515 
       
   516 
       
   517 RParameterFamilyBundleC& RParameterFamilyBundleC::operator=(const RParameterFamilyBundleC& /*aBundle*/)
       
   518 /** Assignment operator
       
   519 */
       
   520 	{
       
   521 	__ASSERT_DEBUG(EFalse, User::Panic(KSpecAssert_ESockCSckCSPrmtF, 3));//can be Unreachable in future
       
   522 	return *this;
       
   523 	}
       
   524 
       
   525 
       
   526 
       
   527 RParameterFamilyBundleC::RParameterFamilyBundleC(const RParameterFamilyBundleC& /*aBundle*/)
       
   528 /** Copy Constructor
       
   529 */
       
   530 	{
       
   531 	__ASSERT_DEBUG(EFalse, User::Panic(KSpecAssert_ESockCSckCSPrmtF, 4));//can be Unreachable in future
       
   532 	}
       
   533 
       
   534 
       
   535 
       
   536