os/mm/mmapitest/devsoundhaitest/src/T_CRepositoryData.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
sl@0
    20
#include "t_crepositorydata.h"
sl@0
    21
sl@0
    22
/*@{*/
sl@0
    23
//Command literals 
sl@0
    24
_LIT(KCmdNewL, 							"NewL");
sl@0
    25
_LIT(KCmdDestructor, 						"~");
sl@0
    26
_LIT(KCmdSet,								"Set");
sl@0
    27
/*@}*/
sl@0
    28
sl@0
    29
/*@{*/
sl@0
    30
//INI Key names literals 
sl@0
    31
_LIT(KRepUID,							"RepUID");
sl@0
    32
_LIT(KRepItemID,						"ItemID");
sl@0
    33
_LIT(KRepSetValue,						"SetValue");
sl@0
    34
/*@{*/
sl@0
    35
sl@0
    36
/**
sl@0
    37
 * Two phase constructor
sl@0
    38
 *
sl@0
    39
 * @leave	system wide error
sl@0
    40
 */
sl@0
    41
CT_CRepositoryData* CT_CRepositoryData::NewL()
sl@0
    42
	{
sl@0
    43
	CT_CRepositoryData* ret = new (ELeave) CT_CRepositoryData();
sl@0
    44
	CleanupStack::PushL(ret);
sl@0
    45
	ret->ConstructL();
sl@0
    46
	CleanupStack::Pop(ret);
sl@0
    47
	return ret;
sl@0
    48
	}
sl@0
    49
sl@0
    50
/**
sl@0
    51
 * Private constructor. First phase construction
sl@0
    52
 */
sl@0
    53
CT_CRepositoryData::CT_CRepositoryData()
sl@0
    54
	:
sl@0
    55
	iRepository(NULL)
sl@0
    56
	{
sl@0
    57
	}
sl@0
    58
sl@0
    59
/**
sl@0
    60
 * Second phase construction
sl@0
    61
 * @internalComponent
sl@0
    62
 * @return	N/A
sl@0
    63
 * @pre		None
sl@0
    64
 * @post	None
sl@0
    65
 * @leave	system wide error
sl@0
    66
 */
sl@0
    67
void CT_CRepositoryData::ConstructL()
sl@0
    68
	{
sl@0
    69
	}
sl@0
    70
sl@0
    71
/**
sl@0
    72
 * Public destructor
sl@0
    73
 */
sl@0
    74
CT_CRepositoryData::~CT_CRepositoryData()
sl@0
    75
	{
sl@0
    76
	DestroyData();
sl@0
    77
	}
sl@0
    78
sl@0
    79
/**
sl@0
    80
 * Return a pointer to the object that the data wraps
sl@0
    81
 *
sl@0
    82
 * @return	pointer to the object that the data wraps
sl@0
    83
 */
sl@0
    84
TAny* CT_CRepositoryData::GetObject()
sl@0
    85
	{
sl@0
    86
	return iRepository;
sl@0
    87
	}
sl@0
    88
sl@0
    89
/**
sl@0
    90
 * Helper Destructor
sl@0
    91
 */
sl@0
    92
void CT_CRepositoryData::DestroyData()
sl@0
    93
	{
sl@0
    94
	if(iRepository)
sl@0
    95
		{
sl@0
    96
		delete iRepository;
sl@0
    97
		iRepository = NULL;
sl@0
    98
		}	
sl@0
    99
	}
sl@0
   100
sl@0
   101
/**
sl@0
   102
 * Process a command read from the Ini file
sl@0
   103
 * @param aCommand 		   -	The command to process
sl@0
   104
 * @param aSection		   -	The section get from the *.ini file of the project T_Wlan
sl@0
   105
 * @param aAsyncErrorIndex -	Command index dor async calls to returns errors to
sl@0
   106
 * @return TBool		   -    ETrue if the command is process
sl@0
   107
 * @leave				   -	system wide error
sl@0
   108
 */
sl@0
   109
TBool CT_CRepositoryData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
sl@0
   110
	{
sl@0
   111
	TBool ret = ETrue;
sl@0
   112
	
sl@0
   113
	if (aCommand == KCmdNewL)
sl@0
   114
		{
sl@0
   115
		DoCmdNewL(aSection);
sl@0
   116
		}
sl@0
   117
	else if (aCommand == KCmdDestructor)
sl@0
   118
		{
sl@0
   119
		DoCmdDestructor();
sl@0
   120
		}
sl@0
   121
	else if (aCommand == KCmdSet)
sl@0
   122
		{
sl@0
   123
		DoCmdSet(aSection);
sl@0
   124
		}
sl@0
   125
	else
sl@0
   126
		{
sl@0
   127
		ERR_PRINTF1(_L("Unknown command."));
sl@0
   128
		ret=EFalse;
sl@0
   129
		}
sl@0
   130
	
sl@0
   131
	return ret;
sl@0
   132
	}
