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_FsData
28 #include "T_SfSrvServer.h"
29 #include "DataWrapperBase.h"
33 _LIT(KMessageSlots, "messageSlots");
35 _LIT(KAddress, "address");
38 _LIT(KResources, "resources");
39 _LIT(KNotify, "notify");
40 _LIT(KInRom, "inRom");
41 _LIT(KThreshold, "threshold");
42 _LIT(KDrive, "drive");
43 _LIT(KFunctionId, "functionId");
46 _LIT(KUseFreeSpace, "use_free_space");
47 _LIT(KVersionName, "name");
48 _LIT(KVersionBuild, "build");
49 _LIT(KVersionMajor, "major");
50 _LIT(KVersionMinor, "minor");
51 _LIT(KIndex, "index");
52 _LIT(KParam1, "param1");
53 _LIT(KParam2, "param2");
55 _LIT(KCount, "count");
59 _LIT(KCmdClose, "Close");
60 _LIT(KCmdDestructor, "~");
61 _LIT(KCmdConnect, "Connect");
62 _LIT(KCmdVersion, "Version");
63 _LIT(KCmdNotifyChange, "NotifyChange");
64 _LIT(KCmdNotifyChangeCancel, "NotifyChangeCancel");
65 _LIT(KCmdNotifyDiskSpace, "NotifyDiskSpace");
66 _LIT(KCmdNotifyDiskSpaceCancel, "NotifyDiskSpaceCancel");
67 _LIT(KCmdIsRomAddress, "IsRomAddress");
68 _LIT(KCmdResourceCountMarkStart, "ResourceCountMarkStart");
69 _LIT(KCmdResourceCountMarkEnd, "ResourceCountMarkEnd");
70 _LIT(KCmdResourceCount, "ResourceCount");
71 _LIT(KCmdGetNotifyUser, "GetNotifyUser");
72 _LIT(KCmdSetNotifyUser, "SetNotifyUser");
73 _LIT(KCmdSetNotifyChange, "SetNotifyChange");
74 _LIT(KCmdLoaderHeapFunction, "LoaderHeapFunction");
75 _LIT(KCmdInitialisePropertiesFile, "InitialisePropertiesFile");
78 CT_FsData* CT_FsData::NewL()
80 * Two phase constructor
83 CT_FsData* ret = new (ELeave) CT_FsData();
84 CleanupStack::PushL(ret);
86 CleanupStack::Pop(ret);
90 CT_FsData::CT_FsData()
92 * Protected constructor. First phase construction
97 void CT_FsData::ConstructL()
99 * Protected constructor. Second phase construction
105 CT_FsData::~CT_FsData()
112 iNotifyChange.ResetAndDestroy();
113 iNotifyDiskSpace.ResetAndDestroy();
114 iNotifyDismount.ResetAndDestroy();
115 iStartupInitComplete.ResetAndDestroy();
118 void CT_FsData::DoCleanup()
120 * Contains cleanup implementation
126 INFO_PRINTF1(_L("Deleting current RFs"));
132 TAny* CT_FsData::GetObject()
134 * Return a pointer to the object that the data wraps
136 * @return pointer to the object that the data wraps
142 TUint64 CT_FsData::ThreadId()
144 RThread currentThread;
145 return currentThread.Id().Id();
148 TBool CT_FsData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
150 * Process a command read from the ini file
152 * @param aCommand the command to process
153 * @param aSection the entry in the ini file requiring the command to be processed
155 * @return ETrue if the command is processed
158 TBool retVal = ETrue;
159 if (aCommand == KCmdNew)
163 else if (aCommand == KCmdClose)
167 else if (aCommand == KCmdDestructor)
171 else if (aCommand == KCmdConnect)
173 DoCmdConnect(aSection);
175 else if (aCommand == KCmdVersion)
177 DoCmdVersion(aSection);
179 else if (aCommand == KCmdNotifyChange)
181 DoCmdNotifyChangeL(aSection, aAsyncErrorIndex);
183 else if (aCommand == KCmdNotifyChangeCancel)
185 DoCmdNotifyChangeCancel(aSection);
187 else if (aCommand == KCmdNotifyDiskSpace)
189 DoCmdNotifyDiskSpaceL(aSection, aAsyncErrorIndex);
191 else if (aCommand == KCmdNotifyDiskSpaceCancel)
193 DoCmdNotifyDiskSpaceCancel(aSection);
195 else if (aCommand == KCmdIsRomAddress)
197 DoCmdIsRomAddress(aSection);
199 else if (aCommand == KCmdResourceCountMarkStart)
201 DoCmdResourceCountMarkStart();
203 else if (aCommand == KCmdResourceCountMarkEnd)
205 DoCmdResourceCountMarkEnd();
207 else if (aCommand == KCmdResourceCount)
209 DoCmdResourceCount(aSection);
211 else if (aCommand == KCmdGetNotifyUser)
213 DoCmdGetNotifyUser(aSection);
215 else if (aCommand == KCmdSetNotifyUser)
217 DoCmdSetNotifyUser(aSection);
219 else if (aCommand == KCmdLoaderHeapFunction)
221 DoCmdLoaderHeapFunctionL(aSection);
223 else if (aCommand == KCmdSetNotifyChange)
225 DoCmdSetNotifyChange(aSection);
227 else if (aCommand == KCmdInitialisePropertiesFile)
229 DoCmdInitialisePropertiesFile(aSection);
233 if (!DoCommandDrivesL(aCommand, aSection, aAsyncErrorIndex))
235 if (!DoCommandMountsL(aCommand, aSection, aAsyncErrorIndex))
237 if (!DoCommandFilesL(aCommand, aSection, aAsyncErrorIndex))
248 void CT_FsData::DoCmdNewL()
249 /** Creates new RFs class instance */
251 INFO_PRINTF1(_L("Create new RFs class instance"));
253 //Deletes previous RFs class instance if it was already created.
257 TRAPD(err, iFs = new (ELeave) RFs());
260 ERR_PRINTF2(_L("new error %d"), err);
265 void CT_FsData::DoCmdClose()
266 /** Close RFs handle */
268 INFO_PRINTF1(_L("Closing RFs"));
273 void CT_FsData::DoCmdDestructor()
274 /** Destroy RFs the object */
276 INFO_PRINTF1(_L("Destroying the RFs object"));
280 void CT_FsData::DoCmdConnect(const TDesC& aSection)
281 /** Connects a client to the file server */
284 TInt messageSlots = KFileServerDefaultMessageSlots;
285 GetIntFromConfig(aSection, KMessageSlots, messageSlots);
287 TInt err = iFs->Connect(messageSlots);
288 INFO_PRINTF2(_L("Call Connect(messageSlots = %d)"), messageSlots);
292 ERR_PRINTF2(_L("Connect() error %d"), err);
297 void CT_FsData::DoCmdVersion(const TDesC& aSection)
298 /** Gets the client side version number */
301 TVersion version=iFs->Version();
302 TVersionName versionName = version.Name();
303 INFO_PRINTF2(_L("Version name : %S"), &versionName);
304 INFO_PRINTF2(_L("Version build : %d"), (TInt)version.iBuild);
305 INFO_PRINTF2(_L("Version major : %d"), (TInt)version.iMajor);
306 INFO_PRINTF2(_L("Version minor : %d"), (TInt)version.iMinor);
309 if ( GET_OPTIONAL_STRING_PARAMETER(KVersionName, aSection, name))
311 if ( name != version.Name() )
313 ERR_PRINTF3(_L("Name does not match expected name: %S, %S"), &name, &versionName);
314 SetBlockResult(EFail);
319 if ( GET_OPTIONAL_INT_PARAMETER(KVersionBuild, aSection, intTemp) )
321 if ( intTemp != version.iBuild )
323 ERR_PRINTF1(_L("Build does not match expected build"));
324 SetBlockResult(EFail);
328 if ( GET_OPTIONAL_INT_PARAMETER(KVersionMajor, aSection, intTemp) )
330 if ( intTemp != version.iMajor )
332 ERR_PRINTF1(_L("Major does not match expected major"));
333 SetBlockResult(EFail);
337 if ( GET_OPTIONAL_INT_PARAMETER(KVersionMinor, aSection, intTemp) )
339 if ( intTemp != version.iMinor )
341 ERR_PRINTF1(_L("Minor does not match expected minor"));
342 SetBlockResult(EFail);
346 if (version.Name() == _L("") && version.iBuild == 0 && version.iMajor == 0 && version.iMinor == 0)
348 ERR_PRINTF1(_L("Some version fields are not set!"));
349 SetBlockResult(EFail);
353 void CT_FsData::DoCmdNotifyChangeL(const TDesC& aSection, const TInt aAsyncErrorIndex)
354 /** Requests a notification of change to files or directories */
356 TNotifyType type = ENotifyAll;
358 TBool dataOk = ETrue;
360 if ( GET_MANDATORY_STRING_PARAMETER(KType, aSection, typeTemp) )
362 if(!ConvertToNotifyType(typeTemp, type))
365 if(GetIntFromConfig(aSection, KType(), typeNumber))
367 type = (TNotifyType)typeNumber;
371 ERR_PRINTF3(_L("NotifyChange() incorrect parameter %S in %S"), &typeTemp, &KType());
372 SetBlockResult(EFail);
383 GET_OPTIONAL_INT_PARAMETER(KCount, aSection, count);
387 CT_ActiveNotifyChange* active = CT_ActiveNotifyChange::NewLC(count, aAsyncErrorIndex, *this);
388 iNotifyChange.AppendL(active);
389 CleanupStack::Pop(active);
392 if ( GetStringFromConfig(aSection, KPath(), path) )
394 iFs->NotifyChange(type, active->iStatus, path);
395 INFO_PRINTF1(_L("NotifyChange(TNotifyType, TRequestStatus, const TDesC)"));
399 iFs->NotifyChange(type, active->iStatus);
400 INFO_PRINTF1(_L("NotifyChange(TNotifyType TRequestStatus)"));
409 void CT_FsData::DoCmdNotifyChangeCancel(const TDesC& aSection)
410 /** Cancels outstanding request(s) for notification of change to files or directories */
414 if ( GET_MANDATORY_BOOL_PARAMETER(KAll, aSection, all) )
418 // Cancels all outstanding requests.
419 iFs->NotifyChangeCancel();
420 INFO_PRINTF1(_L("NotifyChangeCancel()"));
424 // Cancels a specific outstanding request
426 GetIntFromConfig(aSection, KIndex(), index);
428 iFs->NotifyChangeCancel(iNotifyChange[index]->iStatus);
429 INFO_PRINTF1(_L("NotifyChangeCancel(TRequestStatus)"));
434 void CT_FsData::DoCmdNotifyDiskSpaceL(const TDesC& aSection, const TInt aAsyncErrorIndex)
435 /** Requests notification when the free disk space on the specified drive crosses the specified threshold value */
437 //Get drive number from config
438 TDriveNumber drive = EDriveA;
439 TBool dataOk = ETrue;
440 if (!GetDriveNumberFromConfig(aSection, KDrive, drive))
442 ERR_PRINTF2(_L("No %S"), &KDrive());
443 SetBlockResult(EFail);
447 TBool useFreeSpace = EFalse;
448 GET_OPTIONAL_BOOL_PARAMETER(KUseFreeSpace, aSection, useFreeSpace);
450 TInt64 threshold = 0;
451 //Defining treshold by free space
454 threshold = iVolumeInfo.iFree;
455 //For Calculation free-temp(_sub), free+temp(_add)
457 if(GetIntFromConfig(aSection, KAdd, temp))
462 if(GetIntFromConfig(aSection, KSub, temp))
468 //Defining treshold by some value
472 if(GET_MANDATORY_STRING_PARAMETER(KThreshold, aSection, thold))
475 TInt err = lex.Val(threshold);
478 ERR_PRINTF1(_L("NotifyDiskSpace() bad treshold value"));
479 SetBlockResult(EFail);
487 CActiveCallback* active = CActiveCallback::NewLC(*this);
488 iNotifyDiskSpace.AppendL(active);
489 CleanupStack::Pop(active);
491 iFs->NotifyDiskSpace(threshold, drive, active->iStatus);
492 INFO_PRINTF1(_L("NotifyDiskSpace()"));
493 active->Activate(aAsyncErrorIndex);
499 void CT_FsData::DoCmdNotifyDiskSpaceCancel(const TDesC& aSection)
500 /** Cancels a specific outstanding request for free disk space notification */
505 if(GET_MANDATORY_BOOL_PARAMETER(KAll, aSection, all))
509 //Cancels all outstanding requests.
510 iFs->NotifyDiskSpaceCancel();
511 INFO_PRINTF1(_L("NotifyDiskSpaceCancel()"));
515 // Cancels a specific outstanding request
517 GetIntFromConfig(aSection, KIndex, index);
519 iFs->NotifyDiskSpaceCancel(iNotifyDiskSpace[index]->iStatus);
524 void CT_FsData::DoCmdIsRomAddress(const TDesC& aSection)
525 /** Tests whether the specified address is in ROM */
528 TUint8* address = NULL;
530 TBool dataOk = ETrue;
532 if(GetHexFromConfig(aSection, KAddress, intAddress))
534 address = (TUint8*)intAddress;
536 else if(iIsFileInRom)
538 address = iIsFileInRom;
542 ERR_PRINTF1(_L("Address not specified"));
543 SetBlockResult(EFail);
548 INFO_PRINTF2(_L("Address %X"), address);
549 //Address of file in ROM
550 TBool actual = RFs::IsRomAddress(address);
551 INFO_PRINTF2(_L("RFs::IsRomAddress() %d"), actual);
552 //Reading expected result
553 TBool expected = EFalse;
554 if ( GET_OPTIONAL_BOOL_PARAMETER(KInRom, aSection, expected) )
556 if ( expected != actual )
558 ERR_PRINTF1(_L("Expected result does not match actual"));
559 SetBlockResult(EFail);
565 void CT_FsData::DoCmdResourceCountMarkStart()
566 /** Marks the start of resource count checking */
568 iFs->ResourceCountMarkStart();
569 INFO_PRINTF1(_L("ResourceCountMarkStart()"));
572 void CT_FsData::DoCmdResourceCountMarkEnd()
573 /** Ends resource count checking */
575 iFs->ResourceCountMarkEnd();
576 INFO_PRINTF1(_L("ResourceCountMarkEnd()"));
579 void CT_FsData::DoCmdResourceCount(const TDesC& aSection)
580 /** Gets the number of currently open resources */
582 TInt resources = iFs->ResourceCount();//Number of resources currently opened
583 INFO_PRINTF2(_L("ResourceCount() = %d"), resources);
585 TInt expectedValue = 0; //Number of resources from config
586 if(GetIntFromConfig(aSection, KResources, expectedValue))
588 if (expectedValue != resources)
590 ERR_PRINTF3(_L("ResourceCount() %d != %d expected value"), resources, expectedValue);
591 SetBlockResult(EFail);
596 void CT_FsData::DoCmdGetNotifyUser(const TDesC& aSection)
597 /** Tests whether user notification of file read or write failure is in effect */
599 TBool actual = iFs->GetNotifyUser();
600 INFO_PRINTF2(_L("iFs->GetNotifyUser() %d"), actual);
602 TBool expected = EFalse;
603 if ( GET_OPTIONAL_BOOL_PARAMETER(KNotify, aSection, expected) )
605 if ( expected!=actual )
607 ERR_PRINTF1(_L("Expected result does not match actual"));
608 SetBlockResult(EFail);
613 void CT_FsData::DoCmdSetNotifyUser(const TDesC& aSection)
614 /** Sets whether the user should be notified of file read or write failure */
616 TBool notify = EFalse;
618 if(GET_MANDATORY_BOOL_PARAMETER(KNotify, aSection, notify))
620 iFs->SetNotifyUser(notify);
621 TPtrC val = notify ? _L("TRUE") : _L("FALSE");
622 INFO_PRINTF2(_L("SetNotifyUser() %S"), &val);
628 void CT_FsData::DoCmdLoaderHeapFunctionL(const TDesC& aSection)
629 /** returns KErrNotSupported*/
633 if(GetStringFromConfig(aSection, KParam1(), name))
635 //param1 = iDataDictionary->GetObject(name);
639 if(GetStringFromConfig(aSection, KParam2(), name))
641 //param2 = iDataDictionary->GetObjectL(name);
645 if(GET_MANDATORY_INT_PARAMETER(KFunctionId(), aSection, functionId))
647 TInt err = iFs->LoaderHeapFunction(functionId, param1, param2);
650 ERR_PRINTF2(_L("LoaderHeapFunction() ERROR: %d"), err);
656 void CT_FsData::DoCmdSetNotifyChange(const TDesC& aSection)
657 /** Enables/Disables change notification on a per-session basis. */
660 TBool notify = EFalse;
662 if(GET_MANDATORY_BOOL_PARAMETER(KNotify, aSection, notify))
664 TInt err = iFs->SetNotifyChange(notify);
666 TPtrC val = notify ? _L("TRUE") : _L("FALSE");
669 INFO_PRINTF2(_L("SetNotifyChange() %S"), &val);
673 ERR_PRINTF3(_L("SetNotifyChange() %S, Error: %d"), &val, err);
679 void CT_FsData::DoCmdInitialisePropertiesFile(const TDesC& aSection)
680 /** Sets the F32 properties file ONLY in ESTART */
683 if(GET_MANDATORY_STRING_PARAMETER(KFile, aSection, tempStr))
685 TBuf8<KBufferStringLength> buffer;
686 buffer.Copy(tempStr);
687 TPtrC8 iniFilePtr(buffer);
688 INFO_PRINTF2(_L("InitialisePropertiesFile() %S"), &tempStr);
690 TInt err = iFs ->InitialisePropertiesFile(iniFilePtr);
693 ERR_PRINTF2(_L("InitialisePropertiesFile() Error: %d"), err);
699 void CT_FsData::RunL(CActive* aActive, TInt aIndex)
701 INFO_PRINTF1(_L("CT_FsData::RunL Called"));
702 TBool foundActiveObject = EFalse;
705 TBool completed=ETrue;
707 // See if it is in iNotifyChange
708 count=iNotifyChange.Count();
709 for( index=0; (index<count) && (!foundActiveObject); ++index )
711 if( aActive == iNotifyChange[index] )
713 INFO_PRINTF1(_L("RunL iNotifyChange called"));
714 foundActiveObject = ETrue;
715 if ( iNotifyChange[index]->DecCount()>0 )
718 iNotifyChange[index]->Activate();
722 iNotifyChange.Remove(index);
727 // See if it is in iNotifyDiskSpace
728 count=iNotifyDiskSpace.Count();
729 for( index=0; (index<count) && (!foundActiveObject); ++index )
731 if( aActive == iNotifyDiskSpace[index] )
733 INFO_PRINTF1(_L("RunL iNotifyDiskSpace called"));
734 foundActiveObject = ETrue;
735 iNotifyDiskSpace.Remove(index);
739 // See if it is in iNotifyDismount
740 count=iNotifyDismount.Count();
741 for( index=0; (index<count) && (!foundActiveObject); ++index )
743 if( aActive == iNotifyDismount[index] )
745 INFO_PRINTF1(_L("RunL iNotifyDismount called"));
746 foundActiveObject = ETrue;
747 iNotifyDismount.Remove(index);
751 // See if it is in iStartupInitComplete
752 count=iStartupInitComplete.Count();
753 for( index=0; (index<count) && (!foundActiveObject); ++index )
755 if( aActive == iStartupInitComplete[index] )
757 INFO_PRINTF1(_L("RunL iStartupInitComplete called"));
758 foundActiveObject = ETrue;
759 iStartupInitComplete.Remove(index);
763 if( foundActiveObject )
765 TInt err = aActive->iStatus.Int();
766 if( err != KErrNone )
768 ERR_PRINTF2(_L("RunL Error %d"), err);
769 SetAsyncError( aIndex, err );
774 // Reset the outstanding request state
781 ERR_PRINTF1(_L("Stray RunL signal"));
782 SetBlockResult(EFail);
786 void CT_FsData::DoCancel(CActive* aActive, TInt aIndex)
788 TBool foundActiveObject = EFalse;
793 // See if it is in iNotifyChange
794 count=iNotifyChange.Count();
795 for( index=0; (index<count) && (!foundActiveObject); ++index )
797 if( aActive == iNotifyChange[index] )
799 INFO_PRINTF1(_L("DoCancel iNotifyChange called"));
800 foundActiveObject = ETrue;
801 iNotifyChange.Remove(index);
805 // See if it is in iNotifyDiskSpace
806 count=iNotifyDiskSpace.Count();
807 for( index=0; (index<count) && (!foundActiveObject); ++index )
809 if( aActive == iNotifyDiskSpace[index] )
811 INFO_PRINTF1(_L("DoCancel iNotifyDiskSpace called"));
812 foundActiveObject = ETrue;
813 iNotifyDiskSpace.Remove(index);
817 // See if it is in iNotifyDismount
818 count=iNotifyDismount.Count();
819 for( index=0; (index<count) && (!foundActiveObject); ++index )
821 if( aActive == iNotifyDismount[index] )
823 INFO_PRINTF1(_L("DoCancel iNotifyDismount called"));
824 foundActiveObject = ETrue;
825 iNotifyDismount.Remove(index);
829 // See if it is in iStartupInitComplete
830 count=iStartupInitComplete.Count();
831 for( index=0; (index<count) && (!foundActiveObject); ++index )
833 if( aActive == iStartupInitComplete[index] )
835 INFO_PRINTF1(_L("DoCancel iStartupInitComplete called"));
836 foundActiveObject = ETrue;
837 iStartupInitComplete.Remove(index);
841 if( foundActiveObject )
843 TInt err = aActive->iStatus.Int();
844 if( err != KErrNone )
846 ERR_PRINTF2(_L("DoCancel Error %d"), err);
847 SetAsyncError( aIndex, err );
850 // Reset the outstanding request state
857 ERR_PRINTF1(_L("Stray DoCancel signal"));
858 SetBlockResult(EFail);
861 TBool CT_FsData::ConvertToNotifyType(const TDesC& aNotifyTypeStr, TNotifyType& aNotifyType)
864 if(aNotifyTypeStr == _L("ENotifyAll"))
866 aNotifyType = ENotifyAll;
868 else if(aNotifyTypeStr == _L("ENotifyEntry"))
870 aNotifyType = ENotifyEntry;
872 else if(aNotifyTypeStr == _L("ENotifyFile"))
874 aNotifyType = ENotifyFile;
876 else if(aNotifyTypeStr == _L("ENotifyDir"))
878 aNotifyType = ENotifyDir;
880 else if(aNotifyTypeStr == _L("ENotifyAttributes"))
882 aNotifyType = ENotifyAttributes;
884 else if(aNotifyTypeStr == _L("ENotifyWrite"))
886 aNotifyType = ENotifyWrite;
888 else if(aNotifyTypeStr == _L("ENotifyDisk"))
890 aNotifyType = ENotifyDisk;
892 //For COnverting data ENotifyFile|ENotifyDir
895 TInt location=aNotifyTypeStr.Match(_L("*|*"));
896 if( location!=KErrNotFound )
898 //Converting Left part of the data
899 TPtrC tempStr=aNotifyTypeStr.Left(location);
900 ret=ConvertToNotifyType(tempStr, aNotifyType);
902 //Converting right data can be with another "|"
903 tempStr.Set(aNotifyTypeStr.Mid(location+1));
905 TNotifyType notifyTypeTmp;
906 if ( ConvertToNotifyType(tempStr, notifyTypeTmp) )
908 aNotifyType =(TNotifyType)((TInt)aNotifyType|(TInt)notifyTypeTmp);