os/kernelhwsrv/userlibandfileserver/fileserver/sfile/sf_notifier_handlers.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// f32\sfile\sf_notifier_handlers.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
#include "sf_std.h"
sl@0
    18
#include "sf_notifier.h"
sl@0
    19
sl@0
    20
#ifdef SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION
sl@0
    21
sl@0
    22
TInt TFsNotificationOpen::Initialise(CFsRequest* /*aRequest*/)
sl@0
    23
	{
sl@0
    24
	return KErrNone;
sl@0
    25
	}
sl@0
    26
sl@0
    27
TInt TFsNotificationOpen::DoRequestL(CFsRequest* aRequest)
sl@0
    28
	{
sl@0
    29
	__PRINT(_L("TFsNotificationOpen::DoRequestL()"));
sl@0
    30
	//Check whether we've got a notification manager 
sl@0
    31
	//If not, create it and call OpenL
sl@0
    32
	if(!FsNotificationManager::IsInitialised())
sl@0
    33
		{
sl@0
    34
		FsNotificationManager::OpenL();
sl@0
    35
		}
sl@0
    36
	
sl@0
    37
	//Create a new CFsNotifyRequest and add it to the manager
sl@0
    38
	CFsNotifyRequest* notifyRequest = CFsNotifyRequest::NewL();
sl@0
    39
sl@0
    40
	//Get handle and add request to manager and Session->Handles
sl@0
    41
	TInt handle = 0;
sl@0
    42
	TBool addedToManager = EFalse;
sl@0
    43
	TRAPD(ret,HandleRequestL(aRequest, notifyRequest, handle,addedToManager));	
sl@0
    44
	if (ret!=KErrNone)
sl@0
    45
		{
sl@0
    46
		//Remove request from Session->Handles if it was already added
sl@0
    47
		if (handle!=0)
sl@0
    48
			aRequest->Session()->Handles().Remove(handle,ETrue);
sl@0
    49
		
sl@0
    50
		//Remove request from manager
sl@0
    51
		if(addedToManager)
sl@0
    52
			{
sl@0
    53
			FsNotificationManager::Lock();
sl@0
    54
			FsNotificationManager::RemoveNotificationRequest(notifyRequest);
sl@0
    55
			FsNotificationManager::Unlock();
sl@0
    56
			}
sl@0
    57
		delete notifyRequest;
sl@0
    58
		return(ret);
sl@0
    59
		}
sl@0
    60
	
sl@0
    61
	notifyRequest->iSession = aRequest->Session();
sl@0
    62
	aRequest->Session()->IncResourceCount();
sl@0
    63
	return ret;
sl@0
    64
	}
sl@0
    65
sl@0
    66
//Get handle and add request to Session->Handles
sl@0
    67
void TFsNotificationOpen::HandleRequestL(CFsRequest* aRequest, CFsNotifyRequest* aNotifyRequest, TInt& aHandle,TBool& aAddedToManager)
sl@0
    68
	{
sl@0
    69
	aAddedToManager = EFalse;
sl@0
    70
	FsNotificationManager::AddNotificationRequestL(aNotifyRequest);
sl@0
    71
	aAddedToManager = ETrue;
sl@0
    72
	aHandle = aRequest->Session()->Handles().AddL(aNotifyRequest,ETrue);
sl@0
    73
	TPtrC8 pH((TUint8*)&aHandle, sizeof(TInt));
sl@0
    74
	aRequest->WriteL(KMsgPtr3,pH);
sl@0
    75
	}
sl@0
    76
sl@0
    77
TInt TFsNotificationBuffer::Initialise(CFsRequest* /*aRequest*/)
sl@0
    78
	{
sl@0
    79
	return KErrNone;
sl@0
    80
	}
sl@0
    81
sl@0
    82
TInt TFsNotificationBuffer::DoRequestL(CFsRequest* aRequest)
sl@0
    83
	{
sl@0
    84
	__PRINT(_L("TFsNotificationBuffer::DoRequestL()"));
sl@0
    85
	HBufC8* buffer = (HBufC8*)(aRequest->Message().Ptr0());
sl@0
    86
	TInt handle = aRequest->Message().Int3();
sl@0
    87
	CFsNotifyRequest* notifyRequest = (CFsNotifyRequest*)SessionObjectFromHandle(handle,0,aRequest->Session());
sl@0
    88
	if(!notifyRequest)
sl@0
    89
		return KErrBadHandle;
sl@0
    90
	if(!buffer)
sl@0
    91
		return KErrArgument;
sl@0
    92
sl@0
    93
	notifyRequest->iClientBufferSize = aRequest->Message().Int1();
sl@0
    94
	notifyRequest->iBufferMsg = aRequest->Message();
sl@0
    95
	return KErrNone;
sl@0
    96
	}
