// --------------------------------------------------------------------------- // Completes the message // --------------------------------------------------------------------------- // void CCatalogsBaseMessageImpl::CompleteAndReleaseL( RFs& /*aFs*/, RFile& aFile ) { DLTRACEIN(("RFs, RFile,handle: %d, this: %x", Handle(), this)); if ( iSenderLost ) { DLINFO(("Sender was lost, deleting message")); delete this; DLTRACEOUT(("")); return; } //DLTRACE(("Sharing the file session")); //User::LeaveIfError( aFs.ShareProtected() ); DLTRACE(("TransferToClient, completes the message if successful")); aFile.TransferToClient( iMessage, KOutputSlot ); DLTRACE(("Transferred")); // The message should be complete /** * How to handle errors? */ DASSERT( iMessage.IsNull() ); delete this; DLTRACEOUT(("")); }
void CScrHelperSession::GetFileHandleL(RFs& aFs, const RMessage2& aMessage, const TDesC& aFileName) { DEBUG_PRINTF2(_L("Returning file handle of %S."), &aFileName); RBuf filePath; filePath.CreateL(aFileName.Length()); filePath.CleanupClosePushL(); filePath.Copy(aFileName); filePath[0] = aFs.GetSystemDriveChar(); TInt err = aFs.MkDirAll(filePath); if(KErrNone != err && KErrAlreadyExists != err) { DEBUG_PRINTF3(_L("An error (%d) occured while making all directories of %S."), err, &filePath); User::Leave(err); } RFile file; TEntry entry; if(KErrNone == aFs.Entry(filePath, entry)) { // The file exists, just open it. User::LeaveIfError(file.Open(aFs, filePath, EFileShareAny|EFileWrite)); } else { // The file doesn't exist. First, check if the requested file is database or journal file. if(KScrDatabaseFilePath() == aFileName) { // This is the database file. Copy the default one into the requested location. DEBUG_PRINTF(_L8("SCR database file doesn't exist. It is being copied from ROM")); CopyDbFromROMToSystemL(aFs, filePath); // Then, open the file. User::LeaveIfError(file.Open(aFs, filePath, EFileShareAny|EFileWrite)); } else { // This is the journal file, simply create an empty file. User::LeaveIfError(file.Create(aFs, filePath, EFileShareAny|EFileWrite)); } } CleanupStack::PopAndDestroy(&filePath); CleanupClosePushL(file); // Store the RFile handle into the package buffer in slot 0 and complete the message with the RFs handle User::LeaveIfError(file.TransferToClient(aMessage, 0)); ASSERT(aMessage.IsNull()); // The message should have been completed CleanupStack::PopAndDestroy(&file); }
void CTestUtilSessionSwi::ServiceL(const RMessage2& aMessage) { switch (aMessage.Function()) { case ECopy: { HBufC* source = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0); HBufC* destination = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,1); TInt err = Server().FileMan().Copy(*source, *destination, CFileMan::ERecurse | CFileMan::EOverWrite); if (err == KErrNone) { // Turn off the read only attributes TTime time(0); // must specify 0, or a valid time, otherwise sets time to a random value and causes -6/-21 errors err = Server().FileMan().Attribs(*destination, 0, KEntryAttReadOnly, time, CFileMan::ERecurse); } CleanupStack::PopAndDestroy(destination); CleanupStack::PopAndDestroy(source); aMessage.Complete(err); break; } case EMove: { HBufC* source = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0); HBufC* destination = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,1); TInt err = Server().FS().Rename(*source,*destination); if (err == KErrNone) { // Turn off the read only attributes TTime time(0); // must specify 0, or a valid time, otherwise sets time to a random value and causes -6/-21 errors err = Server().FileMan().Attribs(*destination, 0, KEntryAttReadOnly, time, CFileMan::ERecurse); } CleanupStack::PopAndDestroy(destination); CleanupStack::PopAndDestroy(source); aMessage.Complete(err); break; } case EDelete: { HBufC* fileName = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0); TEntry entry; TInt err = Server().FS().Entry(*fileName, entry); if (err == KErrNone) { if (entry.IsDir()) { TPath pathName(*fileName); if (pathName[pathName.Length() - 1] != KPathDelimiter) { pathName.Append(KPathDelimiter); } err = Server().FileMan().RmDir(pathName); } else { err = Server().FS().Delete(*fileName); } } CleanupStack::PopAndDestroy(fileName); aMessage.Complete(err); break; } case ERmDir: { HBufC* fileName = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0); TParsePtrC parsePtr(*fileName); if(parsePtr.IsRoot()) { User::Leave(KErrAccessDenied); } TInt err = Server().FileMan().RmDir(*fileName); CleanupStack::PopAndDestroy(fileName); aMessage.Complete(err); break; } case EMkDirAll: { HBufC* fileName = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0); TInt err = Server().FS().MkDirAll(*fileName); CleanupStack::PopAndDestroy(fileName); aMessage.Complete(err); break; } case EFileExists: { delete iDetector; iDetector=CTestFileDetector::NewL(aMessage, Server().FS()); iDetector->DetectFile(); break; } case ELock: { HBufC* fileName = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0); RFile lockFile; TInt err = lockFile.Open(Server().FS(), *fileName, EFileWrite); if (err == KErrNone) iLockedFileHandles.Append(lockFile); CleanupStack::PopAndDestroy(fileName); aMessage.Complete(err); break; } case EUnlock: { HBufC* fileName = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0); TInt err = KErrNotFound; TFileName lockedFileName; for (TInt i = 0; i < iLockedFileHandles.Count() && err;i++) { TInt err2 = iLockedFileHandles[i].FullName(lockedFileName); User::LeaveIfError(err2); if (lockedFileName.MatchF(*fileName) != KErrNotFound) { iLockedFileHandles[i].Close(); iLockedFileHandles.Remove(i); err = KErrNone; } } CleanupStack::PopAndDestroy(fileName); aMessage.Complete(err); break; } case EFormat: { TInt drive = aMessage.Int0(); TBool formatFatOnly = aMessage.Int1(); TChar aDriveChar; User::LeaveIfError(Server().FS().DriveToChar(drive, aDriveChar)); TBuf<3> bfDrv; bfDrv.Append(aDriveChar); bfDrv.Append(KBP); RFormat format; TInt count; User::LeaveIfError(format.Open(Server().FS(), bfDrv, EHighDensity, count)); CleanupClosePushL(format); if (formatFatOnly) { User::LeaveIfError(format.Next(count)); } else { while (count > 0) { User::LeaveIfError(format.Next(count)); } } CleanupStack::PopAndDestroy(&format); aMessage.Complete(KErrNone); break; } case EMount: { TInt drive = aMessage.Int0(); User::LeaveIfError(Server().FS().Connect()); //Mount the drive synchronizely to make sure the drive is ready for the next operation User::LeaveIfError(Server().FS().MountFileSystem(KFAT, drive, ETrue)); aMessage.Complete(KErrNone); break; } case EUnMount: { TInt drive = aMessage.Int0(); TFileName fsName; User::LeaveIfError(Server().FS().FileSystemName(fsName, drive)); User::LeaveIfError(Server().FS().DismountFileSystem(fsName, drive)); aMessage.Complete(KErrNone); break; } case ESetReadOnly: { HBufC* fileName = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0); TInt setReadOnly = aMessage.Int1(); TUint setmask; TUint clearmask; if (setReadOnly) { // Setting read only attribute setmask = KEntryAttReadOnly; clearmask = 0; } else { // Clearing read only attribute setmask = 0; clearmask = KEntryAttReadOnly; } // Turn off the read only attributes TTime time(0); TInt err = Server().FileMan().Attribs(*fileName, setmask, clearmask, time); CleanupStack::PopAndDestroy(fileName); aMessage.Complete(err); break; } case EGetFileHandle: { HBufC* fileName = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0); RFile file; CleanupClosePushL(file); User::LeaveIfError(file.Open(Server().FS(), *fileName, EFileRead | EFileShareReadersOnly)); User::LeaveIfError(file.TransferToClient(aMessage, 1)); CleanupStack::PopAndDestroy(2, fileName); // file break; } case EWatchFile: { if (iFileWatcher) { if (iFileWatcher->IsActive()) { aMessage.Complete(KErrServerBusy); break; } else { delete iFileWatcher; iFileWatcher = NULL; } } // Create a new file watcher for this session iFileWatcher = CFileWatcher::NewL(Server().FS(), aMessage); break; } case EWatchFileCancel: { if (iFileWatcher) { iFileWatcher->Cancel(); aMessage.Complete(KErrNone); } else { // No file watch request to cancel! aMessage.Complete(KErrNotReady); } break; } case EGetNumFiles: { HBufC* dirPath = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0); CDir* dirContents = NULL; User::LeaveIfError(Server().FS().GetDir(*dirPath, KEntryAttNormal, ESortNone, dirContents)); TPckg<TInt> numFiles(dirContents->Count()); delete dirContents; aMessage.WriteL(1, numFiles); aMessage.Complete(KErrNone); CleanupStack::PopAndDestroy(dirPath); break; } case ERegenerateCache: { #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK Swi::RSisRegistryWritableSession session; User::LeaveIfError(session.Connect()); CleanupClosePushL(session); session.RegenerateCacheL(); CleanupStack::PopAndDestroy(&session); aMessage.Complete(KErrNone); #else aMessage.Complete(KErrNotSupported); #endif break; } case EGetFileHash: { HBufC* fileNameA = CTestUtilSessionCommon::AllocateInputBufferLC(aMessage,0); CMessageDigest* digest = CalculateFileHashLC(*fileNameA); aMessage.WriteL(1, digest->Final()); aMessage.Complete(KErrNone); CleanupStack::PopAndDestroy(2, fileNameA); break; } default: { PanicClient(aMessage,EPanicIllegalFunction); break; } } }