os/kernelhwsrv/kerneltest/f32test/plugins/version_2/src/stacked3_plugin.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/plugins/version_2/src/stacked3_plugin.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,329 @@
     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 +//
    1.18 +
    1.19 +#include "stacked3_plugin.h"
    1.20 +#include "plugincommon.h"
    1.21 +
    1.22 +
    1.23 +/**
    1.24 +Leaving New function for the plugin
    1.25 +@internalComponent
    1.26 + */
    1.27 +CStacked3Plugin* CStacked3Plugin::NewL()
    1.28 +	{
    1.29 +	CStacked3Plugin* self = new(ELeave) CStacked3Plugin;
    1.30 +	CleanupStack::PushL(self);
    1.31 +	self->ConstructL();
    1.32 +	CleanupStack::Pop();
    1.33 +	return self;
    1.34 +	}
    1.35 +
    1.36 +
    1.37 +/**
    1.38 +Constructor for the plugin
    1.39 +@internalComponent
    1.40 + */
    1.41 +CStacked3Plugin::CStacked3Plugin() : iInterceptsEnabled(EFalse),
    1.42 +iLogging(ETrue)
    1.43 +		{
    1.44 +		}
    1.45 +
    1.46 +
    1.47 +void CStacked3Plugin::ConstructL()
    1.48 +	{
    1.49 +	}
    1.50 +
    1.51 +/**
    1.52 +The destructor for the plugin
    1.53 +@internalComponent
    1.54 + */
    1.55 +CStacked3Plugin::~CStacked3Plugin()
    1.56 +	{
    1.57 +	}
    1.58 +
    1.59 +/**
    1.60 +Initialise the plugin.
    1.61 +@internalComponent
    1.62 + */
    1.63 +void CStacked3Plugin::InitialiseL()
    1.64 +	{
    1.65 +	EnableInterceptsL();	
    1.66 +	}
    1.67 +
    1.68 +/**
    1.69 +Enable the plugin's intercepts.
    1.70 +@internalComponent
    1.71 + */
    1.72 +void CStacked3Plugin::EnableInterceptsL()
    1.73 +	{
    1.74 +	if (iInterceptsEnabled) return;
    1.75 +
    1.76 +	User::LeaveIfError(RegisterIntercept(EFsFileWrite, 		 	EPreIntercept));	
    1.77 +
    1.78 +	_LOG(_L("Stacked3 Plugin: Enabled intercepts."));
    1.79 +
    1.80 +	iInterceptsEnabled = ETrue;
    1.81 +	}
    1.82 +
    1.83 +/**
    1.84 +Disable the plugin's intercepts.
    1.85 +@internalComponent
    1.86 + */
    1.87 +void CStacked3Plugin::DisableInterceptsL()
    1.88 +	{
    1.89 +	if (!iInterceptsEnabled) return;
    1.90 +
    1.91 +	User::LeaveIfError(UnregisterIntercept(EFsFileWrite,   		EPreIntercept));
    1.92 +
    1.93 +	_LOG(_L("Stacked3 Plugin: Disabled intercepts."));
    1.94 +
    1.95 +	iInterceptsEnabled = EFalse;
    1.96 +	}
    1.97 +
    1.98 +/**
    1.99 +Handle requests
   1.100 +@internalComponent
   1.101 + */
   1.102 +TInt CStacked3Plugin::DoRequestL(TFsPluginRequest& aRequest)
   1.103 +	{
   1.104 +
   1.105 +	TInt err = KErrNone;
   1.106 +
   1.107 +	TInt function = aRequest.Function();
   1.108 +
   1.109 +	switch(function)
   1.110 +		{
   1.111 +		case EFsFileRead:
   1.112 +			break;
   1.113 +
   1.114 +		case EFsFileWrite:
   1.115 +			TRAP(err, FsFileWriteL(aRequest));
   1.116 +			break;
   1.117 +
   1.118 +		default:
   1.119 +			break;
   1.120 +		}
   1.121 +
   1.122 +	return err;
   1.123 +	}
   1.124 +
   1.125 +
   1.126 +/**
   1.127 +@internalComponent
   1.128 + */
   1.129 +void CStacked3Plugin::FsFileWriteL(TFsPluginRequest& aRequest)
   1.130 +	{
   1.131 +	TInt length = 0;
   1.132 +	TInt64 pos = 0;
   1.133 +	TFileName filename;
   1.134 +	TParse parse;
   1.135 +
   1.136 +	TInt err = aRequest.FileName(filename);
   1.137 +	iLastError = err;
   1.138 +	iLineNumber = __LINE__;
   1.139 +	if(err!=KErrNone)
   1.140 +		User::Leave(err); //trapped in DoRequestL
   1.141 +
   1.142 +	err = aRequest.Read(TFsPluginRequest::ELength, length);
   1.143 +	iLastError = err;
   1.144 +	iLineNumber = __LINE__;
   1.145 +	if(err!=KErrNone)
   1.146 +		User::Leave(err); //trapped in DoRequestL
   1.147 +	
   1.148 +	err = aRequest.Read(TFsPluginRequest::EPosition, pos);
   1.149 +	iLastError = err;
   1.150 +	iLineNumber = __LINE__;
   1.151 +	if(err!=KErrNone)
   1.152 +		User::Leave(err); //trapped in DoRequestL
   1.153 +	
   1.154 +	parse.Set(filename, NULL, NULL);
   1.155 +
   1.156 +	_LOG4(_L("CStacked3Plugin::FsFileWriteL, file: %S, pos: %d, length: %d"), &filename,  pos, length);
   1.157 +
   1.158 +	if (aRequest.IsPostOperation())
   1.159 +		{
   1.160 +		_LOG(_L("CStacked3Plugin::FsFileWriteL, post intercept"));
   1.161 +		}
   1.162 +	else
   1.163 +		{
   1.164 +		_LOG(_L("CStacked3Plugin::FsFileWriteL, pre intercept"));	
   1.165 +
   1.166 +		//set up test data for plugin
   1.167 +		TBuf8<20> wbuffer;			
   1.168 +		wbuffer.Copy(_L8("HELLO WORLD  SYMBIAN"));
   1.169 +		TInt length = wbuffer.Length();
   1.170 +
   1.171 +		HBufC8* tempBuf = HBufC8::NewMaxLC(length);
   1.172 +		TPtr8 tempBufPtr((TUint8 *)tempBuf->Des().Ptr(), length, length);
   1.173 +
   1.174 +		RFilePlugin fileplugin(aRequest);
   1.175 +		err = fileplugin.AdoptFromClient();
   1.176 +		iLastError = err;
   1.177 +		iLineNumber = __LINE__;
   1.178 +		if(err!=KErrNone)
   1.179 +			User::Leave(err); //trapped in DoRequestL
   1.180 +		
   1.181 +		//write to file
   1.182 +		err = fileplugin.Write(pos, wbuffer);
   1.183 +		_LOG2(_L("CStacked3Plugin::FsFileWriteL, RFilePlugin::Write returned %d"), err);
   1.184 +		iLastError = err;
   1.185 +		iLineNumber = __LINE__;
   1.186 +		if(err!=KErrNone)
   1.187 +			User::Leave(err); //trapped in DoRequestL
   1.188 +
   1.189 +		//read from file		
   1.190 +		err = fileplugin.Read(pos, tempBufPtr);
   1.191 +		_LOG2(_L("CStackedPlugin::FsFileWriteL, RFilePlugin::Read returned %d"), err);
   1.192 +		iLastError = err;
   1.193 +		iLineNumber = __LINE__;
   1.194 +		if(err!=KErrNone)
   1.195 +			User::Leave(err); //trapped in DoRequestL
   1.196 +
   1.197 +		//testing the correct thing has been written to the drive
   1.198 +		err = wbuffer.Compare(tempBufPtr);
   1.199 +		iLastError = err;
   1.200 +		iLineNumber = __LINE__;
   1.201 +		if(err!=KErrNone)
   1.202 +			User::Leave(err); //trapped in DoRequestL
   1.203 +
   1.204 +		fileplugin.Close();
   1.205 +		CleanupStack::PopAndDestroy();	
   1.206 +
   1.207 +		// send request down the stack
   1.208 +		User::Leave(KErrCompletion);	
   1.209 +		}
   1.210 +	}
   1.211 +
   1.212 +
   1.213 +CFsPluginConn* CStacked3Plugin::NewPluginConnL()
   1.214 +	{
   1.215 +	return new(ELeave) CStacked3PluginConn();
   1.216 +	}
   1.217 +
   1.218 +
   1.219 +//Synchronous RPlugin::DoControl
   1.220 +TInt CStacked3Plugin::FsPluginDoControlL(CFsPluginConnRequest& aRequest)
   1.221 +	{
   1.222 +	TInt err = KErrNone;
   1.223 +	TPckg<TInt> errCodeDes(iLastError);
   1.224 +	TPckg<TInt> lineNumberDes(iLineNumber);
   1.225 +
   1.226 +	TInt function = aRequest.Function();
   1.227 +	switch(function)
   1.228 +		{
   1.229 +		case KPluginSetDrive:
   1.230 +			{
   1.231 +			TPckg<TChar> drive(iDriveToTest);
   1.232 +			TRAP(err,aRequest.ReadParam1L(drive));
   1.233 +			break;
   1.234 +			}
   1.235 +		case KPluginGetError:
   1.236 +			{
   1.237 +			TRAP(err,aRequest.WriteParam1L(errCodeDes));
   1.238 +			TRAP(err,aRequest.WriteParam2L(lineNumberDes));
   1.239 +			break;
   1.240 +			}
   1.241 +		default:
   1.242 +			break;
   1.243 +		}
   1.244 +
   1.245 +	return err;
   1.246 +	}
   1.247 +
   1.248 +TInt CStacked3PluginConn::DoControl(CFsPluginConnRequest& aRequest)
   1.249 +	{
   1.250 +	return ((CStacked3Plugin*)Plugin())->FsPluginDoControlL(aRequest);
   1.251 +	}
   1.252 +
   1.253 +void CStacked3PluginConn::DoRequest(CFsPluginConnRequest& aRequest)
   1.254 +	{
   1.255 +	DoControl(aRequest);
   1.256 +	}
   1.257 +
   1.258 +void CStacked3PluginConn::DoCancel(TInt /*aReqMask*/)
   1.259 +	{
   1.260 +	}
   1.261 +
   1.262 +//factory functions
   1.263 +
   1.264 +class CStacked3PluginFactory : public CFsPluginFactory
   1.265 +	{
   1.266 +	public:
   1.267 +		CStacked3PluginFactory();
   1.268 +		virtual TInt Install();			
   1.269 +		virtual CFsPlugin* NewPluginL();
   1.270 +		virtual CFsPlugin* NewPluginConnL();
   1.271 +		virtual TInt UniquePosition();
   1.272 +	};
   1.273 +
   1.274 +/**
   1.275 +Constructor for the plugin factory
   1.276 +@internalComponent
   1.277 + */
   1.278 +CStacked3PluginFactory::CStacked3PluginFactory()
   1.279 +	{
   1.280 +	}
   1.281 +
   1.282 +/**
   1.283 +Install function for the plugin factory
   1.284 +@internalComponent
   1.285 + */
   1.286 +TInt CStacked3PluginFactory::Install()
   1.287 +	{
   1.288 +	//SetSupportedDrives(1<<23);
   1.289 +	iSupportedDrives = 1<<23;
   1.290 +	return(SetName(&KStacked3PluginName));
   1.291 +	}
   1.292 +
   1.293 +/**
   1.294 +@internalComponent
   1.295 + */
   1.296 +TInt CStacked3PluginFactory::UniquePosition()
   1.297 +	{
   1.298 +	return(KStacked3Pos);
   1.299 +	}
   1.300 +
   1.301 +/**
   1.302 +Plugin factory function
   1.303 +@internalComponent
   1.304 + */
   1.305 +CFsPlugin* CStacked3PluginFactory::NewPluginL()
   1.306 +
   1.307 +	{
   1.308 +	return CStacked3Plugin::NewL();
   1.309 +	}
   1.310 +
   1.311 +/**
   1.312 +Plugin factory function
   1.313 +@internalComponent
   1.314 + */
   1.315 +CFsPlugin* CStacked3PluginFactory::NewPluginConnL()
   1.316 +
   1.317 +	{
   1.318 +	return CStacked3Plugin::NewL();
   1.319 +	}
   1.320 +
   1.321 +/**
   1.322 +Create a new Plugin
   1.323 +@internalComponent
   1.324 + */
   1.325 +extern "C" {
   1.326 +
   1.327 +EXPORT_C CFsPluginFactory* CreateFileSystem()
   1.328 +		{
   1.329 +		return(new CStacked3PluginFactory());
   1.330 +		}
   1.331 +}
   1.332 +