sl@0
|
1 |
// Copyright (c) 2007-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 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include "stacked_plugin.h"
|
sl@0
|
17 |
#include "plugincommon.h"
|
sl@0
|
18 |
|
sl@0
|
19 |
/**
|
sl@0
|
20 |
Leaving New function for the plugin
|
sl@0
|
21 |
@internalComponent
|
sl@0
|
22 |
*/
|
sl@0
|
23 |
CStackedPlugin* CStackedPlugin::NewL()
|
sl@0
|
24 |
{
|
sl@0
|
25 |
CStackedPlugin* self = new(ELeave) CStackedPlugin;
|
sl@0
|
26 |
CleanupStack::PushL(self);
|
sl@0
|
27 |
self->ConstructL();
|
sl@0
|
28 |
CleanupStack::Pop();
|
sl@0
|
29 |
return self;
|
sl@0
|
30 |
}
|
sl@0
|
31 |
|
sl@0
|
32 |
|
sl@0
|
33 |
/**
|
sl@0
|
34 |
Constructor for the plugin
|
sl@0
|
35 |
@internalComponent
|
sl@0
|
36 |
*/
|
sl@0
|
37 |
CStackedPlugin::CStackedPlugin() : iInterceptsEnabled(EFalse),
|
sl@0
|
38 |
iLogging(ETrue)
|
sl@0
|
39 |
{
|
sl@0
|
40 |
}
|
sl@0
|
41 |
|
sl@0
|
42 |
|
sl@0
|
43 |
void CStackedPlugin::ConstructL()
|
sl@0
|
44 |
{
|
sl@0
|
45 |
}
|
sl@0
|
46 |
|
sl@0
|
47 |
/**
|
sl@0
|
48 |
The destructor for the plugin
|
sl@0
|
49 |
@internalComponent
|
sl@0
|
50 |
*/
|
sl@0
|
51 |
CStackedPlugin::~CStackedPlugin()
|
sl@0
|
52 |
{
|
sl@0
|
53 |
}
|
sl@0
|
54 |
|
sl@0
|
55 |
/**
|
sl@0
|
56 |
Initialise the plugin.
|
sl@0
|
57 |
@internalComponent
|
sl@0
|
58 |
*/
|
sl@0
|
59 |
void CStackedPlugin::InitialiseL()
|
sl@0
|
60 |
{
|
sl@0
|
61 |
EnableInterceptsL();
|
sl@0
|
62 |
}
|
sl@0
|
63 |
|
sl@0
|
64 |
/**
|
sl@0
|
65 |
Enable the plugin's intercepts.
|
sl@0
|
66 |
@internalComponent
|
sl@0
|
67 |
*/
|
sl@0
|
68 |
void CStackedPlugin::EnableInterceptsL()
|
sl@0
|
69 |
{
|
sl@0
|
70 |
if (iInterceptsEnabled) return;
|
sl@0
|
71 |
|
sl@0
|
72 |
User::LeaveIfError(RegisterIntercept(EFsFileWrite, EPreIntercept));
|
sl@0
|
73 |
|
sl@0
|
74 |
_LOG(_L("Stacked Plugin: Enabled intercepts."));
|
sl@0
|
75 |
|
sl@0
|
76 |
iInterceptsEnabled = ETrue;
|
sl@0
|
77 |
}
|
sl@0
|
78 |
|
sl@0
|
79 |
/**
|
sl@0
|
80 |
Disable the plugin's intercepts.
|
sl@0
|
81 |
@internalComponent
|
sl@0
|
82 |
*/
|
sl@0
|
83 |
void CStackedPlugin::DisableInterceptsL()
|
sl@0
|
84 |
{
|
sl@0
|
85 |
if (!iInterceptsEnabled) return;
|
sl@0
|
86 |
|
sl@0
|
87 |
User::LeaveIfError(UnregisterIntercept(EFsFileWrite, EPreIntercept));
|
sl@0
|
88 |
|
sl@0
|
89 |
_LOG(_L("Stacked Plugin: Disabled intercepts."));
|
sl@0
|
90 |
|
sl@0
|
91 |
iInterceptsEnabled = EFalse;
|
sl@0
|
92 |
}
|
sl@0
|
93 |
|
sl@0
|
94 |
/**
|
sl@0
|
95 |
Handle requests
|
sl@0
|
96 |
@internalComponent
|
sl@0
|
97 |
*/
|
sl@0
|
98 |
TInt CStackedPlugin::DoRequestL(TFsPluginRequest& aRequest)
|
sl@0
|
99 |
{
|
sl@0
|
100 |
|
sl@0
|
101 |
TInt err = KErrNone;
|
sl@0
|
102 |
|
sl@0
|
103 |
TInt function = aRequest.Function();
|
sl@0
|
104 |
|
sl@0
|
105 |
switch(function)
|
sl@0
|
106 |
{
|
sl@0
|
107 |
case EFsFileRead:
|
sl@0
|
108 |
break;
|
sl@0
|
109 |
|
sl@0
|
110 |
case EFsFileWrite:
|
sl@0
|
111 |
TRAP(err, FsFileWriteL(aRequest));
|
sl@0
|
112 |
break;
|
sl@0
|
113 |
|
sl@0
|
114 |
default:
|
sl@0
|
115 |
break;
|
sl@0
|
116 |
}
|
sl@0
|
117 |
|
sl@0
|
118 |
return err;
|
sl@0
|
119 |
}
|
sl@0
|
120 |
|
sl@0
|
121 |
|
sl@0
|
122 |
|
sl@0
|
123 |
/**
|
sl@0
|
124 |
@internalComponent
|
sl@0
|
125 |
*/
|
sl@0
|
126 |
void CStackedPlugin::FsFileWriteL(TFsPluginRequest& aRequest)
|
sl@0
|
127 |
{
|
sl@0
|
128 |
TInt length = 0;
|
sl@0
|
129 |
TInt64 pos = 0;
|
sl@0
|
130 |
TFileName filename;
|
sl@0
|
131 |
TParse parse;
|
sl@0
|
132 |
|
sl@0
|
133 |
TInt err = aRequest.FileName(filename);
|
sl@0
|
134 |
iLastError = err;
|
sl@0
|
135 |
iLineNumber = __LINE__;
|
sl@0
|
136 |
if(err!=KErrNone)
|
sl@0
|
137 |
User::Leave(err); //trapped in DoRequestL
|
sl@0
|
138 |
|
sl@0
|
139 |
err = aRequest.Read(TFsPluginRequest::ELength, length);
|
sl@0
|
140 |
iLastError = err;
|
sl@0
|
141 |
iLineNumber = __LINE__;
|
sl@0
|
142 |
if(err!=KErrNone)
|
sl@0
|
143 |
User::Leave(err); //trapped in DoRequestL
|
sl@0
|
144 |
|
sl@0
|
145 |
err = aRequest.Read(TFsPluginRequest::EPosition, pos);
|
sl@0
|
146 |
iLastError = err;
|
sl@0
|
147 |
iLineNumber = __LINE__;
|
sl@0
|
148 |
if(err!=KErrNone)
|
sl@0
|
149 |
User::Leave(err); //trapped in DoRequestL
|
sl@0
|
150 |
|
sl@0
|
151 |
parse.Set(filename, NULL, NULL);
|
sl@0
|
152 |
|
sl@0
|
153 |
_LOG4(_L("CStackedPlugin::FsFileWriteL, file: %S, pos: %d, length: %d"), &filename, pos, length);
|
sl@0
|
154 |
|
sl@0
|
155 |
if (aRequest.IsPostOperation())
|
sl@0
|
156 |
{
|
sl@0
|
157 |
_LOG(_L("CStackedPlugin::FsFileWriteL, post intercept"));
|
sl@0
|
158 |
}
|
sl@0
|
159 |
else
|
sl@0
|
160 |
{
|
sl@0
|
161 |
_LOG(_L("CStackedPlugin::FsFileWriteL, pre intercept"));
|
sl@0
|
162 |
|
sl@0
|
163 |
//set up test data for plugin
|
sl@0
|
164 |
TBuf8<20> wbuffer;
|
sl@0
|
165 |
wbuffer.Copy(_L8("HELLO SYMBIAN WORLD1"));
|
sl@0
|
166 |
TInt length = wbuffer.Length();
|
sl@0
|
167 |
|
sl@0
|
168 |
HBufC8* tempBuf = HBufC8::NewMaxLC(length);
|
sl@0
|
169 |
TPtr8 tempBufPtr((TUint8 *)tempBuf->Des().Ptr(), length, length);
|
sl@0
|
170 |
|
sl@0
|
171 |
RFilePlugin fileplugin(aRequest);
|
sl@0
|
172 |
err = fileplugin.AdoptFromClient();
|
sl@0
|
173 |
iLastError = err;
|
sl@0
|
174 |
iLineNumber = __LINE__;
|
sl@0
|
175 |
if(err!=KErrNone)
|
sl@0
|
176 |
User::Leave(err); //trapped in DoRequestL
|
sl@0
|
177 |
|
sl@0
|
178 |
//read from file
|
sl@0
|
179 |
err = fileplugin.Read(pos, tempBufPtr);
|
sl@0
|
180 |
_LOG2(_L("CStackedPlugin::FsFileWriteL, RFilePlugin::Read returned %d"), err);
|
sl@0
|
181 |
iLastError = err;
|
sl@0
|
182 |
iLineNumber = __LINE__;
|
sl@0
|
183 |
if(err!=KErrNone)
|
sl@0
|
184 |
User::Leave(err); //trapped in DoRequestL
|
sl@0
|
185 |
|
sl@0
|
186 |
//Check that correct data is in file
|
sl@0
|
187 |
err = wbuffer.Compare(tempBufPtr);
|
sl@0
|
188 |
iLastError = err;
|
sl@0
|
189 |
iLineNumber = __LINE__;
|
sl@0
|
190 |
if(err!=KErrNone)
|
sl@0
|
191 |
User::Leave(err); //trapped in DoRequestL
|
sl@0
|
192 |
|
sl@0
|
193 |
fileplugin.Close();
|
sl@0
|
194 |
CleanupStack::PopAndDestroy();
|
sl@0
|
195 |
|
sl@0
|
196 |
// send request down the stack
|
sl@0
|
197 |
User::Leave(KErrNone);
|
sl@0
|
198 |
}
|
sl@0
|
199 |
}
|
sl@0
|
200 |
|
sl@0
|
201 |
|
sl@0
|
202 |
CFsPluginConn* CStackedPlugin::NewPluginConnL()
|
sl@0
|
203 |
{
|
sl@0
|
204 |
return new(ELeave) CStackedPluginConn();
|
sl@0
|
205 |
}
|
sl@0
|
206 |
|
sl@0
|
207 |
|
sl@0
|
208 |
//Synchronous RPlugin::DoControl
|
sl@0
|
209 |
TInt CStackedPlugin::FsPluginDoControlL(CFsPluginConnRequest& aRequest)
|
sl@0
|
210 |
{
|
sl@0
|
211 |
TInt err = KErrNone;
|
sl@0
|
212 |
TPckg<TInt> errCodeDes(iLastError);
|
sl@0
|
213 |
TPckg<TInt> lineNumberDes(iLineNumber);
|
sl@0
|
214 |
|
sl@0
|
215 |
TInt function = aRequest.Function();
|
sl@0
|
216 |
switch(function)
|
sl@0
|
217 |
{
|
sl@0
|
218 |
case KPluginSetDrive:
|
sl@0
|
219 |
{
|
sl@0
|
220 |
TPckg<TChar> drive(iDriveToTest);
|
sl@0
|
221 |
TRAP(err,aRequest.ReadParam1L(drive));
|
sl@0
|
222 |
break;
|
sl@0
|
223 |
}
|
sl@0
|
224 |
case KPluginGetError:
|
sl@0
|
225 |
{
|
sl@0
|
226 |
TRAP(err,aRequest.WriteParam1L(errCodeDes));
|
sl@0
|
227 |
TRAP(err,aRequest.WriteParam2L(lineNumberDes));
|
sl@0
|
228 |
break;
|
sl@0
|
229 |
}
|
sl@0
|
230 |
default:
|
sl@0
|
231 |
break;
|
sl@0
|
232 |
}
|
sl@0
|
233 |
|
sl@0
|
234 |
return err;
|
sl@0
|
235 |
}
|
sl@0
|
236 |
|
sl@0
|
237 |
TInt CStackedPluginConn::DoControl(CFsPluginConnRequest& aRequest)
|
sl@0
|
238 |
{
|
sl@0
|
239 |
return ((CStackedPlugin*)Plugin())->FsPluginDoControlL(aRequest);
|
sl@0
|
240 |
}
|
sl@0
|
241 |
|
sl@0
|
242 |
void CStackedPluginConn::DoRequest(CFsPluginConnRequest& aRequest)
|
sl@0
|
243 |
{
|
sl@0
|
244 |
DoControl(aRequest);
|
sl@0
|
245 |
}
|
sl@0
|
246 |
|
sl@0
|
247 |
void CStackedPluginConn::DoCancel(TInt /*aReqMask*/)
|
sl@0
|
248 |
{
|
sl@0
|
249 |
}
|
sl@0
|
250 |
|
sl@0
|
251 |
//factory functions
|
sl@0
|
252 |
|
sl@0
|
253 |
class CStackedPluginFactory : public CFsPluginFactory
|
sl@0
|
254 |
{
|
sl@0
|
255 |
public:
|
sl@0
|
256 |
CStackedPluginFactory();
|
sl@0
|
257 |
virtual TInt Install();
|
sl@0
|
258 |
virtual CFsPlugin* NewPluginL();
|
sl@0
|
259 |
virtual CFsPlugin* NewPluginConnL();
|
sl@0
|
260 |
virtual TInt UniquePosition();
|
sl@0
|
261 |
};
|
sl@0
|
262 |
|
sl@0
|
263 |
/**
|
sl@0
|
264 |
Constructor for the plugin factory
|
sl@0
|
265 |
@internalComponent
|
sl@0
|
266 |
*/
|
sl@0
|
267 |
CStackedPluginFactory::CStackedPluginFactory()
|
sl@0
|
268 |
{
|
sl@0
|
269 |
}
|
sl@0
|
270 |
|
sl@0
|
271 |
/**
|
sl@0
|
272 |
Install function for the plugin factory
|
sl@0
|
273 |
@internalComponent
|
sl@0
|
274 |
*/
|
sl@0
|
275 |
TInt CStackedPluginFactory::Install()
|
sl@0
|
276 |
{
|
sl@0
|
277 |
//SetSupportedDrives(1<<23);
|
sl@0
|
278 |
iSupportedDrives = 1<<23;
|
sl@0
|
279 |
return(SetName(&KStackedPluginName));
|
sl@0
|
280 |
}
|
sl@0
|
281 |
|
sl@0
|
282 |
/**
|
sl@0
|
283 |
@internalComponent
|
sl@0
|
284 |
*/
|
sl@0
|
285 |
TInt CStackedPluginFactory::UniquePosition()
|
sl@0
|
286 |
{
|
sl@0
|
287 |
return(KStackedPos);
|
sl@0
|
288 |
}
|
sl@0
|
289 |
|
sl@0
|
290 |
/**
|
sl@0
|
291 |
Plugin factory function
|
sl@0
|
292 |
@internalComponent
|
sl@0
|
293 |
*/
|
sl@0
|
294 |
CFsPlugin* CStackedPluginFactory::NewPluginL()
|
sl@0
|
295 |
|
sl@0
|
296 |
{
|
sl@0
|
297 |
return CStackedPlugin::NewL();
|
sl@0
|
298 |
}
|
sl@0
|
299 |
|
sl@0
|
300 |
/**
|
sl@0
|
301 |
Plugin factory function
|
sl@0
|
302 |
@internalComponent
|
sl@0
|
303 |
*/
|
sl@0
|
304 |
CFsPlugin* CStackedPluginFactory::NewPluginConnL()
|
sl@0
|
305 |
|
sl@0
|
306 |
{
|
sl@0
|
307 |
return CStackedPlugin::NewL();
|
sl@0
|
308 |
}
|
sl@0
|
309 |
|
sl@0
|
310 |
/**
|
sl@0
|
311 |
Create a new Plugin
|
sl@0
|
312 |
@internalComponent
|
sl@0
|
313 |
*/
|
sl@0
|
314 |
extern "C" {
|
sl@0
|
315 |
|
sl@0
|
316 |
EXPORT_C CFsPluginFactory* CreateFileSystem()
|
sl@0
|
317 |
{
|
sl@0
|
318 |
return(new CStackedPluginFactory());
|
sl@0
|
319 |
}
|
sl@0
|
320 |
}
|
sl@0
|
321 |
|