sl@0
    97
sl@0
    98
TInt TFsNotificationRequest::Initialise(CFsRequest* aRequest)
sl@0
    99
	{
sl@0
   100
	TInt handle = aRequest->Message().Int3();	
sl@0
   101
	CFsNotifyRequest* notifyRequest = (CFsNotifyRequest*)SessionObjectFromHandle(handle,0,aRequest->Session());
sl@0
   102
	if(!notifyRequest)
sl@0
   103
		return KErrBadHandle;
sl@0
   104
	
sl@0
   105
	//Check the tail's validity
sl@0
   106
	TInt tail;
sl@0
   107
	TPckg<TInt> tailPkg(tail);
sl@0
   108
	TInt r = aRequest->Read(KMsgPtr0,tailPkg);
sl@0
   109
	
sl@0
   110
	if(r!=KErrNone || tail < 0 || tail > notifyRequest->iClientBufferSize)
sl@0
   111
		return KErrArgument;
sl@0
   112
		
sl@0
   113
	return KErrNone;
sl@0
   114
	}
sl@0
   115
sl@0
   116
TInt TFsNotificationRequest::DoRequestL(CFsRequest* aRequest)
sl@0
   117
	{
sl@0
   118
	__PRINT(_L("TFsNotificationRequest::DoRequestL()"));
sl@0
   119
	//We need to check whether there is anything in the buffer
sl@0
   120
	//If so we should complete straight away.
sl@0
   121
	FsNotificationManager::Lock();
sl@0
   122
	
sl@0
   123
	//Get notification request
sl@0
   124
	TInt handle = aRequest->Message().Int3();	
sl@0
   125
	CFsNotifyRequest* notifyRequest = (CFsNotifyRequest*)SessionObjectFromHandle(handle,0,aRequest->Session());
sl@0
   126
	if(!notifyRequest)
sl@0
   127
		{
sl@0
   128
		FsNotificationManager::Unlock();
sl@0
   129
		return KErrBadHandle;
sl@0
   130
		}
sl@0
   131
	
sl@0
   132
	TInt r = notifyRequest->SetClientMessage(aRequest->Message());
sl@0
   133
	if(r != KErrNone)
sl@0
   134
		{
sl@0
   135
		FsNotificationManager::Unlock();
sl@0
   136
		return r;
sl@0
   137
		}
sl@0
   138
sl@0
   139
	CFsNotifyRequest::TNotifyRequestStatus status = notifyRequest->ActiveStatus();
sl@0
   140
	if(status==CFsNotifyRequest::EOutstanding ||
sl@0
   141
		status==CFsNotifyRequest::EOutstandingOverflow)
sl@0
   142
		{
sl@0
   143
		notifyRequest->CompleteClientRequest(KErrNone);
sl@0
   144
		}
sl@0
   145
sl@0
   146
	//Update Status
sl@0
   147
	if(status!=CFsNotifyRequest::EOutstandingOverflow)
sl@0
   148
		{
sl@0
   149
		notifyRequest->SetActive(CFsNotifyRequest::EActive);
sl@0
   150
		// RDebug::Print(_L("TFsNotificationRequest::DoRequestL Not-OutOver- iClientHead==%d, iClientTail==%d"),notifyRequest->iClientHead,notifyRequest->iClientTail);
sl@0
   151
		}
sl@0
   152
	else
sl@0
   153
		{
sl@0
   154
		notifyRequest->SetActive(CFsNotifyRequest::EInactive);
sl@0
   155
		
sl@0
   156
		// RDebug::Print(_L("TFsNotificationRequest::DoRequestL OutOver- iClientHead==%d, iClientTail==%d"),notifyRequest->iClientHead,notifyRequest->iClientTail);
sl@0
   157
		
sl@0
   158
		// If the user is in OutstandingOverflow notification state, 
sl@0
   159
		// then we can set iClientHead to be equal to iServerTail now.
sl@0
   160
		// That way if the client requests again and the state will go 
sl@0
   161
		// back to active, the server will see that buffer as empty 
sl@0
   162
		// rather than full/overflow.
sl@0
   163
		
sl@0
   164
		notifyRequest->iClientHead = notifyRequest->iClientTail;
sl@0
   165
		}
sl@0
   166
	FsNotificationManager::Unlock();
sl@0
   167
	return r;
sl@0
   168
	}
sl@0
   169
sl@0
   170
TInt TFsNotificationCancel::Initialise(CFsRequest* /*aRequest*/)
sl@0
   171
	{
sl@0
   172
	return KErrNone;
sl@0
   173
	}
sl@0
   174
sl@0
   175
TInt TFsNotificationCancel::DoRequestL(CFsRequest* aRequest)
sl@0
   176
	{
sl@0
   177
	__PRINT(_L("TFsNotificationCancel::DoRequestL()"));
sl@0
   178
	FsNotificationManager::Lock();
sl@0
   179
	
sl@0
   180
	//Get notification request and deactivate filter
sl@0
   181
	TInt handle = aRequest->Message().Int3();	
sl@0
   182
	CFsNotifyRequest* notifyRequest = (CFsNotifyRequest*)SessionObjectFromHandle(handle,0,aRequest->Session());
sl@0
   183
	if(!notifyRequest)
sl@0
   184
		{
sl@0
   185
		FsNotificationManager::Unlock();
sl@0
   186
		return KErrBadHandle;
sl@0
   187
		}
sl@0
   188
	
sl@0
   189
	if(notifyRequest->ClientMsgHandle()!=0)
sl@0
   190
		{	
sl@0
   191
		notifyRequest->SetActive(CFsNotifyRequest::EInactive);
sl@0
   192
		notifyRequest->CompleteClientRequest(KErrCancel,ETrue);
sl@0
   193
		}
sl@0
   194
	FsNotificationManager::Unlock();
sl@0
   195
	return KErrNone;
sl@0
   196
	}
sl@0
   197
sl@0
   198
TInt TFsNotificationSubClose::Initialise(CFsRequest* /*aRequest*/)
sl@0
   199
	{
sl@0
   200
	return KErrNone;
sl@0
   201
	}
sl@0
   202
sl@0
   203
TInt TFsNotificationSubClose::DoRequestL(CFsRequest* aRequest)
sl@0
   204
	{
sl@0
   205
	__PRINT(_L("TFsNotificationSubClose::DoRequestL()"));
sl@0
   206
	FsNotificationManager::Lock();
sl@0
   207
	
sl@0
   208
	//We need to complete the buffer request here as this type of request is not
sl@0
   209
	//completed in the normal way as it is kept open in order that we can access the buffer
sl@0
   210
	//in the client-side for the lifetime of this subsession.
sl@0
   211
	TInt handle = aRequest->Message().Int3();
sl@0
   212
	CFsNotifyRequest* notifyRequest = (CFsNotifyRequest*) SessionObjectFromHandle(handle,0,aRequest->Session());
sl@0
   213
	if(!notifyRequest)
sl@0
   214
		{
sl@0
   215
		FsNotificationManager::Unlock();
sl@0
   216
		return KErrBadHandle;
sl@0
   217
		}
sl@0
   218
	
sl@0
   219
	notifyRequest->RemoveFilters();
sl@0
   220
	notifyRequest->CloseNotification(); //Completes the buffer and the client requests.
sl@0
   221
	
sl@0
   222
	TInt count = FsNotificationManager::Count();
sl@0
   223
	
sl@0
   224
	//Also deletes notifyRequest
sl@0
   225
	aRequest->Session()->Handles().Remove(handle,ETrue);
sl@0
   226
	if(count==1)
sl@0
   227
		{
sl@0
   228
		//If this is the last request then we need to remove the manager
sl@0
   229
		FsNotificationManager::Close();
sl@0
   230
		}
sl@0
   231
	
sl@0
   232
	FsNotificationManager::Unlock();
sl@0
   233
	aRequest->Session()->DecResourceCount();
sl@0
   234
	notifyRequest = NULL;
sl@0
   235
sl@0
   236
	return(KErrNone);
sl@0
   237
	}
sl@0
   238
sl@0
   239
