1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/plugins/version_2/src/stacked2_plugin.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,334 @@
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 "stacked2_plugin.h"
1.20 +#include "plugincommon.h"
1.21 +
1.22 +
1.23 +/**
1.24 +Leaving New function for the plugin
1.25 +@internalComponent
1.26 + */
1.27 +CStacked2Plugin* CStacked2Plugin::NewL()
1.28 + {
1.29 + CStacked2Plugin* self = new(ELeave) CStacked2Plugin;
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 +CStacked2Plugin::CStacked2Plugin() : iInterceptsEnabled(EFalse),
1.42 +iLogging(ETrue)
1.43 + {
1.44 + }
1.45 +
1.46 +
1.47 +void CStacked2Plugin::ConstructL()
1.48 + {
1.49 + }
1.50 +
1.51 +/**
1.52 +The destructor for the plugin
1.53 +@internalComponent
1.54 + */
1.55 +CStacked2Plugin::~CStacked2Plugin()
1.56 + {
1.57 + }
1.58 +
1.59 +/**
1.60 +Initialise the plugin.
1.61 +@internalComponent
1.62 + */
1.63 +void CStacked2Plugin::InitialiseL()
1.64 + {
1.65 + EnableInterceptsL();
1.66 + }
1.67 +
1.68 +/**
1.69 +Enable the plugin's intercepts.
1.70 +@internalComponent
1.71 + */
1.72 +void CStacked2Plugin::EnableInterceptsL()
1.73 + {
1.74 + if (iInterceptsEnabled) return;
1.75 +
1.76 + User::LeaveIfError(RegisterIntercept(EFsFileWrite, EPreIntercept));
1.77 +
1.78 + _LOG(_L("Stacked2 Plugin: Enabled intercepts."));
1.79 +
1.80 + iInterceptsEnabled = ETrue;
1.81 + }
1.82 +
1.83 +/**
1.84 +Disable the plugin's intercepts.
1.85 +@internalComponent
1.86 + */
1.87 +void CStacked2Plugin::DisableInterceptsL()
1.88 + {
1.89 + if (!iInterceptsEnabled) return;
1.90 +
1.91 + User::LeaveIfError(UnregisterIntercept(EFsFileWrite, EPreIntercept));
1.92 +
1.93 + _LOG(_L("Stacked2 Plugin: Disabled intercepts."));
1.94 +
1.95 + iInterceptsEnabled = EFalse;
1.96 + }
1.97 +
1.98 +/**
1.99 +Handle requests
1.100 +@internalComponent
1.101 + */
1.102 +TInt CStacked2Plugin::DoRequestL(TFsPluginRequest& aRequest)
1.103 + {
1.104 +
1.105 + TInt err = KErrNone;
1.106 +
1.107 + TInt function = aRequest.Function();
1.108 +
1.109 + switch(function)
1.110 + {
1.111 + case EFsFileRead:
1.112 + break;
1.113 +
1.114 + case EFsFileWrite:
1.115 + TRAP(err, FsFileWriteL(aRequest));
1.116 + break;
1.117 +
1.118 + default:
1.119 + break;
1.120 + }
1.121 +
1.122 + return err;
1.123 + }
1.124 +
1.125 +
1.126 +
1.127 +/**
1.128 +@internalComponent
1.129 + */
1.130 +void CStacked2Plugin::FsFileWriteL(TFsPluginRequest& aRequest)
1.131 + {
1.132 + TInt length = 0;
1.133 + TInt64 pos = 0;
1.134 + TFileName filename;
1.135 + TParse parse;
1.136 +
1.137 + TInt err = aRequest.FileName(filename);
1.138 + iLastError = err;
1.139 + iLineNumber = __LINE__;
1.140 + if(err!=KErrNone)
1.141 + User::Leave(err); //trapped in DoRequestL
1.142 +
1.143 + err = aRequest.Read(TFsPluginRequest::ELength, length);
1.144 + iLastError = err;
1.145 + iLineNumber = __LINE__;
1.146 + if(err!=KErrNone)
1.147 + User::Leave(err); //trapped in DoRequestL
1.148 +
1.149 + err = aRequest.Read(TFsPluginRequest::EPosition, pos);
1.150 + iLastError = err;
1.151 + iLineNumber = __LINE__;
1.152 + if(err!=KErrNone)
1.153 + User::Leave(err); //trapped in DoRequestL
1.154 +
1.155 + parse.Set(filename, NULL, NULL);
1.156 +
1.157 + _LOG4(_L("CStacked2Plugin::FsFileWriteL, file: %S, pos: %d, length: %d"), &filename, pos, length);
1.158 +
1.159 + if (aRequest.IsPostOperation())
1.160 + {
1.161 + _LOG(_L("CStacked2Plugin::FsFileWriteL, post intercept"));
1.162 + }
1.163 + else
1.164 + {
1.165 + _LOG(_L("CStacked2Plugin::FsFileWriteL, pre intercept"));
1.166 +
1.167 + //set up test data for plugin
1.168 + TBuf8<20> wbuffer;
1.169 + wbuffer.Copy(_L8("HELLO SYMBIAN WORLD1"));
1.170 + TInt length = wbuffer.Length();
1.171 +
1.172 + HBufC8* tempBuf = HBufC8::NewMaxLC(length);
1.173 + TPtr8 tempBufPtr((TUint8 *)tempBuf->Des().Ptr(), length, length);
1.174 +
1.175 + RFilePlugin fileplugin(aRequest);
1.176 + err = fileplugin.AdoptFromClient();
1.177 + iLastError = err;
1.178 + iLineNumber = __LINE__;
1.179 + if(err!=KErrNone)
1.180 + User::Leave(err); //trapped in DoRequestL
1.181 +
1.182 + //read from file
1.183 + err = fileplugin.Read(pos, tempBufPtr);
1.184 + _LOG2(_L("CStacked2Plugin::FsFileWriteL, RFilePlugin::Read returned %d"), err);
1.185 + iLastError = err;
1.186 + iLineNumber = __LINE__;
1.187 + if(err!=KErrNone)
1.188 + User::Leave(err); //trapped in DoRequestL
1.189 +
1.190 + //lock and unlock file
1.191 + err = fileplugin.Lock(0,2);
1.192 + iLastError = err;
1.193 + iLineNumber = __LINE__;
1.194 + if(err!=KErrNone)
1.195 + User::Leave(err); //trapped in DoRequestL
1.196 +
1.197 + err = fileplugin.UnLock(0,2);
1.198 + iLastError = err;
1.199 + iLineNumber = __LINE__;
1.200 + if(err!=KErrNone)
1.201 + User::Leave(err); //trapped in DoRequestL
1.202 +
1.203 + //check that correct data is still in file
1.204 + err = wbuffer.Compare(tempBufPtr);
1.205 + iLastError = err;
1.206 + iLineNumber = __LINE__;
1.207 + if(err!=KErrNone)
1.208 + User::Leave(err); //trapped in DoRequestL
1.209 +
1.210 + fileplugin.Close();
1.211 + CleanupStack::PopAndDestroy();
1.212 +
1.213 + // send request down the stack
1.214 + User::Leave(KErrNone);
1.215 + }
1.216 + }
1.217 +
1.218 +
1.219 +CFsPluginConn* CStacked2Plugin::NewPluginConnL()
1.220 + {
1.221 + return new(ELeave) CStacked2PluginConn();
1.222 + }
1.223 +
1.224 +
1.225 +//Synchronous RPlugin::DoControl
1.226 +TInt CStacked2Plugin::FsPluginDoControlL(CFsPluginConnRequest& aRequest)
1.227 + {
1.228 + TInt err = KErrNone;
1.229 + TPckg<TInt> errCodeDes(iLastError);
1.230 + TPckg<TInt> lineNumberDes(iLineNumber);
1.231 +
1.232 + TInt function = aRequest.Function();
1.233 + switch(function)
1.234 + {
1.235 + case KPluginSetDrive:
1.236 + {
1.237 + TPckg<TChar> drive(iDriveToTest);
1.238 + TRAP(err,aRequest.ReadParam1L(drive));
1.239 + break;
1.240 + }
1.241 + case KPluginGetError:
1.242 + {
1.243 + TRAP(err,aRequest.WriteParam1L(errCodeDes));
1.244 + TRAP(err,aRequest.WriteParam2L(lineNumberDes));
1.245 + break;
1.246 + }
1.247 + default:
1.248 + break;
1.249 + }
1.250 +
1.251 + return err;
1.252 + }
1.253 +
1.254 +TInt CStacked2PluginConn::DoControl(CFsPluginConnRequest& aRequest)
1.255 + {
1.256 + return ((CStacked2Plugin*)Plugin())->FsPluginDoControlL(aRequest);
1.257 + }
1.258 +
1.259 +void CStacked2PluginConn::DoRequest(CFsPluginConnRequest& aRequest)
1.260 + {
1.261 + DoControl(aRequest);
1.262 + }
1.263 +
1.264 +void CStacked2PluginConn::DoCancel(TInt /*aReqMask*/)
1.265 + {
1.266 + }
1.267 +
1.268 +//factory functions
1.269 +
1.270 +class CStacked2PluginFactory : public CFsPluginFactory
1.271 + {
1.272 + public:
1.273 + CStacked2PluginFactory();
1.274 + virtual TInt Install();
1.275 + virtual CFsPlugin* NewPluginL();
1.276 + virtual CFsPlugin* NewPluginConnL();
1.277 + virtual TInt UniquePosition();
1.278 + };
1.279 +
1.280 +/**
1.281 +Constructor for the plugin factory
1.282 +@internalComponent
1.283 + */
1.284 +CStacked2PluginFactory::CStacked2PluginFactory()
1.285 + {
1.286 + }
1.287 +
1.288 +/**
1.289 +Install function for the plugin factory
1.290 +@internalComponent
1.291 + */
1.292 +TInt CStacked2PluginFactory::Install()
1.293 + {
1.294 + //SetSupportedDrives(1<<23);
1.295 + iSupportedDrives = 1<<23;
1.296 + return(SetName(&KStacked2PluginName));
1.297 + }
1.298 +
1.299 +/**
1.300 +@internalComponent
1.301 + */
1.302 +TInt CStacked2PluginFactory::UniquePosition()
1.303 + {
1.304 + return(KStacked2Pos);
1.305 + }
1.306 +
1.307 +/**
1.308 +Plugin factory function
1.309 +@internalComponent
1.310 + */
1.311 +CFsPlugin* CStacked2PluginFactory::NewPluginL()
1.312 +
1.313 + {
1.314 + return CStacked2Plugin::NewL();
1.315 + }
1.316 +
1.317 +/**
1.318 +Plugin factory function
1.319 +@internalComponent
1.320 + */
1.321 +CFsPlugin* CStacked2PluginFactory::NewPluginConnL()
1.322 +
1.323 + {
1.324 + return CStacked2Plugin::NewL();
1.325 + }
1.326 +
1.327 +/**
1.328 +Create a new Plugin
1.329 +@internalComponent
1.330 + */
1.331 +extern "C" {
1.332 +
1.333 +EXPORT_C CFsPluginFactory* CreateFileSystem()
1.334 + {
1.335 + return(new CStacked2PluginFactory());
1.336 + }
1.337 +}