os/kernelhwsrv/kerneltest/f32test/plugins/version_2/src/stacked_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 "stacked_plugin.h"
    17 #include "plugincommon.h"
    18 
    19 /**
    20 Leaving New function for the plugin
    21 @internalComponent
    22  */
    23 CStackedPlugin* CStackedPlugin::NewL()
    24 	{
    25 	CStackedPlugin* self = new(ELeave) CStackedPlugin;
    26 	CleanupStack::PushL(self);
    27 	self->ConstructL();
    28 	CleanupStack::Pop();
    29 	return self;
    30 	}
    31 
    32 
    33 /**
    34 Constructor for the plugin
    35 @internalComponent
    36  */
    37 CStackedPlugin::CStackedPlugin() : iInterceptsEnabled(EFalse),
    38 iLogging(ETrue)
    39 		{
    40 		}
    41 
    42 
    43 void CStackedPlugin::ConstructL()
    44 	{
    45 	}
    46 
    47 /**
    48 The destructor for the plugin
    49 @internalComponent
    50  */
    51 CStackedPlugin::~CStackedPlugin()
    52 	{
    53 	}
    54 
    55 /**
    56 Initialise the plugin.
    57 @internalComponent
    58  */
    59 void CStackedPlugin::InitialiseL()
    60 	{	
    61 	EnableInterceptsL();		
    62 	}
    63 
    64 /**
    65 Enable the plugin's intercepts.
    66 @internalComponent
    67  */
    68 void CStackedPlugin::EnableInterceptsL()
    69 	{
    70 	if (iInterceptsEnabled) return;
    71 
    72 	User::LeaveIfError(RegisterIntercept(EFsFileWrite, 		 	EPreIntercept));	
    73 
    74 	_LOG(_L("Stacked Plugin: Enabled intercepts."));
    75 
    76 	iInterceptsEnabled = ETrue;
    77 	}
    78 
    79 /**
    80 Disable the plugin's intercepts.
    81 @internalComponent
    82  */
    83 void CStackedPlugin::DisableInterceptsL()
    84 	{
    85 	if (!iInterceptsEnabled) return;	
    86 
    87 	User::LeaveIfError(UnregisterIntercept(EFsFileWrite,   		EPreIntercept));
    88 
    89 	_LOG(_L("Stacked Plugin: Disabled intercepts."));
    90 
    91 	iInterceptsEnabled = EFalse;
    92 	}
    93 
    94 /**
    95 Handle requests
    96 @internalComponent
    97  */
    98 TInt CStackedPlugin::DoRequestL(TFsPluginRequest& aRequest)
    99 	{
   100 
   101 	TInt err = KErrNone;
   102 
   103 	TInt function = aRequest.Function();
   104 
   105 	switch(function)
   106 		{
   107 		case EFsFileRead:
   108 			break;
   109 
   110 		case EFsFileWrite:
   111 			TRAP(err, FsFileWriteL(aRequest));
   112 			break;
   113 
   114 		default:
   115 			break;
   116 		}
   117 
   118 	return err;
   119 	}
   120 
   121 
   122 
   123 /**
   124 @internalComponent
   125  */
   126 void CStackedPlugin::FsFileWriteL(TFsPluginRequest& aRequest)
   127 	{
   128 	TInt length = 0;
   129 	TInt64 pos = 0;
   130 	TFileName filename;
   131 	TParse parse;	
   132 
   133 	TInt err = aRequest.FileName(filename);
   134 	iLastError = err;
   135 	iLineNumber = __LINE__;
   136 	if(err!=KErrNone)
   137 		User::Leave(err); //trapped in DoRequestL
   138 
   139 	err = aRequest.Read(TFsPluginRequest::ELength, length);
   140 	iLastError = err;
   141 	iLineNumber = __LINE__;
   142 	if(err!=KErrNone)
   143 		User::Leave(err); //trapped in DoRequestL
   144 		
   145 	err = aRequest.Read(TFsPluginRequest::EPosition, pos);
   146 	iLastError = err;
   147 	iLineNumber = __LINE__;
   148 	if(err!=KErrNone)
   149 		User::Leave(err); //trapped in DoRequestL
   150 
   151 	parse.Set(filename, NULL, NULL);
   152 
   153 	_LOG4(_L("CStackedPlugin::FsFileWriteL, file: %S, pos: %d, length: %d"), &filename, pos, length);
   154 
   155 	if (aRequest.IsPostOperation())
   156 		{
   157 		_LOG(_L("CStackedPlugin::FsFileWriteL, post intercept"));
   158 		}
   159 	else
   160 		{
   161 		_LOG(_L("CStackedPlugin::FsFileWriteL, pre intercept"));			
   162 
   163 		//set up test data for plugin
   164 		TBuf8<20> wbuffer;			
   165 		wbuffer.Copy(_L8("HELLO SYMBIAN WORLD1"));
   166 		TInt length = wbuffer.Length();
   167 
   168 		HBufC8* tempBuf = HBufC8::NewMaxLC(length);
   169 		TPtr8 tempBufPtr((TUint8 *)tempBuf->Des().Ptr(), length, length);
   170 
   171 		RFilePlugin fileplugin(aRequest);
   172 		err = fileplugin.AdoptFromClient();
   173 		iLastError = err;
   174 		iLineNumber = __LINE__;
   175 		if(err!=KErrNone)
   176 			User::Leave(err); //trapped in DoRequestL
   177 
   178 		//read from file		
   179 		err = fileplugin.Read(pos, tempBufPtr);
   180 		_LOG2(_L("CStackedPlugin::FsFileWriteL, RFilePlugin::Read returned %d"), err);
   181 		iLastError = err;
   182 		iLineNumber = __LINE__;
   183 		if(err!=KErrNone)
   184 			User::Leave(err); //trapped in DoRequestL
   185 
   186 		//Check that correct data is in file
   187 		err = wbuffer.Compare(tempBufPtr);
   188 		iLastError = err;
   189 		iLineNumber = __LINE__;
   190 		if(err!=KErrNone)
   191 			User::Leave(err); //trapped in DoRequestL
   192 
   193 		fileplugin.Close();
   194 		CleanupStack::PopAndDestroy();
   195 
   196 		// send request down the stack
   197 		User::Leave(KErrNone);			
   198 		}
   199 	}
   200 
   201 
   202 CFsPluginConn* CStackedPlugin::NewPluginConnL()
   203 	{
   204 	return new(ELeave) CStackedPluginConn();
   205 	}
   206 
   207 
   208 //Synchronous RPlugin::DoControl
   209 TInt CStackedPlugin::FsPluginDoControlL(CFsPluginConnRequest& aRequest)
   210 	{
   211 	TInt err = KErrNone;
   212 	TPckg<TInt> errCodeDes(iLastError);
   213 	TPckg<TInt> lineNumberDes(iLineNumber);
   214 
   215 	TInt function = aRequest.Function();
   216 	switch(function)
   217 		{
   218 		case KPluginSetDrive:
   219 			{
   220 			TPckg<TChar> drive(iDriveToTest);
   221 			TRAP(err,aRequest.ReadParam1L(drive));
   222 			break;
   223 			}
   224 		case KPluginGetError:
   225 			{
   226 			TRAP(err,aRequest.WriteParam1L(errCodeDes));
   227 			TRAP(err,aRequest.WriteParam2L(lineNumberDes));
   228 			break;
   229 			}
   230 		default:
   231 			break;
   232 		}
   233 
   234 	return err;
   235 	}
   236 
   237 TInt CStackedPluginConn::DoControl(CFsPluginConnRequest& aRequest)
   238 	{
   239 	return ((CStackedPlugin*)Plugin())->FsPluginDoControlL(aRequest);
   240 	}
   241 
   242 void CStackedPluginConn::DoRequest(CFsPluginConnRequest& aRequest)
   243 	{
   244 	DoControl(aRequest);
   245 	}
   246 
   247 void CStackedPluginConn::DoCancel(TInt /*aReqMask*/)
   248 	{
   249 	}
   250 
   251 //factory functions
   252 
   253 class CStackedPluginFactory : public CFsPluginFactory
   254 	{
   255 	public:
   256 		CStackedPluginFactory();
   257 		virtual TInt Install();			
   258 		virtual CFsPlugin* NewPluginL();
   259 		virtual CFsPlugin* NewPluginConnL();
   260 		virtual TInt UniquePosition();
   261 	};
   262 
   263 /**
   264 Constructor for the plugin factory
   265 @internalComponent
   266  */
   267 CStackedPluginFactory::CStackedPluginFactory()
   268 	{
   269 	}
   270 
   271 /**
   272 Install function for the plugin factory
   273 @internalComponent
   274  */
   275 TInt CStackedPluginFactory::Install()
   276 	{
   277 	//SetSupportedDrives(1<<23);
   278 	iSupportedDrives = 1<<23;
   279 	return(SetName(&KStackedPluginName));
   280 	}
   281 
   282 /**
   283 @internalComponent
   284  */
   285 TInt CStackedPluginFactory::UniquePosition()
   286 	{
   287 	return(KStackedPos);
   288 	}
   289 
   290 /**
   291 Plugin factory function
   292 @internalComponent
   293  */
   294 CFsPlugin* CStackedPluginFactory::NewPluginL()
   295 
   296 	{
   297 	return CStackedPlugin::NewL();
   298 	}
   299 
   300 /**
   301 Plugin factory function
   302 @internalComponent
   303  */
   304 CFsPlugin* CStackedPluginFactory::NewPluginConnL()
   305 
   306 	{
   307 	return CStackedPlugin::NewL();
   308 	}
   309 
   310 /**
   311 Create a new Plugin
   312 @internalComponent
   313  */
   314 extern "C" {
   315 
   316 EXPORT_C CFsPluginFactory* CreateFileSystem()
   317 		{
   318 		return(new CStackedPluginFactory());
   319 		}
   320 }
   321