sl@0: // Copyright (c) 2007-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 the License "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: #include "stacked3_plugin.h" sl@0: #include "plugincommon.h" sl@0: sl@0: sl@0: /** sl@0: Leaving New function for the plugin sl@0: @internalComponent sl@0: */ sl@0: CStacked3Plugin* CStacked3Plugin::NewL() sl@0: { sl@0: CStacked3Plugin* self = new(ELeave) CStacked3Plugin; sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: sl@0: /** sl@0: Constructor for the plugin sl@0: @internalComponent sl@0: */ sl@0: CStacked3Plugin::CStacked3Plugin() : iInterceptsEnabled(EFalse), sl@0: iLogging(ETrue) sl@0: { sl@0: } sl@0: sl@0: sl@0: void CStacked3Plugin::ConstructL() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: The destructor for the plugin sl@0: @internalComponent sl@0: */ sl@0: CStacked3Plugin::~CStacked3Plugin() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Initialise the plugin. sl@0: @internalComponent sl@0: */ sl@0: void CStacked3Plugin::InitialiseL() sl@0: { sl@0: EnableInterceptsL(); sl@0: } sl@0: sl@0: /** sl@0: Enable the plugin's intercepts. sl@0: @internalComponent sl@0: */ sl@0: void CStacked3Plugin::EnableInterceptsL() sl@0: { sl@0: if (iInterceptsEnabled) return; sl@0: sl@0: User::LeaveIfError(RegisterIntercept(EFsFileWrite, EPreIntercept)); sl@0: sl@0: _LOG(_L("Stacked3 Plugin: Enabled intercepts.")); sl@0: sl@0: iInterceptsEnabled = ETrue; sl@0: } sl@0: sl@0: /** sl@0: Disable the plugin's intercepts. sl@0: @internalComponent sl@0: */ sl@0: void CStacked3Plugin::DisableInterceptsL() sl@0: { sl@0: if (!iInterceptsEnabled) return; sl@0: sl@0: User::LeaveIfError(UnregisterIntercept(EFsFileWrite, EPreIntercept)); sl@0: sl@0: _LOG(_L("Stacked3 Plugin: Disabled intercepts.")); sl@0: sl@0: iInterceptsEnabled = EFalse; sl@0: } sl@0: sl@0: /** sl@0: Handle requests sl@0: @internalComponent sl@0: */ sl@0: TInt CStacked3Plugin::DoRequestL(TFsPluginRequest& aRequest) sl@0: { sl@0: sl@0: TInt err = KErrNone; sl@0: sl@0: TInt function = aRequest.Function(); sl@0: sl@0: switch(function) sl@0: { sl@0: case EFsFileRead: sl@0: break; sl@0: sl@0: case EFsFileWrite: sl@0: TRAP(err, FsFileWriteL(aRequest)); sl@0: break; sl@0: sl@0: default: sl@0: break; sl@0: } sl@0: sl@0: return err; sl@0: } sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: void CStacked3Plugin::FsFileWriteL(TFsPluginRequest& aRequest) sl@0: { sl@0: TInt length = 0; sl@0: TInt64 pos = 0; sl@0: TFileName filename; sl@0: TParse parse; sl@0: sl@0: TInt err = aRequest.FileName(filename); sl@0: iLastError = err; sl@0: iLineNumber = __LINE__; sl@0: if(err!=KErrNone) sl@0: User::Leave(err); //trapped in DoRequestL sl@0: sl@0: err = aRequest.Read(TFsPluginRequest::ELength, length); sl@0: iLastError = err; sl@0: iLineNumber = __LINE__; sl@0: if(err!=KErrNone) sl@0: User::Leave(err); //trapped in DoRequestL sl@0: sl@0: err = aRequest.Read(TFsPluginRequest::EPosition, pos); sl@0: iLastError = err; sl@0: iLineNumber = __LINE__; sl@0: if(err!=KErrNone) sl@0: User::Leave(err); //trapped in DoRequestL sl@0: sl@0: parse.Set(filename, NULL, NULL); sl@0: sl@0: _LOG4(_L("CStacked3Plugin::FsFileWriteL, file: %S, pos: %d, length: %d"), &filename, pos, length); sl@0: sl@0: if (aRequest.IsPostOperation()) sl@0: { sl@0: _LOG(_L("CStacked3Plugin::FsFileWriteL, post intercept")); sl@0: } sl@0: else sl@0: { sl@0: _LOG(_L("CStacked3Plugin::FsFileWriteL, pre intercept")); sl@0: sl@0: //set up test data for plugin sl@0: TBuf8<20> wbuffer; sl@0: wbuffer.Copy(_L8("HELLO WORLD SYMBIAN")); sl@0: TInt length = wbuffer.Length(); sl@0: sl@0: HBufC8* tempBuf = HBufC8::NewMaxLC(length); sl@0: TPtr8 tempBufPtr((TUint8 *)tempBuf->Des().Ptr(), length, length); sl@0: sl@0: RFilePlugin fileplugin(aRequest); sl@0: err = fileplugin.AdoptFromClient(); sl@0: iLastError = err; sl@0: iLineNumber = __LINE__; sl@0: if(err!=KErrNone) sl@0: User::Leave(err); //trapped in DoRequestL sl@0: sl@0: //write to file sl@0: err = fileplugin.Write(pos, wbuffer); sl@0: _LOG2(_L("CStacked3Plugin::FsFileWriteL, RFilePlugin::Write returned %d"), err); sl@0: iLastError = err; sl@0: iLineNumber = __LINE__; sl@0: if(err!=KErrNone) sl@0: User::Leave(err); //trapped in DoRequestL sl@0: sl@0: //read from file sl@0: err = fileplugin.Read(pos, tempBufPtr); sl@0: _LOG2(_L("CStackedPlugin::FsFileWriteL, RFilePlugin::Read returned %d"), err); sl@0: iLastError = err; sl@0: iLineNumber = __LINE__; sl@0: if(err!=KErrNone) sl@0: User::Leave(err); //trapped in DoRequestL sl@0: sl@0: //testing the correct thing has been written to the drive sl@0: err = wbuffer.Compare(tempBufPtr); sl@0: iLastError = err; sl@0: iLineNumber = __LINE__; sl@0: if(err!=KErrNone) sl@0: User::Leave(err); //trapped in DoRequestL sl@0: sl@0: fileplugin.Close(); sl@0: CleanupStack::PopAndDestroy(); sl@0: sl@0: // send request down the stack sl@0: User::Leave(KErrCompletion); sl@0: } sl@0: } sl@0: sl@0: sl@0: CFsPluginConn* CStacked3Plugin::NewPluginConnL() sl@0: { sl@0: return new(ELeave) CStacked3PluginConn(); sl@0: } sl@0: sl@0: sl@0: //Synchronous RPlugin::DoControl sl@0: TInt CStacked3Plugin::FsPluginDoControlL(CFsPluginConnRequest& aRequest) sl@0: { sl@0: TInt err = KErrNone; sl@0: TPckg errCodeDes(iLastError); sl@0: TPckg lineNumberDes(iLineNumber); sl@0: sl@0: TInt function = aRequest.Function(); sl@0: switch(function) sl@0: { sl@0: case KPluginSetDrive: sl@0: { sl@0: TPckg drive(iDriveToTest); sl@0: TRAP(err,aRequest.ReadParam1L(drive)); sl@0: break; sl@0: } sl@0: case KPluginGetError: sl@0: { sl@0: TRAP(err,aRequest.WriteParam1L(errCodeDes)); sl@0: TRAP(err,aRequest.WriteParam2L(lineNumberDes)); sl@0: break; sl@0: } sl@0: default: sl@0: break; sl@0: } sl@0: sl@0: return err; sl@0: } sl@0: sl@0: TInt CStacked3PluginConn::DoControl(CFsPluginConnRequest& aRequest) sl@0: { sl@0: return ((CStacked3Plugin*)Plugin())->FsPluginDoControlL(aRequest); sl@0: } sl@0: sl@0: void CStacked3PluginConn::DoRequest(CFsPluginConnRequest& aRequest) sl@0: { sl@0: DoControl(aRequest); sl@0: } sl@0: sl@0: void CStacked3PluginConn::DoCancel(TInt /*aReqMask*/) sl@0: { sl@0: } sl@0: sl@0: //factory functions sl@0: sl@0: class CStacked3PluginFactory : public CFsPluginFactory sl@0: { sl@0: public: sl@0: CStacked3PluginFactory(); sl@0: virtual TInt Install(); sl@0: virtual CFsPlugin* NewPluginL(); sl@0: virtual CFsPlugin* NewPluginConnL(); sl@0: virtual TInt UniquePosition(); sl@0: }; sl@0: sl@0: /** sl@0: Constructor for the plugin factory sl@0: @internalComponent sl@0: */ sl@0: CStacked3PluginFactory::CStacked3PluginFactory() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Install function for the plugin factory sl@0: @internalComponent sl@0: */ sl@0: TInt CStacked3PluginFactory::Install() sl@0: { sl@0: //SetSupportedDrives(1<<23); sl@0: iSupportedDrives = 1<<23; sl@0: return(SetName(&KStacked3PluginName)); sl@0: } sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: TInt CStacked3PluginFactory::UniquePosition() sl@0: { sl@0: return(KStacked3Pos); sl@0: } sl@0: sl@0: /** sl@0: Plugin factory function sl@0: @internalComponent sl@0: */ sl@0: CFsPlugin* CStacked3PluginFactory::NewPluginL() sl@0: sl@0: { sl@0: return CStacked3Plugin::NewL(); sl@0: } sl@0: sl@0: /** sl@0: Plugin factory function sl@0: @internalComponent sl@0: */ sl@0: CFsPlugin* CStacked3PluginFactory::NewPluginConnL() sl@0: sl@0: { sl@0: return CStacked3Plugin::NewL(); sl@0: } sl@0: sl@0: /** sl@0: Create a new Plugin sl@0: @internalComponent sl@0: */ sl@0: extern "C" { sl@0: sl@0: EXPORT_C CFsPluginFactory* CreateFileSystem() sl@0: { sl@0: return(new CStacked3PluginFactory()); sl@0: } sl@0: } sl@0: