|
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 "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 /** |
|
17 @file |
|
18 @internalComponent |
|
19 */ |
|
20 |
|
21 #include "CCntMsgHandler.h" |
|
22 #include "CCntMsgHandlerFptr.h" |
|
23 #include "CCntViewMsgHandler.h" |
|
24 |
|
25 #include "CCntRequest.h" |
|
26 #include "CCntServer.h" |
|
27 #include "CCntPackager.h" |
|
28 #include "CCntIpcCodes.h" |
|
29 #include "CViewSubSessions.h" |
|
30 |
|
31 const TInt KCntViewIpcCodes[] = |
|
32 { |
|
33 ECntItemAtL, |
|
34 ECntReadContactTextDef, |
|
35 ECntTextField, |
|
36 ECntOpenViewSession, |
|
37 ECntCloseViewSession, |
|
38 ECntViewChangeSortOrderL, |
|
39 ECntViewBeginIterate, |
|
40 ECntViewEndIterate, |
|
41 ECntViewNextItemL, |
|
42 ECntCreateView, |
|
43 ECntCreateNamedView, |
|
44 ECntCloseView, |
|
45 ECntMatchesHintField |
|
46 }; |
|
47 |
|
48 CCntViewMsgHandler* CCntViewMsgHandler::NewLC(CCntSession& aSession) |
|
49 { |
|
50 CCntViewMsgHandler* self = new (ELeave) CCntViewMsgHandler(aSession); |
|
51 CleanupStack::PushL(self); |
|
52 self->ConstructorL(); |
|
53 return self; |
|
54 } |
|
55 |
|
56 void CCntViewMsgHandler::ConstructorL() |
|
57 { |
|
58 iSubSessions=CObjectIx::NewL(); |
|
59 } |
|
60 |
|
61 CCntViewMsgHandler::CCntViewMsgHandler(CCntSession& aSession) |
|
62 :CCntMsgHandler(aSession) |
|
63 { |
|
64 } |
|
65 |
|
66 CCntViewMsgHandler::~CCntViewMsgHandler() |
|
67 { |
|
68 delete iSubSessions; |
|
69 |
|
70 /* Remove container from server. CServer2 instance which created session object exists! **/ |
|
71 if(iContainer) |
|
72 { |
|
73 Server().RemoveObjectContainer(*iContainer); |
|
74 } |
|
75 } |
|
76 |
|
77 /** |
|
78 Delegates the incoming op code to a message handling method. |
|
79 |
|
80 First checks if this class services the op code, it then uses the lookup table and finds |
|
81 function pointer(to message handling method) mapped to the incoming message function (op code) |
|
82 and finally delegates the message to handling method. |
|
83 |
|
84 It leaves with KErrNotFound if op code not handled. |
|
85 */ |
|
86 TInt CCntViewMsgHandler::HandleMessageL(const RMessage2& aMessage) |
|
87 { |
|
88 MsgHandlerFptr func_ptr = LookupHandlerMethodL(aMessage.Function(), KCntViewIpcCodes, sizeof(KCntViewIpcCodes)/sizeof(TInt)); |
|
89 |
|
90 if(func_ptr) |
|
91 { |
|
92 ViewMsgHandlerFptr mem_func_ptr = static_cast<ViewMsgHandlerFptr>(func_ptr); |
|
93 (this->*mem_func_ptr)(aMessage); |
|
94 return (KErrNone); |
|
95 } |
|
96 |
|
97 /** Other opcodes processed by view subsession ServiceL() method. |
|
98 View subsession ServiceL() leaves with KErrNotFound if opcode not consumed. |
|
99 */ |
|
100 ViewSubSessionServiceL(aMessage); |
|
101 return (KErrNone); |
|
102 } |
|
103 |
|
104 void CCntViewMsgHandler::CreateViewSubSessionL(const RMessage2& aMessage) |
|
105 { |
|
106 CheckForManagerL(); |
|
107 TObjectCleanup* cleanupData=new(ELeave) TObjectCleanup(); |
|
108 CleanupStack::PushL(TCleanupItem(TObjectCleanup::Cleanup,cleanupData)); |
|
109 CViewSubSession* subSession=CViewSubSession::NewL(iManager->ViewManagerL(),aMessage); |
|
110 cleanupData->iObject=subSession; |
|
111 |
|
112 if(iContainer == NULL) |
|
113 { |
|
114 //Have to get new container after contruction, as CSession2::Server() always |
|
115 //returns empty pointer in contructor. |
|
116 iContainer = Server().NewContainerL(); |
|
117 } |
|
118 iContainer->AddL(subSession); |
|
119 TInt handle=iSubSessions->AddL(subSession); |
|
120 cleanupData->iIndex=iSubSessions; |
|
121 cleanupData->iHandle=handle; |
|
122 TPckg<TInt> handlePckg(handle); |
|
123 aMessage.WriteL(3,handlePckg); |
|
124 CleanupStack::Pop(); // The TCleanupItem. |
|
125 delete cleanupData; |
|
126 } |
|
127 |
|
128 void CCntViewMsgHandler::CreateNamedViewSubSessionL(const RMessage2& aMessage) |
|
129 { |
|
130 CheckForManagerL(); |
|
131 TObjectCleanup* cleanupData=new(ELeave) TObjectCleanup(); |
|
132 CleanupStack::PushL(TCleanupItem(TObjectCleanup::Cleanup,cleanupData)); |
|
133 CNamedViewSubSession* subSession=CNamedViewSubSession::NewL(iManager->ViewManagerL(),aMessage); |
|
134 cleanupData->iObject=subSession; |
|
135 if(iContainer == NULL) |
|
136 { |
|
137 //Have to get new container after contruction, as CSession2::Server() always |
|
138 //returns empty pointer in contructor. |
|
139 iContainer = Server().NewContainerL(); |
|
140 } |
|
141 iContainer->AddL(subSession); |
|
142 TInt handle=iSubSessions->AddL(subSession); |
|
143 cleanupData->iIndex=iSubSessions; |
|
144 cleanupData->iHandle=handle; |
|
145 TPckg<TInt> handlePckg(handle); |
|
146 aMessage.WriteL(3,handlePckg); |
|
147 CleanupStack::Pop(); // The TCleanupItem. |
|
148 delete cleanupData; |
|
149 } |
|
150 |
|
151 void CCntViewMsgHandler::CloseViewSubSessionL(const RMessage2 &aMessage) |
|
152 { |
|
153 const TInt handle=aMessage.Int3(); |
|
154 ViewFromHandleL(handle); // To panic client if passed a bad handle. |
|
155 iSubSessions->Remove(handle); |
|
156 } |
|
157 |
|
158 CViewSubSessionBase& CCntViewMsgHandler::ViewFromHandleL(TUint aHandle) |
|
159 { |
|
160 CViewSubSessionBase* subSession = STATIC_CAST(CViewSubSessionBase*,iSubSessions->At(aHandle)); |
|
161 if (subSession==NULL) |
|
162 { |
|
163 User::Leave(KErrBadHandle); // Will result in client getting panic'd. |
|
164 } |
|
165 return *subSession; |
|
166 } |
|
167 |
|
168 void CCntViewMsgHandler::CompleteMessage(TInt aRet, const RMessage2& aMessage) |
|
169 { |
|
170 if(aRet != KErrNoComplete) |
|
171 { |
|
172 aMessage.Complete(aRet); |
|
173 } |
|
174 } |
|
175 |
|
176 /** |
|
177 Message handling methods. |
|
178 */ |
|
179 void CCntViewMsgHandler::ReadContactTextDefL(const RMessage2& aMessage) |
|
180 { |
|
181 TInt ret(KErrNone); |
|
182 CheckForManagerL(); |
|
183 const TInt receivingBufLen = aMessage.GetDesMaxLength(1); |
|
184 // We cannot return anything, so we can complete the request |
|
185 // immediately. |
|
186 if (receivingBufLen == 0) |
|
187 { |
|
188 aMessage.Complete(ret); |
|
189 return; |
|
190 } |
|
191 // Read CContactTextDef from packager buffer. |
|
192 iPackager.SetBufferFromMessageL(aMessage); |
|
193 // Packager reads from message slot 0. |
|
194 CContactTextDef* textDef = iPackager.UnpackCntTextDefLC(); |
|
195 |
|
196 // Get the iterator manager reference from Persistence Layer. |
|
197 MLplViewIteratorManager& iterManager = iManager->GetPersistenceLayer().FactoryL().GetViewIteratorManagerL(); |
|
198 |
|
199 HBufC* buf = HBufC::NewLC(receivingBufLen); |
|
200 TPtr ptr(const_cast<TUint16*>(buf->Ptr()), receivingBufLen); |
|
201 |
|
202 TInt contactId = aMessage.Int2(); |
|
203 TUid typeUid = iterManager.ReadContactTextDefL(contactId, ptr, *textDef); |
|
204 if(typeUid == KUidContactICCEntry) |
|
205 { |
|
206 MLplPersistenceLayerFactory& factory = iManager->GetPersistenceLayer().FactoryL(); |
|
207 User::LeaveIfError(factory.GetContactSynchroniserL(iSessionId).ValidateContact(MContactSynchroniser::ERead, contactId)); |
|
208 } |
|
209 |
|
210 aMessage.WriteL(1,ptr); |
|
211 CleanupStack::PopAndDestroy(2, textDef); //buf |
|
212 aMessage.Complete(ret); |
|
213 } |
|
214 |
|
215 void CCntViewMsgHandler::TextFieldL(const RMessage2& aMessage) |
|
216 { |
|
217 TInt ret(KErrNone); |
|
218 CheckForManagerL(); |
|
219 MLplViewIteratorManager& iterManager = iManager->GetPersistenceLayer().FactoryL().GetViewIteratorManagerL(); |
|
220 TPckgBuf<TFieldType> package; |
|
221 aMessage.ReadL(1, package); |
|
222 TBuf<64> field; |
|
223 iterManager.TextFieldL(aMessage.Int0(),package(),field); |
|
224 aMessage.WriteL(2,field); |
|
225 aMessage.Complete(ret); |
|
226 } |
|
227 |
|
228 void CCntViewMsgHandler::ValidateViewContactL(const CViewContact& aViewContact, TInt aSessionId) |
|
229 { |
|
230 // If the contact is an ICC entry (held on the phone's SIM), ensure we have |
|
231 // read permission. |
|
232 if(aViewContact.ContactTypeUid() == KUidContactICCEntry) |
|
233 { |
|
234 MLplPersistenceLayerFactory& factory = iManager->GetPersistenceLayer().FactoryL(); |
|
235 User::LeaveIfError(factory.GetContactSynchroniserL(aSessionId).ValidateContact(MContactSynchroniser::ERead, aViewContact.Id())); |
|
236 } |
|
237 } |
|
238 |
|
239 /* |
|
240 Maps to RCntModel::ItemAtL() method. Use real Persistence Layer this side. |
|
241 Call the Persistence Layer view item manager directly. |
|
242 **/ |
|
243 void CCntViewMsgHandler::ItemAtL(const RMessage2& aMessage) |
|
244 { |
|
245 TInt ret(KErrNone); |
|
246 CheckForManagerL(); |
|
247 |
|
248 // Get the pl view item manager reference from persistence layer |
|
249 MLplViewIteratorManager& viewManager = iManager->GetPersistenceLayer().FactoryL().GetViewIteratorManagerL(); |
|
250 |
|
251 // Persistence layer call |
|
252 CViewContact* viewContact = viewManager.ItemAtL(aMessage.Int0(), aMessage.Int1()); |
|
253 // Don't write NULL back across IPC. |
|
254 // Leave KErrNotFound will be picked up by client and propagated as NULL to caller |
|
255 if(viewContact == NULL) |
|
256 { |
|
257 User::Leave(KErrNotFound); |
|
258 } |
|
259 |
|
260 CleanupStack::PushL(viewContact); |
|
261 |
|
262 ValidateViewContactL(*viewContact, iSessionId); |
|
263 |
|
264 // Compare with maximum length of descriptor argument in the client's process. |
|
265 if(viewContact->ExternalizedSize() > aMessage.GetDesMaxLength(2) ) |
|
266 { |
|
267 // Return required size of buffer to the client. |
|
268 aMessage.Complete(viewContact->ExternalizedSize()); |
|
269 ret = KErrNoComplete; |
|
270 } |
|
271 else |
|
272 { |
|
273 // Packager's buffer large enough so write back CViewContact. |
|
274 TPtr8 ptr = iPackager.PackL(*viewContact); |
|
275 aMessage.WriteL(2,ptr); |
|
276 } |
|
277 |
|
278 CleanupStack::PopAndDestroy(viewContact); |
|
279 CompleteMessage(ret, aMessage); |
|
280 } |
|
281 |
|
282 /* |
|
283 Maps to RCntModel::OpenViewL() method. Use real Persistence Layer this side. |
|
284 Call the Persistence Layer view item manager directly. |
|
285 **/ |
|
286 void CCntViewMsgHandler::OpenViewSessionL(const RMessage2& aMessage) |
|
287 { |
|
288 CheckForManagerL(); |
|
289 |
|
290 // Read CContactTextDef from packager buffer |
|
291 iPackager.SetBufferFromMessageL(aMessage); |
|
292 // Packager reads from message slot 0 |
|
293 CContactTextDef* textDef = iPackager.UnpackCntTextDefLC(); |
|
294 |
|
295 // Get the pl view item manager reference from persistence layer |
|
296 MLplViewIteratorManager& viewManager = iManager->GetPersistenceLayer().FactoryL().GetViewIteratorManagerL(); |
|
297 |
|
298 // Persistence layer call |
|
299 TInt viewSessionId = viewManager.OpenViewL(*textDef, static_cast<TContactViewPreferences>(aMessage.Int1())); |
|
300 CleanupStack::PopAndDestroy(textDef); |
|
301 |
|
302 TPckg<TInt> idPckg(viewSessionId); |
|
303 aMessage.WriteL(2,idPckg); |
|
304 |
|
305 aMessage.Complete(KErrNone); |
|
306 } |
|
307 |
|
308 /* |
|
309 Maps to RCntModel::CloseView() method. Use real Persistence Layer this side. |
|
310 Call the Persistence Layer view item manager directly. |
|
311 **/ |
|
312 void CCntViewMsgHandler::CloseViewSessionL(const RMessage2& aMessage) |
|
313 { |
|
314 CheckForManagerL(); |
|
315 |
|
316 // Get the pl view item manager reference from persistence layer |
|
317 MLplViewIteratorManager& viewManager = iManager->GetPersistenceLayer().FactoryL().GetViewIteratorManagerL(); |
|
318 |
|
319 // Persistence layer call |
|
320 viewManager.CloseView(aMessage.Int0()); |
|
321 aMessage.Complete(KErrNone); |
|
322 } |
|
323 |
|
324 void CCntViewMsgHandler::ChangeSortOrderL(const RMessage2& aMessage) |
|
325 { |
|
326 CheckForManagerL(); |
|
327 |
|
328 // Read CContactTextDef from packager buffer, packager reads from message slot 1 |
|
329 iPackager.SetBufferFromMessageL(aMessage, 1); |
|
330 CContactTextDef* textDef = iPackager.UnpackCntTextDefLC(); |
|
331 |
|
332 // Get the pl view item manager reference from persistence layer |
|
333 MLplViewIteratorManager& viewManager = iManager->GetPersistenceLayer().FactoryL().GetViewIteratorManagerL(); |
|
334 |
|
335 // Persistence layer call |
|
336 viewManager.ChangeSortOrderL(aMessage.Int0(), *textDef); |
|
337 CleanupStack::PopAndDestroy(textDef); |
|
338 |
|
339 aMessage.Complete(KErrNone); |
|
340 } |
|
341 |
|
342 void CCntViewMsgHandler::BeginIterateL(const RMessage2& aMessage) |
|
343 { |
|
344 CheckForManagerL(); |
|
345 |
|
346 // Get the pl view item manager reference from persistence layer |
|
347 MLplViewIteratorManager& viewManager = iManager->GetPersistenceLayer().FactoryL().GetViewIteratorManagerL(); |
|
348 viewManager.BeginIterateL(aMessage.Int0()); |
|
349 aMessage.Complete(KErrNone); |
|
350 } |
|
351 |
|
352 void CCntViewMsgHandler::EndIterateL(const RMessage2& aMessage) |
|
353 { |
|
354 CheckForManagerL(); |
|
355 |
|
356 // Get the pl view item manager reference from persistence layer |
|
357 MLplViewIteratorManager& viewManager = iManager->GetPersistenceLayer().FactoryL().GetViewIteratorManagerL(); |
|
358 viewManager.EndIterateL(aMessage.Int0()); |
|
359 aMessage.Complete(KErrNone); |
|
360 } |
|
361 |
|
362 void CCntViewMsgHandler::NextItemL(const RMessage2& aMessage) |
|
363 { |
|
364 TInt ret(KErrNone); |
|
365 CheckForManagerL(); |
|
366 |
|
367 // Get the pl view item manager reference from persistence layer |
|
368 MLplViewIteratorManager& viewManager = iManager->GetPersistenceLayer().FactoryL().GetViewIteratorManagerL(); |
|
369 |
|
370 // Persistence layer call |
|
371 CViewContact* viewContact = viewManager.NextItemL(aMessage.Int0(), static_cast<TContactViewPreferences>(aMessage.Int1())); |
|
372 |
|
373 // Don't write NULL back across IPC. |
|
374 // Leave KErrNotFound will be picked up by client and propagated as NULL to caller |
|
375 if(viewContact == NULL) |
|
376 { |
|
377 User::Leave(KErrNotFound); |
|
378 } |
|
379 |
|
380 CleanupStack::PushL(viewContact); |
|
381 |
|
382 ValidateViewContactL(*viewContact, iSessionId); |
|
383 |
|
384 // Compare with maximum length of descriptor argument in the client's process. |
|
385 if(viewContact->ExternalizedSize() > aMessage.GetDesMaxLength(2) ) |
|
386 { |
|
387 // Return required size of buffer to the client. |
|
388 aMessage.Complete(viewContact->ExternalizedSize()); |
|
389 ret = KErrNoComplete; |
|
390 } |
|
391 else |
|
392 { |
|
393 // Packager's buffer large enough so write back CViewContact. |
|
394 TPtr8 ptr = iPackager.PackL(*viewContact); |
|
395 aMessage.WriteL(2,ptr); |
|
396 } |
|
397 |
|
398 CleanupStack::PopAndDestroy(viewContact); |
|
399 CompleteMessage(ret, aMessage); |
|
400 } |
|
401 |
|
402 void CCntViewMsgHandler::CreateViewL(const RMessage2& aMessage) |
|
403 { |
|
404 // Subsession create anonymous view from client. Create subsession |
|
405 // objects on demand. |
|
406 TInt ret(KErrNone); |
|
407 CreateViewSubSessionL(aMessage); |
|
408 aMessage.Complete(ret); |
|
409 } |
|
410 |
|
411 void CCntViewMsgHandler::CreateNamedViewL(const RMessage2& aMessage) |
|
412 { |
|
413 // Subsession create named view from client. Create subsession |
|
414 // objects on demand. |
|
415 TInt ret(KErrNone); |
|
416 CreateNamedViewSubSessionL(aMessage); |
|
417 aMessage.Complete(ret); |
|
418 } |
|
419 |
|
420 void CCntViewMsgHandler::CloseViewL(const RMessage2& aMessage) |
|
421 { |
|
422 // Subsession close view from client. |
|
423 |
|
424 TInt ret(KErrNone); |
|
425 CloseViewSubSessionL(aMessage); |
|
426 aMessage.Complete(ret); |
|
427 } |
|
428 |
|
429 void CCntViewMsgHandler::MatchesHintFieldL(const RMessage2& aMessage) |
|
430 { |
|
431 // Maps to RCntModel::ContactMatchesHintFieldL(). |
|
432 |
|
433 TInt ret(KErrNone); |
|
434 CheckForManagerL(); |
|
435 TInt bitWiseFilter = aMessage.Int0(); |
|
436 TContactItemId cntId = aMessage.Int1(); |
|
437 ret = iManager->GetPersistenceLayer().FactoryL().GetCollectorL().ContactMatchesHintFieldL(bitWiseFilter, cntId); |
|
438 CompleteMessage(ret, aMessage); |
|
439 } |
|
440 |
|
441 void CCntViewMsgHandler::ViewSubSessionServiceL(const RMessage2& aMessage) |
|
442 { |
|
443 // Other opcodes processed by view subsession ServiceL() method. |
|
444 |
|
445 TInt ret(KErrNone); |
|
446 ret = ViewFromHandleL(aMessage.Int3()).ServiceL(aMessage); |
|
447 CompleteMessage(ret, aMessage); |
|
448 } |
|
449 |