sl@0
   133
sl@0
   134
/**
sl@0
   135
 * Create an instance of CRepository
sl@0
   136
 * @param aSection - Section to read from the ini file
sl@0
   137
 * @return void
sl@0
   138
 */
sl@0
   139
void CT_CRepositoryData::DoCmdNewL(const TTEFSectionName& aSection)
sl@0
   140
	{
sl@0
   141
	INFO_PRINTF1(_L("*START*CT_CRepositoryData::DoCmdNewL"));
sl@0
   142
	DestroyData();
sl@0
   143
	TBool dataOk = ETrue;
sl@0
   144
	
sl@0
   145
	TInt parRepUID = 0;
sl@0
   146
	if(!GetHexFromConfig(aSection, KRepUID, parRepUID))
sl@0
   147
		{
sl@0
   148
		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KRepUID);
sl@0
   149
    	SetBlockResult(EFail);
sl@0
   150
    	dataOk = EFalse;
sl@0
   151
		}
sl@0
   152
sl@0
   153
	if(dataOk)
sl@0
   154
		{
sl@0
   155
		TUid repUid;
sl@0
   156
	    repUid.Null();
sl@0
   157
	    repUid = TUid::Uid(parRepUID);
sl@0
   158
		TRAPD(error, iRepository = CRepository::NewL(repUid));
sl@0
   159
		if(error != KErrNone)
sl@0
   160
			{
sl@0
   161
			ERR_PRINTF2(_L("Could not create CRepository: error %d"), error);
sl@0
   162
			SetError(error);
sl@0
   163
			}
sl@0
   164
		}
sl@0
   165
	
sl@0
   166
	INFO_PRINTF1(_L("*END*CT_CRepositoryData::DoCmdNewL"));
sl@0
   167
	}
sl@0
   168
sl@0
   169
/**
sl@0
   170
 * Delete an instance of CRepository
sl@0
   171
 * @param
sl@0
   172
 * @return
sl@0
   173
 */
sl@0
   174
void CT_CRepositoryData::DoCmdDestructor()
sl@0
   175
	{
sl@0
   176
	INFO_PRINTF1(_L("*START*CT_CRepositoryData::DoCmdDestroyData"));
sl@0
   177
	DestroyData();
sl@0
   178
	INFO_PRINTF1(_L("*END*CT_CRepositoryData::DoCmdDestroyData"));
sl@0
   179
	}
sl@0
   180
sl@0
   181
/**
sl@0
   182
 * Setting the central repository
sl@0
   183
 * @param aSection - Section to read from the ini file
sl@0
   184
 * @return void
sl@0
   185
 */
sl@0
   186
void CT_CRepositoryData::DoCmdSet(const TTEFSectionName& aSection)
sl@0
   187
	{
sl@0
   188
	INFO_PRINTF1(_L("*START* CT_CRepositoryData::DoCmdSet"));
sl@0
   189
	TBool dataOk = ETrue;
sl@0
   190
	
sl@0
   191
	TInt parRepItemID;
sl@0
   192
	if(!GetHexFromConfig(aSection, KRepItemID, parRepItemID))
sl@0
   193
		{
sl@0
   194
		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KRepItemID);
sl@0
   195
    	SetBlockResult(EFail);
sl@0
   196
    	dataOk = EFalse;
sl@0
   197
		}
sl@0
   198
sl@0
   199
	TInt parRepSetValue;
sl@0
   200
	if(!GetIntFromConfig(aSection, KRepSetValue, parRepSetValue))
sl@0
   201
		{
sl@0
   202
		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KRepSetValue);
sl@0
   203
    	SetBlockResult(EFail);
sl@0
   204
    	dataOk = EFalse;
sl@0
   205
		}
sl@0
   206
	
sl@0
   207
	if(dataOk)
sl@0
   208
		{
sl@0
   209
		TInt error = KErrNone;
sl@0
   210
		INFO_PRINTF2(_L("ItemId = %d"),parRepItemID);
sl@0
   211
		INFO_PRINTF2(_L("DataId = %d"),parRepSetValue);
sl@0
   212
		
sl@0
   213
		error = iRepository->Set(parRepItemID, parRepSetValue);
sl@0
   214
		
sl@0
   215
		if(error != KErrNone)
sl@0
   216
			{
sl@0
   217
			ERR_PRINTF3(_L("Setting the central repository parameter %d failed with error %d"),	parRepItemID, error);
sl@0
   218
			SetError(error);			
sl@0
   219
			}
sl@0
   220
		}	
sl@0
   221
	INFO_PRINTF1(_L("*END* CT_CRepositoryData::DoCmdSet"));
sl@0
   222
	}