TInt TFsNotificationAdd::Initialise(CFsRequest* aRequest)
sl@0
   240
	{
sl@0
   241
	__PRINT(_L("TFsNotificationAdd::Initialise()"));
sl@0
   242
	TUint filter = (TUint) aRequest->Message().Int0();
sl@0
   243
	//If it's AllOps then it's ok
sl@0
   244
	if (filter!=TFsNotification::EAllOps)
sl@0
   245
		{
sl@0
   246
sl@0
   247
		TInt invalid = filter & ~KNotificationValidFiltersMask;
sl@0
   248
		//Check: Non-valid values ARE NOT set
sl@0
   249
		//		 and valid values ARE set.
sl@0
   250
		if(invalid || !filter)
sl@0
   251
			{
sl@0
   252
			return KErrArgument;
sl@0
   253
			}
sl@0
   254
		}
sl@0
   255
	
sl@0
   256
	TFileName path;
sl@0
   257
	TInt r = aRequest->Read(KMsgPtr1,path);
sl@0
   258
	if(r != KErrNone)
sl@0
   259
		{
sl@0
   260
		return r;
sl@0
   261
		}
sl@0
   262
	
sl@0
   263
	if(path.Length() >= 2)
sl@0
   264
		r=PathCheck(aRequest,path.Mid(2),&KCapFsSysFileTemp,&KCapFsPriFileTemp,&KCapFsROFileTemp, __PLATSEC_DIAGNOSTIC_STRING("Notification Add Filter"));
sl@0
   265
	return r;
sl@0
   266
	}
sl@0
   267
sl@0
   268
TInt TFsNotificationAdd::DoRequestL(CFsRequest* aRequest)
sl@0
   269
	{
sl@0
   270
	__PRINT(_L("TFsNotificationAdd::DoRequestL()"));
sl@0
   271
	TInt handle = aRequest->Message().Int3();
sl@0
   272
	CFsNotifyRequest* notifyRequest = (CFsNotifyRequest*) SessionObjectFromHandle(handle,0,aRequest->Session());
sl@0
   273
	if(!notifyRequest)
sl@0
   274
		return KErrBadHandle;
sl@0
   275
	
sl@0
   276
	TFileName path;
sl@0
   277
	aRequest->Read(KMsgPtr1,path);
sl@0
   278
	
sl@0
   279
	TFileName filename;
sl@0
   280
	TInt r = aRequest->Read(KMsgPtr2,filename);
sl@0
   281
	if(r!= KErrNone)
sl@0
   282
		return r;
sl@0
   283
	
sl@0
   284
	__PRINT2(_L("TFsNotificationAdd::AddNotification() path=%S, filename=%S"),&path,&filename);
sl@0
   285
	
sl@0
   286
	//If this is a path starting with 'drive-letter:'
sl@0
   287
	TInt driveNum = FsNotificationHelper::DriveNumber(path);
sl@0
   288
	if(path.Length() >= 2 && (driveNum < 0 || driveNum > 25) && ((TChar)driveNum)!=((TChar)'?') && ((TChar)path[1])==(TChar)':')
sl@0
   289
		{
sl@0
   290
		return KErrPathNotFound;
sl@0
   291
		}
sl@0
   292
sl@0
   293
	CleanupStack::PushL(notifyRequest);
sl@0
   294
	CFsNotificationPathFilter* filter = CFsNotificationPathFilter::NewL(path,filename);
sl@0
   295
sl@0
   296
	//Bitmask of filter types
sl@0
   297
	TUint filterMask = (TUint) aRequest->Message().Int0();
sl@0
   298
	
sl@0
   299
	r = notifyRequest->AddFilterL(filter,filterMask);
sl@0
   300
	CleanupStack::Pop(notifyRequest);
sl@0
   301
sl@0
   302
	if(r == KErrNone)
sl@0
   303
		{
sl@0
   304
		FsNotificationManager::Lock();
sl@0
   305
		//Increment global filter register
sl@0
   306
		FsNotificationManager::SetFilterRegisterMask(filterMask,(TBool)ETrue);
sl@0
   307
		FsNotificationManager::Unlock();
sl@0
   308
		}
sl@0
   309
	return r;
sl@0
   310
	}
sl@0
   311
sl@0
   312
TInt TFsNotificationRemove::Initialise(CFsRequest* /*aRequest*/)
sl@0
   313
	{
sl@0
   314
	__PRINT(_L("TFsNotificationRemove::Initialise()"));
sl@0
   315
	return KErrNone;
sl@0
   316
	}
sl@0
   317
sl@0
   318
TInt TFsNotificationRemove::DoRequestL(CFsRequest* aRequest)
sl@0
   319
	{
sl@0
   320
	__PRINT(_L("TFsNotificationRemove::DoRequestL()"));
sl@0
   321
	FsNotificationManager::Lock();
sl@0
   322
	
sl@0
   323
	TInt handle = aRequest->Message().Int3();
sl@0
   324
	CFsNotifyRequest* notifyRequest = (CFsNotifyRequest*) SessionObjectFromHandle(handle,0,aRequest->Session());
sl@0
   325
	if(!notifyRequest)
sl@0
   326
		{
sl@0
   327
		FsNotificationManager::Unlock();
sl@0
   328
		return KErrBadHandle;
sl@0
   329
		}
sl@0
   330
	
sl@0
   331
	TInt r = notifyRequest->RemoveFilters();
sl@0
   332
	FsNotificationManager::Unlock();
sl@0
   333
	return r;
sl@0
   334
	}
