kerneltest/f32test/server/t_notify_plugin.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     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 "t_notify_plugin.h"
       
    17 #include <f32pluginutils.h>
       
    18 
       
    19 TChar gDriveToTest;
       
    20 
       
    21 /**
       
    22 Leaving New function for the plugin
       
    23 @internalComponent
       
    24 */
       
    25 CNotifyPlugin* CNotifyPlugin::NewL()
       
    26 	{
       
    27 	CNotifyPlugin* self = new(ELeave) CNotifyPlugin;
       
    28     CleanupStack::PushL(self);
       
    29     self->ConstructL();
       
    30     CleanupStack::Pop();
       
    31 	return self;
       
    32 	}
       
    33 
       
    34 
       
    35 /**
       
    36 Constructor for the plugin
       
    37 @internalComponent
       
    38 */
       
    39 CNotifyPlugin::CNotifyPlugin() : iInterceptsEnabled(EFalse),
       
    40 									 iLogging(ETrue)
       
    41 	{
       
    42 	}
       
    43 
       
    44 
       
    45 void CNotifyPlugin::ConstructL()
       
    46 	{
       
    47 	}
       
    48 
       
    49 /**
       
    50 The destructor for the plugin
       
    51 @internalComponent
       
    52 */
       
    53 CNotifyPlugin::~CNotifyPlugin()
       
    54 	{
       
    55 	iFs.Close();
       
    56 	}
       
    57 
       
    58 /**
       
    59 Initialise the plugin.
       
    60 @internalComponent
       
    61 */
       
    62 void CNotifyPlugin::InitialiseL()
       
    63 	{
       
    64 	User::LeaveIfError(iFs.Connect());
       
    65 	CleanupClosePushL(iFs);
       
    66 
       
    67 	_LOG(_L("CNotifyPlugin InitialiseL"));
       
    68 	EnableInterceptsL();
       
    69 	
       
    70 	CleanupStack::Pop(); // iFs
       
    71 	}
       
    72 
       
    73 /**
       
    74 Enable the plugin's intercepts.
       
    75 @internalComponent
       
    76 */
       
    77 void CNotifyPlugin::EnableInterceptsL()
       
    78 	{
       
    79 	if (iInterceptsEnabled) return;
       
    80 	
       
    81 	User::LeaveIfError(RegisterIntercept(EFsFileRead,		EPrePostIntercept));
       
    82 	User::LeaveIfError(RegisterIntercept(EFsFileWrite,		EPrePostIntercept));
       
    83 	User::LeaveIfError(RegisterIntercept(EFsDirOpen,		EPrePostIntercept));
       
    84 	User::LeaveIfError(RegisterIntercept(EFsFileLock,		EPrePostIntercept));
       
    85 	User::LeaveIfError(RegisterIntercept(EFsFileUnLock,		EPrePostIntercept));
       
    86 	User::LeaveIfError(RegisterIntercept(EFsFileSeek,		EPrePostIntercept));
       
    87 	User::LeaveIfError(RegisterIntercept(EFsFileSize,		EPrePostIntercept));
       
    88 	User::LeaveIfError(RegisterIntercept(EFsFileSetSize,	EPrePostIntercept));
       
    89 	User::LeaveIfError(RegisterIntercept(EFsDirReadOne,		EPrePostIntercept));
       
    90 	User::LeaveIfError(RegisterIntercept(EFsDirReadPacked,	EPrePostIntercept));
       
    91 	User::LeaveIfError(RegisterIntercept(EFsFileOpen,	EPrePostIntercept));
       
    92 	User::LeaveIfError(RegisterIntercept(EFsFileCreate,	EPrePostIntercept));
       
    93 	User::LeaveIfError(RegisterIntercept(EFsFileReplace,EPrePostIntercept));
       
    94 	User::LeaveIfError(RegisterIntercept(EFsFileRename,	EPrePostIntercept));
       
    95    	User::LeaveIfError(RegisterIntercept(EFsReadFileSection,EPrePostIntercept));
       
    96 	User::LeaveIfError(RegisterIntercept(EFsFileSubClose,        EPrePostIntercept)); 
       
    97 
       
    98 	_LOG(_L("Notify Plugin: Enabled intercepts."));
       
    99     
       
   100 	iInterceptsEnabled = ETrue;
       
   101 	}
       
   102 
       
   103 /**
       
   104 Disable the plugin's intercepts.
       
   105 @internalComponent
       
   106 */
       
   107 void CNotifyPlugin::DisableInterceptsL()
       
   108 	{
       
   109 	if (!iInterceptsEnabled) return;
       
   110 	
       
   111 	User::LeaveIfError(UnregisterIntercept(EFsFileRead,		EPrePostIntercept));
       
   112 	User::LeaveIfError(UnregisterIntercept(EFsFileRename,	EPrePostIntercept));
       
   113 	User::LeaveIfError(UnregisterIntercept(EFsFileWrite,	EPrePostIntercept));
       
   114 	User::LeaveIfError(UnregisterIntercept(EFsDirOpen,		EPrePostIntercept));
       
   115 	User::LeaveIfError(UnregisterIntercept(EFsFileLock,		EPrePostIntercept));
       
   116 	User::LeaveIfError(UnregisterIntercept(EFsFileUnLock,	EPrePostIntercept));
       
   117 	User::LeaveIfError(UnregisterIntercept(EFsFileSeek,		EPrePostIntercept));
       
   118 	User::LeaveIfError(UnregisterIntercept(EFsFileSize,		EPrePostIntercept));
       
   119 	User::LeaveIfError(UnregisterIntercept(EFsFileSetSize,	EPrePostIntercept));
       
   120 	User::LeaveIfError(UnregisterIntercept(EFsFileCreate,	EPrePostIntercept));
       
   121 	User::LeaveIfError(UnregisterIntercept(EFsFileOpen, 	EPrePostIntercept));
       
   122 	User::LeaveIfError(UnregisterIntercept(EFsFileReplace, 	EPrePostIntercept));
       
   123 	User::LeaveIfError(UnregisterIntercept(EFsFileSubClose, EPrePostIntercept));
       
   124 	User::LeaveIfError(UnregisterIntercept(EFsReadFileSection,EPrePostIntercept));
       
   125 	User::LeaveIfError(UnregisterIntercept(EFsDirReadOne,	EPrePostIntercept));
       
   126 	User::LeaveIfError(UnregisterIntercept(EFsDirReadPacked,EPrePostIntercept));
       
   127 
       
   128 
       
   129 	_LOG(_L("Notify Plugin: Disabled intercepts."));
       
   130     
       
   131 	iInterceptsEnabled = EFalse;
       
   132 	}
       
   133 
       
   134 /**
       
   135 Handle requests
       
   136 @internalComponent
       
   137 */
       
   138 TInt CNotifyPlugin::DoRequestL(TFsPluginRequest& aRequest)
       
   139 	{
       
   140 	TInt err = KErrNone;
       
   141 
       
   142 	TInt function = aRequest.Function();
       
   143 
       
   144 	if (aRequest.IsPostOperation())
       
   145 		{
       
   146 		_LOG2(_L("CNotifyPlugin post intercept for function %d"), function);
       
   147 		}
       
   148 	else if(function==EFsFileCreate)
       
   149 		{
       
   150 		_LOG2(_L("CNotifyPlugin pre intercept for function %d"), function);
       
   151 		
       
   152 		TBuf<40> basepath;
       
   153 		basepath.Append(gDriveToTest);
       
   154 		basepath.Append(_L(":\\F32-TST\\T_NOTIFIER\\")); //len=22
       
   155 		
       
   156 		TBuf<40> path1;
       
   157 		path1.Copy(basepath);
       
   158 		path1.Append(_L("plugin.create"));
       
   159 		
       
   160 		RFilePlugin file(aRequest);
       
   161 		//Wrong file - should not notify
       
   162 		file.Replace(path1,EFileWrite);
       
   163 		file.Close();
       
   164 		
       
   165 		TBuf<40> path2;
       
   166 		path2.Copy(basepath);
       
   167 		path2.Append(_L("simple.create"));
       
   168 		
       
   169 		//Correct file, Should notify?
       
   170 		RFilePlugin fileplugin(aRequest);
       
   171 		TInt r = fileplugin.Create(path2,EFileWrite);
       
   172 		r = fileplugin.TransferToClient();
       
   173 		fileplugin.Close();
       
   174 
       
   175 		return KErrCompletion;
       
   176 		}
       
   177 
       
   178 	return err;
       
   179 	}
       
   180 
       
   181 
       
   182 CFsPluginConn* CNotifyPlugin::NewPluginConnL()
       
   183 	{
       
   184 	return new(ELeave) CNotifyPluginConn();
       
   185 	}
       
   186 
       
   187 //Synchronous RPlugin::DoControl
       
   188 TInt CNotifyPlugin::FsPluginDoControlL(CFsPluginConnRequest& aRequest)
       
   189 	{
       
   190 	TInt function = aRequest.Function();
       
   191 
       
   192 	switch(function)
       
   193 		{
       
   194 		case KPluginSetDrive:
       
   195 			{
       
   196 			TPckg<TChar> drive(gDriveToTest);
       
   197 			TRAPD(err,aRequest.ReadParam1L(drive));
       
   198 			if(err != KErrNone)
       
   199 				return err;
       
   200 			break;
       
   201 			}
       
   202 		default:
       
   203 			break;
       
   204 		}
       
   205 	
       
   206 	return KErrNone;
       
   207 	}
       
   208 
       
   209 
       
   210 TInt CNotifyPluginConn::DoControl(CFsPluginConnRequest& aRequest)
       
   211 	{
       
   212 	return ((CNotifyPlugin*)Plugin())->FsPluginDoControlL(aRequest);
       
   213 	}
       
   214 
       
   215 void CNotifyPluginConn::DoRequest(CFsPluginConnRequest& aRequest)
       
   216 	{
       
   217 	DoControl(aRequest);
       
   218 	}
       
   219 
       
   220 void CNotifyPluginConn::DoCancel(TInt /*aReqMask*/)
       
   221 	{
       
   222 	}
       
   223 
       
   224 
       
   225 
       
   226 
       
   227 
       
   228 //factory functions
       
   229 
       
   230 class CNotifyPluginFactory : public CFsPluginFactory
       
   231 	{
       
   232 public:
       
   233 	CNotifyPluginFactory();
       
   234 	virtual TInt Install();			
       
   235 	virtual CFsPlugin* NewPluginL();
       
   236 	virtual CFsPlugin* NewPluginConnL();
       
   237 	virtual TInt UniquePosition();
       
   238 	};
       
   239 
       
   240 /**
       
   241 Constructor for the plugin factory
       
   242 @internalComponent
       
   243 */
       
   244 CNotifyPluginFactory::CNotifyPluginFactory()
       
   245 	{
       
   246 	}
       
   247 
       
   248 /**
       
   249 Install function for the plugin factory
       
   250 @internalComponent
       
   251 */
       
   252 TInt CNotifyPluginFactory::Install()
       
   253 	{
       
   254 	SetSupportedDrives(KPluginSupportAllDrives);
       
   255 	return(SetName(&KNotifyPluginName));
       
   256 	}
       
   257 
       
   258 /**
       
   259 @internalComponent
       
   260 */
       
   261 TInt CNotifyPluginFactory::UniquePosition()
       
   262 	{
       
   263 	return(KNotifyPos);
       
   264 	}
       
   265 
       
   266 /**
       
   267 Plugin factory function
       
   268 @internalComponent
       
   269 */
       
   270 CFsPlugin* CNotifyPluginFactory::NewPluginL()
       
   271 
       
   272 	{
       
   273 	return CNotifyPlugin::NewL();
       
   274 	}
       
   275 
       
   276 /**
       
   277 Plugin factory function
       
   278 @internalComponent
       
   279 */
       
   280 CFsPlugin* CNotifyPluginFactory::NewPluginConnL()
       
   281 
       
   282 	{
       
   283 	return CNotifyPlugin::NewL();
       
   284 	}
       
   285 
       
   286 /**
       
   287 Create a new Plugin
       
   288 @internalComponent
       
   289 */
       
   290 extern "C" {
       
   291 
       
   292 EXPORT_C CFsPluginFactory* CreateFileSystem()
       
   293 	{
       
   294 	return(new CNotifyPluginFactory());
       
   295 	}
       
   296 }
       
   297