os/kernelhwsrv/kerneltest/f32test/plugins/version_2beta/hex/t_hexhook.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_2beta/hex/t_hexhook.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,257 @@
     1.4 +// Copyright (c) 2006-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 +// f32test\plugins\hex\t_hexhook.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include "t_hexhook.h"
    1.22 +#include <f32pluginutils.h>
    1.23 +#include "hex.h"
    1.24 +
    1.25 +_LIT(KHexPluginName, "This is a test plugin which converts binary data to hex");
    1.26 +
    1.27 +
    1.28 +/**
    1.29 +Leaving New function for the plugin
    1.30 +@internalComponent
    1.31 +*/
    1.32 +CTestHexHook* CTestHexHook::NewL()
    1.33 +	{
    1.34 +	return new(ELeave) CTestHexHook;
    1.35 +	}
    1.36 +
    1.37 +
    1.38 +/**
    1.39 +Constructor for the plugin
    1.40 +@internalComponent
    1.41 +*/
    1.42 +CTestHexHook::CTestHexHook()
    1.43 +	{
    1.44 +	}
    1.45 +
    1.46 +
    1.47 +/**
    1.48 +The destructor for the test hex plugin hook. 
    1.49 +@internalComponent
    1.50 +*/
    1.51 +CTestHexHook::~CTestHexHook()
    1.52 +	{
    1.53 +	iFs.Close();
    1.54 +	}
    1.55 +
    1.56 +/**
    1.57 +Initialise the hex plugin.
    1.58 +@internalComponent
    1.59 +*/
    1.60 +void CTestHexHook::InitialiseL()
    1.61 +	{
    1.62 +	User::LeaveIfError(RegisterIntercept(EFsFileOpen,			EPreIntercept));
    1.63 +	User::LeaveIfError(RegisterIntercept(EFsFileRead,			EPrePostIntercept));
    1.64 +//	User::LeaveIfError(RegisterIntercept(EFsFileWrite,			EPreIntercept));
    1.65 +
    1.66 +	User::LeaveIfError(iFs.Connect());
    1.67 +	}
    1.68 +
    1.69 +/**
    1.70 +@internalComponent
    1.71 +*/
    1.72 +TInt CTestHexHook::DoRequestL(TFsPluginRequest& aRequest)
    1.73 +	{
    1.74 +	TInt err = KErrNotSupported;
    1.75 +
    1.76 +	TInt function = aRequest.Function();
    1.77 +	
    1.78 +	iDrvNumber = aRequest.DriveNumber();
    1.79 +
    1.80 +	switch(function)
    1.81 +		{
    1.82 +		case EFsFileOpen:
    1.83 +			err = HexFileOpen(aRequest);
    1.84 +			break;
    1.85 +
    1.86 +		case EFsFileRead:
    1.87 +			// Post intercept does nothing except prove that it is possible and that no deadlock occurs.
    1.88 +			// plugin always calls FileRead() when receiving a EFsFileRead, and so the mesage gets completed
    1.89 +			// by the plugin and has to be post intercepted by the plugin (if registered to post-intercept the request) 
    1.90 +			// and any plugins above it.
    1.91 +
    1.92 +			if (!(aRequest.IsPostOperation()))
    1.93 +				err = HexFileRead(aRequest);
    1.94 +			break;
    1.95 +
    1.96 +		default:
    1.97 +			break;
    1.98 +		}
    1.99 +
   1.100 +	return err;
   1.101 +	}
   1.102 +
   1.103 +
   1.104 +/**
   1.105 +@internalComponent
   1.106 +*/
   1.107 +TInt CTestHexHook::HexFileOpen(TFsPluginRequest& aRequest)
   1.108 +	{
   1.109 +	TFileName fileName;
   1.110 +
   1.111 +	
   1.112 +	
   1.113 +//	TInt driveNumber = aRequest.DriveNumber();
   1.114 +	
   1.115 +	TInt err = GetName(&aRequest, fileName);
   1.116 +	if(err != KErrNone)
   1.117 +		return(err);
   1.118 +	
   1.119 +//	err = ScanFile(fileName);
   1.120 +
   1.121 +	return err;
   1.122 +	}
   1.123 +
   1.124 +
   1.125 +/**
   1.126 +@internalComponent
   1.127 +*/
   1.128 +TInt CTestHexHook::HexFileRead(TFsPluginRequest& aRequest)
   1.129 +	{
   1.130 +	TFileName fileName;
   1.131 +	
   1.132 +//	TInt driveNumber = aRequest.DriveNumber();
   1.133 +	
   1.134 +	TInt r = GetName(&aRequest, fileName);
   1.135 +	if(r != KErrNone)
   1.136 +		return(r);
   1.137 +
   1.138 +	TInt len, pos;
   1.139 +	r = GetFileAccessInfo(&aRequest, len, pos);
   1.140 +	if (r != KErrNone)
   1.141 +		return r;
   1.142 +
   1.143 +	// if length is ODD, then it can't be hex
   1.144 +	if (len & 0x01)
   1.145 +		return KErrCorrupt;
   1.146 +
   1.147 +	TInt offset = 0;
   1.148 +	while(len > 0)
   1.149 +		{
   1.150 +		TInt readLen = Min(len<<1, iHexBuf.MaxLength());
   1.151 +
   1.152 +		// read from file
   1.153 +		TPtr8 ptrHex((TUint8*) iHexBuf.Ptr(), readLen, readLen);
   1.154 +		r = FileRead(aRequest, ptrHex, pos<<1);
   1.155 +		if (r != KErrNone)
   1.156 +			return r;
   1.157 +		readLen = ptrHex.Length();
   1.158 +		if (readLen == 0)
   1.159 +			return KErrCompletion;
   1.160 +
   1.161 +		TInt binLen = readLen>>1;
   1.162 +		TPtr8 ptrBin((TUint8*) iBinBuf.Ptr(), binLen, binLen);
   1.163 +		DeHex(ptrHex, ptrBin);
   1.164 +
   1.165 +		// write back to client (may be an app or another plugin)
   1.166 +		r = ClientWrite(aRequest, ptrBin, offset);
   1.167 +		offset+= binLen;
   1.168 +		len-= binLen;
   1.169 +		pos+= readLen;
   1.170 +		}
   1.171 +	
   1.172 +	return KErrCompletion;
   1.173 +	}
   1.174 +
   1.175 +
   1.176 +
   1.177 +/**
   1.178 +@internalComponent
   1.179 +*/
   1.180 +TInt CTestHexHook::HexPluginName(TDes& aName)
   1.181 +	{
   1.182 +	aName = KHexPluginName;
   1.183 +	return KErrNone;
   1.184 +	}
   1.185 +
   1.186 +
   1.187 +
   1.188 +
   1.189 +//factory functions
   1.190 +
   1.191 +class CHexHookFactory : public CFsPluginFactory
   1.192 +	{
   1.193 +public:
   1.194 +	CHexHookFactory();
   1.195 +	virtual TInt Install();			
   1.196 +	virtual CFsPlugin* NewPluginL();
   1.197 +	virtual CFsPlugin* NewPluginConnL();
   1.198 +	virtual TInt UniquePosition();
   1.199 +	};
   1.200 +
   1.201 +/**
   1.202 +Constructor for the plugin factory
   1.203 +@internalComponent
   1.204 +*/
   1.205 +CHexHookFactory::CHexHookFactory()
   1.206 +	{
   1.207 +	}
   1.208 +
   1.209 +/**
   1.210 +Install function for the plugin factory
   1.211 +@internalComponent
   1.212 +*/
   1.213 +TInt CHexHookFactory::Install()
   1.214 +	{
   1.215 +	iSupportedDrives = KPluginAutoAttach;
   1.216 +
   1.217 +	_LIT(KHexHookName,"HexHook");
   1.218 +	return(SetName(&KHexHookName));
   1.219 +	}
   1.220 +
   1.221 +/**
   1.222 +@internalComponent
   1.223 +*/
   1.224 +TInt CHexHookFactory::UniquePosition()
   1.225 +	{
   1.226 +	return(0x4EC);
   1.227 +	}
   1.228 +
   1.229 +/**
   1.230 +Plugin factory function
   1.231 +@internalComponent
   1.232 +*/
   1.233 +CFsPlugin* CHexHookFactory::NewPluginL()
   1.234 +
   1.235 +	{
   1.236 +	return CTestHexHook::NewL();
   1.237 +	}
   1.238 +
   1.239 +/**
   1.240 +Plugin factory function
   1.241 +@internalComponent
   1.242 +*/
   1.243 +CFsPlugin* CHexHookFactory::NewPluginConnL()
   1.244 +
   1.245 +	{
   1.246 +	return CTestHexHook::NewL();
   1.247 +	}
   1.248 +
   1.249 +/**
   1.250 +Create a new Plugin
   1.251 +@internalComponent
   1.252 +*/
   1.253 +extern "C" {
   1.254 +
   1.255 +EXPORT_C CFsPluginFactory* CreateFileSystem()
   1.256 +	{
   1.257 +	return(new CHexHookFactory());
   1.258 +	}
   1.259 +}
   1.260 +