os/kernelhwsrv/kerneltest/f32test/plugins/version_2/src/unremovable_plugin.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Template_plugin.cpp
    15 // 
    16 //
    17 
    18 #include "unremovable_plugin.h"
    19 #include "plugincommon.h"
    20 #include <f32pluginutils.h>
    21 
    22 /**
    23 Leaving New function for the plugin
    24 @internalComponent
    25 */
    26 CUnremovablePlugin* CUnremovablePlugin::NewL()
    27 	{
    28 	CUnremovablePlugin* self = new(ELeave) CUnremovablePlugin;
    29     CleanupStack::PushL(self);
    30     self->ConstructL();
    31     CleanupStack::Pop();
    32 	return self;
    33 	}
    34 
    35 
    36 /**
    37 Constructor for the plugin
    38 @internalComponent
    39 */
    40 CUnremovablePlugin::CUnremovablePlugin() : iInterceptsEnabled(EFalse),
    41 									 iLogging(ETrue)
    42 	{
    43 	}
    44 
    45 
    46 void CUnremovablePlugin::ConstructL()
    47 	{
    48 	iRemovable = EFalse;
    49 	}
    50 
    51 /**
    52 The destructor for the plugin
    53 @internalComponent
    54 */
    55 CUnremovablePlugin::~CUnremovablePlugin()
    56 	{
    57 	iFs.Close();
    58 	}
    59 
    60 /**
    61 Initialise the plugin.
    62 @internalComponent
    63 */
    64 void CUnremovablePlugin::InitialiseL()
    65 	{
    66 	User::LeaveIfError(iFs.Connect());
    67 	CleanupClosePushL(iFs);
    68 
    69 	_LOG(_L("CUnremovablePlugin InitialiseL"));
    70 	EnableInterceptsL();
    71 
    72 	CleanupStack::Pop(); // iFs
    73 	}
    74 
    75 /**
    76 Enable the plugin's intercepts.
    77 @internalComponent
    78 */
    79 void CUnremovablePlugin::EnableInterceptsL()
    80 	{
    81 	if (iInterceptsEnabled) return;
    82 
    83 	User::LeaveIfError(RegisterIntercept(EFsDismountPlugin,EPreIntercept));
    84 
    85 	_LOG(_L("CUnremovablePlugin : Enabled intercepts."));
    86 
    87 	iInterceptsEnabled = ETrue;
    88 	}
    89 
    90 /**
    91 Disable the plugin's intercepts.
    92 @internalComponent
    93 */
    94 void CUnremovablePlugin::DisableInterceptsL()
    95 	{
    96 	if (!iInterceptsEnabled) return;
    97 
    98 	User::LeaveIfError(UnregisterIntercept(EFsDismountPlugin,EPreIntercept));
    99 	
   100 	_LOG(_L("CUnremovablePlugin : Disabled intercepts."));
   101 
   102 	iInterceptsEnabled = EFalse;
   103 	}
   104 
   105 /**
   106 Handle requests to Dismount the plugin only.
   107 This plugin is designed such that its removal is not allowed.
   108 @internalComponent
   109 */
   110 TInt CUnremovablePlugin::DoRequestL(TFsPluginRequest& aRequest)
   111 	{
   112 	TInt err = KErrNone;
   113 
   114 	TInt function = aRequest.Function();
   115 
   116 	if (aRequest.IsPostOperation())
   117 		{
   118 		_LOG2(_L("CUnremovablePlugin post intercept for function %d"), function);
   119 		//We should never get here
   120 		//Is it even correct to post-intercept a EFsDismountPlugin ??
   121 		User::Invariant();
   122 		}
   123 	else
   124 		{
   125 		_LOG2(_L("CUnremovablePlugin pre intercept for function %d"), function);
   126 
   127 		//If a user is trying to dismount this plugin and this plugin doesn't want
   128 		//to be dismounted then we should eb able to intecept this and return KErrAccessDenied or some
   129 		//appropriate error code.
   130 
   131 		if(iRemovable)
   132 			{
   133 			return KErrNone;
   134 			}
   135 		else
   136 			{
   137 			return KErrPermissionDenied;	
   138 			}
   139 		
   140 		}
   141 
   142 	return err;
   143 	}
   144 
   145 
   146 CFsPluginConn* CUnremovablePlugin::NewPluginConnL()
   147 	{
   148 	return new(ELeave) CUnremovablePluginConn();
   149 	}
   150 
   151 
   152 //Synchronous RPlugin::DoControl
   153 TInt CUnremovablePlugin::FsPluginDoControlL(CFsPluginConnRequest& aRequest)
   154 	{
   155 	TInt err = KErrNone;
   156 
   157 	//We can use this to set the drive
   158 	//We can store this as a member of this class.
   159 	TInt function = aRequest.Function();
   160 	TPckg<TInt> removableDes(iRemovable);
   161 	
   162 	switch(function)
   163 		{
   164 		//case KPluginGetError:
   165 		//	{
   166 		//	TPckg<TInt> errCodeDes(iLastError);
   167 		//	TPckg<TInt> errMsgDes(iMessage);
   168 		//	TRAP(err,aRequest.WriteParam1L(errCodeDes));
   169 		//	TRAP(err,aRequest.WriteParam2L(errMsgDes));
   170 		//	break;
   171 		//	}
   172 		case KPluginSetRemovable:
   173 			{
   174 			TRAP(err,aRequest.ReadParam1L(removableDes));
   175 			break;
   176 			}
   177 		default:
   178 			break;
   179 		}
   180 
   181 	return err;
   182 	}
   183 
   184 TInt CUnremovablePluginConn::DoControl(CFsPluginConnRequest& aRequest)
   185 	{
   186 	return ((CUnremovablePlugin*)Plugin())->FsPluginDoControlL(aRequest);
   187 	}
   188 
   189 void CUnremovablePluginConn::DoRequest(CFsPluginConnRequest& aRequest)
   190 	{
   191 	DoControl(aRequest);
   192 	}
   193 
   194 void CUnremovablePluginConn::DoCancel(TInt /*aReqMask*/)
   195 	{
   196 	}
   197 
   198 
   199 //factory functions
   200 
   201 class CUnremovablePluginFactory : public CFsPluginFactory
   202 	{
   203 public:
   204 	CUnremovablePluginFactory();
   205 	virtual TInt Install();
   206 	virtual CFsPlugin* NewPluginL();
   207 	virtual CFsPlugin* NewPluginConnL();
   208 	virtual TInt UniquePosition();
   209 	};
   210 
   211 /**
   212 Constructor for the plugin factory
   213 @internalComponent
   214 */
   215 CUnremovablePluginFactory::CUnremovablePluginFactory()
   216 	{
   217 	}
   218 
   219 /**
   220 Install function for the plugin factory
   221 @internalComponent
   222 */
   223 TInt CUnremovablePluginFactory::Install()
   224 	{
   225 	iSupportedDrives = KPluginAutoAttach;
   226 	return(SetName(&KUnremovablePluginName));
   227 	}
   228 
   229 /**
   230 @internalComponent
   231 */
   232 TInt CUnremovablePluginFactory::UniquePosition()
   233 	{
   234 	return(KUnremovablePos);
   235 	}
   236 
   237 /**
   238 Plugin factory function
   239 @internalComponent
   240 */
   241 CFsPlugin* CUnremovablePluginFactory::NewPluginL()
   242 
   243 	{
   244 	return CUnremovablePlugin::NewL();
   245 	}
   246 
   247 /**
   248 Plugin factory function
   249 @internalComponent
   250 */
   251 CFsPlugin* CUnremovablePluginFactory::NewPluginConnL()
   252 
   253 	{
   254 	return CUnremovablePlugin::NewL();
   255 	}
   256 
   257 /**
   258 Create a new Plugin
   259 @internalComponent
   260 */
   261 extern "C" {
   262 
   263 EXPORT_C CFsPluginFactory* CreateFileSystem()
   264 	{
   265 	return(new CUnremovablePluginFactory());
   266 	}
   267 }
   268