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 "t_notify_plugin.h" sl@0: #include sl@0: sl@0: TChar gDriveToTest; sl@0: sl@0: /** sl@0: Leaving New function for the plugin sl@0: @internalComponent sl@0: */ sl@0: CNotifyPlugin* CNotifyPlugin::NewL() sl@0: { sl@0: CNotifyPlugin* self = new(ELeave) CNotifyPlugin; 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: CNotifyPlugin::CNotifyPlugin() : iInterceptsEnabled(EFalse), sl@0: iLogging(ETrue) sl@0: { sl@0: } sl@0: sl@0: sl@0: void CNotifyPlugin::ConstructL() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: The destructor for the plugin sl@0: @internalComponent sl@0: */ sl@0: CNotifyPlugin::~CNotifyPlugin() sl@0: { sl@0: iFs.Close(); sl@0: } sl@0: sl@0: /** sl@0: Initialise the plugin. sl@0: @internalComponent sl@0: */ sl@0: void CNotifyPlugin::InitialiseL() sl@0: { sl@0: User::LeaveIfError(iFs.Connect()); sl@0: CleanupClosePushL(iFs); sl@0: sl@0: _LOG(_L("CNotifyPlugin InitialiseL")); sl@0: EnableInterceptsL(); sl@0: sl@0: CleanupStack::Pop(); // iFs sl@0: } sl@0: sl@0: /** sl@0: Enable the plugin's intercepts. sl@0: @internalComponent sl@0: */ sl@0: void CNotifyPlugin::EnableInterceptsL() sl@0: { sl@0: if (iInterceptsEnabled) return; sl@0: sl@0: User::LeaveIfError(RegisterIntercept(EFsFileRead, EPrePostIntercept)); sl@0: User::LeaveIfError(RegisterIntercept(EFsFileWrite, EPrePostIntercept)); sl@0: User::LeaveIfError(RegisterIntercept(EFsDirOpen, EPrePostIntercept)); sl@0: User::LeaveIfError(RegisterIntercept(EFsFileLock, EPrePostIntercept)); sl@0: User::LeaveIfError(RegisterIntercept(EFsFileUnLock, EPrePostIntercept)); sl@0: User::LeaveIfError(RegisterIntercept(EFsFileSeek, EPrePostIntercept)); sl@0: User::LeaveIfError(RegisterIntercept(EFsFileSize, EPrePostIntercept)); sl@0: User::LeaveIfError(RegisterIntercept(EFsFileSetSize, EPrePostIntercept)); sl@0: User::LeaveIfError(RegisterIntercept(EFsDirReadOne, EPrePostIntercept)); sl@0: User::LeaveIfError(RegisterIntercept(EFsDirReadPacked, EPrePostIntercept)); sl@0: User::LeaveIfError(RegisterIntercept(EFsFileOpen, EPrePostIntercept)); sl@0: User::LeaveIfError(RegisterIntercept(EFsFileCreate, EPrePostIntercept)); sl@0: User::LeaveIfError(RegisterIntercept(EFsFileReplace,EPrePostIntercept)); sl@0: User::LeaveIfError(RegisterIntercept(EFsFileRename, EPrePostIntercept)); sl@0: User::LeaveIfError(RegisterIntercept(EFsReadFileSection,EPrePostIntercept)); sl@0: User::LeaveIfError(RegisterIntercept(EFsFileSubClose, EPrePostIntercept)); sl@0: sl@0: _LOG(_L("Notify 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 CNotifyPlugin::DisableInterceptsL() sl@0: { sl@0: if (!iInterceptsEnabled) return; sl@0: sl@0: User::LeaveIfError(UnregisterIntercept(EFsFileRead, EPrePostIntercept)); sl@0: User::LeaveIfError(UnregisterIntercept(EFsFileRename, EPrePostIntercept)); sl@0: User::LeaveIfError(UnregisterIntercept(EFsFileWrite, EPrePostIntercept)); sl@0: User::LeaveIfError(UnregisterIntercept(EFsDirOpen, EPrePostIntercept)); sl@0: User::LeaveIfError(UnregisterIntercept(EFsFileLock, EPrePostIntercept)); sl@0: User::LeaveIfError(UnregisterIntercept(EFsFileUnLock, EPrePostIntercept)); sl@0: User::LeaveIfError(UnregisterIntercept(EFsFileSeek, EPrePostIntercept)); sl@0: User::LeaveIfError(UnregisterIntercept(EFsFileSize, EPrePostIntercept)); sl@0: User::LeaveIfError(UnregisterIntercept(EFsFileSetSize, EPrePostIntercept)); sl@0: User::LeaveIfError(UnregisterIntercept(EFsFileCreate, EPrePostIntercept)); sl@0: User::LeaveIfError(UnregisterIntercept(EFsFileOpen, EPrePostIntercept)); sl@0: User::LeaveIfError(UnregisterIntercept(EFsFileReplace, EPrePostIntercept)); sl@0: User::LeaveIfError(UnregisterIntercept(EFsFileSubClose, EPrePostIntercept)); sl@0: User::LeaveIfError(UnregisterIntercept(EFsReadFileSection,EPrePostIntercept)); sl@0: User::LeaveIfError(UnregisterIntercept(EFsDirReadOne, EPrePostIntercept)); sl@0: User::LeaveIfError(UnregisterIntercept(EFsDirReadPacked,EPrePostIntercept)); sl@0: sl@0: sl@0: _LOG(_L("Notify 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 CNotifyPlugin::DoRequestL(TFsPluginRequest& aRequest) sl@0: { sl@0: TInt err = KErrNone; sl@0: sl@0: TInt function = aRequest.Function(); sl@0: sl@0: if (aRequest.IsPostOperation()) sl@0: { sl@0: _LOG2(_L("CNotifyPlugin post intercept for function %d"), function); sl@0: } sl@0: else if(function==EFsFileCreate) sl@0: { sl@0: _LOG2(_L("CNotifyPlugin pre intercept for function %d"), function); sl@0: sl@0: TBuf<40> basepath; sl@0: basepath.Append(gDriveToTest); sl@0: basepath.Append(_L(":\\F32-TST\\T_NOTIFIER\\")); //len=22 sl@0: sl@0: TBuf<40> path1; sl@0: path1.Copy(basepath); sl@0: path1.Append(_L("plugin.create")); sl@0: sl@0: RFilePlugin file(aRequest); sl@0: //Wrong file - should not notify sl@0: file.Replace(path1,EFileWrite); sl@0: file.Close(); sl@0: sl@0: TBuf<40> path2; sl@0: path2.Copy(basepath); sl@0: path2.Append(_L("simple.create")); sl@0: sl@0: //Correct file, Should notify? sl@0: RFilePlugin fileplugin(aRequest); sl@0: TInt r = fileplugin.Create(path2,EFileWrite); sl@0: r = fileplugin.TransferToClient(); sl@0: fileplugin.Close(); sl@0: sl@0: return KErrCompletion; sl@0: } sl@0: sl@0: return err; sl@0: } sl@0: sl@0: sl@0: CFsPluginConn* CNotifyPlugin::NewPluginConnL() sl@0: { sl@0: return new(ELeave) CNotifyPluginConn(); sl@0: } sl@0: sl@0: //Synchronous RPlugin::DoControl sl@0: TInt CNotifyPlugin::FsPluginDoControlL(CFsPluginConnRequest& aRequest) sl@0: { sl@0: TInt function = aRequest.Function(); sl@0: sl@0: switch(function) sl@0: { sl@0: case KPluginSetDrive: sl@0: { sl@0: TPckg drive(gDriveToTest); sl@0: TRAPD(err,aRequest.ReadParam1L(drive)); sl@0: if(err != KErrNone) sl@0: return err; sl@0: break; sl@0: } sl@0: default: sl@0: break; sl@0: } sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: TInt CNotifyPluginConn::DoControl(CFsPluginConnRequest& aRequest) sl@0: { sl@0: return ((CNotifyPlugin*)Plugin())->FsPluginDoControlL(aRequest); sl@0: } sl@0: sl@0: void CNotifyPluginConn::DoRequest(CFsPluginConnRequest& aRequest) sl@0: { sl@0: DoControl(aRequest); sl@0: } sl@0: sl@0: void CNotifyPluginConn::DoCancel(TInt /*aReqMask*/) sl@0: { sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: //factory functions sl@0: sl@0: class CNotifyPluginFactory : public CFsPluginFactory sl@0: { sl@0: public: sl@0: CNotifyPluginFactory(); 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: CNotifyPluginFactory::CNotifyPluginFactory() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Install function for the plugin factory sl@0: @internalComponent sl@0: */ sl@0: TInt CNotifyPluginFactory::Install() sl@0: { sl@0: SetSupportedDrives(KPluginSupportAllDrives); sl@0: return(SetName(&KNotifyPluginName)); sl@0: } sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: TInt CNotifyPluginFactory::UniquePosition() sl@0: { sl@0: return(KNotifyPos); sl@0: } sl@0: sl@0: /** sl@0: Plugin factory function sl@0: @internalComponent sl@0: */ sl@0: CFsPlugin* CNotifyPluginFactory::NewPluginL() sl@0: sl@0: { sl@0: return CNotifyPlugin::NewL(); sl@0: } sl@0: sl@0: /** sl@0: Plugin factory function sl@0: @internalComponent sl@0: */ sl@0: CFsPlugin* CNotifyPluginFactory::NewPluginConnL() sl@0: sl@0: { sl@0: return CNotifyPlugin::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 CNotifyPluginFactory()); sl@0: } sl@0: } sl@0: