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.
23 This contains CT_RDirData
27 #include "T_RDirData.h"
28 #include "T_SfSrvServer.h"
29 #include "FileserverUtil.h"
36 _LIT(KTUidType, "uidtype");
37 _LIT(KRFsObjectName, "rfsObject");
38 _LIT(KAsync, "async");
39 _LIT(KArrayObjectName, "arrayObject");
40 _LIT(KEntryObjectName, "entryObject");
41 _LIT(KEntryAttMask, "attmask");
42 _LIT(KParamExpectedFileName, "filename%d");
43 _LIT(KReadArray, "readarray");
44 _LIT(KCompareFiles, "compare");
49 _LIT(KCmdDestructor, "~");
50 _LIT(KCmdOpen, "Open");
51 _LIT(KCmdRead, "Read");
52 _LIT(KCmdClose, "Close");
55 const TInt KBufferLength = 64;
57 CT_RDirData* CT_RDirData::NewL()
59 * Two phase constructor
62 CT_RDirData* ret = new (ELeave) CT_RDirData();
63 CleanupStack::PushL(ret);
65 CleanupStack::Pop(ret);
71 CT_RDirData::CT_RDirData()
76 , iExpectedNames(NULL)
80 * Protected constructor. First phase construction
86 void CT_RDirData::ConstructL()
88 * Protected constructor. Second phase construction
91 iRead = CActiveCallback::NewL( *this );
92 iReadBlock = CActiveCallback::NewL( *this );
93 iExpectedNames = new(ELeave) RPointerArray<TPath>();
97 CT_RDirData::~CT_RDirData()
106 TAny* CT_RDirData::GetObject()
112 TBool CT_RDirData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
114 * Process a command read from the ini file
116 * @param aCommand the command to process
117 * @param aSection the entry in the ini file requiring the command to be processed
119 * @return ETrue if the command is processed
124 if (aCommand == KCmdNew)
128 else if (aCommand == KCmdOpen)
130 DoCmdOpenL(aSection);
132 else if (aCommand == KCmdRead)
134 DoCmdReadL(aSection, aAsyncErrorIndex);
136 else if (aCommand == KCmdClose)
140 else if (aCommand == KCmdDestructor)
151 void CT_RDirData::DoCleanup()
153 INFO_PRINTF1(_L("Deleting current RDir"));
163 iExpectedNames->ResetAndDestroy();
166 void CT_RDirData::DoCmdNew()
168 INFO_PRINTF1(_L("Create new RDirs class instance"));
173 TRAPD(err, iRDir = new (ELeave) RDir());
174 if ( err != KErrNone )
176 ERR_PRINTF2(_L("new error %d"), err);
181 void CT_RDirData::DoCmdClose()
186 INFO_PRINTF1(_L("Closing RDir"));
190 void CT_RDirData::DoCmdDestructor()
192 * Destroy RDir the object
195 INFO_PRINTF1(_L("Destroying the RDir object"));
199 void CT_RDirData::DoCmdOpenL(const TDesC& aSection)
201 INFO_PRINTF1(_L("Opening directory!"));
203 TBool dataOk = ETrue;
206 RFs* rfsObject = NULL;
207 if(GET_MANDATORY_STRING_PARAMETER(KRFsObjectName(), aSection, rfsObjectName))
209 rfsObject = (RFs*)GetDataObjectL(rfsObjectName);
217 if(!GET_MANDATORY_STRING_PARAMETER(KPath(), aSection, path))
222 TUidType uidType = KNullUid;
224 TBool isUidType = EFalse;
226 TUint attMask = KEntryAttNormal;
227 INFO_PRINTF2(_L("section name - %S"),&aSection);
229 if(!FileserverUtil::GetAttMask(*this, aSection, KEntryAttMask(), attMask))
231 if (GET_MANDATORY_INT_PARAMETER(KTUidType(), aSection, intUIDType))
233 TUid id = TUid::Uid(intUIDType);
234 uidType = TUidType(id);
235 INFO_PRINTF2(_L("UID type set to %d"), uidType[0].iUid);
241 ERR_PRINTF2(_L("attmask or %S must be declared !!!"), &KTUidType);
251 err = iRDir->Open(*rfsObject, path, uidType);
255 err = iRDir->Open(*rfsObject, path, attMask);
260 INFO_PRINTF2(_L("Open() error: %d"), err);
265 INFO_PRINTF1(_L("Directory has been opened!"));
270 void CT_RDirData::DoCmdReadL(const TDesC& aSection, const TInt aAsyncErrorIndex)
272 INFO_PRINTF1(_L("Reading directory!"));
274 TBool async = EFalse;
275 TBool readArray = EFalse;
276 TBool compare = EFalse;
278 GET_OPTIONAL_BOOL_PARAMETER(KAsync(), aSection, async);
280 if(GET_OPTIONAL_BOOL_PARAMETER(KReadArray(),aSection,readArray))
282 ReadExpectedNamesL( aSection);
285 if(GET_OPTIONAL_BOOL_PARAMETER(KCompareFiles(),aSection,compare))
290 TPtrC entryArrayName;
291 if (GET_OPTIONAL_STRING_PARAMETER(KArrayObjectName(), aSection, entryArrayName))
293 TEntryArray* entryArray = new(ELeave) TEntryArray();
294 CleanupStack::PushL(entryArray);
296 CT_EntryArrayData* entryArrayWrapper =
297 static_cast<CT_EntryArrayData*> (GetDataWrapperL(entryArrayName));
298 if (entryArrayWrapper)
300 entryArrayWrapper->SetObjectL(entryArray);
304 ERR_PRINTF2(_L("Not initialized %S"), &entryArrayName);
305 SetBlockResult(EFail);
307 CleanupStack::Pop(entryArray);
311 iObjName = entryArrayName;
312 iRDir->Read(*entryArray, iReadBlock->iStatus);
313 iReadBlock->Activate(aAsyncErrorIndex);
318 TInt err = iRDir->Read(*entryArray);
320 if((err == KErrNone) || (err == KErrEof))
322 INFO_PRINTF1(_L("Read function completed successfully"));
326 CompareEntryArray(entryArray);
331 ERR_PRINTF2(_L("Read function failed with error: %d"), err);
339 if (GET_MANDATORY_STRING_PARAMETER(KEntryObjectName(), aSection, entryName))
341 TEntry* entry = new(ELeave) TEntry();
342 CleanupStack::PushL(entry);
344 CT_EntryData* entryWrapper =
345 static_cast<CT_EntryData*> (GetDataWrapperL(entryName));
349 entryWrapper->SetObjectL(entry);
353 ERR_PRINTF2(_L("Not initialized %S"), &entryName);
354 SetBlockResult(EFail);
357 CleanupStack::Pop(entry);
361 iObjName = entryName;
364 iEntry = new(ELeave) TPckg<TEntry>(*entry);
365 iRDir->Read(*iEntry, iRead->iStatus);
366 iRead->Activate(aAsyncErrorIndex);
371 TInt err = iRDir->Read(*entry);
373 if((err == KErrNone) || (err == KErrEof))
375 INFO_PRINTF1(_L("Read function completed successfully"));
379 CompareEntryData(entry);
384 ERR_PRINTF2(_L("Read function failed with error: %d"), err);
393 void CT_RDirData::ReadExpectedNamesL( const TDesC& aSection )
395 * Read list of expected file names from ili file
398 iExpectedNames->ResetAndDestroy();
400 TBool moreData = EFalse;
404 TBuf<KBufferLength> tempStore;
405 tempStore.Format(KParamExpectedFileName(), ++index);
407 moreData = GET_OPTIONAL_STRING_PARAMETER(tempStore, aSection, fileName);
410 TPath* path = new(ELeave) TPath(fileName);
411 CleanupStack::PushL(path);
412 iExpectedNames->AppendL(path);
420 void CT_RDirData::CompareEntryArray(TEntryArray* aEntryArray)
422 * Compare TEntryArray entryes with list of expected files
425 if(aEntryArray->Count() == iExpectedNames->Count())
427 for(TInt i = 0; i < aEntryArray->Count(); i++)
430 for(TInt k = 0; !eof && (k < iExpectedNames->Count()); k++)
432 TEntry* tmpEntry = new(ELeave) TEntry();
433 *tmpEntry = aEntryArray->operator[](i);
434 if(*(iExpectedNames->operator[](k)) == tmpEntry->iName)
436 TPath* name = iExpectedNames->operator[](k);
437 INFO_PRINTF3( _L( "Entry name = expected name, %S = %S"), &tmpEntry->iName, name);
439 iExpectedNames->Remove(k);
447 if(iExpectedNames->Count() > 0)
449 ERR_PRINTF1(_L("TEntryArray members are not equal to expected"));
450 SetBlockResult(EFail);
454 INFO_PRINTF1( _L( "TEntryArray members are equal to expected"));
457 else if(aEntryArray->Count() > iExpectedNames->Count())
459 ERR_PRINTF1(_L("Found unexpecded file(s)"));
460 SetBlockResult(EFail);
462 else if(aEntryArray->Count() < iExpectedNames->Count())
464 ERR_PRINTF1(_L("List of expected files more than amount of real files"));
465 SetBlockResult(EFail);
469 void CT_RDirData::CompareEntryData(TEntry* aEntry)
471 * Compare TEntry with entry in list of expected files
475 TBool fileCompare = EFalse;
476 for(TInt i = 0; !eof && (i < iExpectedNames->Count()); i++)
478 if(*(iExpectedNames->operator[](i)) == aEntry->iName)
480 TPath* name = iExpectedNames->operator[](i);
483 iExpectedNames->Remove(i);
490 ERR_PRINTF2(_L("Unexpected file - %S"),&aEntry->iName);
491 SetBlockResult(EFail);
496 void CT_RDirData::RunL(CActive* aActive, TInt aIndex)
498 INFO_PRINTF1(_L("RunL Called!"));
500 if ((aActive == iReadBlock) || (aActive == iRead))
503 TInt err = aActive->iStatus.Int();
506 TEntry &actualEntry = iEntry->operator()();
507 INFO_PRINTF2(_L("Asynchronous Read function completed successfully, %S"),&(actualEntry.iName));
509 else if (err == KErrEof)
511 INFO_PRINTF1(_L("Asynchronous Read function reached the end and returned expectedly KErrEof"));
512 SetAsyncError(aIndex, err);
516 ERR_PRINTF2(_L("RunL Error: %d"), err);
517 SetAsyncError(aIndex, err);
521 if(iCompare && ((err == KErrNone) || (err == KErrEof)))
523 if(aActive == iReadBlock)
525 TEntryArray *entryArray = static_cast<TEntryArray*>(GetDataObjectL(iObjName));
528 CompareEntryArray(entryArray);
532 SetBlockResult(EFail);
533 ERR_PRINTF2(_L("Empty Object: %S"), &iObjName);
536 else if(aActive == iRead)
538 TEntry* entry = static_cast<TEntry*>(GetDataObjectL(iObjName));
541 CompareEntryData(entry);
545 SetBlockResult(EFail);
546 ERR_PRINTF2(_L("Empty Object: %S"), &iObjName);
558 ERR_PRINTF1( _L("Stray RunL signal") );
559 SetBlockResult( EFail );
563 void CT_RDirData::DoCancel(CActive* aActive, TInt aIndex)
565 INFO_PRINTF1(_L("DoCancel Called!"));
567 if ( aActive == iRead )
569 TInt err = aActive->iStatus.Int();
572 ERR_PRINTF2(_L("DoCancel Error: %d"), err);
573 SetAsyncError(aIndex, err);
579 ERR_PRINTF1( _L("Stray RunL signal") );
580 SetBlockResult( EFail );