bluetoothapitest/bluetoothsvs/T_BTUserAPI/src/T_BTAccessRequirementsData.cpp
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "T_BTAccessRequirementsData.h"
       
    19 
       
    20 /*@{*/
       
    21 //Parameters
       
    22 _LIT(KAuthentication,										"authentication");
       
    23 _LIT(KAuthorisation,										"authorisation");
       
    24 _LIT(KEncryption,											"encryption");
       
    25 _LIT(KDenied,												"denied");
       
    26 _LIT(KPasskeyMinLength,										"passkeyminlength");
       
    27 _LIT(KExpected, 											"expected");
       
    28 
       
    29 //Commands
       
    30 _LIT(KCmdTBTAccessRequirements,								"TBTAccessRequirements");
       
    31 _LIT(KCmdSetAuthentication,									"SetAuthentication");
       
    32 _LIT(KCmdSetAuthorisation,									"SetAuthorisation");
       
    33 _LIT(KCmdSetEncryption,										"SetEncryption");
       
    34 _LIT(KCmdSetDenied,											"SetDenied");
       
    35 _LIT(KCmdSetPasskeyMinLength,								"SetPasskeyMinLength");
       
    36 _LIT(KCmdAuthenticationRequired,							"AuthenticationRequired");
       
    37 _LIT(KCmdAuthorisationRequired,								"AuthorisationRequired");
       
    38 _LIT(KCmdEncryptionRequired,								"EncryptionRequired");
       
    39 _LIT(KCmdDenied,											"Denied");
       
    40 _LIT(KCmdPasskeyMinLength,									"PasskeyMinLength");
       
    41 
       
    42 //	Logging
       
    43 _LIT(KLogMissingParameter,			"Missing parameter '%S'");
       
    44 /*@}*/
       
    45 
       
    46 //////////////////////////////////////////////////////////////////////
       
    47 // Construction/Destruction
       
    48 //////////////////////////////////////////////////////////////////////
       
    49 
       
    50 CT_BTAccessRequirementsData* CT_BTAccessRequirementsData::NewL()
       
    51 	{
       
    52 	CT_BTAccessRequirementsData*	ret=new (ELeave) CT_BTAccessRequirementsData();
       
    53 	CleanupStack::PushL(ret);
       
    54 	ret->ConstructL();
       
    55 	CleanupStack::Pop(ret);
       
    56 	return ret;
       
    57 	}
       
    58 
       
    59 CT_BTAccessRequirementsData::CT_BTAccessRequirementsData()
       
    60 :	iData(NULL)
       
    61 	{
       
    62 	}
       
    63 
       
    64 void CT_BTAccessRequirementsData::ConstructL()
       
    65 	{
       
    66 	}
       
    67 
       
    68 CT_BTAccessRequirementsData::~CT_BTAccessRequirementsData()
       
    69 	{
       
    70 	DestroyData();
       
    71 	}
       
    72 
       
    73 //	Service methods
       
    74 TAny* CT_BTAccessRequirementsData::GetObject()
       
    75 	{
       
    76 	return iData;
       
    77 	}
       
    78 
       
    79 void CT_BTAccessRequirementsData::SetObjectL(TAny* aAny)
       
    80 	{
       
    81 	//called when loading up persistent data
       
    82 	DestroyData();
       
    83 	iData = static_cast<TBTAccessRequirements*> (aAny);
       
    84 	}
       
    85 
       
    86 
       
    87 void CT_BTAccessRequirementsData::DisownObjectL()
       
    88 	{
       
    89 	iData=NULL;
       
    90 	}
       
    91 
       
    92 void CT_BTAccessRequirementsData::DestroyData()
       
    93 	{
       
    94 	delete iData;
       
    95 	iData=NULL;	
       
    96 	}
       
    97 
       
    98 inline TCleanupOperation CT_BTAccessRequirementsData::CleanupOperation()
       
    99 	{
       
   100 	return CleanupOperation;
       
   101 	}
       
   102 
       
   103 void CT_BTAccessRequirementsData::CleanupOperation(TAny* aAny)
       
   104 	{
       
   105 	TBTAccessRequirements* arg=static_cast<TBTAccessRequirements*>(aAny);
       
   106 	delete arg;
       
   107 	}
       
   108 
       
   109 TBool CT_BTAccessRequirementsData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
       
   110 	{
       
   111 	TBool	ret = ETrue;
       
   112 	if ( aCommand==KCmdTBTAccessRequirements )
       
   113 		{
       
   114 		DoCmdTBTAccessRequirements();
       
   115 		}
       
   116 	else if ( aCommand==KCmdSetAuthentication )
       
   117 		{
       
   118 		DoCmdSetAuthentication(aSection);
       
   119 		}
       
   120 	else if ( aCommand==KCmdSetAuthorisation )
       
   121 		{
       
   122 		DoCmdSetAuthorisation(aSection);
       
   123 		}
       
   124 	else if ( aCommand==KCmdSetEncryption )
       
   125 		{
       
   126 		DoCmdSetEncryption(aSection);
       
   127 		}
       
   128 	else if ( aCommand==KCmdSetDenied )
       
   129 		{
       
   130 		DoCmdSetDenied(aSection);
       
   131 		}
       
   132 	else if ( aCommand==KCmdSetPasskeyMinLength )
       
   133 		{
       
   134 		DoCmdSetPasskeyMinLength(aSection);
       
   135 		}
       
   136 	else if ( aCommand==KCmdAuthenticationRequired )
       
   137 		{
       
   138 		DoCmdAuthenticationRequired(aSection);
       
   139 		}
       
   140 	else if ( aCommand==KCmdAuthorisationRequired )
       
   141 		{
       
   142 		DoCmdAuthorisationRequired(aSection);
       
   143 		}
       
   144 	else if ( aCommand==KCmdEncryptionRequired )
       
   145 		{
       
   146 		DoCmdEncryptionRequired(aSection);
       
   147 		}
       
   148 	else if ( aCommand==KCmdDenied )
       
   149 		{
       
   150 		DoCmdDenied(aSection);
       
   151 		}
       
   152 	else if ( aCommand==KCmdPasskeyMinLength )
       
   153 		{
       
   154 		DoCmdPasskeyMinLength(aSection);
       
   155 		}
       
   156 	else
       
   157 		{
       
   158 		ret=EFalse;
       
   159 		}
       
   160 
       
   161 	return ret;
       
   162 	}
       
   163 
       
   164 
       
   165 /**
       
   166 Test TBTAccessRequirements()
       
   167 */
       
   168 void CT_BTAccessRequirementsData::DoCmdTBTAccessRequirements()
       
   169 	{
       
   170 	INFO_PRINTF1(_L("TBTAccessRequirements Constructor Call"));
       
   171 	DestroyData();
       
   172 	iData = new (ELeave) TBTAccessRequirements();
       
   173 	}
       
   174 
       
   175 
       
   176 /**
       
   177 Test SetAuthentication()
       
   178 */
       
   179 void CT_BTAccessRequirementsData::DoCmdSetAuthentication(const TDesC& aSection)
       
   180 	{
       
   181 	INFO_PRINTF1(_L("TBTAccessRequirements SetAuthentication Call"));
       
   182 
       
   183 	TBool	authentication = EFalse;
       
   184 	if(GetBoolFromConfig(aSection, KAuthentication(), authentication) )
       
   185 		{
       
   186 		iData->SetAuthentication(authentication);
       
   187 		}
       
   188 	else
       
   189 		{
       
   190 		ERR_PRINTF2(KLogMissingParameter, &KAuthentication());
       
   191 		SetBlockResult(EFail);
       
   192 		}
       
   193 	}
       
   194 
       
   195 
       
   196 /**
       
   197 Test SetAuthorisation()
       
   198 */
       
   199 void CT_BTAccessRequirementsData::DoCmdSetAuthorisation(const TDesC& aSection)
       
   200 	{
       
   201 	INFO_PRINTF1(_L("TBTAccessRequirements SetAuthorisation Call"));
       
   202 
       
   203 	TBool	authorisation = EFalse;
       
   204 	if(GetBoolFromConfig(aSection, KAuthorisation(), authorisation) )
       
   205 		{
       
   206 		iData->SetAuthorisation(authorisation);
       
   207 		}
       
   208 	else
       
   209 		{
       
   210 		ERR_PRINTF2(KLogMissingParameter, &KAuthorisation());
       
   211 		SetBlockResult(EFail);
       
   212 		}
       
   213 	}
       
   214 
       
   215 
       
   216 /**
       
   217 Test SetEncryption()
       
   218 */
       
   219 void CT_BTAccessRequirementsData::DoCmdSetEncryption(const TDesC& aSection)
       
   220 	{
       
   221 	INFO_PRINTF1(_L("TBTAccessRequirements SetEncryption Call"));
       
   222 
       
   223 	TBool	encryption = EFalse;
       
   224 	if(GetBoolFromConfig(aSection, KEncryption(), encryption) )
       
   225 		{
       
   226 		iData->SetEncryption(encryption);
       
   227 		}
       
   228 	else
       
   229 		{
       
   230 		ERR_PRINTF2(KLogMissingParameter, &KEncryption());
       
   231 		SetBlockResult(EFail);
       
   232 		}
       
   233 	}
       
   234 
       
   235 
       
   236 /**
       
   237 Test SetDenied()
       
   238 */
       
   239 void CT_BTAccessRequirementsData::DoCmdSetDenied(const TDesC& aSection)
       
   240 	{
       
   241 	INFO_PRINTF1(_L("TBTAccessRequirements SetDenied Call"));
       
   242 
       
   243 	TBool	denied = EFalse;
       
   244 	if(GetBoolFromConfig(aSection, KDenied(), denied) )
       
   245 		{
       
   246 		iData->SetDenied(denied);
       
   247 		}
       
   248 	else
       
   249 		{
       
   250 		ERR_PRINTF2(KLogMissingParameter, &KDenied());
       
   251 		SetBlockResult(EFail);
       
   252 		}
       
   253 	}
       
   254 
       
   255 
       
   256 /**
       
   257 Test SetPasskeyMinLength()
       
   258 */
       
   259 void CT_BTAccessRequirementsData::DoCmdSetPasskeyMinLength(const TDesC& aSection)
       
   260 	{
       
   261 	INFO_PRINTF1(_L("TBTAccessRequirements SetPasskeyMinLength Call"));
       
   262 
       
   263 	TInt	passkeyMinLength = EFalse;
       
   264 	if(GetIntFromConfig(aSection, KPasskeyMinLength(), passkeyMinLength) )
       
   265 		{
       
   266 		TInt result = iData->SetPasskeyMinLength(passkeyMinLength);
       
   267 		if(result != KErrNone)
       
   268 			{
       
   269 			ERR_PRINTF2(_L("**** TBTAccessRequirements SetPasskeyMinLength failed with error %d"), result);
       
   270 			SetError(result);
       
   271 			}
       
   272 		}
       
   273 	else
       
   274 		{
       
   275 		ERR_PRINTF2(KLogMissingParameter, &KPasskeyMinLength());
       
   276 		SetBlockResult(EFail);
       
   277 		}
       
   278 	}
       
   279 
       
   280 
       
   281 /**
       
   282 Test AuthenticationRequired()
       
   283 */
       
   284 void CT_BTAccessRequirementsData::DoCmdAuthenticationRequired(const TDesC& aSection)
       
   285 	{
       
   286 	INFO_PRINTF1(_L("TBTAccessRequirements AuthenticationRequired Call"));
       
   287 	
       
   288 	TBool authentification = iData->AuthenticationRequired();
       
   289 	INFO_PRINTF2(_L("TBTAccessRequirements AuthenticationRequired result: actual = %d"), authentification);
       
   290 	
       
   291 	TBool	expected = EFalse;
       
   292 	if(GetBoolFromConfig(aSection, KExpected(), expected) )
       
   293 		{
       
   294 		if( expected != authentification )
       
   295 			{
       
   296 			ERR_PRINTF1(_L("AuthenticationRequired not as expected!"));
       
   297 			SetBlockResult(EFail);
       
   298 			}
       
   299 		}
       
   300 	else
       
   301 		{
       
   302 		ERR_PRINTF2(KLogMissingParameter, &KExpected());
       
   303 		SetBlockResult(EFail);
       
   304 		}
       
   305 	}
       
   306 
       
   307 
       
   308 /**
       
   309 Test AuthorisationRequired()
       
   310 */
       
   311 void CT_BTAccessRequirementsData::DoCmdAuthorisationRequired(const TDesC& aSection)
       
   312 	{
       
   313 	INFO_PRINTF1(_L("TBTAccessRequirements AuthorisationRequired Call"));
       
   314 	
       
   315 	TBool authorisation = iData->AuthorisationRequired();
       
   316 	INFO_PRINTF2(_L("TBTAccessRequirements AuthorisationRequired result: actual = %d"), authorisation);
       
   317 	
       
   318 	TBool	expected = EFalse;
       
   319 	if(GetBoolFromConfig(aSection, KExpected(), expected) )
       
   320 		{
       
   321 		if( expected != authorisation )
       
   322 			{
       
   323 			ERR_PRINTF1(_L("AuthorisationRequired not as expected!"));
       
   324 			SetBlockResult(EFail);
       
   325 			}
       
   326 		}
       
   327 	else
       
   328 		{
       
   329 		ERR_PRINTF2(KLogMissingParameter, &KExpected());
       
   330 		SetBlockResult(EFail);
       
   331 		}
       
   332 	}
       
   333 
       
   334 
       
   335 /**
       
   336 Test EncryptionRequired()
       
   337 */
       
   338 void CT_BTAccessRequirementsData::DoCmdEncryptionRequired(const TDesC& aSection)
       
   339 	{
       
   340 	INFO_PRINTF1(_L("TBTAccessRequirements EncryptionRequired Call"));
       
   341 	
       
   342 	TBool encryption = iData->EncryptionRequired();
       
   343 	INFO_PRINTF2(_L("TBTAccessRequirements EncryptionRequired result: actual = %d"), encryption);
       
   344 	
       
   345 	TBool	expected = EFalse;
       
   346 	if(GetBoolFromConfig(aSection, KExpected(), expected))
       
   347 		{
       
   348 		if( expected != encryption )
       
   349 			{
       
   350 			ERR_PRINTF1(_L("EncryptionRequired not as expected!"));
       
   351 			SetBlockResult(EFail);
       
   352 			}
       
   353 		}
       
   354 	else
       
   355 		{
       
   356 		ERR_PRINTF2(KLogMissingParameter, &KExpected());
       
   357 		SetBlockResult(EFail);
       
   358 		}
       
   359 	}
       
   360 
       
   361 
       
   362 /**
       
   363 Test Denied()
       
   364 */
       
   365 void CT_BTAccessRequirementsData::DoCmdDenied(const TDesC& aSection)
       
   366 	{
       
   367 	INFO_PRINTF1(_L("TBTAccessRequirements Denied Call"));
       
   368 	
       
   369 	TBool denied = iData->Denied();
       
   370 	INFO_PRINTF2(_L("TBTAccessRequirements Denied result: actual = %d"), denied);
       
   371 	
       
   372 	TBool	expected = EFalse;
       
   373 	if(GetBoolFromConfig(aSection, KExpected(), expected) )
       
   374 		{
       
   375 		if( expected != denied )
       
   376 			{
       
   377 			ERR_PRINTF1(_L("Denied not as expected!"));
       
   378 			SetBlockResult(EFail);
       
   379 			}
       
   380 		}
       
   381 	else
       
   382 		{
       
   383 		ERR_PRINTF2(KLogMissingParameter, &KExpected());
       
   384 		SetBlockResult(EFail);
       
   385 		}
       
   386 	}
       
   387 
       
   388 
       
   389 /**
       
   390 Test PasskeyMinLength()
       
   391 */
       
   392 void CT_BTAccessRequirementsData::DoCmdPasskeyMinLength(const TDesC& aSection)
       
   393 	{
       
   394 	INFO_PRINTF1(_L("TBTAccessRequirements PasskeyMinLength Call"));
       
   395 	
       
   396 	TUint passkeyMinLength = iData->PasskeyMinLength();
       
   397 	INFO_PRINTF2(_L("TBTAccessRequirements PasskeyMinLength result: actual = %d"), passkeyMinLength);
       
   398 	
       
   399 	TInt	expected = EFalse;
       
   400 	if(GetIntFromConfig(aSection, KExpected(), expected) )
       
   401 		{
       
   402 		if( expected != passkeyMinLength )
       
   403 			{
       
   404 			ERR_PRINTF1(_L("PasskeyMinLength not as expected!"));
       
   405 			SetBlockResult(EFail);
       
   406 			}
       
   407 		}
       
   408 	else
       
   409 		{
       
   410 		ERR_PRINTF2(KLogMissingParameter, &KExpected());
       
   411 		SetBlockResult(EFail);
       
   412 		}
       
   413 	}
       
   414