sl@0
|
1 |
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// f32test\plugins\hex\t_hexhook.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include "t_hexhook.h"
|
sl@0
|
19 |
#include <f32pluginutils.h>
|
sl@0
|
20 |
#include "hex.h"
|
sl@0
|
21 |
|
sl@0
|
22 |
_LIT(KHexPluginName, "This is a test plugin which converts binary data to hex");
|
sl@0
|
23 |
|
sl@0
|
24 |
|
sl@0
|
25 |
/**
|
sl@0
|
26 |
Leaving New function for the plugin
|
sl@0
|
27 |
@internalComponent
|
sl@0
|
28 |
*/
|
sl@0
|
29 |
CTestHexHook* CTestHexHook::NewL()
|
sl@0
|
30 |
{
|
sl@0
|
31 |
return new(ELeave) CTestHexHook;
|
sl@0
|
32 |
}
|
sl@0
|
33 |
|
sl@0
|
34 |
|
sl@0
|
35 |
/**
|
sl@0
|
36 |
Constructor for the plugin
|
sl@0
|
37 |
@internalComponent
|
sl@0
|
38 |
*/
|
sl@0
|
39 |
CTestHexHook::CTestHexHook()
|
sl@0
|
40 |
{
|
sl@0
|
41 |
}
|
sl@0
|
42 |
|
sl@0
|
43 |
|
sl@0
|
44 |
/**
|
sl@0
|
45 |
The destructor for the test hex plugin hook.
|
sl@0
|
46 |
@internalComponent
|
sl@0
|
47 |
*/
|
sl@0
|
48 |
CTestHexHook::~CTestHexHook()
|
sl@0
|
49 |
{
|
sl@0
|
50 |
iFs.Close();
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
/**
|
sl@0
|
54 |
Initialise the hex plugin.
|
sl@0
|
55 |
@internalComponent
|
sl@0
|
56 |
*/
|
sl@0
|
57 |
void CTestHexHook::InitialiseL()
|
sl@0
|
58 |
{
|
sl@0
|
59 |
User::LeaveIfError(RegisterIntercept(EFsFileOpen, EPreIntercept));
|
sl@0
|
60 |
User::LeaveIfError(RegisterIntercept(EFsFileRead, EPrePostIntercept));
|
sl@0
|
61 |
// User::LeaveIfError(RegisterIntercept(EFsFileWrite, EPreIntercept));
|
sl@0
|
62 |
|
sl@0
|
63 |
User::LeaveIfError(iFs.Connect());
|
sl@0
|
64 |
}
|
sl@0
|
65 |
|
sl@0
|
66 |
/**
|
sl@0
|
67 |
@internalComponent
|
sl@0
|
68 |
*/
|
sl@0
|
69 |
TInt CTestHexHook::DoRequestL(TFsPluginRequest& aRequest)
|
sl@0
|
70 |
{
|
sl@0
|
71 |
TInt err = KErrNotSupported;
|
sl@0
|
72 |
|
sl@0
|
73 |
TInt function = aRequest.Function();
|
sl@0
|
74 |
|
sl@0
|
75 |
iDrvNumber = aRequest.DriveNumber();
|
sl@0
|
76 |
|
sl@0
|
77 |
switch(function)
|
sl@0
|
78 |
{
|
sl@0
|
79 |
case EFsFileOpen:
|
sl@0
|
80 |
err = HexFileOpen(aRequest);
|
sl@0
|
81 |
break;
|
sl@0
|
82 |
|
sl@0
|
83 |
case EFsFileRead:
|
sl@0
|
84 |
// Post intercept does nothing except prove that it is possible and that no deadlock occurs.
|
sl@0
|
85 |
// plugin always calls FileRead() when receiving a EFsFileRead, and so the mesage gets completed
|
sl@0
|
86 |
// by the plugin and has to be post intercepted by the plugin (if registered to post-intercept the request)
|
sl@0
|
87 |
// and any plugins above it.
|
sl@0
|
88 |
|
sl@0
|
89 |
if (!(aRequest.IsPostOperation()))
|
sl@0
|
90 |
err = HexFileRead(aRequest);
|
sl@0
|
91 |
break;
|
sl@0
|
92 |
|
sl@0
|
93 |
default:
|
sl@0
|
94 |
break;
|
sl@0
|
95 |
}
|
sl@0
|
96 |
|
sl@0
|
97 |
return err;
|
sl@0
|
98 |
}
|
sl@0
|
99 |
|
sl@0
|
100 |
|
sl@0
|
101 |
/**
|
sl@0
|
102 |
@internalComponent
|
sl@0
|
103 |
*/
|
sl@0
|
104 |
TInt CTestHexHook::HexFileOpen(TFsPluginRequest& aRequest)
|
sl@0
|
105 |
{
|
sl@0
|
106 |
TFileName fileName;
|
sl@0
|
107 |
|
sl@0
|
108 |
|
sl@0
|
109 |
|
sl@0
|
110 |
// TInt driveNumber = aRequest.DriveNumber();
|
sl@0
|
111 |
|
sl@0
|
112 |
TInt err = GetName(&aRequest, fileName);
|
sl@0
|
113 |
if(err != KErrNone)
|
sl@0
|
114 |
return(err);
|
sl@0
|
115 |
|
sl@0
|
116 |
// err = ScanFile(fileName);
|
sl@0
|
117 |
|
sl@0
|
118 |
return err;
|
sl@0
|
119 |
}
|
sl@0
|
120 |
|
sl@0
|
121 |
|
sl@0
|
122 |
/**
|
sl@0
|
123 |
@internalComponent
|
sl@0
|
124 |
*/
|
sl@0
|
125 |
TInt CTestHexHook::HexFileRead(TFsPluginRequest& aRequest)
|
sl@0
|
126 |
{
|
sl@0
|
127 |
TFileName fileName;
|
sl@0
|
128 |
|
sl@0
|
129 |
// TInt driveNumber = aRequest.DriveNumber();
|
sl@0
|
130 |
|
sl@0
|
131 |
TInt r = GetName(&aRequest, fileName);
|
sl@0
|
132 |
if(r != KErrNone)
|
sl@0
|
133 |
return(r);
|
sl@0
|
134 |
|
sl@0
|
135 |
TInt len, pos;
|
sl@0
|
136 |
r = GetFileAccessInfo(&aRequest, len, pos);
|
sl@0
|
137 |
if (r != KErrNone)
|
sl@0
|
138 |
return r;
|
sl@0
|
139 |
|
sl@0
|
140 |
// if length is ODD, then it can't be hex
|
sl@0
|
141 |
if (len & 0x01)
|
sl@0
|
142 |
return KErrCorrupt;
|
sl@0
|
143 |
|
sl@0
|
144 |
TInt offset = 0;
|
sl@0
|
145 |
while(len > 0)
|
sl@0
|
146 |
{
|
sl@0
|
147 |
TInt readLen = Min(len<<1, iHexBuf.MaxLength());
|
sl@0
|
148 |
|
sl@0
|
149 |
// read from file
|
sl@0
|
150 |
TPtr8 ptrHex((TUint8*) iHexBuf.Ptr(), readLen, readLen);
|
sl@0
|
151 |
r = FileRead(aRequest, ptrHex, pos<<1);
|
sl@0
|
152 |
if (r != KErrNone)
|
sl@0
|
153 |
return r;
|
sl@0
|
154 |
readLen = ptrHex.Length();
|
sl@0
|
155 |
if (readLen == 0)
|
sl@0
|
156 |
return KErrCompletion;
|
sl@0
|
157 |
|
sl@0
|
158 |
TInt binLen = readLen>>1;
|
sl@0
|
159 |
TPtr8 ptrBin((TUint8*) iBinBuf.Ptr(), binLen, binLen);
|
sl@0
|
160 |
DeHex(ptrHex, ptrBin);
|
sl@0
|
161 |
|
sl@0
|
162 |
// write back to client (may be an app or another plugin)
|
sl@0
|
163 |
r = ClientWrite(aRequest, ptrBin, offset);
|
sl@0
|
164 |
offset+= binLen;
|
sl@0
|
165 |
len-= binLen;
|
sl@0
|
166 |
pos+= readLen;
|
sl@0
|
167 |
}
|
sl@0
|
168 |
|
sl@0
|
169 |
return KErrCompletion;
|
sl@0
|
170 |
}
|
sl@0
|
171 |
|
sl@0
|
172 |
|
sl@0
|
173 |
|
sl@0
|
174 |
/**
|
sl@0
|
175 |
@internalComponent
|
sl@0
|
176 |
*/
|
sl@0
|
177 |
TInt CTestHexHook::HexPluginName(TDes& aName)
|
sl@0
|
178 |
{
|
sl@0
|
179 |
aName = KHexPluginName;
|
sl@0
|
180 |
return KErrNone;
|
sl@0
|
181 |
}
|
sl@0
|
182 |
|
sl@0
|
183 |
|
sl@0
|
184 |
|
sl@0
|
185 |
|
sl@0
|
186 |
//factory functions
|
sl@0
|
187 |
|
sl@0
|
188 |
class CHexHookFactory : public CFsPluginFactory
|
sl@0
|
189 |
{
|
sl@0
|
190 |
public:
|
sl@0
|
191 |
CHexHookFactory();
|
sl@0
|
192 |
virtual TInt Install();
|
sl@0
|
193 |
virtual CFsPlugin* NewPluginL();
|
sl@0
|
194 |
virtual CFsPlugin* NewPluginConnL();
|
sl@0
|
195 |
virtual TInt UniquePosition();
|
sl@0
|
196 |
};
|
sl@0
|
197 |
|
sl@0
|
198 |
/**
|
sl@0
|
199 |
Constructor for the plugin factory
|
sl@0
|
200 |
@internalComponent
|
sl@0
|
201 |
*/
|
sl@0
|
202 |
CHexHookFactory::CHexHookFactory()
|
sl@0
|
203 |
{
|
sl@0
|
204 |
}
|
sl@0
|
205 |
|
sl@0
|
206 |
/**
|
sl@0
|
207 |
Install function for the plugin factory
|
sl@0
|
208 |
@internalComponent
|
sl@0
|
209 |
*/
|
sl@0
|
210 |
TInt CHexHookFactory::Install()
|
sl@0
|
211 |
{
|
sl@0
|
212 |
iSupportedDrives = KPluginAutoAttach;
|
sl@0
|
213 |
|
sl@0
|
214 |
_LIT(KHexHookName,"HexHook");
|
sl@0
|
215 |
return(SetName(&KHexHookName));
|
sl@0
|
216 |
}
|
sl@0
|
217 |
|
sl@0
|
218 |
/**
|
sl@0
|
219 |
@internalComponent
|
sl@0
|
220 |
*/
|
sl@0
|
221 |
TInt CHexHookFactory::UniquePosition()
|
sl@0
|
222 |
{
|
sl@0
|
223 |
return(0x4EC);
|
sl@0
|
224 |
}
|
sl@0
|
225 |
|
sl@0
|
226 |
/**
|
sl@0
|
227 |
Plugin factory function
|
sl@0
|
228 |
@internalComponent
|
sl@0
|
229 |
*/
|
sl@0
|
230 |
CFsPlugin* CHexHookFactory::NewPluginL()
|
sl@0
|
231 |
|
sl@0
|
232 |
{
|
sl@0
|
233 |
return CTestHexHook::NewL();
|
sl@0
|
234 |
}
|
sl@0
|
235 |
|
sl@0
|
236 |
/**
|
sl@0
|
237 |
Plugin factory function
|
sl@0
|
238 |
@internalComponent
|
sl@0
|
239 |
*/
|
sl@0
|
240 |
CFsPlugin* CHexHookFactory::NewPluginConnL()
|
sl@0
|
241 |
|
sl@0
|
242 |
{
|
sl@0
|
243 |
return CTestHexHook::NewL();
|
sl@0
|
244 |
}
|
sl@0
|
245 |
|
sl@0
|
246 |
/**
|
sl@0
|
247 |
Create a new Plugin
|
sl@0
|
248 |
@internalComponent
|
sl@0
|
249 |
*/
|
sl@0
|
250 |
extern "C" {
|
sl@0
|
251 |
|
sl@0
|
252 |
EXPORT_C CFsPluginFactory* CreateFileSystem()
|
sl@0
|
253 |
{
|
sl@0
|
254 |
return(new CHexHookFactory());
|
sl@0
|
255 |
}
|
sl@0
|
256 |
}
|
sl@0
|
257 |
|