1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/plugins/version_2/src/unremovable_plugin.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,268 @@
1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Template_plugin.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include "unremovable_plugin.h"
1.22 +#include "plugincommon.h"
1.23 +#include <f32pluginutils.h>
1.24 +
1.25 +/**
1.26 +Leaving New function for the plugin
1.27 +@internalComponent
1.28 +*/
1.29 +CUnremovablePlugin* CUnremovablePlugin::NewL()
1.30 + {
1.31 + CUnremovablePlugin* self = new(ELeave) CUnremovablePlugin;
1.32 + CleanupStack::PushL(self);
1.33 + self->ConstructL();
1.34 + CleanupStack::Pop();
1.35 + return self;
1.36 + }
1.37 +
1.38 +
1.39 +/**
1.40 +Constructor for the plugin
1.41 +@internalComponent
1.42 +*/
1.43 +CUnremovablePlugin::CUnremovablePlugin() : iInterceptsEnabled(EFalse),
1.44 + iLogging(ETrue)
1.45 + {
1.46 + }
1.47 +
1.48 +
1.49 +void CUnremovablePlugin::ConstructL()
1.50 + {
1.51 + iRemovable = EFalse;
1.52 + }
1.53 +
1.54 +/**
1.55 +The destructor for the plugin
1.56 +@internalComponent
1.57 +*/
1.58 +CUnremovablePlugin::~CUnremovablePlugin()
1.59 + {
1.60 + iFs.Close();
1.61 + }
1.62 +
1.63 +/**
1.64 +Initialise the plugin.
1.65 +@internalComponent
1.66 +*/
1.67 +void CUnremovablePlugin::InitialiseL()
1.68 + {
1.69 + User::LeaveIfError(iFs.Connect());
1.70 + CleanupClosePushL(iFs);
1.71 +
1.72 + _LOG(_L("CUnremovablePlugin InitialiseL"));
1.73 + EnableInterceptsL();
1.74 +
1.75 + CleanupStack::Pop(); // iFs
1.76 + }
1.77 +
1.78 +/**
1.79 +Enable the plugin's intercepts.
1.80 +@internalComponent
1.81 +*/
1.82 +void CUnremovablePlugin::EnableInterceptsL()
1.83 + {
1.84 + if (iInterceptsEnabled) return;
1.85 +
1.86 + User::LeaveIfError(RegisterIntercept(EFsDismountPlugin,EPreIntercept));
1.87 +
1.88 + _LOG(_L("CUnremovablePlugin : Enabled intercepts."));
1.89 +
1.90 + iInterceptsEnabled = ETrue;
1.91 + }
1.92 +
1.93 +/**
1.94 +Disable the plugin's intercepts.
1.95 +@internalComponent
1.96 +*/
1.97 +void CUnremovablePlugin::DisableInterceptsL()
1.98 + {
1.99 + if (!iInterceptsEnabled) return;
1.100 +
1.101 + User::LeaveIfError(UnregisterIntercept(EFsDismountPlugin,EPreIntercept));
1.102 +
1.103 + _LOG(_L("CUnremovablePlugin : Disabled intercepts."));
1.104 +
1.105 + iInterceptsEnabled = EFalse;
1.106 + }
1.107 +
1.108 +/**
1.109 +Handle requests to Dismount the plugin only.
1.110 +This plugin is designed such that its removal is not allowed.
1.111 +@internalComponent
1.112 +*/
1.113 +TInt CUnremovablePlugin::DoRequestL(TFsPluginRequest& aRequest)
1.114 + {
1.115 + TInt err = KErrNone;
1.116 +
1.117 + TInt function = aRequest.Function();
1.118 +
1.119 + if (aRequest.IsPostOperation())
1.120 + {
1.121 + _LOG2(_L("CUnremovablePlugin post intercept for function %d"), function);
1.122 + //We should never get here
1.123 + //Is it even correct to post-intercept a EFsDismountPlugin ??
1.124 + User::Invariant();
1.125 + }
1.126 + else
1.127 + {
1.128 + _LOG2(_L("CUnremovablePlugin pre intercept for function %d"), function);
1.129 +
1.130 + //If a user is trying to dismount this plugin and this plugin doesn't want
1.131 + //to be dismounted then we should eb able to intecept this and return KErrAccessDenied or some
1.132 + //appropriate error code.
1.133 +
1.134 + if(iRemovable)
1.135 + {
1.136 + return KErrNone;
1.137 + }
1.138 + else
1.139 + {
1.140 + return KErrPermissionDenied;
1.141 + }
1.142 +
1.143 + }
1.144 +
1.145 + return err;
1.146 + }
1.147 +
1.148 +
1.149 +CFsPluginConn* CUnremovablePlugin::NewPluginConnL()
1.150 + {
1.151 + return new(ELeave) CUnremovablePluginConn();
1.152 + }
1.153 +
1.154 +
1.155 +//Synchronous RPlugin::DoControl
1.156 +TInt CUnremovablePlugin::FsPluginDoControlL(CFsPluginConnRequest& aRequest)
1.157 + {
1.158 + TInt err = KErrNone;
1.159 +
1.160 + //We can use this to set the drive
1.161 + //We can store this as a member of this class.
1.162 + TInt function = aRequest.Function();
1.163 + TPckg<TInt> removableDes(iRemovable);
1.164 +
1.165 + switch(function)
1.166 + {
1.167 + //case KPluginGetError:
1.168 + // {
1.169 + // TPckg<TInt> errCodeDes(iLastError);
1.170 + // TPckg<TInt> errMsgDes(iMessage);
1.171 + // TRAP(err,aRequest.WriteParam1L(errCodeDes));
1.172 + // TRAP(err,aRequest.WriteParam2L(errMsgDes));
1.173 + // break;
1.174 + // }
1.175 + case KPluginSetRemovable:
1.176 + {
1.177 + TRAP(err,aRequest.ReadParam1L(removableDes));
1.178 + break;
1.179 + }
1.180 + default:
1.181 + break;
1.182 + }
1.183 +
1.184 + return err;
1.185 + }
1.186 +
1.187 +TInt CUnremovablePluginConn::DoControl(CFsPluginConnRequest& aRequest)
1.188 + {
1.189 + return ((CUnremovablePlugin*)Plugin())->FsPluginDoControlL(aRequest);
1.190 + }
1.191 +
1.192 +void CUnremovablePluginConn::DoRequest(CFsPluginConnRequest& aRequest)
1.193 + {
1.194 + DoControl(aRequest);
1.195 + }
1.196 +
1.197 +void CUnremovablePluginConn::DoCancel(TInt /*aReqMask*/)
1.198 + {
1.199 + }
1.200 +
1.201 +
1.202 +//factory functions
1.203 +
1.204 +class CUnremovablePluginFactory : public CFsPluginFactory
1.205 + {
1.206 +public:
1.207 + CUnremovablePluginFactory();
1.208 + virtual TInt Install();
1.209 + virtual CFsPlugin* NewPluginL();
1.210 + virtual CFsPlugin* NewPluginConnL();
1.211 + virtual TInt UniquePosition();
1.212 + };
1.213 +
1.214 +/**
1.215 +Constructor for the plugin factory
1.216 +@internalComponent
1.217 +*/
1.218 +CUnremovablePluginFactory::CUnremovablePluginFactory()
1.219 + {
1.220 + }
1.221 +
1.222 +/**
1.223 +Install function for the plugin factory
1.224 +@internalComponent
1.225 +*/
1.226 +TInt CUnremovablePluginFactory::Install()
1.227 + {
1.228 + iSupportedDrives = KPluginAutoAttach;
1.229 + return(SetName(&KUnremovablePluginName));
1.230 + }
1.231 +
1.232 +/**
1.233 +@internalComponent
1.234 +*/
1.235 +TInt CUnremovablePluginFactory::UniquePosition()
1.236 + {
1.237 + return(KUnremovablePos);
1.238 + }
1.239 +
1.240 +/**
1.241 +Plugin factory function
1.242 +@internalComponent
1.243 +*/
1.244 +CFsPlugin* CUnremovablePluginFactory::NewPluginL()
1.245 +
1.246 + {
1.247 + return CUnremovablePlugin::NewL();
1.248 + }
1.249 +
1.250 +/**
1.251 +Plugin factory function
1.252 +@internalComponent
1.253 +*/
1.254 +CFsPlugin* CUnremovablePluginFactory::NewPluginConnL()
1.255 +
1.256 + {
1.257 + return CUnremovablePlugin::NewL();
1.258 + }
1.259 +
1.260 +/**
1.261 +Create a new Plugin
1.262 +@internalComponent
1.263 +*/
1.264 +extern "C" {
1.265 +
1.266 +EXPORT_C CFsPluginFactory* CreateFileSystem()
1.267 + {
1.268 + return(new CUnremovablePluginFactory());
1.269 + }
1.270 +}
1.271 +