os/kernelhwsrv/baseapitest/basesvs/validation/f32/sfsrv/src/T_ParsePtrData.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_ParsePtrData.h"
    20 
    21 
    22 // Commands
    23 _LIT( KCmdDelete,					"~" );
    24 _LIT( KCmdNew,						"new" );
    25 _LIT( KCmdAddDir,					"AddDir");
    26 _LIT( KCmdPopDir,					"PopDir");
    27 
    28 // Parameters
    29 _LIT( KParamFileName,				"FileName" );
    30 _LIT( KParamDirName,				"DirName" );
    31 
    32 CT_ParsePtrData* CT_ParsePtrData::NewL()
    33 /**
    34 * Two phase constructor
    35 */
    36 	{
    37 	CT_ParsePtrData* ret = new (ELeave) CT_ParsePtrData();
    38 	CleanupStack::PushL( ret );
    39 	ret->ConstructL();
    40 	CleanupStack::Pop( ret );
    41 	return ret;
    42 	}
    43 
    44 CT_ParsePtrData::CT_ParsePtrData( )
    45 :	iParsePtr(NULL)
    46 /**
    47 * Protected constructor. First phase construction
    48 */
    49 	{
    50 	}
    51 
    52 TParseBase* CT_ParsePtrData::GetParse()
    53 	{
    54 	return iParsePtr;
    55 	}
    56 
    57 void CT_ParsePtrData::ConstructL()
    58 /**
    59 * Protected constructor. Second phase construction
    60 */
    61 	{
    62 	}
    63 	
    64 CT_ParsePtrData::~CT_ParsePtrData()
    65 /**
    66 * Destructor.
    67 */
    68 	{
    69 	DoCleanup();
    70 	}
    71 	
    72 
    73 TAny* CT_ParsePtrData::GetObject()
    74 /**
    75 * Return a pointer to the object that the data wraps
    76 *
    77 * @return pointer to the object that the data wraps
    78 */
    79 	{
    80 	return iParsePtr;
    81 	}
    82 
    83 TBool CT_ParsePtrData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex )
    84 /**
    85 * Process a command read from the ini file
    86 *
    87 * @param aCommand	the command to process
    88 * @param aEntry		the entry in the ini file requiring the command to be processed
    89 *
    90 * @return ETrue if the command is processed
    91 */
    92 	{
    93 	TBool retVal = ETrue;
    94 	
    95 	if ( aCommand == KCmdDelete )
    96 		{
    97 		DoCleanup();
    98 		}
    99 	else if ( aCommand == KCmdNew )
   100 		{
   101 		DoCmdNew( aSection );
   102 		}
   103 	else if ( aCommand == KCmdAddDir )
   104 		{
   105 		DoCmdAddDir( aSection );
   106 		}
   107 	else if ( aCommand == KCmdPopDir )
   108 		{
   109 		DoCmdPopDir();
   110 		}
   111 	else
   112 	    {
   113 	    retVal = CT_ParseBaseData::DoCommandL(aCommand, aSection, aAsyncErrorIndex);    
   114 	    }
   115 	
   116 	return retVal;
   117 	}
   118 	
   119 void CT_ParsePtrData::DoCleanup()
   120 /** Deletes TParsePtr class instance */
   121     {
   122     INFO_PRINTF1( _L( "Delete TParsePtr class instance." ) );
   123     
   124 	delete iParsePtr;
   125 	iParsePtr = NULL;
   126     }
   127 
   128 void CT_ParsePtrData::DoCmdNew( const TDesC& aSection )
   129 /** Creates new TParsePtr class instance */
   130 	{
   131 	DoCleanup();
   132 
   133 	TPtrC fileName;
   134 	if ( GET_MANDATORY_STRING_PARAMETER( KParamFileName, aSection, fileName ) )
   135 		{
   136 		INFO_PRINTF2( _L( "Create new TParsePtr(\"%S\") class instance." ), &fileName );
   137 		
   138 		iFileName = fileName;
   139 		TRAPD( err, iParsePtr = new (ELeave) TParsePtr( iFileName ) );
   140 		if ( err != KErrNone )
   141 			{
   142 			ERR_PRINTF3( _L( "new TParsePtr(\"%S\") error=%d" ), &fileName, err );
   143 			SetError( err );
   144 			}
   145 		}
   146 	}
   147 
   148  
   149 void CT_ParsePtrData::DoCmdPopDir()
   150 /** Removes the last directory from the path using PopDir(). */
   151 	{
   152 	INFO_PRINTF1( _L( "PopDir()" ) );
   153 		
   154 	TInt err = iParsePtr->PopDir();
   155 	
   156 	if( err != KErrNone)
   157 			{
   158 			ERR_PRINTF2( _L( "PopDir() returned %d error"), err);
   159 			SetError(err);
   160 			}
   161 	}
   162 
   163 
   164     
   165 void CT_ParsePtrData::DoCmdAddDir( const TDesC& aSection )
   166 /** Adds a single directory onto the end of the path using AddDir. */
   167 	{
   168 	TPtrC dirName;
   169 	if ( GET_MANDATORY_STRING_PARAMETER( KParamDirName, aSection, dirName ) )
   170 		{
   171 		INFO_PRINTF2( _L( "AddDir(\"%S\")" ), &dirName );
   172 		
   173 		TInt err = iParsePtr->AddDir( dirName );
   174 		if(	err != KErrNone)
   175 			{
   176 			ERR_PRINTF2( _L( "AddDir() returned %d error"), err);
   177 			SetError(err);
   178 			}
   179 		}
   180 	}