Update contrib.
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\plugins\hex\t_hexhook.cpp
18 #include "t_hexhook.h"
19 #include <f32pluginutils.h>
22 _LIT(KHexPluginName, "This is a test plugin which converts binary data to hex");
26 Leaving New function for the plugin
29 CTestHexHook* CTestHexHook::NewL()
31 return new(ELeave) CTestHexHook;
36 Constructor for the plugin
39 CTestHexHook::CTestHexHook()
45 The destructor for the test hex plugin hook.
48 CTestHexHook::~CTestHexHook()
54 Initialise the hex plugin.
57 void CTestHexHook::InitialiseL()
59 User::LeaveIfError(RegisterIntercept(EFsFileOpen, EPreIntercept));
60 User::LeaveIfError(RegisterIntercept(EFsFileRead, EPrePostIntercept));
61 // User::LeaveIfError(RegisterIntercept(EFsFileWrite, EPreIntercept));
63 User::LeaveIfError(iFs.Connect());
69 TInt CTestHexHook::DoRequestL(TFsPluginRequest& aRequest)
71 TInt err = KErrNotSupported;
73 TInt function = aRequest.Function();
75 iDrvNumber = aRequest.DriveNumber();
80 err = HexFileOpen(aRequest);
84 // Post intercept does nothing except prove that it is possible and that no deadlock occurs.
85 // plugin always calls FileRead() when receiving a EFsFileRead, and so the mesage gets completed
86 // by the plugin and has to be post intercepted by the plugin (if registered to post-intercept the request)
87 // and any plugins above it.
89 if (!(aRequest.IsPostOperation()))
90 err = HexFileRead(aRequest);
104 TInt CTestHexHook::HexFileOpen(TFsPluginRequest& aRequest)
110 // TInt driveNumber = aRequest.DriveNumber();
112 TInt err = GetName(&aRequest, fileName);
116 // err = ScanFile(fileName);
125 TInt CTestHexHook::HexFileRead(TFsPluginRequest& aRequest)
129 // TInt driveNumber = aRequest.DriveNumber();
131 TInt r = GetName(&aRequest, fileName);
136 r = GetFileAccessInfo(&aRequest, len, pos);
140 // if length is ODD, then it can't be hex
147 TInt readLen = Min(len<<1, iHexBuf.MaxLength());
150 TPtr8 ptrHex((TUint8*) iHexBuf.Ptr(), readLen, readLen);
151 r = FileRead(aRequest, ptrHex, pos<<1);
154 readLen = ptrHex.Length();
156 return KErrCompletion;
158 TInt binLen = readLen>>1;
159 TPtr8 ptrBin((TUint8*) iBinBuf.Ptr(), binLen, binLen);
160 DeHex(ptrHex, ptrBin);
162 // write back to client (may be an app or another plugin)
163 r = ClientWrite(aRequest, ptrBin, offset);
169 return KErrCompletion;
177 TInt CTestHexHook::HexPluginName(TDes& aName)
179 aName = KHexPluginName;
188 class CHexHookFactory : public CFsPluginFactory
192 virtual TInt Install();
193 virtual CFsPlugin* NewPluginL();
194 virtual CFsPlugin* NewPluginConnL();
195 virtual TInt UniquePosition();
199 Constructor for the plugin factory
202 CHexHookFactory::CHexHookFactory()
207 Install function for the plugin factory
210 TInt CHexHookFactory::Install()
212 iSupportedDrives = KPluginAutoAttach;
214 _LIT(KHexHookName,"HexHook");
215 return(SetName(&KHexHookName));
221 TInt CHexHookFactory::UniquePosition()
227 Plugin factory function
230 CFsPlugin* CHexHookFactory::NewPluginL()
233 return CTestHexHook::NewL();
237 Plugin factory function
240 CFsPlugin* CHexHookFactory::NewPluginConnL()
243 return CTestHexHook::NewL();
252 EXPORT_C CFsPluginFactory* CreateFileSystem()
254 return(new CHexHookFactory());