1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/server/t_notify_plugin.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,297 @@
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 "t_notify_plugin.h"
1.20 +#include <f32pluginutils.h>
1.21 +
1.22 +TChar gDriveToTest;
1.23 +
1.24 +/**
1.25 +Leaving New function for the plugin
1.26 +@internalComponent
1.27 +*/
1.28 +CNotifyPlugin* CNotifyPlugin::NewL()
1.29 + {
1.30 + CNotifyPlugin* self = new(ELeave) CNotifyPlugin;
1.31 + CleanupStack::PushL(self);
1.32 + self->ConstructL();
1.33 + CleanupStack::Pop();
1.34 + return self;
1.35 + }
1.36 +
1.37 +
1.38 +/**
1.39 +Constructor for the plugin
1.40 +@internalComponent
1.41 +*/
1.42 +CNotifyPlugin::CNotifyPlugin() : iInterceptsEnabled(EFalse),
1.43 + iLogging(ETrue)
1.44 + {
1.45 + }
1.46 +
1.47 +
1.48 +void CNotifyPlugin::ConstructL()
1.49 + {
1.50 + }
1.51 +
1.52 +/**
1.53 +The destructor for the plugin
1.54 +@internalComponent
1.55 +*/
1.56 +CNotifyPlugin::~CNotifyPlugin()
1.57 + {
1.58 + iFs.Close();
1.59 + }
1.60 +
1.61 +/**
1.62 +Initialise the plugin.
1.63 +@internalComponent
1.64 +*/
1.65 +void CNotifyPlugin::InitialiseL()
1.66 + {
1.67 + User::LeaveIfError(iFs.Connect());
1.68 + CleanupClosePushL(iFs);
1.69 +
1.70 + _LOG(_L("CNotifyPlugin InitialiseL"));
1.71 + EnableInterceptsL();
1.72 +
1.73 + CleanupStack::Pop(); // iFs
1.74 + }
1.75 +
1.76 +/**
1.77 +Enable the plugin's intercepts.
1.78 +@internalComponent
1.79 +*/
1.80 +void CNotifyPlugin::EnableInterceptsL()
1.81 + {
1.82 + if (iInterceptsEnabled) return;
1.83 +
1.84 + User::LeaveIfError(RegisterIntercept(EFsFileRead, EPrePostIntercept));
1.85 + User::LeaveIfError(RegisterIntercept(EFsFileWrite, EPrePostIntercept));
1.86 + User::LeaveIfError(RegisterIntercept(EFsDirOpen, EPrePostIntercept));
1.87 + User::LeaveIfError(RegisterIntercept(EFsFileLock, EPrePostIntercept));
1.88 + User::LeaveIfError(RegisterIntercept(EFsFileUnLock, EPrePostIntercept));
1.89 + User::LeaveIfError(RegisterIntercept(EFsFileSeek, EPrePostIntercept));
1.90 + User::LeaveIfError(RegisterIntercept(EFsFileSize, EPrePostIntercept));
1.91 + User::LeaveIfError(RegisterIntercept(EFsFileSetSize, EPrePostIntercept));
1.92 + User::LeaveIfError(RegisterIntercept(EFsDirReadOne, EPrePostIntercept));
1.93 + User::LeaveIfError(RegisterIntercept(EFsDirReadPacked, EPrePostIntercept));
1.94 + User::LeaveIfError(RegisterIntercept(EFsFileOpen, EPrePostIntercept));
1.95 + User::LeaveIfError(RegisterIntercept(EFsFileCreate, EPrePostIntercept));
1.96 + User::LeaveIfError(RegisterIntercept(EFsFileReplace,EPrePostIntercept));
1.97 + User::LeaveIfError(RegisterIntercept(EFsFileRename, EPrePostIntercept));
1.98 + User::LeaveIfError(RegisterIntercept(EFsReadFileSection,EPrePostIntercept));
1.99 + User::LeaveIfError(RegisterIntercept(EFsFileSubClose, EPrePostIntercept));
1.100 +
1.101 + _LOG(_L("Notify Plugin: Enabled intercepts."));
1.102 +
1.103 + iInterceptsEnabled = ETrue;
1.104 + }
1.105 +
1.106 +/**
1.107 +Disable the plugin's intercepts.
1.108 +@internalComponent
1.109 +*/
1.110 +void CNotifyPlugin::DisableInterceptsL()
1.111 + {
1.112 + if (!iInterceptsEnabled) return;
1.113 +
1.114 + User::LeaveIfError(UnregisterIntercept(EFsFileRead, EPrePostIntercept));
1.115 + User::LeaveIfError(UnregisterIntercept(EFsFileRename, EPrePostIntercept));
1.116 + User::LeaveIfError(UnregisterIntercept(EFsFileWrite, EPrePostIntercept));
1.117 + User::LeaveIfError(UnregisterIntercept(EFsDirOpen, EPrePostIntercept));
1.118 + User::LeaveIfError(UnregisterIntercept(EFsFileLock, EPrePostIntercept));
1.119 + User::LeaveIfError(UnregisterIntercept(EFsFileUnLock, EPrePostIntercept));
1.120 + User::LeaveIfError(UnregisterIntercept(EFsFileSeek, EPrePostIntercept));
1.121 + User::LeaveIfError(UnregisterIntercept(EFsFileSize, EPrePostIntercept));
1.122 + User::LeaveIfError(UnregisterIntercept(EFsFileSetSize, EPrePostIntercept));
1.123 + User::LeaveIfError(UnregisterIntercept(EFsFileCreate, EPrePostIntercept));
1.124 + User::LeaveIfError(UnregisterIntercept(EFsFileOpen, EPrePostIntercept));
1.125 + User::LeaveIfError(UnregisterIntercept(EFsFileReplace, EPrePostIntercept));
1.126 + User::LeaveIfError(UnregisterIntercept(EFsFileSubClose, EPrePostIntercept));
1.127 + User::LeaveIfError(UnregisterIntercept(EFsReadFileSection,EPrePostIntercept));
1.128 + User::LeaveIfError(UnregisterIntercept(EFsDirReadOne, EPrePostIntercept));
1.129 + User::LeaveIfError(UnregisterIntercept(EFsDirReadPacked,EPrePostIntercept));
1.130 +
1.131 +
1.132 + _LOG(_L("Notify Plugin: Disabled intercepts."));
1.133 +
1.134 + iInterceptsEnabled = EFalse;
1.135 + }
1.136 +
1.137 +/**
1.138 +Handle requests
1.139 +@internalComponent
1.140 +*/
1.141 +TInt CNotifyPlugin::DoRequestL(TFsPluginRequest& aRequest)
1.142 + {
1.143 + TInt err = KErrNone;
1.144 +
1.145 + TInt function = aRequest.Function();
1.146 +
1.147 + if (aRequest.IsPostOperation())
1.148 + {
1.149 + _LOG2(_L("CNotifyPlugin post intercept for function %d"), function);
1.150 + }
1.151 + else if(function==EFsFileCreate)
1.152 + {
1.153 + _LOG2(_L("CNotifyPlugin pre intercept for function %d"), function);
1.154 +
1.155 + TBuf<40> basepath;
1.156 + basepath.Append(gDriveToTest);
1.157 + basepath.Append(_L(":\\F32-TST\\T_NOTIFIER\\")); //len=22
1.158 +
1.159 + TBuf<40> path1;
1.160 + path1.Copy(basepath);
1.161 + path1.Append(_L("plugin.create"));
1.162 +
1.163 + RFilePlugin file(aRequest);
1.164 + //Wrong file - should not notify
1.165 + file.Replace(path1,EFileWrite);
1.166 + file.Close();
1.167 +
1.168 + TBuf<40> path2;
1.169 + path2.Copy(basepath);
1.170 + path2.Append(_L("simple.create"));
1.171 +
1.172 + //Correct file, Should notify?
1.173 + RFilePlugin fileplugin(aRequest);
1.174 + TInt r = fileplugin.Create(path2,EFileWrite);
1.175 + r = fileplugin.TransferToClient();
1.176 + fileplugin.Close();
1.177 +
1.178 + return KErrCompletion;
1.179 + }
1.180 +
1.181 + return err;
1.182 + }
1.183 +
1.184 +
1.185 +CFsPluginConn* CNotifyPlugin::NewPluginConnL()
1.186 + {
1.187 + return new(ELeave) CNotifyPluginConn();
1.188 + }
1.189 +
1.190 +//Synchronous RPlugin::DoControl
1.191 +TInt CNotifyPlugin::FsPluginDoControlL(CFsPluginConnRequest& aRequest)
1.192 + {
1.193 + TInt function = aRequest.Function();
1.194 +
1.195 + switch(function)
1.196 + {
1.197 + case KPluginSetDrive:
1.198 + {
1.199 + TPckg<TChar> drive(gDriveToTest);
1.200 + TRAPD(err,aRequest.ReadParam1L(drive));
1.201 + if(err != KErrNone)
1.202 + return err;
1.203 + break;
1.204 + }
1.205 + default:
1.206 + break;
1.207 + }
1.208 +
1.209 + return KErrNone;
1.210 + }
1.211 +
1.212 +
1.213 +TInt CNotifyPluginConn::DoControl(CFsPluginConnRequest& aRequest)
1.214 + {
1.215 + return ((CNotifyPlugin*)Plugin())->FsPluginDoControlL(aRequest);
1.216 + }
1.217 +
1.218 +void CNotifyPluginConn::DoRequest(CFsPluginConnRequest& aRequest)
1.219 + {
1.220 + DoControl(aRequest);
1.221 + }
1.222 +
1.223 +void CNotifyPluginConn::DoCancel(TInt /*aReqMask*/)
1.224 + {
1.225 + }
1.226 +
1.227 +
1.228 +
1.229 +
1.230 +
1.231 +//factory functions
1.232 +
1.233 +class CNotifyPluginFactory : public CFsPluginFactory
1.234 + {
1.235 +public:
1.236 + CNotifyPluginFactory();
1.237 + virtual TInt Install();
1.238 + virtual CFsPlugin* NewPluginL();
1.239 + virtual CFsPlugin* NewPluginConnL();
1.240 + virtual TInt UniquePosition();
1.241 + };
1.242 +
1.243 +/**
1.244 +Constructor for the plugin factory
1.245 +@internalComponent
1.246 +*/
1.247 +CNotifyPluginFactory::CNotifyPluginFactory()
1.248 + {
1.249 + }
1.250 +
1.251 +/**
1.252 +Install function for the plugin factory
1.253 +@internalComponent
1.254 +*/
1.255 +TInt CNotifyPluginFactory::Install()
1.256 + {
1.257 + SetSupportedDrives(KPluginSupportAllDrives);
1.258 + return(SetName(&KNotifyPluginName));
1.259 + }
1.260 +
1.261 +/**
1.262 +@internalComponent
1.263 +*/
1.264 +TInt CNotifyPluginFactory::UniquePosition()
1.265 + {
1.266 + return(KNotifyPos);
1.267 + }
1.268 +
1.269 +/**
1.270 +Plugin factory function
1.271 +@internalComponent
1.272 +*/
1.273 +CFsPlugin* CNotifyPluginFactory::NewPluginL()
1.274 +
1.275 + {
1.276 + return CNotifyPlugin::NewL();
1.277 + }
1.278 +
1.279 +/**
1.280 +Plugin factory function
1.281 +@internalComponent
1.282 +*/
1.283 +CFsPlugin* CNotifyPluginFactory::NewPluginConnL()
1.284 +
1.285 + {
1.286 + return CNotifyPlugin::NewL();
1.287 + }
1.288 +
1.289 +/**
1.290 +Create a new Plugin
1.291 +@internalComponent
1.292 +*/
1.293 +extern "C" {
1.294 +
1.295 +EXPORT_C CFsPluginFactory* CreateFileSystem()
1.296 + {
1.297 + return(new CNotifyPluginFactory());
1.298 + }
1.299 +}
1.300 +