Update contrib.
1 // Copyright (c) 2008-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.
14 // f32\sfile\sf_notifier_handlers.cpp
18 #include "sf_notifier.h"
20 #ifdef SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION
22 TInt TFsNotificationOpen::Initialise(CFsRequest* /*aRequest*/)
27 TInt TFsNotificationOpen::DoRequestL(CFsRequest* aRequest)
29 __PRINT(_L("TFsNotificationOpen::DoRequestL()"));
30 //Check whether we've got a notification manager
31 //If not, create it and call OpenL
32 if(!FsNotificationManager::IsInitialised())
34 FsNotificationManager::OpenL();
37 //Create a new CFsNotifyRequest and add it to the manager
38 CFsNotifyRequest* notifyRequest = CFsNotifyRequest::NewL();
40 //Get handle and add request to manager and Session->Handles
42 TBool addedToManager = EFalse;
43 TRAPD(ret,HandleRequestL(aRequest, notifyRequest, handle,addedToManager));
46 //Remove request from Session->Handles if it was already added
48 aRequest->Session()->Handles().Remove(handle,ETrue);
50 //Remove request from manager
53 FsNotificationManager::Lock();
54 FsNotificationManager::RemoveNotificationRequest(notifyRequest);
55 FsNotificationManager::Unlock();
61 notifyRequest->iSession = aRequest->Session();
62 aRequest->Session()->IncResourceCount();
66 //Get handle and add request to Session->Handles
67 void TFsNotificationOpen::HandleRequestL(CFsRequest* aRequest, CFsNotifyRequest* aNotifyRequest, TInt& aHandle,TBool& aAddedToManager)
69 aAddedToManager = EFalse;
70 FsNotificationManager::AddNotificationRequestL(aNotifyRequest);
71 aAddedToManager = ETrue;
72 aHandle = aRequest->Session()->Handles().AddL(aNotifyRequest,ETrue);
73 TPtrC8 pH((TUint8*)&aHandle, sizeof(TInt));
74 aRequest->WriteL(KMsgPtr3,pH);
77 TInt TFsNotificationBuffer::Initialise(CFsRequest* /*aRequest*/)
82 TInt TFsNotificationBuffer::DoRequestL(CFsRequest* aRequest)
84 __PRINT(_L("TFsNotificationBuffer::DoRequestL()"));
85 HBufC8* buffer = (HBufC8*)(aRequest->Message().Ptr0());
86 TInt handle = aRequest->Message().Int3();
87 CFsNotifyRequest* notifyRequest = (CFsNotifyRequest*)SessionObjectFromHandle(handle,0,aRequest->Session());
93 notifyRequest->iClientBufferSize = aRequest->Message().Int1();
94 notifyRequest->iBufferMsg = aRequest->Message();
98 TInt TFsNotificationRequest::Initialise(CFsRequest* aRequest)
100 TInt handle = aRequest->Message().Int3();
101 CFsNotifyRequest* notifyRequest = (CFsNotifyRequest*)SessionObjectFromHandle(handle,0,aRequest->Session());
103 return KErrBadHandle;
105 //Check the tail's validity
107 TPckg<TInt> tailPkg(tail);
108 TInt r = aRequest->Read(KMsgPtr0,tailPkg);
110 if(r!=KErrNone || tail < 0 || tail > notifyRequest->iClientBufferSize)
116 TInt TFsNotificationRequest::DoRequestL(CFsRequest* aRequest)
118 __PRINT(_L("TFsNotificationRequest::DoRequestL()"));
119 //We need to check whether there is anything in the buffer
120 //If so we should complete straight away.
121 FsNotificationManager::Lock();
123 //Get notification request
124 TInt handle = aRequest->Message().Int3();
125 CFsNotifyRequest* notifyRequest = (CFsNotifyRequest*)SessionObjectFromHandle(handle,0,aRequest->Session());
128 FsNotificationManager::Unlock();
129 return KErrBadHandle;
132 TInt r = notifyRequest->SetClientMessage(aRequest->Message());
135 FsNotificationManager::Unlock();
139 CFsNotifyRequest::TNotifyRequestStatus status = notifyRequest->ActiveStatus();
140 if(status==CFsNotifyRequest::EOutstanding ||
141 status==CFsNotifyRequest::EOutstandingOverflow)
143 notifyRequest->CompleteClientRequest(KErrNone);
147 if(status!=CFsNotifyRequest::EOutstandingOverflow)
149 notifyRequest->SetActive(CFsNotifyRequest::EActive);
150 // RDebug::Print(_L("TFsNotificationRequest::DoRequestL Not-OutOver- iClientHead==%d, iClientTail==%d"),notifyRequest->iClientHead,notifyRequest->iClientTail);
154 notifyRequest->SetActive(CFsNotifyRequest::EInactive);
156 // RDebug::Print(_L("TFsNotificationRequest::DoRequestL OutOver- iClientHead==%d, iClientTail==%d"),notifyRequest->iClientHead,notifyRequest->iClientTail);
158 // If the user is in OutstandingOverflow notification state,
159 // then we can set iClientHead to be equal to iServerTail now.
160 // That way if the client requests again and the state will go
161 // back to active, the server will see that buffer as empty
162 // rather than full/overflow.
164 notifyRequest->iClientHead = notifyRequest->iClientTail;
166 FsNotificationManager::Unlock();
170 TInt TFsNotificationCancel::Initialise(CFsRequest* /*aRequest*/)
175 TInt TFsNotificationCancel::DoRequestL(CFsRequest* aRequest)
177 __PRINT(_L("TFsNotificationCancel::DoRequestL()"));
178 FsNotificationManager::Lock();
180 //Get notification request and deactivate filter
181 TInt handle = aRequest->Message().Int3();
182 CFsNotifyRequest* notifyRequest = (CFsNotifyRequest*)SessionObjectFromHandle(handle,0,aRequest->Session());
185 FsNotificationManager::Unlock();
186 return KErrBadHandle;
189 if(notifyRequest->ClientMsgHandle()!=0)
191 notifyRequest->SetActive(CFsNotifyRequest::EInactive);
192 notifyRequest->CompleteClientRequest(KErrCancel,ETrue);
194 FsNotificationManager::Unlock();
198 TInt TFsNotificationSubClose::Initialise(CFsRequest* /*aRequest*/)
203 TInt TFsNotificationSubClose::DoRequestL(CFsRequest* aRequest)
205 __PRINT(_L("TFsNotificationSubClose::DoRequestL()"));
206 FsNotificationManager::Lock();
208 //We need to complete the buffer request here as this type of request is not
209 //completed in the normal way as it is kept open in order that we can access the buffer
210 //in the client-side for the lifetime of this subsession.
211 TInt handle = aRequest->Message().Int3();
212 CFsNotifyRequest* notifyRequest = (CFsNotifyRequest*) SessionObjectFromHandle(handle,0,aRequest->Session());
215 FsNotificationManager::Unlock();
216 return KErrBadHandle;
219 notifyRequest->RemoveFilters();
220 notifyRequest->CloseNotification(); //Completes the buffer and the client requests.
222 TInt count = FsNotificationManager::Count();
224 //Also deletes notifyRequest
225 aRequest->Session()->Handles().Remove(handle,ETrue);
228 //If this is the last request then we need to remove the manager
229 FsNotificationManager::Close();
232 FsNotificationManager::Unlock();
233 aRequest->Session()->DecResourceCount();
234 notifyRequest = NULL;
239 TInt TFsNotificationAdd::Initialise(CFsRequest* aRequest)
241 __PRINT(_L("TFsNotificationAdd::Initialise()"));
242 TUint filter = (TUint) aRequest->Message().Int0();
243 //If it's AllOps then it's ok
244 if (filter!=TFsNotification::EAllOps)
247 TInt invalid = filter & ~KNotificationValidFiltersMask;
248 //Check: Non-valid values ARE NOT set
249 // and valid values ARE set.
250 if(invalid || !filter)
257 TInt r = aRequest->Read(KMsgPtr1,path);
263 if(path.Length() >= 2)
264 r=PathCheck(aRequest,path.Mid(2),&KCapFsSysFileTemp,&KCapFsPriFileTemp,&KCapFsROFileTemp, __PLATSEC_DIAGNOSTIC_STRING("Notification Add Filter"));
268 TInt TFsNotificationAdd::DoRequestL(CFsRequest* aRequest)
270 __PRINT(_L("TFsNotificationAdd::DoRequestL()"));
271 TInt handle = aRequest->Message().Int3();
272 CFsNotifyRequest* notifyRequest = (CFsNotifyRequest*) SessionObjectFromHandle(handle,0,aRequest->Session());
274 return KErrBadHandle;
277 aRequest->Read(KMsgPtr1,path);
280 TInt r = aRequest->Read(KMsgPtr2,filename);
284 __PRINT2(_L("TFsNotificationAdd::AddNotification() path=%S, filename=%S"),&path,&filename);
286 //If this is a path starting with 'drive-letter:'
287 TInt driveNum = FsNotificationHelper::DriveNumber(path);
288 if(path.Length() >= 2 && (driveNum < 0 || driveNum > 25) && ((TChar)driveNum)!=((TChar)'?') && ((TChar)path[1])==(TChar)':')
290 return KErrPathNotFound;
293 CleanupStack::PushL(notifyRequest);
294 CFsNotificationPathFilter* filter = CFsNotificationPathFilter::NewL(path,filename);
296 //Bitmask of filter types
297 TUint filterMask = (TUint) aRequest->Message().Int0();
299 r = notifyRequest->AddFilterL(filter,filterMask);
300 CleanupStack::Pop(notifyRequest);
304 FsNotificationManager::Lock();
305 //Increment global filter register
306 FsNotificationManager::SetFilterRegisterMask(filterMask,(TBool)ETrue);
307 FsNotificationManager::Unlock();
312 TInt TFsNotificationRemove::Initialise(CFsRequest* /*aRequest*/)
314 __PRINT(_L("TFsNotificationRemove::Initialise()"));
318 TInt TFsNotificationRemove::DoRequestL(CFsRequest* aRequest)
320 __PRINT(_L("TFsNotificationRemove::DoRequestL()"));
321 FsNotificationManager::Lock();
323 TInt handle = aRequest->Message().Int3();
324 CFsNotifyRequest* notifyRequest = (CFsNotifyRequest*) SessionObjectFromHandle(handle,0,aRequest->Session());
327 FsNotificationManager::Unlock();
328 return KErrBadHandle;
331 TInt r = notifyRequest->RemoveFilters();
332 FsNotificationManager::Unlock();
336 #else //SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION
338 CFsObjectCon* FsNotificationManager::iNotifyRequests = NULL;
340 CFsNotifyRequest::CFsNotifyRequest()
344 CFsNotifyRequest::~CFsNotifyRequest()
348 TInt TFsNotificationOpen::Initialise(CFsRequest* /*aRequest*/)
350 return KErrNotSupported;
353 TInt TFsNotificationOpen::DoRequestL(CFsRequest* /*aRequest*/)
355 return KErrNotSupported;
358 void TFsNotificationOpen::HandleRequestL(CFsRequest* /*aRequest*/, CFsNotifyRequest* /*aNotifyRequest*/, TInt& /*aHandle*/,TBool& /*aAddedToManager*/)
360 User::Leave(KErrNotSupported);
363 TInt TFsNotificationBuffer::Initialise(CFsRequest* /*aRequest*/)
365 return KErrNotSupported;
368 TInt TFsNotificationBuffer::DoRequestL(CFsRequest* /*aRequest*/)
370 return KErrNotSupported;
373 TInt TFsNotificationRequest::Initialise(CFsRequest* /*aRequest*/)
375 return KErrNotSupported;
378 TInt TFsNotificationRequest::DoRequestL(CFsRequest* /*aRequest*/)
380 return KErrNotSupported;
383 TInt TFsNotificationCancel::Initialise(CFsRequest* /*aRequest*/)
385 return KErrNotSupported;
388 TInt TFsNotificationCancel::DoRequestL(CFsRequest* /*aRequest*/)
390 return KErrNotSupported;
393 TInt TFsNotificationSubClose::Initialise(CFsRequest* /*aRequest*/)
395 return KErrNotSupported;
398 TInt TFsNotificationSubClose::DoRequestL(CFsRequest* /*aRequest*/)
400 return KErrNotSupported;
403 TInt TFsNotificationAdd::Initialise(CFsRequest* /*aRequest*/)
405 return KErrNotSupported;
408 TInt TFsNotificationAdd::DoRequestL(CFsRequest* /*aRequest*/)
410 return KErrNotSupported;
413 TInt TFsNotificationRemove::Initialise(CFsRequest* /*aRequest*/)
415 return KErrNotSupported;
418 TInt TFsNotificationRemove::DoRequestL(CFsRequest* /*aRequest*/)
420 return KErrNotSupported;
423 #endif //SYMBIAN_F32_ENHANCED_CHANGE_NOTIFICATION