sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // f32test\plugins\hex\t_hexhook.cpp sl@0: // sl@0: // sl@0: sl@0: #include "t_hexhook.h" sl@0: #include sl@0: #include "hex.h" sl@0: sl@0: _LIT(KHexPluginName, "This is a test plugin which converts binary data to hex"); sl@0: sl@0: sl@0: /** sl@0: Leaving New function for the plugin sl@0: @internalComponent sl@0: */ sl@0: CTestHexHook* CTestHexHook::NewL() sl@0: { sl@0: return new(ELeave) CTestHexHook; sl@0: } sl@0: sl@0: sl@0: /** sl@0: Constructor for the plugin sl@0: @internalComponent sl@0: */ sl@0: CTestHexHook::CTestHexHook() sl@0: { sl@0: } sl@0: sl@0: sl@0: /** sl@0: The destructor for the test hex plugin hook. sl@0: @internalComponent sl@0: */ sl@0: CTestHexHook::~CTestHexHook() sl@0: { sl@0: iFs.Close(); sl@0: } sl@0: sl@0: /** sl@0: Initialise the hex plugin. sl@0: @internalComponent sl@0: */ sl@0: void CTestHexHook::InitialiseL() sl@0: { sl@0: User::LeaveIfError(RegisterIntercept(EFsFileOpen, EPreIntercept)); sl@0: User::LeaveIfError(RegisterIntercept(EFsFileRead, EPrePostIntercept)); sl@0: // User::LeaveIfError(RegisterIntercept(EFsFileWrite, EPreIntercept)); sl@0: sl@0: User::LeaveIfError(iFs.Connect()); sl@0: } sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: TInt CTestHexHook::DoRequestL(TFsPluginRequest& aRequest) sl@0: { sl@0: TInt err = KErrNotSupported; sl@0: sl@0: TInt function = aRequest.Function(); sl@0: sl@0: iDrvNumber = aRequest.DriveNumber(); sl@0: sl@0: switch(function) sl@0: { sl@0: case EFsFileOpen: sl@0: err = HexFileOpen(aRequest); sl@0: break; sl@0: sl@0: case EFsFileRead: sl@0: // Post intercept does nothing except prove that it is possible and that no deadlock occurs. sl@0: // plugin always calls FileRead() when receiving a EFsFileRead, and so the mesage gets completed sl@0: // by the plugin and has to be post intercepted by the plugin (if registered to post-intercept the request) sl@0: // and any plugins above it. sl@0: sl@0: if (!(aRequest.IsPostOperation())) sl@0: err = HexFileRead(aRequest); sl@0: break; sl@0: sl@0: default: sl@0: break; sl@0: } sl@0: sl@0: return err; sl@0: } sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: TInt CTestHexHook::HexFileOpen(TFsPluginRequest& aRequest) sl@0: { sl@0: TFileName fileName; sl@0: sl@0: sl@0: sl@0: // TInt driveNumber = aRequest.DriveNumber(); sl@0: sl@0: TInt err = GetName(&aRequest, fileName); sl@0: if(err != KErrNone) sl@0: return(err); sl@0: sl@0: // err = ScanFile(fileName); sl@0: sl@0: return err; sl@0: } sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: TInt CTestHexHook::HexFileRead(TFsPluginRequest& aRequest) sl@0: { sl@0: TFileName fileName; sl@0: sl@0: // TInt driveNumber = aRequest.DriveNumber(); sl@0: sl@0: TInt r = GetName(&aRequest, fileName); sl@0: if(r != KErrNone) sl@0: return(r); sl@0: sl@0: TInt len, pos; sl@0: r = GetFileAccessInfo(&aRequest, len, pos); sl@0: if (r != KErrNone) sl@0: return r; sl@0: sl@0: // if length is ODD, then it can't be hex sl@0: if (len & 0x01) sl@0: return KErrCorrupt; sl@0: sl@0: TInt offset = 0; sl@0: while(len > 0) sl@0: { sl@0: TInt readLen = Min(len<<1, iHexBuf.MaxLength()); sl@0: sl@0: // read from file sl@0: TPtr8 ptrHex((TUint8*) iHexBuf.Ptr(), readLen, readLen); sl@0: r = FileRead(aRequest, ptrHex, pos<<1); sl@0: if (r != KErrNone) sl@0: return r; sl@0: readLen = ptrHex.Length(); sl@0: if (readLen == 0) sl@0: return KErrCompletion; sl@0: sl@0: TInt binLen = readLen>>1; sl@0: TPtr8 ptrBin((TUint8*) iBinBuf.Ptr(), binLen, binLen); sl@0: DeHex(ptrHex, ptrBin); sl@0: sl@0: // write back to client (may be an app or another plugin) sl@0: r = ClientWrite(aRequest, ptrBin, offset); sl@0: offset+= binLen; sl@0: len-= binLen; sl@0: pos+= readLen; sl@0: } sl@0: sl@0: return KErrCompletion; sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: TInt CTestHexHook::HexPluginName(TDes& aName) sl@0: { sl@0: aName = KHexPluginName; sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: //factory functions sl@0: sl@0: class CHexHookFactory : public CFsPluginFactory sl@0: { sl@0: public: sl@0: CHexHookFactory(); sl@0: virtual TInt Install(); sl@0: virtual CFsPlugin* NewPluginL(); sl@0: virtual CFsPlugin* NewPluginConnL(); sl@0: virtual TInt UniquePosition(); sl@0: }; sl@0: sl@0: /** sl@0: Constructor for the plugin factory sl@0: @internalComponent sl@0: */ sl@0: CHexHookFactory::CHexHookFactory() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Install function for the plugin factory sl@0: @internalComponent sl@0: */ sl@0: TInt CHexHookFactory::Install() sl@0: { sl@0: iSupportedDrives = KPluginAutoAttach; sl@0: sl@0: _LIT(KHexHookName,"HexHook"); sl@0: return(SetName(&KHexHookName)); sl@0: } sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: TInt CHexHookFactory::UniquePosition() sl@0: { sl@0: return(0x4EC); sl@0: } sl@0: sl@0: /** sl@0: Plugin factory function sl@0: @internalComponent sl@0: */ sl@0: CFsPlugin* CHexHookFactory::NewPluginL() sl@0: sl@0: { sl@0: return CTestHexHook::NewL(); sl@0: } sl@0: sl@0: /** sl@0: Plugin factory function sl@0: @internalComponent sl@0: */ sl@0: CFsPlugin* CHexHookFactory::NewPluginConnL() sl@0: sl@0: { sl@0: return CTestHexHook::NewL(); sl@0: } sl@0: sl@0: /** sl@0: Create a new Plugin sl@0: @internalComponent sl@0: */ sl@0: extern "C" { sl@0: sl@0: EXPORT_C CFsPluginFactory* CreateFileSystem() sl@0: { sl@0: return(new CHexHookFactory()); sl@0: } sl@0: } sl@0: