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: // Template_plugin.cpp sl@0: // sl@0: // sl@0: sl@0: #include "unremovable_plugin.h" sl@0: #include "plugincommon.h" sl@0: #include sl@0: sl@0: /** sl@0: Leaving New function for the plugin sl@0: @internalComponent sl@0: */ sl@0: CUnremovablePlugin* CUnremovablePlugin::NewL() sl@0: { sl@0: CUnremovablePlugin* self = new(ELeave) CUnremovablePlugin; 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: CUnremovablePlugin::CUnremovablePlugin() : iInterceptsEnabled(EFalse), sl@0: iLogging(ETrue) sl@0: { sl@0: } sl@0: sl@0: sl@0: void CUnremovablePlugin::ConstructL() sl@0: { sl@0: iRemovable = EFalse; sl@0: } sl@0: sl@0: /** sl@0: The destructor for the plugin sl@0: @internalComponent sl@0: */ sl@0: CUnremovablePlugin::~CUnremovablePlugin() 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 CUnremovablePlugin::InitialiseL() sl@0: { sl@0: User::LeaveIfError(iFs.Connect()); sl@0: CleanupClosePushL(iFs); sl@0: sl@0: _LOG(_L("CUnremovablePlugin 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 CUnremovablePlugin::EnableInterceptsL() sl@0: { sl@0: if (iInterceptsEnabled) return; sl@0: sl@0: User::LeaveIfError(RegisterIntercept(EFsDismountPlugin,EPreIntercept)); sl@0: sl@0: _LOG(_L("CUnremovablePlugin : 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 CUnremovablePlugin::DisableInterceptsL() sl@0: { sl@0: if (!iInterceptsEnabled) return; sl@0: sl@0: User::LeaveIfError(UnregisterIntercept(EFsDismountPlugin,EPreIntercept)); sl@0: sl@0: _LOG(_L("CUnremovablePlugin : Disabled intercepts.")); sl@0: sl@0: iInterceptsEnabled = EFalse; sl@0: } sl@0: sl@0: /** sl@0: Handle requests to Dismount the plugin only. sl@0: This plugin is designed such that its removal is not allowed. sl@0: @internalComponent sl@0: */ sl@0: TInt CUnremovablePlugin::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("CUnremovablePlugin post intercept for function %d"), function); sl@0: //We should never get here sl@0: //Is it even correct to post-intercept a EFsDismountPlugin ?? sl@0: User::Invariant(); sl@0: } sl@0: else sl@0: { sl@0: _LOG2(_L("CUnremovablePlugin pre intercept for function %d"), function); sl@0: sl@0: //If a user is trying to dismount this plugin and this plugin doesn't want sl@0: //to be dismounted then we should eb able to intecept this and return KErrAccessDenied or some sl@0: //appropriate error code. sl@0: sl@0: if(iRemovable) sl@0: { sl@0: return KErrNone; sl@0: } sl@0: else sl@0: { sl@0: return KErrPermissionDenied; sl@0: } sl@0: sl@0: } sl@0: sl@0: return err; sl@0: } sl@0: sl@0: sl@0: CFsPluginConn* CUnremovablePlugin::NewPluginConnL() sl@0: { sl@0: return new(ELeave) CUnremovablePluginConn(); sl@0: } sl@0: sl@0: sl@0: //Synchronous RPlugin::DoControl sl@0: TInt CUnremovablePlugin::FsPluginDoControlL(CFsPluginConnRequest& aRequest) sl@0: { sl@0: TInt err = KErrNone; sl@0: sl@0: //We can use this to set the drive sl@0: //We can store this as a member of this class. sl@0: TInt function = aRequest.Function(); sl@0: TPckg removableDes(iRemovable); sl@0: sl@0: switch(function) sl@0: { sl@0: //case KPluginGetError: sl@0: // { sl@0: // TPckg errCodeDes(iLastError); sl@0: // TPckg errMsgDes(iMessage); sl@0: // TRAP(err,aRequest.WriteParam1L(errCodeDes)); sl@0: // TRAP(err,aRequest.WriteParam2L(errMsgDes)); sl@0: // break; sl@0: // } sl@0: case KPluginSetRemovable: sl@0: { sl@0: TRAP(err,aRequest.ReadParam1L(removableDes)); 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 CUnremovablePluginConn::DoControl(CFsPluginConnRequest& aRequest) sl@0: { sl@0: return ((CUnremovablePlugin*)Plugin())->FsPluginDoControlL(aRequest); sl@0: } sl@0: sl@0: void CUnremovablePluginConn::DoRequest(CFsPluginConnRequest& aRequest) sl@0: { sl@0: DoControl(aRequest); sl@0: } sl@0: sl@0: void CUnremovablePluginConn::DoCancel(TInt /*aReqMask*/) sl@0: { sl@0: } sl@0: sl@0: sl@0: //factory functions sl@0: sl@0: class CUnremovablePluginFactory : public CFsPluginFactory sl@0: { sl@0: public: sl@0: CUnremovablePluginFactory(); 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: CUnremovablePluginFactory::CUnremovablePluginFactory() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Install function for the plugin factory sl@0: @internalComponent sl@0: */ sl@0: TInt CUnremovablePluginFactory::Install() sl@0: { sl@0: iSupportedDrives = KPluginAutoAttach; sl@0: return(SetName(&KUnremovablePluginName)); sl@0: } sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: TInt CUnremovablePluginFactory::UniquePosition() sl@0: { sl@0: return(KUnremovablePos); sl@0: } sl@0: sl@0: /** sl@0: Plugin factory function sl@0: @internalComponent sl@0: */ sl@0: CFsPlugin* CUnremovablePluginFactory::NewPluginL() sl@0: sl@0: { sl@0: return CUnremovablePlugin::NewL(); sl@0: } sl@0: sl@0: /** sl@0: Plugin factory function sl@0: @internalComponent sl@0: */ sl@0: CFsPlugin* CUnremovablePluginFactory::NewPluginConnL() sl@0: sl@0: { sl@0: return CUnremovablePlugin::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 CUnremovablePluginFactory()); sl@0: } sl@0: } sl@0: