os/kernelhwsrv/kerneltest/f32test/plugins/version_2/src/observer_plugin.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include "observer_plugin.h"
    17 #include "plugincommon.h"
    18 #include <f32pluginutils.h>
    19 
    20 /**
    21 Leaving New function for the plugin
    22 @internalComponent
    23 */
    24 CObserverPlugin* CObserverPlugin::NewL()
    25 	{
    26 	CObserverPlugin* self = new(ELeave) CObserverPlugin;
    27     CleanupStack::PushL(self);
    28     self->ConstructL();
    29     CleanupStack::Pop();
    30 	return self;
    31 	}
    32 
    33 
    34 /**
    35 Constructor for the plugin
    36 @internalComponent
    37 */
    38 CObserverPlugin::CObserverPlugin() : iInterceptsEnabled(EFalse),
    39 									 iLogging(ETrue)
    40 	{
    41 	}
    42 
    43 
    44 void CObserverPlugin::ConstructL()
    45 	{
    46 	}
    47 
    48 /**
    49 The destructor for the plugin
    50 @internalComponent
    51 */
    52 CObserverPlugin::~CObserverPlugin()
    53 	{
    54 	iFs.Close();
    55 	}
    56 
    57 /**
    58 Initialise the plugin.
    59 @internalComponent
    60 */
    61 void CObserverPlugin::InitialiseL()
    62 	{
    63 	User::LeaveIfError(iFs.Connect());
    64 	CleanupClosePushL(iFs);
    65 
    66 	_LOG(_L("CObserverPlugin InitialiseL"));
    67 	EnableInterceptsL();
    68 	
    69 	CleanupStack::Pop(); // iFs
    70 	}
    71 
    72 /**
    73 Enable the plugin's intercepts.
    74 @internalComponent
    75 */
    76 void CObserverPlugin::EnableInterceptsL()
    77 	{
    78 	if (iInterceptsEnabled) return;
    79 	
    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));
    99 	
   100 	_LOG(_L("Observer Plugin: Enabled intercepts."));
   101     
   102 	iInterceptsEnabled = ETrue;
   103 	}
   104 
   105 /**
   106 Disable the plugin's intercepts.
   107 @internalComponent
   108 */
   109 void CObserverPlugin::DisableInterceptsL()
   110 	{
   111 	if (!iInterceptsEnabled) return;
   112 	
   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));
   132 
   133 
   134 	_LOG(_L("Observer Plugin: Disabled intercepts."));
   135     
   136 	iInterceptsEnabled = EFalse;
   137 	}
   138 
   139 /**
   140 Handle requests
   141 @internalComponent
   142 */
   143 TInt CObserverPlugin::DoRequestL(TFsPluginRequest& aRequest)
   144 	{
   145 	TInt err = KErrNone;
   146 
   147 	TInt function = aRequest.Function();
   148 
   149 	if (aRequest.IsPostOperation())
   150 		{
   151 		_LOG2(_L("CObserverPlugin post intercept for function %d"), function);
   152 		}
   153 	else
   154 		{
   155 		_LOG2(_L("CObserverPlugin pre intercept for function %d"), function);
   156 		_LOG2(_L("CObserverPlugin pre intercept on drive %d"), aRequest.DriveNumber());
   157 		}
   158 
   159 	if(function == EFsFileOpen)
   160 		{
   161 		// Check that FileName can't be used in pre-operation (as the handle doesn't exist yet!)
   162 		TFileName shareName;
   163 		TInt nErr = aRequest.FileName(shareName);
   164 		if (aRequest.IsPostOperation())
   165 			{
   166 			TFileName fileName = aRequest.Src().FullName();
   167 			nErr = shareName.Compare(fileName);
   168 			User::LeaveIfError(nErr);
   169 			}
   170 		else if(nErr != KErrNotSupported)
   171 			{
   172 			User::Leave(KErrArgument);
   173 			}
   174 		}
   175 
   176 	return err;
   177 	}
   178 
   179 
   180 CFsPluginConn* CObserverPlugin::NewPluginConnL()
   181 	{
   182 	return new(ELeave) CObserverPluginConn();
   183 	}
   184 
   185 
   186 //Synchronous RPlugin::DoControl
   187 TInt CObserverPlugin::FsPluginDoControlL(CFsPluginConnRequest& aRequest)
   188 	{
   189 	TInt err = KErrNone;
   190 	TPckg<TBool> interceptStatusDes(iInterceptsEnabled);
   191 	
   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();
   195 	switch(function)
   196 		{
   197 		//case KPluginSetDrive:
   198 		//	//{
   199 		//	TPckg<TChar> drive(iDriveToTest);
   200 		//	TRAP(err,aRequest.ReadParam1L(drive));
   201 		//	break;
   202 		//	}
   203 		//case KPluginGetError:
   204 		//	{
   205 		//	TPckg<TInt> errCodeDes(iLastError);
   206 		//	TPckg<TInt> errMsgDes(iMessage);
   207 		//	TRAP(err,aRequest.WriteParam1L(errCodeDes));
   208 		//	TRAP(err,aRequest.WriteParam2L(errMsgDes));
   209 		//	break;
   210 		//	}
   211 		case KPluginToggleIntercepts:
   212 			{
   213 			iInterceptsEnabled ^= (TBool)1; //toggle intercepts;
   214 			TRAP(err,aRequest.WriteParam1L(interceptStatusDes));
   215 			break;
   216 			}
   217 		default:
   218 			break;
   219 		}
   220 
   221 	return err;
   222 	}
   223 
   224 TInt CObserverPluginConn::DoControl(CFsPluginConnRequest& aRequest)
   225 	{
   226 	return ((CObserverPlugin*)Plugin())->FsPluginDoControlL(aRequest);
   227 	}
   228 
   229 void CObserverPluginConn::DoRequest(CFsPluginConnRequest& aRequest)
   230 	{
   231 	DoControl(aRequest);
   232 	}
   233 
   234 void CObserverPluginConn::DoCancel(TInt /*aReqMask*/)
   235 	{
   236 	}
   237 
   238 
   239 //factory functions
   240 
   241 class CObserverPluginFactory : public CFsPluginFactory
   242 	{
   243 public:
   244 	CObserverPluginFactory();
   245 	virtual TInt Install();			
   246 	virtual CFsPlugin* NewPluginL();
   247 	virtual CFsPlugin* NewPluginConnL();
   248 	virtual TInt UniquePosition();
   249 	};
   250 
   251 /**
   252 Constructor for the plugin factory
   253 @internalComponent
   254 */
   255 CObserverPluginFactory::CObserverPluginFactory()
   256 	{
   257 	}
   258 
   259 /**
   260 Install function for the plugin factory
   261 @internalComponent
   262 */
   263 TInt CObserverPluginFactory::Install()
   264 	{
   265 	//SetSupportedDrives(1<<23);
   266 	iSupportedDrives = KPluginSupportAllDrives; 
   267 	return(SetName(&KObserverPluginName));
   268 	}
   269 
   270 /**
   271 @internalComponent
   272 */
   273 TInt CObserverPluginFactory::UniquePosition()
   274 	{
   275 	return(KObserverPos);
   276 	}
   277 
   278 /**
   279 Plugin factory function
   280 @internalComponent
   281 */
   282 CFsPlugin* CObserverPluginFactory::NewPluginL()
   283 
   284 	{
   285 	return CObserverPlugin::NewL();
   286 	}
   287 
   288 /**
   289 Plugin factory function
   290 @internalComponent
   291 */
   292 CFsPlugin* CObserverPluginFactory::NewPluginConnL()
   293 
   294 	{
   295 	return CObserverPlugin::NewL();
   296 	}
   297 
   298 /**
   299 Create a new Plugin
   300 @internalComponent
   301 */
   302 extern "C" {
   303 
   304 EXPORT_C CFsPluginFactory* CreateFileSystem()
   305 	{
   306 	return(new CObserverPluginFactory());
   307 	}
   308 }
   309