os/mm/mmapitest/devsoundhaitest/src/T_CRepositoryData.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmapitest/devsoundhaitest/src/T_CRepositoryData.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,222 @@
     1.4 +/*
     1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +
    1.23 +#include "t_crepositorydata.h"
    1.24 +
    1.25 +/*@{*/
    1.26 +//Command literals 
    1.27 +_LIT(KCmdNewL, 							"NewL");
    1.28 +_LIT(KCmdDestructor, 						"~");
    1.29 +_LIT(KCmdSet,								"Set");
    1.30 +/*@}*/
    1.31 +
    1.32 +/*@{*/
    1.33 +//INI Key names literals 
    1.34 +_LIT(KRepUID,							"RepUID");
    1.35 +_LIT(KRepItemID,						"ItemID");
    1.36 +_LIT(KRepSetValue,						"SetValue");
    1.37 +/*@{*/
    1.38 +
    1.39 +/**
    1.40 + * Two phase constructor
    1.41 + *
    1.42 + * @leave	system wide error
    1.43 + */
    1.44 +CT_CRepositoryData* CT_CRepositoryData::NewL()
    1.45 +	{
    1.46 +	CT_CRepositoryData* ret = new (ELeave) CT_CRepositoryData();
    1.47 +	CleanupStack::PushL(ret);
    1.48 +	ret->ConstructL();
    1.49 +	CleanupStack::Pop(ret);
    1.50 +	return ret;
    1.51 +	}
    1.52 +
    1.53 +/**
    1.54 + * Private constructor. First phase construction
    1.55 + */
    1.56 +CT_CRepositoryData::CT_CRepositoryData()
    1.57 +	:
    1.58 +	iRepository(NULL)
    1.59 +	{
    1.60 +	}
    1.61 +
    1.62 +/**
    1.63 + * Second phase construction
    1.64 + * @internalComponent
    1.65 + * @return	N/A
    1.66 + * @pre		None
    1.67 + * @post	None
    1.68 + * @leave	system wide error
    1.69 + */
    1.70 +void CT_CRepositoryData::ConstructL()
    1.71 +	{
    1.72 +	}
    1.73 +
    1.74 +/**
    1.75 + * Public destructor
    1.76 + */
    1.77 +CT_CRepositoryData::~CT_CRepositoryData()
    1.78 +	{
    1.79 +	DestroyData();
    1.80 +	}
    1.81 +
    1.82 +/**
    1.83 + * Return a pointer to the object that the data wraps
    1.84 + *
    1.85 + * @return	pointer to the object that the data wraps
    1.86 + */
    1.87 +TAny* CT_CRepositoryData::GetObject()
    1.88 +	{
    1.89 +	return iRepository;
    1.90 +	}
    1.91 +
    1.92 +/**
    1.93 + * Helper Destructor
    1.94 + */
    1.95 +void CT_CRepositoryData::DestroyData()
    1.96 +	{
    1.97 +	if(iRepository)
    1.98 +		{
    1.99 +		delete iRepository;
   1.100 +		iRepository = NULL;
   1.101 +		}	
   1.102 +	}
   1.103 +
   1.104 +/**
   1.105 + * Process a command read from the Ini file
   1.106 + * @param aCommand 		   -	The command to process
   1.107 + * @param aSection		   -	The section get from the *.ini file of the project T_Wlan
   1.108 + * @param aAsyncErrorIndex -	Command index dor async calls to returns errors to
   1.109 + * @return TBool		   -    ETrue if the command is process
   1.110 + * @leave				   -	system wide error
   1.111 + */
   1.112 +TBool CT_CRepositoryData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
   1.113 +	{
   1.114 +	TBool ret = ETrue;
   1.115 +	
   1.116 +	if (aCommand == KCmdNewL)
   1.117 +		{
   1.118 +		DoCmdNewL(aSection);
   1.119 +		}
   1.120 +	else if (aCommand == KCmdDestructor)
   1.121 +		{
   1.122 +		DoCmdDestructor();
   1.123 +		}
   1.124 +	else if (aCommand == KCmdSet)
   1.125 +		{
   1.126 +		DoCmdSet(aSection);
   1.127 +		}
   1.128 +	else
   1.129 +		{
   1.130 +		ERR_PRINTF1(_L("Unknown command."));
   1.131 +		ret=EFalse;
   1.132 +		}
   1.133 +	
   1.134 +	return ret;
   1.135 +	}
   1.136 +
   1.137 +/**
   1.138 + * Create an instance of CRepository
   1.139 + * @param aSection - Section to read from the ini file
   1.140 + * @return void
   1.141 + */
   1.142 +void CT_CRepositoryData::DoCmdNewL(const TTEFSectionName& aSection)
   1.143 +	{
   1.144 +	INFO_PRINTF1(_L("*START*CT_CRepositoryData::DoCmdNewL"));
   1.145 +	DestroyData();
   1.146 +	TBool dataOk = ETrue;
   1.147 +	
   1.148 +	TInt parRepUID = 0;
   1.149 +	if(!GetHexFromConfig(aSection, KRepUID, parRepUID))
   1.150 +		{
   1.151 +		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KRepUID);
   1.152 +    	SetBlockResult(EFail);
   1.153 +    	dataOk = EFalse;
   1.154 +		}
   1.155 +
   1.156 +	if(dataOk)
   1.157 +		{
   1.158 +		TUid repUid;
   1.159 +	    repUid.Null();
   1.160 +	    repUid = TUid::Uid(parRepUID);
   1.161 +		TRAPD(error, iRepository = CRepository::NewL(repUid));
   1.162 +		if(error != KErrNone)
   1.163 +			{
   1.164 +			ERR_PRINTF2(_L("Could not create CRepository: error %d"), error);
   1.165 +			SetError(error);
   1.166 +			}
   1.167 +		}
   1.168 +	
   1.169 +	INFO_PRINTF1(_L("*END*CT_CRepositoryData::DoCmdNewL"));
   1.170 +	}
   1.171 +
   1.172 +/**
   1.173 + * Delete an instance of CRepository
   1.174 + * @param
   1.175 + * @return
   1.176 + */
   1.177 +void CT_CRepositoryData::DoCmdDestructor()
   1.178 +	{
   1.179 +	INFO_PRINTF1(_L("*START*CT_CRepositoryData::DoCmdDestroyData"));
   1.180 +	DestroyData();
   1.181 +	INFO_PRINTF1(_L("*END*CT_CRepositoryData::DoCmdDestroyData"));
   1.182 +	}
   1.183 +
   1.184 +/**
   1.185 + * Setting the central repository
   1.186 + * @param aSection - Section to read from the ini file
   1.187 + * @return void
   1.188 + */
   1.189 +void CT_CRepositoryData::DoCmdSet(const TTEFSectionName& aSection)
   1.190 +	{
   1.191 +	INFO_PRINTF1(_L("*START* CT_CRepositoryData::DoCmdSet"));
   1.192 +	TBool dataOk = ETrue;
   1.193 +	
   1.194 +	TInt parRepItemID;
   1.195 +	if(!GetHexFromConfig(aSection, KRepItemID, parRepItemID))
   1.196 +		{
   1.197 +		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KRepItemID);
   1.198 +    	SetBlockResult(EFail);
   1.199 +    	dataOk = EFalse;
   1.200 +		}
   1.201 +
   1.202 +	TInt parRepSetValue;
   1.203 +	if(!GetIntFromConfig(aSection, KRepSetValue, parRepSetValue))
   1.204 +		{
   1.205 +		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KRepSetValue);
   1.206 +    	SetBlockResult(EFail);
   1.207 +    	dataOk = EFalse;
   1.208 +		}
   1.209 +	
   1.210 +	if(dataOk)
   1.211 +		{
   1.212 +		TInt error = KErrNone;
   1.213 +		INFO_PRINTF2(_L("ItemId = %d"),parRepItemID);
   1.214 +		INFO_PRINTF2(_L("DataId = %d"),parRepSetValue);
   1.215 +		
   1.216 +		error = iRepository->Set(parRepItemID, parRepSetValue);
   1.217 +		
   1.218 +		if(error != KErrNone)
   1.219 +			{
   1.220 +			ERR_PRINTF3(_L("Setting the central repository parameter %d failed with error %d"),	parRepItemID, error);
   1.221 +			SetError(error);			
   1.222 +			}
   1.223 +		}	
   1.224 +	INFO_PRINTF1(_L("*END* CT_CRepositoryData::DoCmdSet"));
   1.225 +	}