sl@0: /* sl@0: * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: sl@0: #include "t_crepositorydata.h" sl@0: sl@0: /*@{*/ sl@0: //Command literals sl@0: _LIT(KCmdNewL, "NewL"); sl@0: _LIT(KCmdDestructor, "~"); sl@0: _LIT(KCmdSet, "Set"); sl@0: /*@}*/ sl@0: sl@0: /*@{*/ sl@0: //INI Key names literals sl@0: _LIT(KRepUID, "RepUID"); sl@0: _LIT(KRepItemID, "ItemID"); sl@0: _LIT(KRepSetValue, "SetValue"); sl@0: /*@{*/ sl@0: sl@0: /** sl@0: * Two phase constructor sl@0: * sl@0: * @leave system wide error sl@0: */ sl@0: CT_CRepositoryData* CT_CRepositoryData::NewL() sl@0: { sl@0: CT_CRepositoryData* ret = new (ELeave) CT_CRepositoryData(); sl@0: CleanupStack::PushL(ret); sl@0: ret->ConstructL(); sl@0: CleanupStack::Pop(ret); sl@0: return ret; sl@0: } sl@0: sl@0: /** sl@0: * Private constructor. First phase construction sl@0: */ sl@0: CT_CRepositoryData::CT_CRepositoryData() sl@0: : sl@0: iRepository(NULL) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: * Second phase construction sl@0: * @internalComponent sl@0: * @return N/A sl@0: * @pre None sl@0: * @post None sl@0: * @leave system wide error sl@0: */ sl@0: void CT_CRepositoryData::ConstructL() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: * Public destructor sl@0: */ sl@0: CT_CRepositoryData::~CT_CRepositoryData() sl@0: { sl@0: DestroyData(); sl@0: } sl@0: sl@0: /** sl@0: * Return a pointer to the object that the data wraps sl@0: * sl@0: * @return pointer to the object that the data wraps sl@0: */ sl@0: TAny* CT_CRepositoryData::GetObject() sl@0: { sl@0: return iRepository; sl@0: } sl@0: sl@0: /** sl@0: * Helper Destructor sl@0: */ sl@0: void CT_CRepositoryData::DestroyData() sl@0: { sl@0: if(iRepository) sl@0: { sl@0: delete iRepository; sl@0: iRepository = NULL; sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Process a command read from the Ini file sl@0: * @param aCommand - The command to process sl@0: * @param aSection - The section get from the *.ini file of the project T_Wlan sl@0: * @param aAsyncErrorIndex - Command index dor async calls to returns errors to sl@0: * @return TBool - ETrue if the command is process sl@0: * @leave - system wide error sl@0: */ sl@0: TBool CT_CRepositoryData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/) sl@0: { sl@0: TBool ret = ETrue; sl@0: sl@0: if (aCommand == KCmdNewL) sl@0: { sl@0: DoCmdNewL(aSection); sl@0: } sl@0: else if (aCommand == KCmdDestructor) sl@0: { sl@0: DoCmdDestructor(); sl@0: } sl@0: else if (aCommand == KCmdSet) sl@0: { sl@0: DoCmdSet(aSection); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF1(_L("Unknown command.")); sl@0: ret=EFalse; sl@0: } sl@0: sl@0: return ret; sl@0: } sl@0: sl@0: /** sl@0: * Create an instance of CRepository sl@0: * @param aSection - Section to read from the ini file sl@0: * @return void sl@0: */ sl@0: void CT_CRepositoryData::DoCmdNewL(const TTEFSectionName& aSection) sl@0: { sl@0: INFO_PRINTF1(_L("*START*CT_CRepositoryData::DoCmdNewL")); sl@0: DestroyData(); sl@0: TBool dataOk = ETrue; sl@0: sl@0: TInt parRepUID = 0; sl@0: if(!GetHexFromConfig(aSection, KRepUID, parRepUID)) sl@0: { sl@0: ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KRepUID); sl@0: SetBlockResult(EFail); sl@0: dataOk = EFalse; sl@0: } sl@0: sl@0: if(dataOk) sl@0: { sl@0: TUid repUid; sl@0: repUid.Null(); sl@0: repUid = TUid::Uid(parRepUID); sl@0: TRAPD(error, iRepository = CRepository::NewL(repUid)); sl@0: if(error != KErrNone) sl@0: { sl@0: ERR_PRINTF2(_L("Could not create CRepository: error %d"), error); sl@0: SetError(error); sl@0: } sl@0: } sl@0: sl@0: INFO_PRINTF1(_L("*END*CT_CRepositoryData::DoCmdNewL")); sl@0: } sl@0: sl@0: /** sl@0: * Delete an instance of CRepository sl@0: * @param sl@0: * @return sl@0: */ sl@0: void CT_CRepositoryData::DoCmdDestructor() sl@0: { sl@0: INFO_PRINTF1(_L("*START*CT_CRepositoryData::DoCmdDestroyData")); sl@0: DestroyData(); sl@0: INFO_PRINTF1(_L("*END*CT_CRepositoryData::DoCmdDestroyData")); sl@0: } sl@0: sl@0: /** sl@0: * Setting the central repository sl@0: * @param aSection - Section to read from the ini file sl@0: * @return void sl@0: */ sl@0: void CT_CRepositoryData::DoCmdSet(const TTEFSectionName& aSection) sl@0: { sl@0: INFO_PRINTF1(_L("*START* CT_CRepositoryData::DoCmdSet")); sl@0: TBool dataOk = ETrue; sl@0: sl@0: TInt parRepItemID; sl@0: if(!GetHexFromConfig(aSection, KRepItemID, parRepItemID)) sl@0: { sl@0: ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KRepItemID); sl@0: SetBlockResult(EFail); sl@0: dataOk = EFalse; sl@0: } sl@0: sl@0: TInt parRepSetValue; sl@0: if(!GetIntFromConfig(aSection, KRepSetValue, parRepSetValue)) sl@0: { sl@0: ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KRepSetValue); sl@0: SetBlockResult(EFail); sl@0: dataOk = EFalse; sl@0: } sl@0: sl@0: if(dataOk) sl@0: { sl@0: TInt error = KErrNone; sl@0: INFO_PRINTF2(_L("ItemId = %d"),parRepItemID); sl@0: INFO_PRINTF2(_L("DataId = %d"),parRepSetValue); sl@0: sl@0: error = iRepository->Set(parRepItemID, parRepSetValue); sl@0: sl@0: if(error != KErrNone) sl@0: { sl@0: ERR_PRINTF3(_L("Setting the central repository parameter %d failed with error %d"), parRepItemID, error); sl@0: SetError(error); sl@0: } sl@0: } sl@0: INFO_PRINTF1(_L("*END* CT_CRepositoryData::DoCmdSet")); sl@0: }