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 "stacked_plugin.h" sl@0: #include "plugincommon.h" sl@0: sl@0: /** sl@0: Leaving New function for the plugin sl@0: @internalComponent sl@0: */ sl@0: CStackedPlugin* CStackedPlugin::NewL() sl@0: { sl@0: CStackedPlugin* self = new(ELeave) CStackedPlugin; 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: CStackedPlugin::CStackedPlugin() : iInterceptsEnabled(EFalse), sl@0: iLogging(ETrue) sl@0: { sl@0: } sl@0: sl@0: sl@0: void CStackedPlugin::ConstructL() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: The destructor for the plugin sl@0: @internalComponent sl@0: */ sl@0: CStackedPlugin::~CStackedPlugin() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Initialise the plugin. sl@0: @internalComponent sl@0: */ sl@0: void CStackedPlugin::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 CStackedPlugin::EnableInterceptsL() sl@0: { sl@0: if (iInterceptsEnabled) return; sl@0: sl@0: User::LeaveIfError(RegisterIntercept(EFsFileWrite, EPreIntercept)); sl@0: sl@0: _LOG(_L("Stacked 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 CStackedPlugin::DisableInterceptsL() sl@0: { sl@0: if (!iInterceptsEnabled) return; sl@0: sl@0: User::LeaveIfError(UnregisterIntercept(EFsFileWrite, EPreIntercept)); sl@0: sl@0: _LOG(_L("Stacked 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 CStackedPlugin::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: /** sl@0: @internalComponent sl@0: */ sl@0: void CStackedPlugin::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("CStackedPlugin::FsFileWriteL, file: %S, pos: %d, length: %d"), &filename, pos, length); sl@0: sl@0: if (aRequest.IsPostOperation()) sl@0: { sl@0: _LOG(_L("CStackedPlugin::FsFileWriteL, post intercept")); sl@0: } sl@0: else sl@0: { sl@0: _LOG(_L("CStackedPlugin::FsFileWriteL, pre intercept")); sl@0: sl@0: //set up test data for plugin sl@0: TBuf8<20> wbuffer; sl@0: wbuffer.Copy(_L8("HELLO SYMBIAN WORLD1")); 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: //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: //Check that correct data is in file 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(KErrNone); sl@0: } sl@0: } sl@0: sl@0: sl@0: CFsPluginConn* CStackedPlugin::NewPluginConnL() sl@0: { sl@0: return new(ELeave) CStackedPluginConn(); sl@0: } sl@0: sl@0: sl@0: //Synchronous RPlugin::DoControl sl@0: TInt CStackedPlugin::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 CStackedPluginConn::DoControl(CFsPluginConnRequest& aRequest) sl@0: { sl@0: return ((CStackedPlugin*)Plugin())->FsPluginDoControlL(aRequest); sl@0: } sl@0: sl@0: void CStackedPluginConn::DoRequest(CFsPluginConnRequest& aRequest) sl@0: { sl@0: DoControl(aRequest); sl@0: } sl@0: sl@0: void CStackedPluginConn::DoCancel(TInt /*aReqMask*/) sl@0: { sl@0: } sl@0: sl@0: //factory functions sl@0: sl@0: class CStackedPluginFactory : public CFsPluginFactory sl@0: { sl@0: public: sl@0: CStackedPluginFactory(); 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: CStackedPluginFactory::CStackedPluginFactory() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Install function for the plugin factory sl@0: @internalComponent sl@0: */ sl@0: TInt CStackedPluginFactory::Install() sl@0: { sl@0: //SetSupportedDrives(1<<23); sl@0: iSupportedDrives = 1<<23; sl@0: return(SetName(&KStackedPluginName)); sl@0: } sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: TInt CStackedPluginFactory::UniquePosition() sl@0: { sl@0: return(KStackedPos); sl@0: } sl@0: sl@0: /** sl@0: Plugin factory function sl@0: @internalComponent sl@0: */ sl@0: CFsPlugin* CStackedPluginFactory::NewPluginL() sl@0: sl@0: { sl@0: return CStackedPlugin::NewL(); sl@0: } sl@0: sl@0: /** sl@0: Plugin factory function sl@0: @internalComponent sl@0: */ sl@0: CFsPlugin* CStackedPluginFactory::NewPluginConnL() sl@0: sl@0: { sl@0: return CStackedPlugin::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 CStackedPluginFactory()); sl@0: } sl@0: } sl@0: