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 "observer_plugin.h"
17 #include "plugincommon.h"
18 #include <f32pluginutils.h>
21 Leaving New function for the plugin
24 CObserverPlugin* CObserverPlugin::NewL()
26 CObserverPlugin* self = new(ELeave) CObserverPlugin;
27 CleanupStack::PushL(self);
35 Constructor for the plugin
38 CObserverPlugin::CObserverPlugin() : iInterceptsEnabled(EFalse),
44 void CObserverPlugin::ConstructL()
49 The destructor for the plugin
52 CObserverPlugin::~CObserverPlugin()
58 Initialise the plugin.
61 void CObserverPlugin::InitialiseL()
63 User::LeaveIfError(iFs.Connect());
64 CleanupClosePushL(iFs);
66 _LOG(_L("CObserverPlugin InitialiseL"));
69 CleanupStack::Pop(); // iFs
73 Enable the plugin's intercepts.
76 void CObserverPlugin::EnableInterceptsL()
78 if (iInterceptsEnabled) return;
80 User::LeaveIfError(RegisterIntercept(EFsFileRead, EPrePostIntercept));
81 User::LeaveIfError(RegisterIntercept(EFsFileWrite, EPrePostIntercept));
82 User::LeaveIfError(RegisterIntercept(EFsDirOpen, EPrePostIntercept));
83 User::LeaveIfError(RegisterIntercept(EFsFileLock, EPrePostIntercept));
84 User::LeaveIfError(RegisterIntercept(EFsFileUnLock, EPrePostIntercept));
85 User::LeaveIfError(RegisterIntercept(EFsFileSeek, EPrePostIntercept));
86 User::LeaveIfError(RegisterIntercept(EFsFileSize, EPrePostIntercept));
87 User::LeaveIfError(RegisterIntercept(EFsFileSetSize, EPrePostIntercept));
88 User::LeaveIfError(RegisterIntercept(EFsDirReadOne, EPrePostIntercept));
89 User::LeaveIfError(RegisterIntercept(EFsDirReadPacked, EPrePostIntercept));
90 User::LeaveIfError(RegisterIntercept(EFsFileOpen, EPrePostIntercept));
91 User::LeaveIfError(RegisterIntercept(EFsFileCreate, EPrePostIntercept));
92 User::LeaveIfError(RegisterIntercept(EFsFileReplace, EPrePostIntercept));
93 User::LeaveIfError(RegisterIntercept(EFsFileRename, EPrePostIntercept));
94 User::LeaveIfError(RegisterIntercept(EFsReadFileSection,EPrePostIntercept));
95 User::LeaveIfError(RegisterIntercept(EFsFileSubClose, EPrePostIntercept));
96 User::LeaveIfError(RegisterIntercept(EFsDriveList, EPrePostIntercept));
97 User::LeaveIfError(RegisterIntercept(EFsSubst, EPrePostIntercept));
98 User::LeaveIfError(RegisterIntercept(EFsSetSubst, EPrePostIntercept));
100 _LOG(_L("Observer Plugin: Enabled intercepts."));
102 iInterceptsEnabled = ETrue;
106 Disable the plugin's intercepts.
109 void CObserverPlugin::DisableInterceptsL()
111 if (!iInterceptsEnabled) return;
113 User::LeaveIfError(UnregisterIntercept(EFsFileRead, EPrePostIntercept));
114 User::LeaveIfError(UnregisterIntercept(EFsFileRename, EPrePostIntercept));
115 User::LeaveIfError(UnregisterIntercept(EFsFileWrite, EPrePostIntercept));
116 User::LeaveIfError(UnregisterIntercept(EFsDirOpen, EPrePostIntercept));
117 User::LeaveIfError(UnregisterIntercept(EFsFileLock, EPrePostIntercept));
118 User::LeaveIfError(UnregisterIntercept(EFsFileUnLock, EPrePostIntercept));
119 User::LeaveIfError(UnregisterIntercept(EFsFileSeek, EPrePostIntercept));
120 User::LeaveIfError(UnregisterIntercept(EFsFileSize, EPrePostIntercept));
121 User::LeaveIfError(UnregisterIntercept(EFsFileSetSize, EPrePostIntercept));
122 User::LeaveIfError(UnregisterIntercept(EFsFileCreate, EPrePostIntercept));
123 User::LeaveIfError(UnregisterIntercept(EFsFileOpen, EPrePostIntercept));
124 User::LeaveIfError(UnregisterIntercept(EFsFileReplace, EPrePostIntercept));
125 User::LeaveIfError(UnregisterIntercept(EFsFileSubClose, EPrePostIntercept));
126 User::LeaveIfError(UnregisterIntercept(EFsReadFileSection,EPrePostIntercept));
127 User::LeaveIfError(UnregisterIntercept(EFsDirReadOne, EPrePostIntercept));
128 User::LeaveIfError(UnregisterIntercept(EFsDirReadPacked,EPrePostIntercept));
129 User::LeaveIfError(UnregisterIntercept(EFsDriveList, EPrePostIntercept));
130 User::LeaveIfError(UnregisterIntercept(EFsSubst, EPrePostIntercept));
131 User::LeaveIfError(UnregisterIntercept(EFsSetSubst, EPrePostIntercept));
134 _LOG(_L("Observer Plugin: Disabled intercepts."));
136 iInterceptsEnabled = EFalse;
143 TInt CObserverPlugin::DoRequestL(TFsPluginRequest& aRequest)
147 TInt function = aRequest.Function();
149 if (aRequest.IsPostOperation())
151 _LOG2(_L("CObserverPlugin post intercept for function %d"), function);
155 _LOG2(_L("CObserverPlugin pre intercept for function %d"), function);
156 _LOG2(_L("CObserverPlugin pre intercept on drive %d"), aRequest.DriveNumber());
159 if(function == EFsFileOpen)
161 // Check that FileName can't be used in pre-operation (as the handle doesn't exist yet!)
163 TInt nErr = aRequest.FileName(shareName);
164 if (aRequest.IsPostOperation())
166 TFileName fileName = aRequest.Src().FullName();
167 nErr = shareName.Compare(fileName);
168 User::LeaveIfError(nErr);
170 else if(nErr != KErrNotSupported)
172 User::Leave(KErrArgument);
180 CFsPluginConn* CObserverPlugin::NewPluginConnL()
182 return new(ELeave) CObserverPluginConn();
186 //Synchronous RPlugin::DoControl
187 TInt CObserverPlugin::FsPluginDoControlL(CFsPluginConnRequest& aRequest)
190 TPckg<TBool> interceptStatusDes(iInterceptsEnabled);
192 //We can use this to set the drive
193 //We can store this as a member of this class.
194 TInt function = aRequest.Function();
197 //case KPluginSetDrive:
199 // TPckg<TChar> drive(iDriveToTest);
200 // TRAP(err,aRequest.ReadParam1L(drive));
203 //case KPluginGetError:
205 // TPckg<TInt> errCodeDes(iLastError);
206 // TPckg<TInt> errMsgDes(iMessage);
207 // TRAP(err,aRequest.WriteParam1L(errCodeDes));
208 // TRAP(err,aRequest.WriteParam2L(errMsgDes));
211 case KPluginToggleIntercepts:
213 iInterceptsEnabled ^= (TBool)1; //toggle intercepts;
214 TRAP(err,aRequest.WriteParam1L(interceptStatusDes));
224 TInt CObserverPluginConn::DoControl(CFsPluginConnRequest& aRequest)
226 return ((CObserverPlugin*)Plugin())->FsPluginDoControlL(aRequest);
229 void CObserverPluginConn::DoRequest(CFsPluginConnRequest& aRequest)
234 void CObserverPluginConn::DoCancel(TInt /*aReqMask*/)
241 class CObserverPluginFactory : public CFsPluginFactory
244 CObserverPluginFactory();
245 virtual TInt Install();
246 virtual CFsPlugin* NewPluginL();
247 virtual CFsPlugin* NewPluginConnL();
248 virtual TInt UniquePosition();
252 Constructor for the plugin factory
255 CObserverPluginFactory::CObserverPluginFactory()
260 Install function for the plugin factory
263 TInt CObserverPluginFactory::Install()
265 //SetSupportedDrives(1<<23);
266 iSupportedDrives = KPluginSupportAllDrives;
267 return(SetName(&KObserverPluginName));
273 TInt CObserverPluginFactory::UniquePosition()
275 return(KObserverPos);
279 Plugin factory function
282 CFsPlugin* CObserverPluginFactory::NewPluginL()
285 return CObserverPlugin::NewL();
289 Plugin factory function
292 CFsPlugin* CObserverPluginFactory::NewPluginConnL()
295 return CObserverPlugin::NewL();
304 EXPORT_C CFsPluginFactory* CreateFileSystem()
306 return(new CObserverPluginFactory());