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 "stacked2_plugin.h"
17 #include "plugincommon.h"
21 Leaving New function for the plugin
24 CStacked2Plugin* CStacked2Plugin::NewL()
26 CStacked2Plugin* self = new(ELeave) CStacked2Plugin;
27 CleanupStack::PushL(self);
35 Constructor for the plugin
38 CStacked2Plugin::CStacked2Plugin() : iInterceptsEnabled(EFalse),
44 void CStacked2Plugin::ConstructL()
49 The destructor for the plugin
52 CStacked2Plugin::~CStacked2Plugin()
57 Initialise the plugin.
60 void CStacked2Plugin::InitialiseL()
66 Enable the plugin's intercepts.
69 void CStacked2Plugin::EnableInterceptsL()
71 if (iInterceptsEnabled) return;
73 User::LeaveIfError(RegisterIntercept(EFsFileWrite, EPreIntercept));
75 _LOG(_L("Stacked2 Plugin: Enabled intercepts."));
77 iInterceptsEnabled = ETrue;
81 Disable the plugin's intercepts.
84 void CStacked2Plugin::DisableInterceptsL()
86 if (!iInterceptsEnabled) return;
88 User::LeaveIfError(UnregisterIntercept(EFsFileWrite, EPreIntercept));
90 _LOG(_L("Stacked2 Plugin: Disabled intercepts."));
92 iInterceptsEnabled = EFalse;
99 TInt CStacked2Plugin::DoRequestL(TFsPluginRequest& aRequest)
104 TInt function = aRequest.Function();
112 TRAP(err, FsFileWriteL(aRequest));
127 void CStacked2Plugin::FsFileWriteL(TFsPluginRequest& aRequest)
134 TInt err = aRequest.FileName(filename);
136 iLineNumber = __LINE__;
138 User::Leave(err); //trapped in DoRequestL
140 err = aRequest.Read(TFsPluginRequest::ELength, length);
142 iLineNumber = __LINE__;
144 User::Leave(err); //trapped in DoRequestL
146 err = aRequest.Read(TFsPluginRequest::EPosition, pos);
148 iLineNumber = __LINE__;
150 User::Leave(err); //trapped in DoRequestL
152 parse.Set(filename, NULL, NULL);
154 _LOG4(_L("CStacked2Plugin::FsFileWriteL, file: %S, pos: %d, length: %d"), &filename, pos, length);
156 if (aRequest.IsPostOperation())
158 _LOG(_L("CStacked2Plugin::FsFileWriteL, post intercept"));
162 _LOG(_L("CStacked2Plugin::FsFileWriteL, pre intercept"));
164 //set up test data for plugin
166 wbuffer.Copy(_L8("HELLO SYMBIAN WORLD1"));
167 TInt length = wbuffer.Length();
169 HBufC8* tempBuf = HBufC8::NewMaxLC(length);
170 TPtr8 tempBufPtr((TUint8 *)tempBuf->Des().Ptr(), length, length);
172 RFilePlugin fileplugin(aRequest);
173 err = fileplugin.AdoptFromClient();
175 iLineNumber = __LINE__;
177 User::Leave(err); //trapped in DoRequestL
180 err = fileplugin.Read(pos, tempBufPtr);
181 _LOG2(_L("CStacked2Plugin::FsFileWriteL, RFilePlugin::Read returned %d"), err);
183 iLineNumber = __LINE__;
185 User::Leave(err); //trapped in DoRequestL
187 //lock and unlock file
188 err = fileplugin.Lock(0,2);
190 iLineNumber = __LINE__;
192 User::Leave(err); //trapped in DoRequestL
194 err = fileplugin.UnLock(0,2);
196 iLineNumber = __LINE__;
198 User::Leave(err); //trapped in DoRequestL
200 //check that correct data is still in file
201 err = wbuffer.Compare(tempBufPtr);
203 iLineNumber = __LINE__;
205 User::Leave(err); //trapped in DoRequestL
208 CleanupStack::PopAndDestroy();
210 // send request down the stack
211 User::Leave(KErrNone);
216 CFsPluginConn* CStacked2Plugin::NewPluginConnL()
218 return new(ELeave) CStacked2PluginConn();
222 //Synchronous RPlugin::DoControl
223 TInt CStacked2Plugin::FsPluginDoControlL(CFsPluginConnRequest& aRequest)
226 TPckg<TInt> errCodeDes(iLastError);
227 TPckg<TInt> lineNumberDes(iLineNumber);
229 TInt function = aRequest.Function();
232 case KPluginSetDrive:
234 TPckg<TChar> drive(iDriveToTest);
235 TRAP(err,aRequest.ReadParam1L(drive));
238 case KPluginGetError:
240 TRAP(err,aRequest.WriteParam1L(errCodeDes));
241 TRAP(err,aRequest.WriteParam2L(lineNumberDes));
251 TInt CStacked2PluginConn::DoControl(CFsPluginConnRequest& aRequest)
253 return ((CStacked2Plugin*)Plugin())->FsPluginDoControlL(aRequest);
256 void CStacked2PluginConn::DoRequest(CFsPluginConnRequest& aRequest)
261 void CStacked2PluginConn::DoCancel(TInt /*aReqMask*/)
267 class CStacked2PluginFactory : public CFsPluginFactory
270 CStacked2PluginFactory();
271 virtual TInt Install();
272 virtual CFsPlugin* NewPluginL();
273 virtual CFsPlugin* NewPluginConnL();
274 virtual TInt UniquePosition();
278 Constructor for the plugin factory
281 CStacked2PluginFactory::CStacked2PluginFactory()
286 Install function for the plugin factory
289 TInt CStacked2PluginFactory::Install()
291 //SetSupportedDrives(1<<23);
292 iSupportedDrives = 1<<23;
293 return(SetName(&KStacked2PluginName));
299 TInt CStacked2PluginFactory::UniquePosition()
301 return(KStacked2Pos);
305 Plugin factory function
308 CFsPlugin* CStacked2PluginFactory::NewPluginL()
311 return CStacked2Plugin::NewL();
315 Plugin factory function
318 CFsPlugin* CStacked2PluginFactory::NewPluginConnL()
321 return CStacked2Plugin::NewL();
330 EXPORT_C CFsPluginFactory* CreateFileSystem()
332 return(new CStacked2PluginFactory());