First public contribution.
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 "stacked3_plugin.h"
17 #include "plugincommon.h"
21 Leaving New function for the plugin
24 CStacked3Plugin* CStacked3Plugin::NewL()
26 CStacked3Plugin* self = new(ELeave) CStacked3Plugin;
27 CleanupStack::PushL(self);
35 Constructor for the plugin
38 CStacked3Plugin::CStacked3Plugin() : iInterceptsEnabled(EFalse),
44 void CStacked3Plugin::ConstructL()
49 The destructor for the plugin
52 CStacked3Plugin::~CStacked3Plugin()
57 Initialise the plugin.
60 void CStacked3Plugin::InitialiseL()
66 Enable the plugin's intercepts.
69 void CStacked3Plugin::EnableInterceptsL()
71 if (iInterceptsEnabled) return;
73 User::LeaveIfError(RegisterIntercept(EFsFileWrite, EPreIntercept));
75 _LOG(_L("Stacked3 Plugin: Enabled intercepts."));
77 iInterceptsEnabled = ETrue;
81 Disable the plugin's intercepts.
84 void CStacked3Plugin::DisableInterceptsL()
86 if (!iInterceptsEnabled) return;
88 User::LeaveIfError(UnregisterIntercept(EFsFileWrite, EPreIntercept));
90 _LOG(_L("Stacked3 Plugin: Disabled intercepts."));
92 iInterceptsEnabled = EFalse;
99 TInt CStacked3Plugin::DoRequestL(TFsPluginRequest& aRequest)
104 TInt function = aRequest.Function();
112 TRAP(err, FsFileWriteL(aRequest));
126 void CStacked3Plugin::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("CStacked3Plugin::FsFileWriteL, file: %S, pos: %d, length: %d"), &filename, pos, length);
155 if (aRequest.IsPostOperation())
157 _LOG(_L("CStacked3Plugin::FsFileWriteL, post intercept"));
161 _LOG(_L("CStacked3Plugin::FsFileWriteL, pre intercept"));
163 //set up test data for plugin
165 wbuffer.Copy(_L8("HELLO WORLD SYMBIAN"));
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.Write(pos, wbuffer);
180 _LOG2(_L("CStacked3Plugin::FsFileWriteL, RFilePlugin::Write returned %d"), err);
182 iLineNumber = __LINE__;
184 User::Leave(err); //trapped in DoRequestL
187 err = fileplugin.Read(pos, tempBufPtr);
188 _LOG2(_L("CStackedPlugin::FsFileWriteL, RFilePlugin::Read returned %d"), err);
190 iLineNumber = __LINE__;
192 User::Leave(err); //trapped in DoRequestL
194 //testing the correct thing has been written to the drive
195 err = wbuffer.Compare(tempBufPtr);
197 iLineNumber = __LINE__;
199 User::Leave(err); //trapped in DoRequestL
202 CleanupStack::PopAndDestroy();
204 // send request down the stack
205 User::Leave(KErrCompletion);
210 CFsPluginConn* CStacked3Plugin::NewPluginConnL()
212 return new(ELeave) CStacked3PluginConn();
216 //Synchronous RPlugin::DoControl
217 TInt CStacked3Plugin::FsPluginDoControlL(CFsPluginConnRequest& aRequest)
220 TPckg<TInt> errCodeDes(iLastError);
221 TPckg<TInt> lineNumberDes(iLineNumber);
223 TInt function = aRequest.Function();
226 case KPluginSetDrive:
228 TPckg<TChar> drive(iDriveToTest);
229 TRAP(err,aRequest.ReadParam1L(drive));
232 case KPluginGetError:
234 TRAP(err,aRequest.WriteParam1L(errCodeDes));
235 TRAP(err,aRequest.WriteParam2L(lineNumberDes));
245 TInt CStacked3PluginConn::DoControl(CFsPluginConnRequest& aRequest)
247 return ((CStacked3Plugin*)Plugin())->FsPluginDoControlL(aRequest);
250 void CStacked3PluginConn::DoRequest(CFsPluginConnRequest& aRequest)
255 void CStacked3PluginConn::DoCancel(TInt /*aReqMask*/)
261 class CStacked3PluginFactory : public CFsPluginFactory
264 CStacked3PluginFactory();
265 virtual TInt Install();
266 virtual CFsPlugin* NewPluginL();
267 virtual CFsPlugin* NewPluginConnL();
268 virtual TInt UniquePosition();
272 Constructor for the plugin factory
275 CStacked3PluginFactory::CStacked3PluginFactory()
280 Install function for the plugin factory
283 TInt CStacked3PluginFactory::Install()
285 //SetSupportedDrives(1<<23);
286 iSupportedDrives = 1<<23;
287 return(SetName(&KStacked3PluginName));
293 TInt CStacked3PluginFactory::UniquePosition()
295 return(KStacked3Pos);
299 Plugin factory function
302 CFsPlugin* CStacked3PluginFactory::NewPluginL()
305 return CStacked3Plugin::NewL();
309 Plugin factory function
312 CFsPlugin* CStacked3PluginFactory::NewPluginConnL()
315 return CStacked3Plugin::NewL();
324 EXPORT_C CFsPluginFactory* CreateFileSystem()
326 return(new CStacked3PluginFactory());