os/kernelhwsrv/baseapitest/basesvs/validation/f32/sfsrv/src/T_OpenFileScanData.cpp
Update contrib.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #include "T_OpenFileScanData.h"
20 #include "FileserverUtil.h"
23 const TInt KBufferLength = 64;
27 _LIT( KCmdDestructor, "~" );
28 _LIT( KCmdNew, "new" );
29 _LIT( KCmdNextL, "NextL" );
30 _LIT( KCmdThreadId, "ThreadId" );
33 _LIT( KParamFileSession, "FileSession" );
34 _LIT( KParamExpectedFileName, "expected_filename%d");
35 _LIT( KParamDirWrapper, "wrapper");
38 CT_OpenFileScanData* CT_OpenFileScanData::NewL()
40 * Two phase constructor
43 CT_OpenFileScanData* ret = new (ELeave) CT_OpenFileScanData();
44 CleanupStack::PushL( ret );
46 CleanupStack::Pop( ret );
50 CT_OpenFileScanData::CT_OpenFileScanData()
53 * Protected constructor. First phase construction
58 void CT_OpenFileScanData::ConstructL()
60 * Protected constructor. Second phase construction
65 CT_OpenFileScanData::~CT_OpenFileScanData()
73 void CT_OpenFileScanData::DoCleanup()
75 * Contains cleanup implementation
82 TAny* CT_OpenFileScanData::GetObject()
84 * Return a pointer to the object that the data wraps
86 * @return pointer to the object that the data wraps
92 TBool CT_OpenFileScanData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
94 * Process a command read from the ini file
96 * @param aCommand the command to process
97 * @param aSection the entry in the ini file requiring the command to be processed
99 * @return ETrue if the command is processed
102 TBool retVal = ETrue;
104 if ( aCommand == KCmdDestructor )
108 else if ( aCommand == KCmdNew )
110 DoCmdNew( aSection );
112 else if ( aCommand == KCmdNextL )
114 DoCmdNextL( aSection );
116 else if ( aCommand == KCmdThreadId )
118 DoCmdThreadId( aSection );
128 void CT_OpenFileScanData::DoCmdNew( const TDesC& aSection )
129 /** Creates new TOpenFileScan class instance */
133 if ( GetRfsParam( aSection, rfs, rfsName ) )
135 INFO_PRINTF2( _L( "Create new TOpenFileScan(%S) class instance." ), &rfsName );
138 TRAPD( err, iOpenFileScan = new (ELeave) TOpenFileScan( *rfs ) );
139 if ( err != KErrNone )
141 ERR_PRINTF3( _L( "new TOpenFileScan(%S) error=%d" ), &rfsName, err );
147 void CT_OpenFileScanData::DoCmdNextL( const TDesC& aSection )
148 /** Calls NextL() function */
150 RPointerArray<TPath> pathsToFind;
151 CleanupResetAndDestroyPushL(pathsToFind);
153 // Read expected file names into array
158 TBuf<KBufferLength> tempStore;
159 tempStore.Format(KParamExpectedFileName(), ++index);
161 eof = !GET_OPTIONAL_STRING_PARAMETER(tempStore, aSection, fileName);
164 TPath* path = new(ELeave) TPath(fileName);
165 CleanupStack::PushL(path);
166 pathsToFind.AppendL(path);
174 CFileList* fileList = NULL;
175 if(pathsToFind.Count() == 0)
177 TRAP( err, iOpenFileScan->NextL( fileList ));
181 CleanupStack::PushL(fileList);
182 // NB! CDir == CFileList
184 if (!err && GET_OPTIONAL_STRING_PARAMETER(KParamDirWrapper, aSection, wrapperName))
186 CT_DirData *wrapper = NULL;
188 TRAPD( error, wrapper = static_cast<CT_DirData*>(GetDataWrapperL(wrapperName)))
190 if( wrapper && (error==KErrNone) )
192 wrapper->SetObjectL(fileList);
197 ERR_PRINTF2( _L( "Wrong CDir wrapper name %S"), &wrapperName );
198 SetBlockResult( EFail );
209 // Check expected file names
210 for( eof = EFalse ; !eof && (pathsToFind.Count() > 0); )
212 iOpenFileScan->NextL(fileList);
215 for ( TInt i = 0; i < fileList->Count(); i++ )
217 INFO_PRINTF1((*fileList)[i].iName );
218 for(TInt j = pathsToFind.Count() - 1 ; j >= 0; j--)
220 if( *(pathsToFind[j]) == (*fileList)[i].iName )
222 TPath* elemForRemove = pathsToFind[j];
223 pathsToFind.Remove(j);
224 delete elemForRemove;
238 // Some file names are not found
239 if (pathsToFind.Count() > 0)
241 for(TInt i = 0; i < pathsToFind.Count(); i++)
243 ERR_PRINTF2( _L( "File %S haven't been found" ), pathsToFind[i] );
245 SetBlockResult( EFail );
249 if ( err != KErrNone )
251 ERR_PRINTF2( _L( "NextL() error=%d" ), err );
256 CleanupStack::PopAndDestroy(&pathsToFind);
259 // Calls ThreadId() function
260 void CT_OpenFileScanData::DoCmdThreadId( const TDesC& aSection )
264 if(GET_MANDATORY_STRING_PARAMETER( KParamFileSession, aSection, rfsName))
266 CT_FsData *fsData = NULL;
268 TRAPD(err,fsData = static_cast<CT_FsData*>(GetDataWrapperL(rfsName)));
272 //Recieving thread ids.
273 TUint64 rfsThreadId = fsData->ThreadId();
274 TUint64 id = iOpenFileScan->ThreadId().Id();
276 if(rfsThreadId != id)
278 ERR_PRINTF3( _L( "Diffrent thread id's %u %u"),rfsThreadId,id);
279 SetBlockResult( EFail );
284 ERR_PRINTF2( _L( "Wrong session name:%S"),&rfsName);
285 SetBlockResult( EFail );
291 TBool CT_OpenFileScanData::GetRfsParam( const TDesC& aSection, RFs*& aRfs, TPtrC& aRfsName )
292 /** this function retrieves the "rfs" current command parameter using
293 * GET_MANDATORY_STRING_PAREMETER macro
295 * @param aSection - the entry in the ini file requiring the command to be processed
296 * @param aRfs - the returned RFs pointer
297 * @param aRfsName - the returned RFs's name as stated in ini file
299 * @return ETrue - if the the parameter has been successfully read and interpreted
303 TBool result = EFalse;
305 if ( GET_MANDATORY_STRING_PARAMETER( KParamFileSession, aSection, aRfsName ) )
307 TRAPD( err, aRfs = (RFs*)GetDataObjectL( aRfsName ) );
309 if ( err != KErrNone )
311 ERR_PRINTF3( _L( "Unrecognized object name: %S (error = %d)" ), &aRfsName, err );
312 SetBlockResult( EFail );