Update contrib.
1 // Copyright (c) 2007-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.
16 #include "stacked_plugin.h"
17 #include "plugincommon.h"
20 Leaving New function for the plugin
23 CStackedPlugin* CStackedPlugin::NewL()
25 CStackedPlugin* self = new(ELeave) CStackedPlugin;
26 CleanupStack::PushL(self);
34 Constructor for the plugin
37 CStackedPlugin::CStackedPlugin() : iInterceptsEnabled(EFalse),
43 void CStackedPlugin::ConstructL()
48 The destructor for the plugin
51 CStackedPlugin::~CStackedPlugin()
56 Initialise the plugin.
59 void CStackedPlugin::InitialiseL()
65 Enable the plugin's intercepts.
68 void CStackedPlugin::EnableInterceptsL()
70 if (iInterceptsEnabled) return;
72 User::LeaveIfError(RegisterIntercept(EFsFileWrite, EPreIntercept));
74 _LOG(_L("Stacked Plugin: Enabled intercepts."));
76 iInterceptsEnabled = ETrue;
80 Disable the plugin's intercepts.
83 void CStackedPlugin::DisableInterceptsL()
85 if (!iInterceptsEnabled) return;
87 User::LeaveIfError(UnregisterIntercept(EFsFileWrite, EPreIntercept));
89 _LOG(_L("Stacked Plugin: Disabled intercepts."));
91 iInterceptsEnabled = EFalse;
98 TInt CStackedPlugin::DoRequestL(TFsPluginRequest& aRequest)
103 TInt function = aRequest.Function();
111 TRAP(err, FsFileWriteL(aRequest));
126 void CStackedPlugin::FsFileWriteL(TFsPluginRequest& aRequest)
133 TInt err = aRequest.FileName(filename);
135 iLineNumber = __LINE__;
137 User::Leave(err); //trapped in DoRequestL
139 err = aRequest.Read(TFsPluginRequest::ELength, length);
141 iLineNumber = __LINE__;
143 User::Leave(err); //trapped in DoRequestL
145 err = aRequest.Read(TFsPluginRequest::EPosition, pos);
147 iLineNumber = __LINE__;
149 User::Leave(err); //trapped in DoRequestL
151 parse.Set(filename, NULL, NULL);
153 _LOG4(_L("CStackedPlugin::FsFileWriteL, file: %S, pos: %d, length: %d"), &filename, pos, length);
155 if (aRequest.IsPostOperation())
157 _LOG(_L("CStackedPlugin::FsFileWriteL, post intercept"));
161 _LOG(_L("CStackedPlugin::FsFileWriteL, pre intercept"));
163 //set up test data for plugin
165 wbuffer.Copy(_L8("HELLO SYMBIAN WORLD1"));
166 TInt length = wbuffer.Length();
168 HBufC8* tempBuf = HBufC8::NewMaxLC(length);
169 TPtr8 tempBufPtr((TUint8 *)tempBuf->Des().Ptr(), length, length);
171 RFilePlugin fileplugin(aRequest);
172 err = fileplugin.AdoptFromClient();
174 iLineNumber = __LINE__;
176 User::Leave(err); //trapped in DoRequestL
179 err = fileplugin.Read(pos, tempBufPtr);
180 _LOG2(_L("CStackedPlugin::FsFileWriteL, RFilePlugin::Read returned %d"), err);
182 iLineNumber = __LINE__;
184 User::Leave(err); //trapped in DoRequestL
186 //Check that correct data is in file
187 err = wbuffer.Compare(tempBufPtr);
189 iLineNumber = __LINE__;
191 User::Leave(err); //trapped in DoRequestL
194 CleanupStack::PopAndDestroy();
196 // send request down the stack
197 User::Leave(KErrNone);
202 CFsPluginConn* CStackedPlugin::NewPluginConnL()
204 return new(ELeave) CStackedPluginConn();
208 //Synchronous RPlugin::DoControl
209 TInt CStackedPlugin::FsPluginDoControlL(CFsPluginConnRequest& aRequest)
212 TPckg<TInt> errCodeDes(iLastError);
213 TPckg<TInt> lineNumberDes(iLineNumber);
215 TInt function = aRequest.Function();
218 case KPluginSetDrive:
220 TPckg<TChar> drive(iDriveToTest);
221 TRAP(err,aRequest.ReadParam1L(drive));
224 case KPluginGetError:
226 TRAP(err,aRequest.WriteParam1L(errCodeDes));
227 TRAP(err,aRequest.WriteParam2L(lineNumberDes));
237 TInt CStackedPluginConn::DoControl(CFsPluginConnRequest& aRequest)
239 return ((CStackedPlugin*)Plugin())->FsPluginDoControlL(aRequest);
242 void CStackedPluginConn::DoRequest(CFsPluginConnRequest& aRequest)
247 void CStackedPluginConn::DoCancel(TInt /*aReqMask*/)
253 class CStackedPluginFactory : public CFsPluginFactory
256 CStackedPluginFactory();
257 virtual TInt Install();
258 virtual CFsPlugin* NewPluginL();
259 virtual CFsPlugin* NewPluginConnL();
260 virtual TInt UniquePosition();
264 Constructor for the plugin factory
267 CStackedPluginFactory::CStackedPluginFactory()
272 Install function for the plugin factory
275 TInt CStackedPluginFactory::Install()
277 //SetSupportedDrives(1<<23);
278 iSupportedDrives = 1<<23;
279 return(SetName(&KStackedPluginName));
285 TInt CStackedPluginFactory::UniquePosition()
291 Plugin factory function
294 CFsPlugin* CStackedPluginFactory::NewPluginL()
297 return CStackedPlugin::NewL();
301 Plugin factory function
304 CFsPlugin* CStackedPluginFactory::NewPluginConnL()
307 return CStackedPlugin::NewL();
316 EXPORT_C CFsPluginFactory* CreateFileSystem()
318 return(new CStackedPluginFactory());