os/kernelhwsrv/kerneltest/f32test/plugins/version_2/src/drivez_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 //
    15 
    16 #include "DriveZ_plugin.h"
    17 #include <f32pluginutils.h>
    18 #include "plugincommon.h"
    19 
    20 /**
    21 Leaving New function for the plugin
    22 @internalComponent
    23 */
    24 CDriveZPlugin* CDriveZPlugin::NewL()
    25 	{
    26 	CDriveZPlugin* self = new(ELeave) CDriveZPlugin;
    27     CleanupStack::PushL(self);
    28     self->ConstructL();
    29     CleanupStack::Pop();
    30 	return self;
    31 	}
    32 
    33 
    34 /**
    35 Constructor for the plugin
    36 @internalComponent
    37 */
    38 CDriveZPlugin::CDriveZPlugin() : iInterceptsEnabled(EFalse),
    39 									 iLogging(ETrue)
    40 	{
    41 	}
    42 
    43 
    44 void CDriveZPlugin::ConstructL()
    45 	{
    46 	}
    47 
    48 /**
    49 The destructor for the plugin
    50 @internalComponent
    51 */
    52 CDriveZPlugin::~CDriveZPlugin()
    53 	{
    54 	iFs.Close();
    55 	}
    56 
    57 /**
    58 Initialise the plugin.
    59 @internalComponent
    60 */
    61 void CDriveZPlugin::InitialiseL()
    62 	{
    63 	User::LeaveIfError(iFs.Connect());
    64 	CleanupClosePushL(iFs);
    65 
    66 	_LOG(_L("CDriveZPlugin InitialiseL"));
    67 	EnableInterceptsL();
    68 	
    69 	CleanupStack::Pop(); // iFs
    70 	}
    71 
    72 /**
    73 Enable the plugin's intercepts.
    74 @internalComponent
    75 */
    76 void CDriveZPlugin::EnableInterceptsL()
    77 	{
    78 	if (iInterceptsEnabled) return;
    79 	
    80 	User::LeaveIfError(RegisterIntercept(EFsFileRead,		EPrePostIntercept));
    81 	User::LeaveIfError(RegisterIntercept(EFsFileWrite,		EPrePostIntercept));
    82 	User::LeaveIfError(RegisterIntercept(EFsDirOpen,		EPrePostIntercept));
    83 	User::LeaveIfError(RegisterIntercept(EFsFileLock,		EPrePostIntercept));
    84 	User::LeaveIfError(RegisterIntercept(EFsFileUnLock,		EPrePostIntercept));
    85 	User::LeaveIfError(RegisterIntercept(EFsFileSeek,		EPrePostIntercept));
    86 	User::LeaveIfError(RegisterIntercept(EFsFileSize,		EPrePostIntercept));
    87 	User::LeaveIfError(RegisterIntercept(EFsFileSetSize,	EPrePostIntercept));
    88 	User::LeaveIfError(RegisterIntercept(EFsDirReadOne,		EPrePostIntercept));
    89 	User::LeaveIfError(RegisterIntercept(EFsDirReadPacked,	EPrePostIntercept));
    90 	User::LeaveIfError(RegisterIntercept(EFsFileOpen,		EPrePostIntercept));
    91 	User::LeaveIfError(RegisterIntercept(EFsFileCreate,		EPrePostIntercept));
    92 	User::LeaveIfError(RegisterIntercept(EFsFileReplace,	EPrePostIntercept));
    93 	User::LeaveIfError(RegisterIntercept(EFsFileRename,		EPrePostIntercept));
    94    	User::LeaveIfError(RegisterIntercept(EFsReadFileSection,EPrePostIntercept));
    95 	User::LeaveIfError(RegisterIntercept(EFsFileSubClose,	EPrePostIntercept)); 
    96 
    97 	_LOG(_L("DriveZ Plugin: Enabled intercepts."));
    98     
    99 	iInterceptsEnabled = ETrue;
   100 	}
   101 
   102 /**
   103 Disable the plugin's intercepts.
   104 @internalComponent
   105 */
   106 void CDriveZPlugin::DisableInterceptsL()
   107 	{
   108 	if (!iInterceptsEnabled) return;
   109 	
   110 	User::LeaveIfError(UnregisterIntercept(EFsFileRead,		EPrePostIntercept));
   111 	User::LeaveIfError(UnregisterIntercept(EFsFileRename,	EPrePostIntercept));
   112 	User::LeaveIfError(UnregisterIntercept(EFsFileWrite,	EPrePostIntercept));
   113 	User::LeaveIfError(UnregisterIntercept(EFsDirOpen,		EPrePostIntercept));
   114 	User::LeaveIfError(UnregisterIntercept(EFsFileLock,		EPrePostIntercept));
   115 	User::LeaveIfError(UnregisterIntercept(EFsFileUnLock,	EPrePostIntercept));
   116 	User::LeaveIfError(UnregisterIntercept(EFsFileSeek,		EPrePostIntercept));
   117 	User::LeaveIfError(UnregisterIntercept(EFsFileSize,		EPrePostIntercept));
   118 	User::LeaveIfError(UnregisterIntercept(EFsFileSetSize,	EPrePostIntercept));
   119 	User::LeaveIfError(UnregisterIntercept(EFsFileCreate,	EPrePostIntercept));
   120 	User::LeaveIfError(UnregisterIntercept(EFsFileOpen, 	EPrePostIntercept));
   121 	User::LeaveIfError(UnregisterIntercept(EFsFileReplace, 	EPrePostIntercept));
   122 	User::LeaveIfError(UnregisterIntercept(EFsFileSubClose, EPrePostIntercept));
   123 	User::LeaveIfError(UnregisterIntercept(EFsReadFileSection,EPrePostIntercept));
   124 	User::LeaveIfError(UnregisterIntercept(EFsDirReadOne,	EPrePostIntercept));
   125 	User::LeaveIfError(UnregisterIntercept(EFsDirReadPacked,EPrePostIntercept));
   126 
   127 
   128 	_LOG(_L("DriveZ Plugin: Disabled intercepts."));
   129     
   130 	iInterceptsEnabled = EFalse;
   131 	}
   132 
   133 /**
   134 Handle requests
   135 @internalComponent
   136 */
   137 TInt CDriveZPlugin::DoRequestL(TFsPluginRequest& aRequest)
   138 	{
   139 	TInt err = KErrNone;
   140 
   141 	TInt function = aRequest.Function();
   142 	
   143 	if(aRequest.DriveNumber() != 25)
   144 		{
   145 		iLineNumber=__LINE__;
   146 		iLastError=KErrNotSupported;
   147 		return KErrNotSupported;
   148 		}
   149 
   150 	
   151 	if (aRequest.IsPostOperation())
   152 		{
   153 		_LOG2(_L("CDriveZPlugin post intercept for function %d"), function);
   154 		}
   155 	else
   156 		{
   157 		_LOG2(_L("CDriveZPlugin pre intercept for function %d"), function);
   158 		}
   159 
   160 	return err;
   161 	}
   162 
   163 
   164 CFsPluginConn* CDriveZPlugin::NewPluginConnL()
   165 	{
   166 	return new(ELeave) CDriveZPluginConn();
   167 	}
   168 
   169 
   170 //Synchronous RPlugin::DoControl
   171 TInt CDriveZPlugin::FsPluginDoControlL(CFsPluginConnRequest& aRequest)
   172 	{	
   173 	TInt err = KErrNone;
   174 
   175 	//We can use this to set the drive
   176 	//We can store this as a member of this class.
   177 	TInt function = aRequest.Function();
   178 	TPckg<TInt> errCodeDes(iLastError);
   179 	TPckg<TInt> lineNumberDes(iLineNumber);
   180 	
   181 	switch(function)
   182 		{
   183 		case KPluginGetError:
   184 			{
   185 			TRAP(err,aRequest.WriteParam1L(errCodeDes));
   186 			TRAP(err,aRequest.WriteParam2L(lineNumberDes));
   187 			break;
   188 			}
   189 		default:
   190 			break;
   191 		}
   192 
   193 	return err;
   194 	}
   195 
   196 
   197 TInt CDriveZPluginConn::DoControl(CFsPluginConnRequest& aRequest)
   198 	{
   199 	return ((CDriveZPlugin*)Plugin())->FsPluginDoControlL(aRequest);
   200 	}
   201 
   202 void CDriveZPluginConn::DoRequest(CFsPluginConnRequest& aRequest)
   203 	{
   204 	DoControl(aRequest);
   205 	}
   206 
   207 void CDriveZPluginConn::DoCancel(TInt /*aReqMask*/)
   208 	{
   209 	}
   210 
   211 
   212 //factory functions
   213 
   214 class CDriveZPluginFactory : public CFsPluginFactory
   215 	{
   216 public:
   217 	CDriveZPluginFactory();
   218 	virtual TInt Install();			
   219 	virtual CFsPlugin* NewPluginL();
   220 	virtual CFsPlugin* NewPluginConnL();
   221 	virtual TInt UniquePosition();
   222 	};
   223 
   224 /**
   225 Constructor for the plugin factory
   226 @internalComponent
   227 */
   228 CDriveZPluginFactory::CDriveZPluginFactory()
   229 	{
   230 	}
   231 
   232 /**
   233 Install function for the plugin factory
   234 @internalComponent
   235 */
   236 TInt CDriveZPluginFactory::Install()
   237 	{
   238 	SetSupportedDrives(1<<EDriveZ);
   239 	//iSupportedDrives = 1<<25;
   240 	return(SetName(&KDriveZPluginName));
   241 	}
   242 
   243 /**
   244 @internalComponent
   245 */
   246 TInt CDriveZPluginFactory::UniquePosition()
   247 	{
   248 	return(KDriveZPos);
   249 	}
   250 
   251 /**
   252 Plugin factory function
   253 @internalComponent
   254 */
   255 CFsPlugin* CDriveZPluginFactory::NewPluginL()
   256 
   257 	{
   258 	return CDriveZPlugin::NewL();
   259 	}
   260 
   261 /**
   262 Plugin factory function
   263 @internalComponent
   264 */
   265 CFsPlugin* CDriveZPluginFactory::NewPluginConnL()
   266 
   267 	{
   268 	return CDriveZPlugin::NewL();
   269 	}
   270 
   271 /**
   272 Create a new Plugin
   273 @internalComponent
   274 */
   275 extern "C" {
   276 
   277 EXPORT_C CFsPluginFactory* CreateFileSystem()
   278 	{
   279 	return(new CDriveZPluginFactory());
   280 	}
   281 }
   282