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: #include "T_OpenFileScanData.h" sl@0: #include "FileserverUtil.h" sl@0: sl@0: //Constants sl@0: const TInt KBufferLength = 64; sl@0: sl@0: sl@0: // Commands sl@0: _LIT( KCmdDestructor, "~" ); sl@0: _LIT( KCmdNew, "new" ); sl@0: _LIT( KCmdNextL, "NextL" ); sl@0: _LIT( KCmdThreadId, "ThreadId" ); sl@0: sl@0: // Parameters sl@0: _LIT( KParamFileSession, "FileSession" ); sl@0: _LIT( KParamExpectedFileName, "expected_filename%d"); sl@0: _LIT( KParamDirWrapper, "wrapper"); sl@0: sl@0: sl@0: CT_OpenFileScanData* CT_OpenFileScanData::NewL() sl@0: /** sl@0: * Two phase constructor sl@0: */ sl@0: { sl@0: CT_OpenFileScanData* ret = new (ELeave) CT_OpenFileScanData(); sl@0: CleanupStack::PushL( ret ); sl@0: ret->ConstructL(); sl@0: CleanupStack::Pop( ret ); sl@0: return ret; sl@0: } sl@0: sl@0: CT_OpenFileScanData::CT_OpenFileScanData() sl@0: : iOpenFileScan(NULL) sl@0: /** sl@0: * Protected constructor. First phase construction sl@0: */ sl@0: { sl@0: } sl@0: sl@0: void CT_OpenFileScanData::ConstructL() sl@0: /** sl@0: * Protected constructor. Second phase construction sl@0: */ sl@0: { sl@0: } sl@0: sl@0: CT_OpenFileScanData::~CT_OpenFileScanData() sl@0: /** sl@0: * Destructor. sl@0: */ sl@0: { sl@0: DoCleanup(); sl@0: } sl@0: sl@0: void CT_OpenFileScanData::DoCleanup() sl@0: /** sl@0: * Contains cleanup implementation sl@0: */ sl@0: { sl@0: delete iOpenFileScan; sl@0: iOpenFileScan = NULL; sl@0: } sl@0: sl@0: TAny* CT_OpenFileScanData::GetObject() 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: { sl@0: return iOpenFileScan; sl@0: } sl@0: sl@0: TBool CT_OpenFileScanData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/) sl@0: /** sl@0: * Process a command read from the ini file sl@0: * sl@0: * @param aCommand the command to process sl@0: * @param aSection the entry in the ini file requiring the command to be processed sl@0: * sl@0: * @return ETrue if the command is processed sl@0: */ sl@0: { sl@0: TBool retVal = ETrue; sl@0: sl@0: if ( aCommand == KCmdDestructor ) sl@0: { sl@0: DoCleanup(); sl@0: } sl@0: else if ( aCommand == KCmdNew ) sl@0: { sl@0: DoCmdNew( aSection ); sl@0: } sl@0: else if ( aCommand == KCmdNextL ) sl@0: { sl@0: DoCmdNextL( aSection ); sl@0: } sl@0: else if ( aCommand == KCmdThreadId ) sl@0: { sl@0: DoCmdThreadId( aSection ); sl@0: } sl@0: else sl@0: { sl@0: retVal = EFalse; sl@0: } sl@0: sl@0: return retVal; sl@0: } sl@0: sl@0: void CT_OpenFileScanData::DoCmdNew( const TDesC& aSection ) sl@0: /** Creates new TOpenFileScan class instance */ sl@0: { sl@0: TPtrC rfsName; sl@0: RFs* rfs = NULL; sl@0: if ( GetRfsParam( aSection, rfs, rfsName ) ) sl@0: { sl@0: INFO_PRINTF2( _L( "Create new TOpenFileScan(%S) class instance." ), &rfsName ); sl@0: sl@0: // do create sl@0: TRAPD( err, iOpenFileScan = new (ELeave) TOpenFileScan( *rfs ) ); sl@0: if ( err != KErrNone ) sl@0: { sl@0: ERR_PRINTF3( _L( "new TOpenFileScan(%S) error=%d" ), &rfsName, err ); sl@0: SetError( err ); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_OpenFileScanData::DoCmdNextL( const TDesC& aSection ) sl@0: /** Calls NextL() function */ sl@0: { sl@0: RPointerArray pathsToFind; sl@0: CleanupResetAndDestroyPushL(pathsToFind); sl@0: sl@0: // Read expected file names into array sl@0: TBool eof = EFalse; sl@0: TInt index = 0; sl@0: do sl@0: { sl@0: TBuf tempStore; sl@0: tempStore.Format(KParamExpectedFileName(), ++index); sl@0: TPtrC fileName; sl@0: eof = !GET_OPTIONAL_STRING_PARAMETER(tempStore, aSection, fileName); sl@0: if (!eof) sl@0: { sl@0: TPath* path = new(ELeave) TPath(fileName); sl@0: CleanupStack::PushL(path); sl@0: pathsToFind.AppendL(path); sl@0: CleanupStack::Pop(); sl@0: } sl@0: } sl@0: while (!eof); sl@0: sl@0: TInt err = KErrNone; sl@0: sl@0: CFileList* fileList = NULL; sl@0: if(pathsToFind.Count() == 0) sl@0: { sl@0: TRAP( err, iOpenFileScan->NextL( fileList )); sl@0: sl@0: if( fileList) sl@0: { sl@0: CleanupStack::PushL(fileList); sl@0: // NB! CDir == CFileList sl@0: TPtrC wrapperName; sl@0: if (!err && GET_OPTIONAL_STRING_PARAMETER(KParamDirWrapper, aSection, wrapperName)) sl@0: { sl@0: CT_DirData *wrapper = NULL; sl@0: sl@0: TRAPD( error, wrapper = static_cast(GetDataWrapperL(wrapperName))) sl@0: sl@0: if( wrapper && (error==KErrNone) ) sl@0: { sl@0: wrapper->SetObjectL(fileList); sl@0: fileList = NULL; sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2( _L( "Wrong CDir wrapper name %S"), &wrapperName ); sl@0: SetBlockResult( EFail ); sl@0: } sl@0: } sl@0: sl@0: CleanupStack::Pop(); sl@0: delete fileList; sl@0: fileList = NULL; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: // Check expected file names sl@0: for( eof = EFalse ; !eof && (pathsToFind.Count() > 0); ) sl@0: { sl@0: iOpenFileScan->NextL(fileList); sl@0: if( fileList) sl@0: { sl@0: for ( TInt i = 0; i < fileList->Count(); i++ ) sl@0: { sl@0: INFO_PRINTF1((*fileList)[i].iName ); sl@0: for(TInt j = pathsToFind.Count() - 1 ; j >= 0; j--) sl@0: { sl@0: if( *(pathsToFind[j]) == (*fileList)[i].iName ) sl@0: { sl@0: TPath* elemForRemove = pathsToFind[j]; sl@0: pathsToFind.Remove(j); sl@0: delete elemForRemove; sl@0: } sl@0: } sl@0: } sl@0: sl@0: delete fileList; sl@0: fileList = NULL; sl@0: } sl@0: else sl@0: { sl@0: eof = ETrue; sl@0: } sl@0: } sl@0: sl@0: // Some file names are not found sl@0: if (pathsToFind.Count() > 0) sl@0: { sl@0: for(TInt i = 0; i < pathsToFind.Count(); i++) sl@0: { sl@0: ERR_PRINTF2( _L( "File %S haven't been found" ), pathsToFind[i] ); sl@0: } sl@0: SetBlockResult( EFail ); sl@0: } sl@0: } sl@0: sl@0: if ( err != KErrNone ) sl@0: { sl@0: ERR_PRINTF2( _L( "NextL() error=%d" ), err ); sl@0: SetError( err ); sl@0: } sl@0: sl@0: //Free massive sl@0: CleanupStack::PopAndDestroy(&pathsToFind); sl@0: } sl@0: sl@0: // Calls ThreadId() function sl@0: void CT_OpenFileScanData::DoCmdThreadId( const TDesC& aSection ) sl@0: { sl@0: TPtrC rfsName; sl@0: sl@0: if(GET_MANDATORY_STRING_PARAMETER( KParamFileSession, aSection, rfsName)) sl@0: { sl@0: CT_FsData *fsData = NULL; sl@0: sl@0: TRAPD(err,fsData = static_cast(GetDataWrapperL(rfsName))); sl@0: sl@0: if( err==KErrNone ) sl@0: { sl@0: //Recieving thread ids. sl@0: TUint64 rfsThreadId = fsData->ThreadId(); sl@0: TUint64 id = iOpenFileScan->ThreadId().Id(); sl@0: //Comparing id's sl@0: if(rfsThreadId != id) sl@0: { sl@0: ERR_PRINTF3( _L( "Diffrent thread id's %u %u"),rfsThreadId,id); sl@0: SetBlockResult( EFail ); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2( _L( "Wrong session name:%S"),&rfsName); sl@0: SetBlockResult( EFail ); sl@0: } sl@0: } sl@0: sl@0: } sl@0: sl@0: TBool CT_OpenFileScanData::GetRfsParam( const TDesC& aSection, RFs*& aRfs, TPtrC& aRfsName ) sl@0: /** this function retrieves the "rfs" current command parameter using sl@0: * GET_MANDATORY_STRING_PAREMETER macro sl@0: * sl@0: * @param aSection - the entry in the ini file requiring the command to be processed sl@0: * @param aRfs - the returned RFs pointer sl@0: * @param aRfsName - the returned RFs's name as stated in ini file sl@0: * sl@0: * @return ETrue - if the the parameter has been successfully read and interpreted sl@0: * EFalse - otherwise sl@0: */ sl@0: { sl@0: TBool result = EFalse; sl@0: sl@0: if ( GET_MANDATORY_STRING_PARAMETER( KParamFileSession, aSection, aRfsName ) ) sl@0: { sl@0: TRAPD( err, aRfs = (RFs*)GetDataObjectL( aRfsName ) ); sl@0: sl@0: if ( err != KErrNone ) sl@0: { sl@0: ERR_PRINTF3( _L( "Unrecognized object name: %S (error = %d)" ), &aRfsName, err ); sl@0: SetBlockResult( EFail ); sl@0: } sl@0: else sl@0: { sl@0: result = ETrue; sl@0: } sl@0: } sl@0: sl@0: return result; sl@0: } sl@0: