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