sl@0
   335
sl@0
   336
#else //SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION
sl@0
   337
sl@0
   338
CFsObjectCon* FsNotificationManager::iNotifyRequests = NULL;
sl@0
   339
sl@0
   340
CFsNotifyRequest::CFsNotifyRequest()
sl@0
   341
	{
sl@0
   342
	}
sl@0
   343
sl@0
   344
CFsNotifyRequest::~CFsNotifyRequest()
sl@0
   345
	{
sl@0
   346
	}
sl@0
   347
sl@0
   348
TInt TFsNotificationOpen::Initialise(CFsRequest* /*aRequest*/)
sl@0
   349
	{
sl@0
   350
	return KErrNotSupported;
sl@0
   351
	}
sl@0
   352
sl@0
   353
TInt TFsNotificationOpen::DoRequestL(CFsRequest* /*aRequest*/)
sl@0
   354
	{
sl@0
   355
	return KErrNotSupported;
sl@0
   356
	}
sl@0
   357
sl@0
   358
void TFsNotificationOpen::HandleRequestL(CFsRequest* /*aRequest*/, CFsNotifyRequest* /*aNotifyRequest*/, TInt& /*aHandle*/,TBool& /*aAddedToManager*/)
sl@0
   359
	{
sl@0
   360
	User::Leave(KErrNotSupported);
sl@0
   361
	}
sl@0
   362
sl@0
   363
TInt TFsNotificationBuffer::Initialise(CFsRequest* /*aRequest*/)
sl@0
   364
	{
sl@0
   365
	return KErrNotSupported;
sl@0
   366
	}
sl@0
   367
sl@0
   368
TInt TFsNotificationBuffer::DoRequestL(CFsRequest* /*aRequest*/)
sl@0
   369
	{
sl@0
   370
	return KErrNotSupported;
sl@0
   371
	}
sl@0
   372
sl@0
   373
TInt TFsNotificationRequest::Initialise(CFsRequest* /*aRequest*/)
sl@0
   374
	{
sl@0
   375
	return KErrNotSupported;
sl@0
   376
	}
sl@0
   377
sl@0
   378
TInt TFsNotificationRequest::DoRequestL(CFsRequest* /*aRequest*/)
sl@0
   379
	{
sl@0
   380
	return KErrNotSupported;
sl@0
   381
	}
sl@0
   382
sl@0
   383
TInt TFsNotificationCancel::Initialise(CFsRequest* /*aRequest*/)
sl@0
   384
	{
sl@0
   385
	return KErrNotSupported;
sl@0
   386
	}
sl@0
   387
sl@0
   388
TInt TFsNotificationCancel::DoRequestL(CFsRequest* /*aRequest*/)
sl@0
   389
	{
sl@0
   390
	return KErrNotSupported;
sl@0
   391
	}
sl@0
   392
sl@0
   393
TInt TFsNotificationSubClose::Initialise(CFsRequest* /*aRequest*/)
sl@0
   394
	{
sl@0
   395
	return KErrNotSupported;
sl@0
   396
	}
sl@0
   397
sl@0
   398
TInt TFsNotificationSubClose::DoRequestL(CFsRequest* /*aRequest*/)
sl@0
   399
	{
sl@0
   400
	return KErrNotSupported;
sl@0
   401
	}
sl@0
   402
sl@0
   403
TInt TFsNotificationAdd::Initialise(CFsRequest* /*aRequest*/)
sl@0
   404
	{
sl@0
   405
	return KErrNotSupported;
sl@0
   406
	}
sl@0
   407
sl@0
   408
TInt TFsNotificationAdd::DoRequestL(CFsRequest* /*aRequest*/)
sl@0
   409
	{
sl@0
   410
	return KErrNotSupported;
sl@0
   411
	}
sl@0
   412
sl@0
   413
TInt TFsNotificationRemove::Initialise(CFsRequest* /*aRequest*/)
sl@0
   414
	{
sl@0
   415
	return KErrNotSupported;
sl@0
   416
	}
sl@0
   417
sl@0
   418
TInt TFsNotificationRemove::DoRequestL(CFsRequest* /*aRequest*/)
sl@0
   419
	{
sl@0
   420
	return KErrNotSupported;
sl@0
   421
	}
sl@0
   422
sl@0
   423
#endif //SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION
sl@0
   424