os/kernelhwsrv/kerneltest/f32test/plugins/version_2/src/combinational_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/combinational_plugin.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,834 @@
     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 "combinational_plugin.h"
    1.20 +#include "plugincommon.h"
    1.21 +#include <f32pluginutils.h>
    1.22 +
    1.23 +/**
    1.24 +Leaving New function for the plugin
    1.25 +@internalComponent
    1.26 +*/
    1.27 +CCombinationalPlugin* CCombinationalPlugin::NewL()
    1.28 +	{
    1.29 +	CCombinationalPlugin* self = new(ELeave) CCombinationalPlugin;
    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 +CCombinationalPlugin::CCombinationalPlugin() : iInterceptsEnabled(EFalse),
    1.42 +									 iLogging(ETrue)
    1.43 +	{
    1.44 +	}
    1.45 +
    1.46 +
    1.47 +void CCombinationalPlugin::ConstructL()
    1.48 +	{
    1.49 +	//iFile = RFilePlugin::Open();
    1.50 +	}
    1.51 +
    1.52 +/**
    1.53 +The destructor for the plugin
    1.54 +@internalComponent
    1.55 +*/
    1.56 +CCombinationalPlugin::~CCombinationalPlugin()
    1.57 +	{
    1.58 +	}
    1.59 +
    1.60 +/**
    1.61 +Initialise the plugin.
    1.62 +@internalComponent
    1.63 +*/
    1.64 +void CCombinationalPlugin::InitialiseL()
    1.65 +	{
    1.66 +	_LOG(_L("CCombinationalPlugin InitialiseL"));
    1.67 +	EnableInterceptsL();
    1.68 +	}
    1.69 +
    1.70 +/**
    1.71 +Enable the plugin's intercepts.
    1.72 +@internalComponent
    1.73 +*/
    1.74 +void CCombinationalPlugin::EnableInterceptsL()
    1.75 +	{
    1.76 +	if (iInterceptsEnabled) return;
    1.77 +	
    1.78 +	User::LeaveIfError(RegisterIntercept(EFsFileRead,			EPrePostIntercept));
    1.79 +	User::LeaveIfError(RegisterIntercept(EFsFileWrite,			EPrePostIntercept));
    1.80 +	User::LeaveIfError(RegisterIntercept(EFsDirOpen,			EPrePostIntercept));
    1.81 +	User::LeaveIfError(RegisterIntercept(EFsFileLock,			EPrePostIntercept));
    1.82 +	User::LeaveIfError(RegisterIntercept(EFsFileUnLock,			EPrePostIntercept));
    1.83 +	User::LeaveIfError(RegisterIntercept(EFsFileSeek,			EPrePostIntercept));
    1.84 +	User::LeaveIfError(RegisterIntercept(EFsFileSize,			EPrePostIntercept));
    1.85 +	User::LeaveIfError(RegisterIntercept(EFsFileSetSize,		EPrePostIntercept));
    1.86 +	User::LeaveIfError(RegisterIntercept(EFsDirReadOne,			EPrePostIntercept));
    1.87 +	User::LeaveIfError(RegisterIntercept(EFsDirReadPacked,		EPrePostIntercept));
    1.88 +	User::LeaveIfError(RegisterIntercept(EFsFileOpen,			EPrePostIntercept));
    1.89 +	User::LeaveIfError(RegisterIntercept(EFsFileCreate,			EPrePostIntercept));
    1.90 +	User::LeaveIfError(RegisterIntercept(EFsFileReplace,		EPrePostIntercept));
    1.91 +	User::LeaveIfError(RegisterIntercept(EFsFileRename,			EPrePostIntercept));
    1.92 +   	User::LeaveIfError(RegisterIntercept(EFsReadFileSection,	EPrePostIntercept));
    1.93 +	User::LeaveIfError(RegisterIntercept(EFsFileSubClose,       EPrePostIntercept));
    1.94 +	User::LeaveIfError(RegisterIntercept(EFsEntry,        		EPrePostIntercept));
    1.95 +	User::LeaveIfError(RegisterIntercept(EFsSetEntry,      		EPrePostIntercept));
    1.96 +
    1.97 +	_LOG(_L("Combinational Plugin: Enabled intercepts."));
    1.98 +    
    1.99 +	iInterceptsEnabled = ETrue;
   1.100 +	}
   1.101 +
   1.102 +/**
   1.103 +Disable the plugin's intercepts.
   1.104 +@internalComponent
   1.105 +*/
   1.106 +void CCombinationalPlugin::DisableInterceptsL()
   1.107 +	{
   1.108 +	if (!iInterceptsEnabled) return;
   1.109 +	
   1.110 +	User::LeaveIfError(UnregisterIntercept(EFsFileRead,			EPrePostIntercept));
   1.111 +	User::LeaveIfError(UnregisterIntercept(EFsFileRename,		EPrePostIntercept));
   1.112 +	User::LeaveIfError(UnregisterIntercept(EFsFileWrite,		EPrePostIntercept));
   1.113 +	User::LeaveIfError(UnregisterIntercept(EFsDirOpen,			EPrePostIntercept));
   1.114 +	User::LeaveIfError(UnregisterIntercept(EFsFileLock,			EPrePostIntercept));
   1.115 +	User::LeaveIfError(UnregisterIntercept(EFsFileUnLock,		EPrePostIntercept));
   1.116 +	User::LeaveIfError(UnregisterIntercept(EFsFileSeek,			EPrePostIntercept));
   1.117 +	User::LeaveIfError(UnregisterIntercept(EFsFileSize,			EPrePostIntercept));
   1.118 +	User::LeaveIfError(UnregisterIntercept(EFsFileSetSize,		EPrePostIntercept));
   1.119 +	User::LeaveIfError(UnregisterIntercept(EFsFileCreate,		EPrePostIntercept));
   1.120 +	User::LeaveIfError(UnregisterIntercept(EFsFileOpen, 		EPrePostIntercept));
   1.121 +	User::LeaveIfError(UnregisterIntercept(EFsFileReplace, 		EPrePostIntercept));
   1.122 +	User::LeaveIfError(UnregisterIntercept(EFsFileSubClose, 	EPrePostIntercept));
   1.123 +	User::LeaveIfError(UnregisterIntercept(EFsReadFileSection,	EPrePostIntercept));
   1.124 +	User::LeaveIfError(UnregisterIntercept(EFsDirReadOne,		EPrePostIntercept));
   1.125 +	User::LeaveIfError(UnregisterIntercept(EFsDirReadPacked,	EPrePostIntercept));
   1.126 +	User::LeaveIfError(UnregisterIntercept(EFsEntry,        	EPrePostIntercept));
   1.127 +	User::LeaveIfError(UnregisterIntercept(EFsSetEntry,      	EPrePostIntercept));
   1.128 +
   1.129 +	_LOG(_L("Combinational Plugin: Disabled intercepts."));
   1.130 +    
   1.131 +	iInterceptsEnabled = EFalse;
   1.132 +	}
   1.133 +
   1.134 +/**
   1.135 +Handle requests
   1.136 +@internalComponent
   1.137 +*/
   1.138 +TInt CCombinationalPlugin::DoRequestL(TFsPluginRequest& aRequest)
   1.139 +	{
   1.140 +	TInt r = KErrNone;
   1.141 +	TInt function = aRequest.Function();
   1.142 +	
   1.143 +	if (aRequest.IsPostOperation())
   1.144 +		{
   1.145 +		_LOG2(_L("CCombinationalPlugin post intercept for function %d"), function);
   1.146 +		}
   1.147 +	else
   1.148 +		{
   1.149 +		_LOG2(_L("CCombinationalPlugin pre intercept for function %d"), function);
   1.150 +		}
   1.151 +
   1.152 +	switch (function)
   1.153 +		{
   1.154 +		case EFsFileOpen:
   1.155 +			r= DoFileOpen(aRequest);
   1.156 +			break;
   1.157 +		case EFsFileSubClose:
   1.158 +			r = DoFileSubClose(aRequest);
   1.159 +			break;
   1.160 +		case EFsFileReplace:
   1.161 +			r = DoFileReplace(aRequest);
   1.162 +			break;
   1.163 +		case EFsEntry:
   1.164 +			r = DoEntry(aRequest);
   1.165 +			break;
   1.166 +		case EFsDirReadPacked:
   1.167 +			r = DoDirReadPacked(aRequest);
   1.168 +			break;
   1.169 +		case EFsDirOpen:
   1.170 +			aRequest.Src();
   1.171 +			break;
   1.172 +		default:
   1.173 +			break;
   1.174 +		}
   1.175 +	return r;
   1.176 +	}
   1.177 +
   1.178 +
   1.179 +
   1.180 +
   1.181 +TInt CCombinationalPlugin::DoFileRead(TFsPluginRequest& /*aRequest*/)
   1.182 +	{
   1.183 +	iLastError = KErrNotSupported;
   1.184 +	iLineNumber = __LINE__;
   1.185 +	return KErrNotSupported;
   1.186 +	}
   1.187 +TInt CCombinationalPlugin::DoFileWrite(TFsPluginRequest& /*aRequest*/)
   1.188 +	{
   1.189 +	iLastError = KErrNotSupported;
   1.190 +	iLineNumber = __LINE__;
   1.191 +	return KErrNotSupported;
   1.192 +	}
   1.193 +
   1.194 +/*
   1.195 +Test - 	Perform an Open here,
   1.196 + 		then make sure we get the right details in the second plugin.
   1.197 +*/
   1.198 +TInt CCombinationalPlugin::DoEntry(TFsPluginRequest& aRequest)
   1.199 +	{
   1.200 +	TInt err = KErrNone;
   1.201 +	TFileName name;
   1.202 +	
   1.203 +	TBuf<256> testfilename1;
   1.204 +
   1.205 +	//setting up test files
   1.206 +	testfilename1.Append(iDriveToTest);
   1.207 +	testfilename1.Append(_L(":\\data\\test.entry.combi"));
   1.208 +
   1.209 +	name = aRequest.Src().FullName();
   1.210 +	
   1.211 +	if(!aRequest.IsPostOperation()) //pre
   1.212 +		{
   1.213 +		err = KErrNone;
   1.214 +		
   1.215 +		TBuf<256> clientfilename;
   1.216 +		clientfilename.Append(iDriveToTest);
   1.217 +		clientfilename.Append(_L(":\\combi.txt"));
   1.218 +		
   1.219 +		if(name.Compare(clientfilename) == 0)
   1.220 +			{
   1.221 +			RFilePlugin file(aRequest);
   1.222 +			err = file.Replace(testfilename1, EFileWrite);//open
   1.223 +			iLastError = err;
   1.224 +			iLineNumber = __LINE__;
   1.225 +			if(err!=KErrNone)
   1.226 +				return err;
   1.227 +			
   1.228 +			file.Close();
   1.229 +			}
   1.230 +		
   1.231 +		}
   1.232 +	else //post
   1.233 +		{
   1.234 +		TEntry entry;
   1.235 +		TPckg<TEntry> entryPckg(entry);
   1.236 +		err = aRequest.Read(TFsPluginRequest::EEntry, entryPckg);
   1.237 +		iLastError = err;
   1.238 +		iLineNumber = __LINE__;
   1.239 +		if(err!=KErrNone)
   1.240 +			return err;
   1.241 +		}
   1.242 +
   1.243 +	return err;
   1.244 +	}
   1.245 +
   1.246 +TInt CCombinationalPlugin::DoDirReadPacked(TFsPluginRequest& aRequest)
   1.247 +	{
   1.248 +	TInt err = KErrNone;
   1.249 +	
   1.250 +	TBuf<16> compareName;
   1.251 +	compareName.Append(iDriveToTest);
   1.252 +	compareName.Append(_L(":\\dir3\\"));
   1.253 +	if(iDirFullName.Compare(compareName) == 0)
   1.254 +		{
   1.255 +		return KErrNone;
   1.256 +		}
   1.257 +	
   1.258 +	if (aRequest.IsPostOperation()) //Post
   1.259 +		{
   1.260 +		// NOP
   1.261 +		}
   1.262 +	else							//Pre 
   1.263 +		{
   1.264 +		RDirPlugin dir1(aRequest);
   1.265 +		err = dir1.Open(iDirFullName, KEntryAttMatchMask); 
   1.266 +		iLastError = err;
   1.267 +		iLineNumber = __LINE__;
   1.268 +		if(err!=KErrNone)
   1.269 +			return err;
   1.270 +
   1.271 +		TBuf<16> dirname2;
   1.272 +		dirname2.Append(iDriveToTest);
   1.273 +		dirname2.Append(_L(":\\dir2\\"));
   1.274 +		
   1.275 +		TEntryArray entryarray1;
   1.276 +		err = dir1.Read(entryarray1); //we can complete
   1.277 +		iLastError = err;
   1.278 +		iLineNumber = __LINE__;
   1.279 +		if(err!=KErrNone && err!=KErrEof)
   1.280 +			return err;
   1.281 +
   1.282 +		TUidType uid(TUid::Null(),TUid::Null(),TUid::Null());
   1.283 +	
   1.284 +		RDirPlugin dir2(aRequest);
   1.285 +		err = dir2.Open(dirname2,uid);
   1.286 +		iLastError = err;
   1.287 +		iLineNumber = __LINE__;
   1.288 +		if(err!=KErrNone)
   1.289 +			return err;
   1.290 +		
   1.291 +		TEntryArray entryarray2;
   1.292 +		err = dir2.Read(entryarray2);
   1.293 +		iLastError = err;
   1.294 +		iLineNumber = __LINE__;
   1.295 +		if(err!=KErrNone && err!=KErrEof)
   1.296 +			return err;
   1.297 +		
   1.298 +		if(entryarray1.Count() >= 1 && entryarray2.Count() >= 1)
   1.299 +			{
   1.300 +			TEntry e1 = entryarray1[0];
   1.301 +			
   1.302 +			TBuf<16> dir1file;
   1.303 +			dir1file.Append(_L("dir1.file"));
   1.304 +			if(e1.iName.Compare(dir1file) != 0)
   1.305 +				{
   1.306 +				iLastError = err;
   1.307 +				iLineNumber = __LINE__;
   1.308 +				if(err!=KErrNone)
   1.309 +					return err;
   1.310 +				}
   1.311 +			}
   1.312 +		else 
   1.313 +			{
   1.314 +			iLastError = err;
   1.315 +			iLineNumber = __LINE__;
   1.316 +			if(err!=KErrNone)
   1.317 +				return err;
   1.318 +			}
   1.319 +		
   1.320 +		TBuf<16> dirname3;
   1.321 +		dirname3.Append(iDriveToTest);
   1.322 +		dirname3.Append(_L(":\\dir3\\"));
   1.323 +
   1.324 +		TRawEntryArray entryarray3;
   1.325 +		RDirPlugin dir3(aRequest);
   1.326 +		TUidType uid3(TUid::Null(), TUid::Null(), TUid::Null());
   1.327 +		err = dir3.Open(dirname3,uid3);
   1.328 +		iLastError = err;
   1.329 +		iLineNumber = __LINE__;
   1.330 +		if(err!=KErrNone)
   1.331 +			return err;
   1.332 +		
   1.333 +		err = dir3.Read(entryarray3);
   1.334 +		iLastError = err;
   1.335 +		iLineNumber = __LINE__;
   1.336 +		if(err!=KErrNone && err!=KErrEof)
   1.337 +			return err;
   1.338 +		
   1.339 +		err = aRequest.Write(TFsPluginRequest::EEntryArray,entryarray3.Buf());
   1.340 +		iLastError = err;
   1.341 +		iLineNumber = __LINE__;
   1.342 +		if(err!=KErrNone)
   1.343 +			return err;
   1.344 +
   1.345 +		dir1.Close();
   1.346 +		dir2.Close();
   1.347 +		dir3.Close();
   1.348 +		
   1.349 +		return KErrCompletion;
   1.350 +		}
   1.351 +		
   1.352 +	return err;
   1.353 +	}
   1.354 +
   1.355 +
   1.356 +/*
   1.357 +
   1.358 +Test 1 - This test opens 3 files and reads their contents (which was written in the test harness)
   1.359 +
   1.360 +Test 2 - 
   1.361 +
   1.362 +*/
   1.363 +TInt CCombinationalPlugin::DoFileOpen(TFsPluginRequest& aRequest)
   1.364 +	{
   1.365 +	//intercept open
   1.366 +	TInt err = KErrNone;
   1.367 +
   1.368 +	if (aRequest.IsPostOperation()) //Post
   1.369 +		{
   1.370 +		//Start of test
   1.371 +		RFilePlugin file(aRequest);
   1.372 +		err = file.AdoptFromClient();
   1.373 +		iLastError = err;
   1.374 +		iLineNumber = __LINE__;
   1.375 +		if(err!=KErrNone)
   1.376 +			return err;
   1.377 +		
   1.378 +		TFileName filename;
   1.379 +		filename.FillZ();
   1.380 +
   1.381 +		//TODO: get rid of this?
   1.382 +		#ifdef __WINS__ 
   1.383 +			_LIT(KSecondFile,"X:\\combi1.txt");
   1.384 +		#else
   1.385 +			_LIT(KSecondFile,"D:\\combi1.txt");
   1.386 +		#endif
   1.387 +
   1.388 +		filename.SetLength(KSecondFile().Length());
   1.389 +		filename.Replace(0,KSecondFile().Length(),KSecondFile());
   1.390 +		
   1.391 +		TUint mode;
   1.392 +		err = aRequest.Read(TFsPluginRequest::EMode, mode);
   1.393 +		iLastError = err;
   1.394 +		iLineNumber = __LINE__;
   1.395 +		if(err!=KErrNone)
   1.396 +			return err;
   1.397 +
   1.398 +		//try to open a second file.			
   1.399 +		err = file.Open(filename, mode);
   1.400 +		
   1.401 +		//NEGATIVE TESTING: 
   1.402 +		if(err!=KErrBadHandle)
   1.403 +			{
   1.404 +			iLastError = err;
   1.405 +			iLineNumber = __LINE__;
   1.406 +			if(err!=KErrNone)
   1.407 +				return err;
   1.408 +			}
   1.409 +		
   1.410 +		RFilePlugin file2(aRequest);
   1.411 +		err = file2.Open(filename, mode);
   1.412 +		iLastError = err;
   1.413 +		iLineNumber = __LINE__;
   1.414 +		if(err!=KErrNone)
   1.415 +			return err;
   1.416 +		
   1.417 +		//Lets write something
   1.418 +		TBuf8<64> combi1Buf;
   1.419 +		combi1Buf.SetLength(10);
   1.420 +		err = file2.Read(0,combi1Buf,6);
   1.421 +		iLastError = err;
   1.422 +		iLineNumber = __LINE__;
   1.423 +		if(err!=KErrNone)
   1.424 +			return err;
   1.425 +		
   1.426 +		// second file is open.
   1.427 +		// lets be wild and open a third!
   1.428 +		filename.FillZ();
   1.429 +		
   1.430 +		//TODO: Get rid of this?
   1.431 +		#ifdef __WINS__ 
   1.432 +			_LIT(KThirdFile,"X:\\combi2.txt");
   1.433 +		#else
   1.434 +			_LIT(KThirdFile,"D:\\combi2.txt");
   1.435 +		#endif
   1.436 +
   1.437 +		filename.SetLength(KThirdFile().Length());
   1.438 +		filename.Replace(0,KThirdFile().Length(),KThirdFile());
   1.439 +		
   1.440 +		RFilePlugin file3(aRequest);
   1.441 +		err = file3.Open(filename, mode);
   1.442 +		User::LeaveIfError(err);
   1.443 +		
   1.444 +		TBuf8<64> combi2Buf;
   1.445 +		combi2Buf.SetLength(20);
   1.446 +		err = file3.Read(0, combi2Buf, 18);
   1.447 +		User::LeaveIfError(err);
   1.448 +		
   1.449 +		_LOG2(_L("combi1Buf := %S"),&combi1Buf);
   1.450 +		_LOG2(_L("combi2Buf := %S"),&combi2Buf);
   1.451 +		
   1.452 +		err = combi1Buf.Compare(combi2Buf);
   1.453 +		if(err != 0) // is equal
   1.454 +		    {
   1.455 +			iLastError = err;
   1.456 +			iLineNumber = __LINE__;
   1.457 +			return err;
   1.458 +		    }
   1.459 +		
   1.460 +		// Right, best close these then eh?
   1.461 +		
   1.462 +		//close in different order - should be fine.
   1.463 +		file2.Close();
   1.464 +		file.Close();
   1.465 +		file3.Close();
   1.466 +		
   1.467 +		return KErrNone;
   1.468 +		} 
   1.469 +	else // PRE
   1.470 +		{
   1.471 +		RFilePlugin file(aRequest);
   1.472 +		
   1.473 +		TFileName filename;
   1.474 +
   1.475 +
   1.476 +		filename = aRequest.Src().FullName();
   1.477 +
   1.478 +		TUint mode;
   1.479 +		err = aRequest.Read(TFsPluginRequest::EMode, mode);
   1.480 +		iLastError = err;
   1.481 +		iLineNumber = __LINE__;
   1.482 +		if(err!=KErrNone)
   1.483 +			return err;
   1.484 +
   1.485 +		// Combinational test 1) Try to perform an RfilePlugin:Open on the same file.
   1.486 +		err = file.Open(filename, mode);
   1.487 +		iLastError = err;
   1.488 +		iLineNumber = __LINE__;
   1.489 +		if(err!=KErrNone)
   1.490 +			return err;
   1.491 +
   1.492 +		err = file.TransferToClient();
   1.493 +		iLastError = err;
   1.494 +		iLineNumber = __LINE__;
   1.495 +		if(err!=KErrNone)
   1.496 +			return err;
   1.497 +
   1.498 +		file.Close();
   1.499 +
   1.500 +		return KErrCompletion;
   1.501 +		}
   1.502 +	}
   1.503 +
   1.504 +TInt CCombinationalPlugin::DoFileSubClose(TFsPluginRequest& aRequest)
   1.505 +	{
   1.506 +	TInt err = KErrNone;
   1.507 +	if (aRequest.IsPostOperation())
   1.508 +		{
   1.509 +		} 
   1.510 +	else 
   1.511 +		{ //PRE
   1.512 +		RFilePlugin file(aRequest);
   1.513 +		err = file.AdoptFromClient(); //This is weird but it follows the open/close pattern;
   1.514 +		iLastError = err;
   1.515 +		iLineNumber = __LINE__;
   1.516 +		if(err!=KErrNone)
   1.517 +			return err;
   1.518 +		file.Close(); 
   1.519 +		}
   1.520 +	return err;
   1.521 +	}
   1.522 +
   1.523 +/*
   1.524 + * This test is testing the following scenario : 
   1.525 + * 
   1.526 +Intercept Replace:
   1.527 +	plugin: replace file1, write to file1,replace file2, write to file2, rfsplugin.delete file3, create file3, write3, read, compare, close, read, compare 2, close, read, compare 1, close.
   1.528 +	(basically, open/replace/create 3 files, write to them and read back from them and check the contents)  
   1.529 + */
   1.530 +TInt CCombinationalPlugin::DoFileReplace(TFsPluginRequest& aRequest)
   1.531 +	{
   1.532 +	TInt err = KErrNone;
   1.533 +
   1.534 +	TBuf<256> testfilename1;
   1.535 +	TBuf<256> testfilename2;
   1.536 +
   1.537 +	//setting up test files
   1.538 +	testfilename1.Append(iDriveToTest);
   1.539 +	testfilename1.Append(_L(":\\combiReplace2.txt"));
   1.540 +
   1.541 +	testfilename2.Append(iDriveToTest);
   1.542 +	testfilename2.Append(_L(":\\combiReplace3.txt"));
   1.543 +
   1.544 +	if (aRequest.IsPostOperation()) //POST
   1.545 +		{
   1.546 +		}
   1.547 +	else //PRE
   1.548 +		{
   1.549 +		TFileName filename;
   1.550 +		filename = aRequest.Src().FullName();
   1.551 +		
   1.552 +		RFsPlugin rfs(aRequest);
   1.553 +		err = rfs.Connect();
   1.554 +		iLastError = err;
   1.555 +		iLineNumber = __LINE__;
   1.556 +		if(err!=KErrNone)
   1.557 +			return err;
   1.558 +
   1.559 +		//rfs.Delete(aRequest,filename);
   1.560 +		
   1.561 +		RFilePlugin file(aRequest);
   1.562 +
   1.563 +		TUint mode = 0;
   1.564 +		err = aRequest.Read(TFsPluginRequest::EMode, mode);
   1.565 +		iLastError = err;
   1.566 +		iLineNumber = __LINE__;
   1.567 +		if(err!=KErrNone)
   1.568 +			return err;
   1.569 +
   1.570 +		err = file.Replace(filename, mode);
   1.571 +		iLastError = err;
   1.572 +		iLineNumber = __LINE__;
   1.573 +		if(err!=KErrNone)
   1.574 +			return err;
   1.575 +		
   1.576 +		//we have replace/opened our file, now lets write to it.
   1.577 +		
   1.578 +		TBuf8<64> writeData;
   1.579 +		writeData.FillZ(64);
   1.580 +		writeData.Copy(_L8("0123456789"));
   1.581 +		err = file.Write(0, writeData, 10);
   1.582 +		iLastError = err;
   1.583 +		iLineNumber = __LINE__;
   1.584 +		if(err!=KErrNone)
   1.585 +			return err;
   1.586 +		
   1.587 +		//Now lets EFsFileReplace another file
   1.588 +		TFileName secondName;
   1.589 +		secondName.Append(testfilename1);
   1.590 +		RFilePlugin file2(aRequest);
   1.591 +		err = file2.Replace(secondName, mode);
   1.592 +		iLastError = err;
   1.593 +		iLineNumber = __LINE__;
   1.594 +		if(err!=KErrNone)
   1.595 +			return err;
   1.596 +		
   1.597 +		//Now lets write to it.
   1.598 +		TBuf8<64> writeData2;
   1.599 +		writeData2.FillZ(64);
   1.600 +		writeData2.Copy(_L8("9876543210"));
   1.601 +		err = file2.Write(0,writeData2,10);
   1.602 +		iLastError = err;
   1.603 +		iLineNumber = __LINE__;
   1.604 +		if(err!=KErrNone)
   1.605 +			return err;
   1.606 +		
   1.607 +		//Now lets open another file.
   1.608 +		TFileName thirdFile;
   1.609 +		thirdFile.Append(testfilename2);
   1.610 +		err = rfs.Delete(thirdFile);
   1.611 +		if(err == KErrNotFound)
   1.612 +			err = KErrNone;
   1.613 +		iLastError = err;
   1.614 +		iLineNumber = __LINE__;
   1.615 +		if(err!=KErrNone)
   1.616 +			return err;
   1.617 +
   1.618 +		RFilePlugin file3(aRequest);
   1.619 +		err = file3.Create(thirdFile, EFileWrite);
   1.620 +		iLastError = err;
   1.621 +		iLineNumber = __LINE__;
   1.622 +		if(err!=KErrNone)
   1.623 +			return err;
   1.624 +		
   1.625 +		//Now lets write to it.
   1.626 +		TBuf8<64> writeData3;
   1.627 +		writeData3.FillZ(64);
   1.628 +		writeData3.Copy(_L8("3333333333"));
   1.629 +		err = file3.Write(0,writeData3,10);
   1.630 +		iLastError = err;
   1.631 +		iLineNumber = __LINE__;
   1.632 +		if(err!=KErrNone)
   1.633 +			return err;
   1.634 +		
   1.635 +		// Now we need to read the data and make sure that the correct data is in the correct files,
   1.636 +		// this check probably needs to be checked from RFile/test_harness as well.
   1.637 +		TBuf8<64> readData3;
   1.638 +		readData3.SetLength(10);
   1.639 +		err = file3.Read(0, readData3, 10);
   1.640 +		iLastError = err;
   1.641 +		iLineNumber = __LINE__;
   1.642 +		if(err!=KErrNone)
   1.643 +			return err;
   1.644 +			
   1.645 +		err = readData3.Compare(writeData3);
   1.646 +		if(err != KErrNone)
   1.647 +			{
   1.648 +			iLastError = err;
   1.649 +			iLineNumber = __LINE__;
   1.650 +			return err;
   1.651 +			}
   1.652 +		
   1.653 +		//close file 3
   1.654 +		file3.Close();
   1.655 +		
   1.656 +		// read from file2
   1.657 +		TBuf8<64> readData2;
   1.658 +		readData2.SetLength(10);
   1.659 +		err = file2.Read(0, readData2, 10);
   1.660 +		iLastError = err;
   1.661 +		iLineNumber = __LINE__;
   1.662 +		if(err!=KErrNone)
   1.663 +			return err;
   1.664 +		
   1.665 +		err = readData2.Compare(writeData2);
   1.666 +		if(err != KErrNone)
   1.667 +			{
   1.668 +			iLastError = err;
   1.669 +			iLineNumber = __LINE__;
   1.670 +			return err;
   1.671 +			}
   1.672 +		
   1.673 +		//close file 2
   1.674 +		file2.Close();
   1.675 +		
   1.676 +		// read from file1
   1.677 +		TBuf8<64> readData1;
   1.678 +		readData1.SetLength(10);
   1.679 +		err = file.Read(0, readData1, 10);
   1.680 +		iLastError = err;
   1.681 +		iLineNumber = __LINE__;
   1.682 +		if(err!=KErrNone)
   1.683 +			return err;
   1.684 +		
   1.685 +		err = readData1.Compare(writeData);
   1.686 +		if(err != KErrNone)
   1.687 +			{
   1.688 +			iLastError = err;
   1.689 +			iLineNumber = __LINE__;
   1.690 +			return err;
   1.691 +			}
   1.692 +
   1.693 +		file.TransferToClient();
   1.694 +
   1.695 +		rfs.Close();
   1.696 +		
   1.697 +		return KErrCompletion;
   1.698 +	
   1.699 +		}
   1.700 +	return err;
   1.701 +	}
   1.702 +
   1.703 +
   1.704 +CFsPluginConn* CCombinationalPlugin::NewPluginConnL()
   1.705 +	{
   1.706 +	return new(ELeave) CCombinationalPluginConn();
   1.707 +	}
   1.708 +
   1.709 +
   1.710 +//Synchronous RPlugin::DoControl
   1.711 +TInt CCombinationalPlugin::FsPluginDoControlL(CFsPluginConnRequest& aRequest)
   1.712 +	{	
   1.713 +	TInt err = KErrNone;
   1.714 +
   1.715 +	//We can use this to set the drive
   1.716 +	//We can store this as a member of this class.
   1.717 +	TInt function = aRequest.Function();
   1.718 +	TPckg<TChar> drive(iDriveToTest);
   1.719 +	typedef TBuf<256> TDirName;
   1.720 +	TPckg<TDirName> dirnamePckg(iDirFullName);
   1.721 +	TPckg<TInt> errCodeDes(iLastError);
   1.722 +	TPckg<TInt> lineNumberDes(iLineNumber);
   1.723 +	
   1.724 +	switch(function)
   1.725 +		{
   1.726 +		case KPluginSetDrive:
   1.727 +			{
   1.728 +			TRAP(err,aRequest.ReadParam1L(drive));
   1.729 +			break;
   1.730 +			}
   1.731 +		case KPluginSetDirFullName:
   1.732 +			{
   1.733 +			//This is necessary as at present we have nwo way of getting the name of
   1.734 +			//a directory!
   1.735 +			TRAP(err,aRequest.ReadParam1L(dirnamePckg));
   1.736 +			break;
   1.737 +			}
   1.738 +		case KPluginGetError:
   1.739 +			{
   1.740 +			TRAP(err,aRequest.WriteParam1L(errCodeDes));
   1.741 +			TRAP(err,aRequest.WriteParam2L(lineNumberDes));
   1.742 +			break;
   1.743 +			}
   1.744 +		default:
   1.745 +			break;
   1.746 +		}
   1.747 +
   1.748 +	return err;
   1.749 +	}
   1.750 +
   1.751 +
   1.752 +TInt CCombinationalPluginConn::DoControl(CFsPluginConnRequest& aRequest)
   1.753 +	{
   1.754 +	return ((CCombinationalPlugin*)Plugin())->FsPluginDoControlL(aRequest);
   1.755 +	}
   1.756 +
   1.757 +void CCombinationalPluginConn::DoRequest(CFsPluginConnRequest& aRequest)
   1.758 +	{
   1.759 +	DoControl(aRequest);
   1.760 +	}
   1.761 +
   1.762 +void CCombinationalPluginConn::DoCancel(TInt /*aReqMask*/)
   1.763 +	{
   1.764 +	}
   1.765 +
   1.766 +
   1.767 +
   1.768 +//factory functions
   1.769 +
   1.770 +class CCombinationalPluginFactory : public CFsPluginFactory
   1.771 +	{
   1.772 +public:
   1.773 +	CCombinationalPluginFactory();
   1.774 +	virtual TInt Install();			
   1.775 +	virtual CFsPlugin* NewPluginL();
   1.776 +	virtual CFsPlugin* NewPluginConnL();
   1.777 +	virtual TInt UniquePosition();
   1.778 +	};
   1.779 +
   1.780 +/**
   1.781 +Constructor for the plugin factory
   1.782 +@internalComponent
   1.783 +*/
   1.784 +CCombinationalPluginFactory::CCombinationalPluginFactory()
   1.785 +	{
   1.786 +	}
   1.787 +
   1.788 +/**
   1.789 +Install function for the plugin factory
   1.790 +@internalComponent
   1.791 +*/
   1.792 +TInt CCombinationalPluginFactory::Install()
   1.793 +	{
   1.794 +	SetSupportedDrives(KPluginSupportAllDrives);
   1.795 +	return(SetName(&KCombinationalPluginName));
   1.796 +	}
   1.797 +
   1.798 +/**
   1.799 +@internalComponent
   1.800 +*/
   1.801 +TInt CCombinationalPluginFactory::UniquePosition()
   1.802 +	{
   1.803 +	return(KCombinationalPos);
   1.804 +	}
   1.805 +
   1.806 +/**
   1.807 +Plugin factory function
   1.808 +@internalComponent
   1.809 +*/
   1.810 +CFsPlugin* CCombinationalPluginFactory::NewPluginL()
   1.811 +
   1.812 +	{
   1.813 +	return CCombinationalPlugin::NewL();
   1.814 +	}
   1.815 +
   1.816 +/**
   1.817 +Plugin factory function
   1.818 +@internalComponent
   1.819 +*/
   1.820 +CFsPlugin* CCombinationalPluginFactory::NewPluginConnL()
   1.821 +
   1.822 +	{
   1.823 +	return CCombinationalPlugin::NewL();
   1.824 +	}
   1.825 +
   1.826 +/**
   1.827 +Create a new Plugin
   1.828 +@internalComponent
   1.829 +*/
   1.830 +extern "C" {
   1.831 +
   1.832 +EXPORT_C CFsPluginFactory* CreateFileSystem()
   1.833 +	{
   1.834 +	return(new CCombinationalPluginFactory());
   1.835 +	}
   1.836 +}
   1.837 +