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