os/kernelhwsrv/baseapitest/basesvs/validation/f32/sfsrv/src/T_EntryArrayData.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 
    19 #include "T_EntryArrayData.h"
    20 #include "T_EntryData.h"
    21 #include "FileserverUtil.h"
    22 
    23 // Commands
    24 _LIT( KCmdCount,				"count" );
    25 _LIT( KCmdDelete,				"~" );
    26 _LIT( KCmdNew,					"new" );
    27 _LIT( KCmdIndexOperator,		"[]" );
    28 
    29 // Parameters
    30 _LIT( KParamDestination,		"destination" );
    31 _LIT( KParamExpected,			"expected" );
    32 _LIT( KParamIndex,				"index" );
    33 
    34 
    35 CT_EntryArrayData* CT_EntryArrayData::NewL()
    36 /**
    37 * Two phase constructor
    38 */
    39 	{
    40 	CT_EntryArrayData* ret = new (ELeave) CT_EntryArrayData();
    41 	CleanupStack::PushL( ret );
    42 	ret->ConstructL();
    43 	CleanupStack::Pop( ret );
    44 	return ret;
    45 	}
    46 
    47 CT_EntryArrayData::CT_EntryArrayData()
    48 :	iEntryArray(NULL)
    49 /**
    50 * Protected constructor. First phase construction
    51 */
    52 	{
    53 	}
    54 	
    55 void CT_EntryArrayData::ConstructL()
    56 /**
    57 * Protected constructor. Second phase construction
    58 */
    59 	{
    60 	}
    61 	
    62 CT_EntryArrayData::~CT_EntryArrayData()
    63 /**
    64 * Destructor.
    65 */
    66 
    67 	{
    68 	DoCmdDelete();
    69 	}
    70 	
    71 TAny* CT_EntryArrayData::GetObject()
    72 /**
    73 * Return a pointer to the object that the data wraps
    74 *
    75 * @return pointer to the object that the data wraps
    76 */
    77 
    78 	{
    79 	return iEntryArray;
    80 	}
    81 
    82 TBool CT_EntryArrayData::DoCommandL( const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/ )
    83 /**
    84 * Process a command read from the ini file
    85 *
    86 * @param aCommand	the command to process
    87 * @param aSection		the entry in the ini file requiring the command to be processed
    88 *
    89 * @return ETrue if the command is processed
    90 */	
    91 	{
    92 	TBool retVal = ETrue;
    93 	
    94 	if ( aCommand == KCmdIndexOperator )
    95 		{
    96 		DoCmdIndexOperatorL( aSection );
    97 		}
    98 	else if ( aCommand == KCmdCount )
    99 		{
   100 		DoCmdCount( aSection );
   101 		}
   102 	else if ( aCommand == KCmdDelete )
   103 		{
   104 		DoCmdDelete();
   105 		}
   106 	else if ( aCommand == KCmdNew )
   107 		{
   108 		DoCmdNew();
   109 		}
   110 	else
   111 	    {
   112 	    retVal = EFalse;    
   113 	    }
   114 	
   115 	return retVal;
   116 	}
   117 	
   118 void CT_EntryArrayData::DoCmdIndexOperatorL( const TDesC& aSection )
   119 /**
   120 * Assigns an element of TEntryArray to another TEntry object using "=" operator
   121 */
   122 	{
   123 	TInt index;
   124 	TPtrC entryObjectName;
   125 	
   126 	if( GET_MANDATORY_INT_PARAMETER( KParamIndex, aSection, index ) && 
   127 		GET_MANDATORY_STRING_PARAMETER( KParamDestination, aSection, entryObjectName ))
   128 		{
   129 		TEntry* entry = new(ELeave) TEntry();
   130 		CleanupStack::PushL(entry);
   131 		
   132 		*entry = iEntryArray->operator[](index);
   133 		CT_EntryData* entryWrapperObject = static_cast<CT_EntryData*>(GetDataWrapperL(entryObjectName));
   134 		
   135 		if(!entryWrapperObject)
   136 		    {
   137 			ERR_PRINTF2(_L("%S is not initialised"), &entryObjectName);
   138 		    SetBlockResult(EFail); 
   139 		    CleanupStack::PopAndDestroy(entry);
   140 		    }
   141 		else
   142 			{
   143 			entryWrapperObject->SetObjectL(entry);
   144 			CleanupStack::Pop(entry);
   145 			}
   146 		}
   147 	}
   148 	
   149 void CT_EntryArrayData::DoCmdCount( const TDesC& aSection )
   150 /**
   151 * Checks if TEntryArray has expected number of elements
   152 */
   153 	{
   154 	TInt expected;	
   155 	if( GET_MANDATORY_INT_PARAMETER( KParamExpected, aSection, expected ) )
   156 		{
   157 		INFO_PRINTF2( _L( "Count(). Expected value = %d" ), expected );
   158 		
   159 		TInt result = iEntryArray->Count();
   160 		if ( result != expected )
   161 			{
   162 			ERR_PRINTF3(_L("Count %d != expected %d"), result, expected );
   163 			SetBlockResult( EFail );
   164 			}
   165 		}
   166 	}
   167 	
   168 void CT_EntryArrayData::DoCmdDelete()
   169 /**
   170 * Deletes TEntryArray class instance
   171 */
   172     {
   173 	DoCleanup();
   174     }
   175 	
   176 void CT_EntryArrayData::DoCmdNew()
   177 /**
   178 * Creates new TEntryArray class instance
   179 */
   180 	{
   181 	DoCmdDelete();
   182 	
   183 	INFO_PRINTF1( _L( "Create new TEntryArray() class instance." ) );
   184 	TRAPD( err, iEntryArray = new (ELeave) TEntryArray() );
   185 	if ( err != KErrNone )
   186 		{
   187 		ERR_PRINTF2( _L( "new TEntryArray() error %d" ), err );
   188 		SetBlockResult( EFail );
   189 		}
   190 	}
   191 	
   192 	
   193 void CT_EntryArrayData::SetObjectL( TAny* aAny )
   194 /**
   195 * Set the wrapped data object with new value
   196 */
   197 	{
   198 	DoCleanup();
   199 	iEntryArray = static_cast<TEntryArray*> ( aAny );
   200 	}
   201 	
   202 void CT_EntryArrayData::DoCleanup()
   203 /** Deltes TEntry class instance */
   204     {
   205 	INFO_PRINTF1( _L( "Delete TEntryArray class instance" ) );
   206 	delete iEntryArray;
   207 	iEntryArray = NULL;
   208     }
   209 
   210