os/kernelhwsrv/kerneltest/f32test/plugins/version_2/src/stacked2_plugin.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
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 "stacked2_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
CStacked2Plugin* CStacked2Plugin::NewL()
sl@0
    25
	{
sl@0
    26
	CStacked2Plugin* self = new(ELeave) CStacked2Plugin;
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
CStacked2Plugin::CStacked2Plugin() : iInterceptsEnabled(EFalse),
sl@0
    39
iLogging(ETrue)
sl@0
    40
		{
sl@0
    41
		}
sl@0
    42
sl@0
    43
sl@0
    44
void CStacked2Plugin::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
CStacked2Plugin::~CStacked2Plugin()
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 CStacked2Plugin::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 CStacked2Plugin::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("Stacked2 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 CStacked2Plugin::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("Stacked2 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 CStacked2Plugin::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
/**
sl@0
   125
@internalComponent
sl@0
   126
 */
sl@0
   127
void CStacked2Plugin::FsFileWriteL(TFsPluginRequest& aRequest)
sl@0
   128
	{
sl@0
   129
	TInt length = 0;
sl@0
   130
	TInt64 pos = 0;
sl@0
   131
	TFileName filename;
sl@0
   132
	TParse parse;
sl@0
   133
sl@0
   134
	TInt err = aRequest.FileName(filename);
sl@0
   135
	iLastError = err;
sl@0
   136
	iLineNumber = __LINE__;
sl@0
   137
	if(err!=KErrNone)
sl@0
   138
		User::Leave(err); //trapped in DoRequestL
sl@0
   139
sl@0
   140
	err = aRequest.Read(TFsPluginRequest::ELength, length);
sl@0
   141
	iLastError = err;
sl@0
   142
	iLineNumber = __LINE__;
sl@0
   143
	if(err!=KErrNone)
sl@0
   144
		User::Leave(err); //trapped in DoRequestL
sl@0
   145
sl@0
   146
	err = aRequest.Read(TFsPluginRequest::EPosition, pos);
sl@0
   147
	iLastError = err;
sl@0
   148
	iLineNumber = __LINE__;
sl@0
   149
	if(err!=KErrNone)
sl@0
   150
		User::Leave(err); //trapped in DoRequestL
sl@0
   151
	
sl@0
   152
	parse.Set(filename, NULL, NULL);
sl@0
   153
sl@0
   154
	_LOG4(_L("CStacked2Plugin::FsFileWriteL, file: %S, pos: %d, length: %d"), &filename, pos, length);
sl@0
   155
sl@0
   156
	if (aRequest.IsPostOperation())
sl@0
   157
		{
sl@0
   158
		_LOG(_L("CStacked2Plugin::FsFileWriteL, post intercept"));
sl@0
   159
		}
sl@0
   160
	else
sl@0
   161
		{
sl@0
   162
		_LOG(_L("CStacked2Plugin::FsFileWriteL, pre intercept"));
sl@0
   163
sl@0
   164
		//set up test data for plugin
sl@0
   165
		TBuf8<20> wbuffer;			
sl@0
   166
		wbuffer.Copy(_L8("HELLO SYMBIAN WORLD1"));
sl@0
   167
		TInt length = wbuffer.Length();
sl@0
   168
sl@0
   169
		HBufC8* tempBuf = HBufC8::NewMaxLC(length);
sl@0
   170
		TPtr8 tempBufPtr((TUint8 *)tempBuf->Des().Ptr(), length, length);
sl@0
   171
sl@0
   172
		RFilePlugin fileplugin(aRequest);
sl@0
   173
		err = fileplugin.AdoptFromClient();
sl@0
   174
		iLastError = err;
sl@0
   175
		iLineNumber = __LINE__;
sl@0
   176
		if(err!=KErrNone)
sl@0
   177
			User::Leave(err); //trapped in DoRequestL
sl@0
   178
sl@0
   179
		//read from file		
sl@0
   180
		err = fileplugin.Read(pos, tempBufPtr);
sl@0
   181
		_LOG2(_L("CStacked2Plugin::FsFileWriteL, RFilePlugin::Read returned %d"), err);
sl@0
   182
		iLastError = err;
sl@0
   183
		iLineNumber = __LINE__;
sl@0
   184
		if(err!=KErrNone)
sl@0
   185
			User::Leave(err); //trapped in DoRequestL
sl@0
   186
		
sl@0
   187
		//lock and unlock file
sl@0
   188
		err = fileplugin.Lock(0,2);
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
		err = fileplugin.UnLock(0,2);
sl@0
   195
		iLastError = err;
sl@0
   196
		iLineNumber = __LINE__;
sl@0
   197
		if(err!=KErrNone)
sl@0
   198
			User::Leave(err); //trapped in DoRequestL
sl@0
   199
sl@0
   200
		//check that correct data is still in file
sl@0
   201
		err = wbuffer.Compare(tempBufPtr);
sl@0
   202
		iLastError = err;
sl@0
   203
		iLineNumber = __LINE__;
sl@0
   204
		if(err!=KErrNone)
sl@0
   205
			User::Leave(err); //trapped in DoRequestL
sl@0
   206
sl@0
   207
		fileplugin.Close();
sl@0
   208
		CleanupStack::PopAndDestroy();	
sl@0
   209
sl@0
   210
		// send request down the stack
sl@0
   211
		User::Leave(KErrNone);	
sl@0
   212
		}
sl@0
   213
	}
sl@0
   214
sl@0
   215
sl@0
   216
CFsPluginConn* CStacked2Plugin::NewPluginConnL()
sl@0
   217
	{
sl@0
   218
	return new(ELeave) CStacked2PluginConn();
sl@0
   219
	}
sl@0
   220
sl@0
   221
sl@0
   222
//Synchronous RPlugin::DoControl
sl@0
   223
TInt CStacked2Plugin::FsPluginDoControlL(CFsPluginConnRequest& aRequest)
sl@0
   224
	{
sl@0
   225
	TInt err = KErrNone;
sl@0
   226
	TPckg<TInt> errCodeDes(iLastError);
sl@0
   227
	TPckg<TInt> lineNumberDes(iLineNumber);
sl@0
   228
	
sl@0
   229
	TInt function = aRequest.Function();
sl@0
   230
	switch(function)
sl@0
   231
		{
sl@0
   232
		case KPluginSetDrive:
sl@0
   233
			{
sl@0
   234
			TPckg<TChar> drive(iDriveToTest);
sl@0
   235
			TRAP(err,aRequest.ReadParam1L(drive));
sl@0
   236
			break;
sl@0
   237
			}
sl@0
   238
		case KPluginGetError:
sl@0
   239
			{
sl@0
   240
			TRAP(err,aRequest.WriteParam1L(errCodeDes));
sl@0
   241
			TRAP(err,aRequest.WriteParam2L(lineNumberDes));
sl@0
   242
			break;
sl@0
   243
			}
sl@0
   244
		default:
sl@0
   245
			break;
sl@0
   246
		}
sl@0
   247
sl@0
   248
	return err;
sl@0
   249
	}
sl@0
   250
sl@0
   251
TInt CStacked2PluginConn::DoControl(CFsPluginConnRequest& aRequest)
sl@0
   252
	{
sl@0
   253
	return ((CStacked2Plugin*)Plugin())->FsPluginDoControlL(aRequest);
sl@0
   254
	}
sl@0
   255
sl@0
   256
void CStacked2PluginConn::DoRequest(CFsPluginConnRequest& aRequest)
sl@0
   257
	{
sl@0
   258
	DoControl(aRequest);
sl@0
   259
	}
sl@0
   260
sl@0
   261
void CStacked2PluginConn::DoCancel(TInt /*aReqMask*/)
sl@0
   262
	{
sl@0
   263
	}
sl@0
   264
sl@0
   265
//factory functions
sl@0
   266
sl@0
   267
class CStacked2PluginFactory : public CFsPluginFactory
sl@0
   268
	{
sl@0
   269
	public:
sl@0
   270
		CStacked2PluginFactory();
sl@0
   271
		virtual TInt Install();			
sl@0
   272
		virtual CFsPlugin* NewPluginL();
sl@0
   273
		virtual CFsPlugin* NewPluginConnL();
sl@0
   274
		virtual TInt UniquePosition();
sl@0
   275
	};
sl@0
   276
sl@0
   277
/**
sl@0
   278
Constructor for the plugin factory
sl@0
   279
@internalComponent
sl@0
   280
 */
sl@0
   281
CStacked2PluginFactory::CStacked2PluginFactory()
sl@0
   282
	{
sl@0
   283
	}
sl@0
   284
sl@0
   285
/**
sl@0
   286
Install function for the plugin factory
sl@0
   287
@internalComponent
sl@0
   288
 */
sl@0
   289
TInt CStacked2PluginFactory::Install()
sl@0
   290
	{
sl@0
   291
	//SetSupportedDrives(1<<23);
sl@0
   292
	iSupportedDrives = 1<<23;
sl@0
   293
	return(SetName(&KStacked2PluginName));
sl@0
   294
	}
sl@0
   295
sl@0
   296
/**
sl@0
   297
@internalComponent
sl@0
   298
 */
sl@0
   299
TInt CStacked2PluginFactory::UniquePosition()
sl@0
   300
	{
sl@0
   301
	return(KStacked2Pos);
sl@0
   302
	}
sl@0
   303
sl@0
   304
/**
sl@0
   305
Plugin factory function
sl@0
   306
@internalComponent
sl@0
   307
 */
sl@0
   308
CFsPlugin* CStacked2PluginFactory::NewPluginL()
sl@0
   309
sl@0
   310
	{
sl@0
   311
	return CStacked2Plugin::NewL();
sl@0
   312
	}
sl@0
   313
sl@0
   314
/**
sl@0
   315
Plugin factory function
sl@0
   316
@internalComponent
sl@0
   317
 */
sl@0
   318
CFsPlugin* CStacked2PluginFactory::NewPluginConnL()
sl@0
   319
sl@0
   320
	{
sl@0
   321
	return CStacked2Plugin::NewL();
sl@0
   322
	}
sl@0
   323
sl@0
   324
/**
sl@0
   325
Create a new Plugin
sl@0
   326
@internalComponent
sl@0
   327
 */
sl@0
   328
extern "C" {
sl@0
   329
sl@0
   330
EXPORT_C CFsPluginFactory* CreateFileSystem()
sl@0
   331
		{
sl@0
   332
		return(new CStacked2PluginFactory());
sl@0
   333
		}
sl@0
   334
}