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