|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: CS Session class |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <ccsconversationentry.h> |
|
20 #include <ccsclientconversation.h> |
|
21 |
|
22 #include "ccsconversationevent.h" |
|
23 #include "ccsdebug.h" |
|
24 #include "ccsserver.h" |
|
25 #include "ccssession.h" |
|
26 #include "ccsplugininterface.h" |
|
27 #include "ccsconversationcache.h" |
|
28 #include "ccscontactsresolver.h" |
|
29 #include "ccsconversationdeletehandler.h" |
|
30 #include "ccsconversationmarkreadhandler.h" |
|
31 |
|
32 // CONSTANTS |
|
33 const TInt KTinyBuffer = 256; // 256 bytes |
|
34 const TInt KBigBuffer = 2048; // 2K |
|
35 |
|
36 // ============================== MEMBER FUNCTIONS ============================ |
|
37 |
|
38 // ---------------------------------------------------------------------------- |
|
39 // CCsSession::NewL |
|
40 // Two Phase Construction |
|
41 // ---------------------------------------------------------------------------- |
|
42 CCsSession* CCsSession::NewL(CCsServer* aServer) |
|
43 { |
|
44 PRINT ( _L("Enter CCsSession::NewL") ); |
|
45 |
|
46 CCsSession* self = new (ELeave) CCsSession(aServer); |
|
47 CleanupStack::PushL(self); |
|
48 self->ConstructL(); |
|
49 CleanupStack::Pop(self); // self |
|
50 |
|
51 PRINT ( _L("End CCsSession::NewL") ); |
|
52 |
|
53 return self; |
|
54 } |
|
55 |
|
56 // ---------------------------------------------------------------------------- |
|
57 // CCsSession::CCsSession |
|
58 // Construtor |
|
59 // ---------------------------------------------------------------------------- |
|
60 CCsSession::CCsSession(CCsServer* aServer) : |
|
61 iServer(aServer) |
|
62 { |
|
63 } |
|
64 |
|
65 // ---------------------------------------------------------------------------- |
|
66 // CCsSession::ConstructL |
|
67 // Second phase constructor |
|
68 // ---------------------------------------------------------------------------- |
|
69 void CCsSession::ConstructL() |
|
70 { |
|
71 PRINT ( _L("Enter CCsSession::ConstructL") ); |
|
72 |
|
73 iBufferOverflow = EFalse; |
|
74 iGetConversationBufferOverflow = EFalse; |
|
75 des = NULL; |
|
76 |
|
77 iNotifyHandling = EFalse; |
|
78 iConversationListChangeObserver = EFalse; |
|
79 iConversationChangeObserver = EFalse; |
|
80 iCachingChangeObserver = EFalse; |
|
81 iMonitoredConversation = NULL; |
|
82 |
|
83 // initialize the event List |
|
84 iEventList = new (ELeave) RPointerArray<CCsConversationEvent> (); |
|
85 |
|
86 iReqCnt = 1; //Let's start the event ID from 1 |
|
87 |
|
88 PRINT ( _L("End CCsSession::ConstructL") ); |
|
89 } |
|
90 |
|
91 // ---------------------------------------------------------------------------- |
|
92 // CCsSession::CCsSession |
|
93 // Destructor |
|
94 // ---------------------------------------------------------------------------- |
|
95 CCsSession::~CCsSession() |
|
96 { |
|
97 PRINT ( _L("Enter CCsSession::~CCsSession") ); |
|
98 |
|
99 if (des) |
|
100 { |
|
101 delete des; |
|
102 des = NULL; |
|
103 } |
|
104 |
|
105 if (iEventList) |
|
106 { |
|
107 iEventList->ResetAndDestroy(); |
|
108 iEventList->Close(); |
|
109 delete iEventList; |
|
110 iEventList = NULL; |
|
111 } |
|
112 |
|
113 if (iMonitoredConversation) |
|
114 { |
|
115 delete iMonitoredConversation; |
|
116 iMonitoredConversation = NULL; |
|
117 } |
|
118 |
|
119 PRINT ( _L("End CCsSession::~CCsSession") ); |
|
120 } |
|
121 |
|
122 // ---------------------------------------------------------------------------- |
|
123 // CCsSession::ServiceL |
|
124 // |
|
125 // ---------------------------------------------------------------------------- |
|
126 void CCsSession::ServiceL(const RMessage2& aMessage) |
|
127 { |
|
128 TInt errStatus = KErrNone; |
|
129 |
|
130 // Do the service |
|
131 TRAP ( errStatus, DoServiceL(aMessage) ); |
|
132 |
|
133 // Check the error status returned |
|
134 if (errStatus != KErrNone) |
|
135 { |
|
136 aMessage.Complete(errStatus); |
|
137 } |
|
138 } |
|
139 |
|
140 // ---------------------------------------------------------------------------- |
|
141 // CCsSession::DoServiceL |
|
142 // |
|
143 // ---------------------------------------------------------------------------- |
|
144 void CCsSession::DoServiceL(const RMessage2& aMessage) |
|
145 { |
|
146 switch (aMessage.Function()) |
|
147 { |
|
148 case EGetConversationList: |
|
149 PRINT ( _L("Received function EGetConversationList") ) |
|
150 GetConversationListL(aMessage); |
|
151 break; |
|
152 |
|
153 case EGetConversationUnreadList: |
|
154 PRINT ( _L("Received function EGetConversationUnreadList") ) |
|
155 GetConversationUnreadListL(aMessage); |
|
156 break; |
|
157 |
|
158 case EGetConversations: |
|
159 PRINT ( _L("Received function EGetConversations") ) |
|
160 GetConversationsL(aMessage); |
|
161 break; |
|
162 |
|
163 case EGetTotalUnreadCount: |
|
164 PRINT ( _L("Received function EGetTotalUnreadCount") ) |
|
165 GetTotalUnreadCountL(aMessage); |
|
166 break; |
|
167 |
|
168 case ERequestChangeEvent: |
|
169 PRINT ( _L("Received function ERequestChangeEvent") ) |
|
170 RequestChangeEventL(aMessage); |
|
171 break; |
|
172 |
|
173 case ERemoveChangeEvent: |
|
174 PRINT ( _L("Received function ERemoveChangeEvent") ) |
|
175 RemoveChangeEventL(aMessage); |
|
176 break; |
|
177 |
|
178 case ESetConversationListChangeObserver: |
|
179 PRINT ( _L("Received function ESetConversationListChangeObserver") ) |
|
180 SetConversationListChangeObserverL(aMessage); |
|
181 break; |
|
182 |
|
183 case EResetConversationListChangeObserver: |
|
184 PRINT ( _L("Received function EResetConversationListChangeObserver") ) |
|
185 ResetConversationListChangeObserverL(aMessage); |
|
186 break; |
|
187 |
|
188 case ESetConversationChangeObserver: |
|
189 PRINT ( _L("Received function ESetConversationChangeObserver") ) |
|
190 SetConversationChangeObserverL(aMessage); |
|
191 break; |
|
192 |
|
193 case EResetConversationChangeObserver: |
|
194 PRINT ( _L("Received function EResetConversationChangeObserver") ) |
|
195 ResetConversationChangeObserverL(aMessage); |
|
196 break; |
|
197 |
|
198 case ESetCachingStatusObserver: |
|
199 PRINT ( _L("Received function ESetCachingStatusObserver") ) |
|
200 SetCachingStatusObserverL(aMessage); |
|
201 break; |
|
202 |
|
203 case EResetCachingStatusObserver: |
|
204 PRINT ( _L("Received function EResetCachingStatusObserver") ) |
|
205 ResetCachingStatusObserverL(aMessage); |
|
206 break; |
|
207 |
|
208 case EGetCachingStatus: |
|
209 GetCachingStatusL(aMessage); |
|
210 break; |
|
211 |
|
212 case EShutdown: |
|
213 PRINT ( _L("Received function EShutdown") ) |
|
214 ShutdownServerL(aMessage); |
|
215 break; |
|
216 |
|
217 case EUserDeleteConversation: |
|
218 PRINT ( _L("Received function EDeleteConversation") ) |
|
219 DeleteConversationL(aMessage); |
|
220 break; |
|
221 |
|
222 case EGetConversationId: |
|
223 PRINT ( _L("Received function EGetConversationId") ) |
|
224 GetConversationIdL(aMessage); |
|
225 break; |
|
226 |
|
227 case EGetConversationIdFromAddress: |
|
228 PRINT ( _L("Received function EGetConversationId") ) |
|
229 GetConversationIdfromAddressL(aMessage); |
|
230 break; |
|
231 |
|
232 case EUserMarkReadConversation: |
|
233 PRINT ( _L("Received function EUserMarkReadConversation") ) |
|
234 MarkConversationReadL(aMessage); |
|
235 break; |
|
236 } |
|
237 |
|
238 return; |
|
239 } |
|
240 |
|
241 // ---------------------------------------------------------------------------- |
|
242 // CCsSession::ServiceError |
|
243 // |
|
244 // ---------------------------------------------------------------------------- |
|
245 void CCsSession::ServiceError(const RMessage2& aMessage, TInt aError) |
|
246 { |
|
247 aMessage.Complete(aError); |
|
248 } |
|
249 |
|
250 // ---------------------------------------------------------------------------- |
|
251 // CCsSession::GetConversationEntryListL |
|
252 // the function to handle the request of Listing |
|
253 // of recent(latest) conversation entry and |
|
254 // list of dispalyname for all stored conversation entry ID |
|
255 // ---------------------------------------------------------------------------- |
|
256 void CCsSession::GetConversationListL(const RMessage2& aMessage) |
|
257 { |
|
258 PRINT ( _L("Enter CCsSession::GetConversationListL") ); |
|
259 PRINT_TIMESTAMP ("Enter CCsSession::GetConversationListL"); |
|
260 |
|
261 if (iBufferOverflow == EFalse) |
|
262 { |
|
263 RPointerArray<CCsClientConversation>* ClientConversationList = |
|
264 new (ELeave) RPointerArray<CCsClientConversation> (); |
|
265 |
|
266 // get cache pointer |
|
267 CCsConversationCache* cache = iServer->ConversationCacheInterface(); |
|
268 |
|
269 // Call cache function to get recent conversation entry list |
|
270 // with dispaly name for all stored conversation entry ID |
|
271 cache->GetConversationListL(ClientConversationList); |
|
272 CleanupStack::PushL(ClientConversationList); |
|
273 |
|
274 //write all list data into stream |
|
275 // create a new buffer for writing into stream |
|
276 CBufFlat* buf = CBufFlat::NewL(KBigBuffer); |
|
277 CleanupStack::PushL(buf); |
|
278 |
|
279 RBufWriteStream writeStream(*buf); |
|
280 writeStream.PushL(); |
|
281 |
|
282 TInt listCount = ClientConversationList->Count(); |
|
283 |
|
284 if (listCount == 0) |
|
285 { |
|
286 iConversationListChangeObserver = ETrue; |
|
287 } |
|
288 |
|
289 // write the count first |
|
290 writeStream.WriteUint16L(listCount); |
|
291 |
|
292 // now go through the list and do externalize |
|
293 for (int iloop = 0; iloop < listCount; iloop++) |
|
294 { |
|
295 CCsClientConversation |
|
296 * ClientConversation = |
|
297 static_cast<CCsClientConversation*> ( (*ClientConversationList)[iloop]); |
|
298 //write list of ClientConversation |
|
299 ClientConversation->ExternalizeL(writeStream); |
|
300 } |
|
301 |
|
302 // Results are already packed in the stream |
|
303 writeStream.CommitL(); |
|
304 |
|
305 // -------------------------------------------------------------- |
|
306 // Create a heap descriptor from the buffer |
|
307 des = HBufC8::NewLC(buf->Size()); |
|
308 CleanupStack::Pop(des); |
|
309 TPtr8 ptr(des->Des()); |
|
310 buf->Read(0, ptr, buf->Size()); |
|
311 |
|
312 // cleanup |
|
313 CleanupStack::PopAndDestroy(2, buf); // writestream, buf |
|
314 CleanupStack::Pop(ClientConversationList); |
|
315 |
|
316 // destroy objects inside list |
|
317 ClientConversationList->ResetAndDestroy(); |
|
318 ClientConversationList->Close(); |
|
319 delete ClientConversationList; |
|
320 ClientConversationList = NULL; |
|
321 } |
|
322 |
|
323 TInt rcevdBufferSize = aMessage.GetDesMaxLength(1); |
|
324 TInt reqdBufferSize = des->Size(); |
|
325 |
|
326 PRINT1 ( _L("Received buffer size = %d"), rcevdBufferSize ); |
|
327 PRINT1 ( _L("Required buffer size = %d"), reqdBufferSize ); |
|
328 |
|
329 // If the received buffer size from Client API is less than |
|
330 // the required buffer size write the required buffer size |
|
331 // and return. |
|
332 if (rcevdBufferSize < reqdBufferSize) |
|
333 { |
|
334 PRINT ( _L("In-adequate buffer received") ); |
|
335 PRINT ( _L("Packing the required buffer size in response") ); |
|
336 |
|
337 TPckgC<TInt> bufferSizePackage(reqdBufferSize); |
|
338 aMessage.WriteL(1, bufferSizePackage); |
|
339 aMessage.Complete(EGetConversationListBufferOverflow); |
|
340 iBufferOverflow = ETrue; |
|
341 } |
|
342 else |
|
343 { |
|
344 PRINT ( _L("Adequate buffer received") ); |
|
345 PRINT ( _L("Packing the results in response") ) |
|
346 |
|
347 aMessage.Write(1, *des); |
|
348 aMessage.Complete(EGetConversationListOperationComplete); |
|
349 iBufferOverflow = EFalse; |
|
350 delete des; |
|
351 des = NULL; |
|
352 } |
|
353 |
|
354 PRINT_TIMESTAMP ("End CCsSession::GetConversationListL"); |
|
355 PRINT ( _L("End CCsSession::GetConversationListL") ); |
|
356 } |
|
357 |
|
358 // ---------------------------------------------------------------------------- |
|
359 // CCsSession::GetConversationUnreadListL |
|
360 // the function to handle the request of Listing |
|
361 // of recent(latest) unread conversation entry and |
|
362 // list of dispalyname for all stored conversation entry ID |
|
363 // ---------------------------------------------------------------------------- |
|
364 void CCsSession::GetConversationUnreadListL(const RMessage2& aMessage) |
|
365 { |
|
366 PRINT ( _L("Enter CCsSession::GetConversationUnreadListL") ); |
|
367 PRINT_TIMESTAMP ("Enter CCsSession::GetConversationUnreadListL"); |
|
368 |
|
369 if (iBufferOverflow == EFalse) |
|
370 { |
|
371 RPointerArray<CCsClientConversation>* ClientConversationList = |
|
372 new (ELeave) RPointerArray<CCsClientConversation> (); |
|
373 |
|
374 // get cache pointer |
|
375 CCsConversationCache* cache = iServer->ConversationCacheInterface(); |
|
376 |
|
377 // Call cache function to get recent conversation entry list |
|
378 // with dispaly name for all stored conversation entry ID |
|
379 cache->GetConversationUnreadListL(ClientConversationList); |
|
380 |
|
381 CleanupStack::PushL(ClientConversationList); |
|
382 |
|
383 //write all list data into stream |
|
384 // create a new buffer for writing into stream |
|
385 CBufFlat* buf = CBufFlat::NewL(KBigBuffer); |
|
386 CleanupStack::PushL(buf); |
|
387 |
|
388 RBufWriteStream writeStream(*buf); |
|
389 writeStream.PushL(); |
|
390 |
|
391 TInt listCount = ClientConversationList->Count(); |
|
392 |
|
393 if (listCount == 0) |
|
394 { |
|
395 iConversationListChangeObserver = ETrue; |
|
396 } |
|
397 |
|
398 // write the count first |
|
399 writeStream.WriteUint16L(listCount); |
|
400 |
|
401 // now go through the list and do externalize |
|
402 for (int iloop=0 ; iloop < listCount ; iloop++) |
|
403 { |
|
404 CCsClientConversation* ClientConversation = |
|
405 static_cast<CCsClientConversation*>((*ClientConversationList)[iloop]); |
|
406 //write list of ClientConversation |
|
407 ClientConversation->ExternalizeL(writeStream); |
|
408 } |
|
409 |
|
410 // Results are already packed in the stream |
|
411 writeStream.CommitL(); |
|
412 |
|
413 // -------------------------------------------------------------- |
|
414 // Create a heap descriptor from the buffer |
|
415 des = HBufC8::NewLC(buf->Size()); |
|
416 CleanupStack::Pop(des); |
|
417 TPtr8 ptr(des->Des()); |
|
418 buf->Read(0, ptr, buf->Size()); |
|
419 |
|
420 // cleanup |
|
421 CleanupStack::PopAndDestroy(2, buf); // writestream, buf |
|
422 CleanupStack::Pop(ClientConversationList); |
|
423 |
|
424 // destroy objects inside list |
|
425 ClientConversationList->ResetAndDestroy(); |
|
426 ClientConversationList->Close(); |
|
427 delete ClientConversationList; |
|
428 ClientConversationList = NULL; |
|
429 } |
|
430 |
|
431 TInt rcevdBufferSize = aMessage.GetDesMaxLength(1); |
|
432 TInt reqdBufferSize = des->Size(); |
|
433 |
|
434 PRINT1 ( _L("Received buffer size = %d"), rcevdBufferSize ); |
|
435 PRINT1 ( _L("Required buffer size = %d"), reqdBufferSize ); |
|
436 |
|
437 if ( rcevdBufferSize < reqdBufferSize ) |
|
438 { |
|
439 PRINT ( _L("In-adequate buffer received") ); |
|
440 PRINT ( _L("Packing the required buffer size in response") ); |
|
441 |
|
442 TPckgC<TInt> overflowPackage(ETrue); |
|
443 aMessage.WriteL(0, overflowPackage); |
|
444 TPckgC<TInt> bufferSizePackage(reqdBufferSize); |
|
445 aMessage.WriteL(1, bufferSizePackage); |
|
446 aMessage.Complete(KErrNone); |
|
447 iBufferOverflow = ETrue; |
|
448 } |
|
449 else |
|
450 { |
|
451 PRINT ( _L("Adequate buffer received") ); |
|
452 PRINT ( _L("Packing the results in response") ) |
|
453 |
|
454 TPckgC<TInt> overflowPackage(EFalse); |
|
455 aMessage.WriteL(0, overflowPackage); |
|
456 aMessage.Write(1, *des); |
|
457 aMessage.Complete(KErrNone); |
|
458 iBufferOverflow = EFalse; |
|
459 delete des; |
|
460 des = NULL; |
|
461 } |
|
462 |
|
463 PRINT_TIMESTAMP ("End CCsSession::GetConversationUnreadListL"); |
|
464 PRINT ( _L("End CCsSession::GetConversationUnreadListL") ); |
|
465 } |
|
466 |
|
467 // ---------------------------------------------------------------------------- |
|
468 // CCsSession::GetConversationsL |
|
469 // the function to handle the request |
|
470 // of conversation entry list for one conversation entry ID |
|
471 // ---------------------------------------------------------------------------- |
|
472 void CCsSession::GetConversationsL(const RMessage2& aMessage) |
|
473 { |
|
474 PRINT ( _L("Enter CCsSession::GetConversationsL") ); |
|
475 |
|
476 if (iGetConversationBufferOverflow == EFalse) |
|
477 { |
|
478 // Read Contact from the message |
|
479 HBufC8* buffer = HBufC8::NewLC(KBigBuffer); |
|
480 |
|
481 TPtr8 bufferPtr(buffer->Des()); |
|
482 aMessage.ReadL(0, bufferPtr); |
|
483 |
|
484 // Stream over the buffer |
|
485 RDesReadStream stream(bufferPtr); |
|
486 stream.PushL(); |
|
487 |
|
488 // get cache pointer |
|
489 CCsConversationCache* cache = iServer->ConversationCacheInterface(); |
|
490 |
|
491 // read the Client Conversation consist of Entry Id |
|
492 CCsClientConversation* ClientConversation = |
|
493 CCsClientConversation::NewL(); |
|
494 CleanupStack::PushL(ClientConversation); |
|
495 ClientConversation->InternalizeL(stream); |
|
496 CleanupStack::Pop(ClientConversation); |
|
497 CleanupStack::PopAndDestroy(2, buffer);//stream, buffer |
|
498 |
|
499 CleanupStack::PushL(ClientConversation); |
|
500 RPointerArray<CCsConversationEntry>* conversationEntryList = |
|
501 new (ELeave) RPointerArray<CCsConversationEntry> (); |
|
502 CleanupStack::PushL(conversationEntryList); |
|
503 |
|
504 // get conversationlist for given ClientConversation |
|
505 cache->GetConversationsL(ClientConversation, conversationEntryList); |
|
506 |
|
507 // create a new buffer for writing into stream |
|
508 // write all list data into stream |
|
509 CBufFlat* buf = CBufFlat::NewL(KBigBuffer); |
|
510 CleanupStack::PushL(buf); |
|
511 |
|
512 RBufWriteStream writeStream(*buf); |
|
513 writeStream.PushL(); |
|
514 |
|
515 TInt ItemCount = conversationEntryList->Count(); |
|
516 //write recent conversation entry list |
|
517 writeStream.WriteInt32L(ItemCount); |
|
518 |
|
519 // Write the conversation entry |
|
520 for (TInt iloop = 0; iloop < ItemCount; iloop++) |
|
521 { |
|
522 CCsConversationEntry |
|
523 * entry = |
|
524 static_cast<CCsConversationEntry*> ( (*conversationEntryList)[iloop]); |
|
525 entry->ExternalizeL(writeStream); |
|
526 } |
|
527 |
|
528 // Results are already packed in the stream |
|
529 writeStream.CommitL(); |
|
530 |
|
531 // -------------------------------------------------------------- |
|
532 // Create a heap descriptor from the buffer |
|
533 des = HBufC8::NewLC(buf->Size()); |
|
534 CleanupStack::Pop(des); |
|
535 TPtr8 ptr(des->Des()); |
|
536 buf->Read(0, ptr, buf->Size()); |
|
537 |
|
538 CleanupStack::PopAndDestroy(2, buf); // writestream, buf |
|
539 CleanupStack::Pop(conversationEntryList); |
|
540 |
|
541 // Cleanup |
|
542 conversationEntryList->ResetAndDestroy(); |
|
543 conversationEntryList->Close(); |
|
544 delete conversationEntryList; |
|
545 conversationEntryList = NULL; |
|
546 CleanupStack::PopAndDestroy(ClientConversation); |
|
547 } |
|
548 |
|
549 TInt rcevdBufferSize = aMessage.GetDesMaxLength(1); |
|
550 TInt reqdBufferSize = des->Size(); |
|
551 |
|
552 PRINT1 ( _L("Received buffer size = %d"), rcevdBufferSize ); |
|
553 PRINT1 ( _L("Required buffer size = %d"), reqdBufferSize ); |
|
554 |
|
555 // If the received buffer size from Client API is less than |
|
556 // the required buffer size write the required buffer size |
|
557 if (rcevdBufferSize < reqdBufferSize) |
|
558 { |
|
559 PRINT ( _L("In-adequate buffer received") ); |
|
560 PRINT ( _L("Packing the required buffer size in response") ); |
|
561 |
|
562 TPckgC<TInt> bufferSizePackage(reqdBufferSize); |
|
563 aMessage.WriteL(1, bufferSizePackage); |
|
564 aMessage.Complete(EGetConversationBufferOverflow); |
|
565 iGetConversationBufferOverflow = ETrue; |
|
566 } |
|
567 else |
|
568 { |
|
569 PRINT ( _L("Adequate buffer received") ); |
|
570 PRINT ( _L("Packing the results in response") ) |
|
571 |
|
572 aMessage.Write(1, *des); |
|
573 aMessage.Complete(EGetConversationOperationComplete); |
|
574 iGetConversationBufferOverflow = EFalse; |
|
575 delete des; |
|
576 des = NULL; |
|
577 } |
|
578 |
|
579 PRINT ( _L("End CCsSession::GetConversationsL") ); |
|
580 } |
|
581 |
|
582 // ---------------------------------------------------------------------------- |
|
583 // CCsSession::ShutdownServerL |
|
584 // Stops the scheduler |
|
585 // ---------------------------------------------------------------------------- |
|
586 void CCsSession::ShutdownServerL(const RMessage2& aMessage) |
|
587 { |
|
588 aMessage.Complete(KErrNone); |
|
589 CActiveScheduler::Stop(); |
|
590 |
|
591 PRINT ( _L("CCsSession::ShutdownServerL - Server ShutDown") ); |
|
592 } |
|
593 |
|
594 // ---------------------------------------------------------------------------- |
|
595 // CCsSession::HandleNewConversationListEventL |
|
596 // Notify client about new conversation event |
|
597 // ---------------------------------------------------------------------------- |
|
598 void CCsSession::HandleNewConversationListEventL( |
|
599 CCsClientConversation* aClientConversation) |
|
600 { |
|
601 PRINT ( _L("Enter CCsSession::HandleNewConversationListEventL") ); |
|
602 |
|
603 if (!iConversationListChangeObserver) |
|
604 return; |
|
605 |
|
606 if (! (iNotifyHandling)) |
|
607 { |
|
608 //append in notify list |
|
609 CCsConversationEvent* conversationEvent = CCsConversationEvent::NewL(); |
|
610 CleanupStack::PushL(conversationEvent); |
|
611 conversationEvent->SetClientConversationL(*aClientConversation); |
|
612 conversationEvent->SetEvent(KConversationListEventNew); |
|
613 iEventList->AppendL(conversationEvent); |
|
614 CleanupStack::Pop(conversationEvent); |
|
615 } |
|
616 else |
|
617 { |
|
618 // create a new buffer for writing into stream |
|
619 CBufFlat* buf = CBufFlat::NewL(KBigBuffer); |
|
620 CleanupStack::PushL(buf); |
|
621 |
|
622 RBufWriteStream writeStream(*buf); |
|
623 writeStream.PushL(); |
|
624 |
|
625 //externalize ClientConversation |
|
626 aClientConversation->ExternalizeL(writeStream); |
|
627 |
|
628 // Results are already packed in the stream |
|
629 writeStream.CommitL(); |
|
630 |
|
631 // -------------------------------------------------------------- |
|
632 // Create a heap descriptor from the buffer |
|
633 HBufC8* notifyDes = HBufC8::NewLC(buf->Size()); |
|
634 TPtr8 ptr(notifyDes->Des()); |
|
635 buf->Read(0, ptr, buf->Size()); |
|
636 |
|
637 iAsyncReqRMessage.Write(1, *notifyDes); |
|
638 iAsyncReqRMessage.Complete(EAddConversationListEvent); |
|
639 CleanupStack::PopAndDestroy(3, buf); // notifyDes, writestream, buf |
|
640 iNotifyHandling = EFalse; |
|
641 } |
|
642 |
|
643 PRINT ( _L("End CCsSession::HandleNewConversationListEventL") ); |
|
644 } |
|
645 |
|
646 // ---------------------------------------------------------------------------- |
|
647 // CCsSession::HandleDeleteConversationListEventL |
|
648 // Notify client about delete conversation event |
|
649 // ---------------------------------------------------------------------------- |
|
650 void CCsSession::HandleDeleteConversationListEventL( |
|
651 CCsClientConversation* aClientConversation) |
|
652 { |
|
653 PRINT ( _L("Enter CCsSession::HandleDeleteConversationListEventL") ); |
|
654 |
|
655 if (!iConversationListChangeObserver) |
|
656 return; |
|
657 |
|
658 if (! (iNotifyHandling)) |
|
659 { |
|
660 //append in notify list |
|
661 CCsConversationEvent* conversationEvent = CCsConversationEvent::NewL(); |
|
662 conversationEvent->SetClientConversationL(*aClientConversation); |
|
663 CleanupStack::PushL(conversationEvent); |
|
664 conversationEvent->SetEvent(KConversationListEventDelete); |
|
665 iEventList->AppendL(conversationEvent); |
|
666 CleanupStack::Pop(conversationEvent); |
|
667 } |
|
668 else |
|
669 { |
|
670 // create a new buffer for writing into stream |
|
671 CBufFlat* buf = CBufFlat::NewL(KBigBuffer); |
|
672 CleanupStack::PushL(buf); |
|
673 |
|
674 RBufWriteStream writeStream(*buf); |
|
675 writeStream.PushL(); |
|
676 |
|
677 //externalize ClientConversation |
|
678 aClientConversation->ExternalizeL(writeStream); |
|
679 |
|
680 // Results are already packed in the stream |
|
681 writeStream.CommitL(); |
|
682 |
|
683 // -------------------------------------------------------------- |
|
684 // Create a heap descriptor from the buffer |
|
685 HBufC8* notifyDes = HBufC8::NewLC(buf->Size()); |
|
686 TPtr8 ptr(notifyDes->Des()); |
|
687 buf->Read(0, ptr, buf->Size()); |
|
688 |
|
689 iAsyncReqRMessage.Write(1, *notifyDes); |
|
690 iAsyncReqRMessage.Complete(EDeleteConversationListEvent); |
|
691 CleanupStack::PopAndDestroy(3, buf); // notifyDes, writestream, buf |
|
692 iNotifyHandling = EFalse; |
|
693 } |
|
694 |
|
695 PRINT ( _L("End CCsSession::HandleDeleteConversationListEventL") ); |
|
696 } |
|
697 |
|
698 // ---------------------------------------------------------------------------- |
|
699 // CCsSession::HandleModifyConversationListEventL |
|
700 // Notify client about update conversation event |
|
701 // ---------------------------------------------------------------------------- |
|
702 void CCsSession::HandleModifyConversationListEventL( |
|
703 CCsClientConversation* aClientConversation) |
|
704 { |
|
705 PRINT ( _L("Enter CCsSession::HandleModifyConversationListEventL") ); |
|
706 |
|
707 if (!iConversationListChangeObserver) |
|
708 return; |
|
709 |
|
710 if (! (iNotifyHandling)) |
|
711 { |
|
712 //append in notify list |
|
713 CCsConversationEvent* conversationEvent = CCsConversationEvent::NewL(); |
|
714 conversationEvent->SetClientConversationL(*aClientConversation); |
|
715 CleanupStack::PushL(conversationEvent); |
|
716 conversationEvent->SetEvent(KConversationListEventUpdate); |
|
717 iEventList->AppendL(conversationEvent); |
|
718 CleanupStack::Pop(conversationEvent); |
|
719 } |
|
720 else |
|
721 { |
|
722 // create a new buffer for writing into stream |
|
723 CBufFlat* buf = CBufFlat::NewL(KBigBuffer); |
|
724 CleanupStack::PushL(buf); |
|
725 |
|
726 RBufWriteStream writeStream(*buf); |
|
727 writeStream.PushL(); |
|
728 |
|
729 //externalize ClientConversation |
|
730 aClientConversation->ExternalizeL(writeStream); |
|
731 |
|
732 // Results are already packed in the stream |
|
733 writeStream.CommitL(); |
|
734 // -------------------------------------------------------------- |
|
735 |
|
736 // Create a heap descriptor from the buffer |
|
737 HBufC8* notifyDes = HBufC8::NewLC(buf->Size()); |
|
738 TPtr8 ptr(notifyDes->Des()); |
|
739 buf->Read(0, ptr, buf->Size()); |
|
740 |
|
741 iAsyncReqRMessage.Write(1, *notifyDes); |
|
742 iAsyncReqRMessage.Complete(EModifyConversationListEvent); |
|
743 CleanupStack::PopAndDestroy(3, buf); // notifyDes, writestream, buf |
|
744 iNotifyHandling = EFalse; |
|
745 } |
|
746 |
|
747 PRINT ( _L("End CCsSession::HandleModifyConversationListEventL") ); |
|
748 } |
|
749 |
|
750 // ---------------------------------------------------------------------------- |
|
751 // CCsSession::RequestChangeEventL |
|
752 // the function to register for cache change event notification |
|
753 // ---------------------------------------------------------------------------- |
|
754 void CCsSession::RequestChangeEventL(const RMessage2& aMessage) |
|
755 { |
|
756 iAsyncReqRMessage = aMessage; |
|
757 iNotifyHandling = ETrue; |
|
758 |
|
759 if (iEventList->Count() > 0) |
|
760 { |
|
761 CCsConversationEvent* conversationEvent = (*iEventList)[0]; |
|
762 |
|
763 // check if the reqCnt matches with the latest arrived count |
|
764 // then its not a duplicate, delete the top event |
|
765 if (iReqCnt == aMessage.Int2()) |
|
766 { |
|
767 iEventList->Remove(0); |
|
768 delete conversationEvent; |
|
769 |
|
770 if (iEventList->Count() > 0) |
|
771 { |
|
772 // increment the count |
|
773 iReqCnt++; |
|
774 conversationEvent = (*iEventList)[0]; |
|
775 } |
|
776 else |
|
777 { |
|
778 // no more pending events, simply return |
|
779 return; |
|
780 } |
|
781 } |
|
782 |
|
783 HBufC8* buffer = HBufC8::NewLC(4); |
|
784 TPtr8 cntPtr(buffer->Des()); |
|
785 _LIT8(KFormat,"%d"); |
|
786 cntPtr.Format(KFormat, iReqCnt); |
|
787 iAsyncReqRMessage.Write(0, *buffer); |
|
788 |
|
789 // create a new buffer for writing into stream |
|
790 CBufFlat* buf = CBufFlat::NewL(KBigBuffer); |
|
791 CleanupStack::PushL(buf); |
|
792 |
|
793 RBufWriteStream writeStream(*buf); |
|
794 writeStream.PushL(); |
|
795 |
|
796 // Externalize ClientConversation |
|
797 if (conversationEvent->ClientConversation()) |
|
798 conversationEvent->ClientConversation()->ExternalizeL(writeStream); |
|
799 |
|
800 // Results are already packed in the stream |
|
801 writeStream.CommitL(); |
|
802 |
|
803 // -------------------------------------------------------------- |
|
804 // Create a heap descriptor from the buffer |
|
805 HBufC8* notifyDes = HBufC8::NewLC(buf->Size()); |
|
806 TPtr8 ptr(notifyDes->Des()); |
|
807 buf->Read(0, ptr, buf->Size()); |
|
808 |
|
809 iAsyncReqRMessage.Write(1, *notifyDes); |
|
810 |
|
811 NotifyClient(conversationEvent); |
|
812 |
|
813 CleanupStack::PopAndDestroy(4, buffer); |
|
814 // notifyDes, writestream, buf, buffer |
|
815 iNotifyHandling = EFalse; |
|
816 } |
|
817 } |
|
818 |
|
819 // ---------------------------------------------------------------------------- |
|
820 // CCsSession::RemoveChangeEventL |
|
821 // Deregister the cache change event notification |
|
822 // ---------------------------------------------------------------------------- |
|
823 void CCsSession::RemoveChangeEventL(const RMessage2& aMessage) |
|
824 { |
|
825 if (! (iNotifyHandling)) |
|
826 { |
|
827 // complete message with aMessage |
|
828 aMessage.Complete(KErrNone); |
|
829 } |
|
830 else |
|
831 { |
|
832 iAsyncReqRMessage.Complete(KErrCancel); |
|
833 iNotifyHandling = EFalse; |
|
834 // complete message with aMessage |
|
835 aMessage.Complete(KErrNone); |
|
836 } |
|
837 } |
|
838 |
|
839 // ---------------------------------------------------------------------------- |
|
840 // CCsSession::GetCachingStatusL |
|
841 // the function to request conversation server |
|
842 // to get caching status. |
|
843 // ---------------------------------------------------------------------------- |
|
844 void CCsSession::GetCachingStatusL(const RMessage2& aMessage) |
|
845 { |
|
846 PRINT ( _L("Enter CCsSession::GetCachingStatusL") ); |
|
847 |
|
848 // create a new buffer for writing into stream |
|
849 CBufFlat* buf = CBufFlat::NewL(KTinyBuffer); |
|
850 |
|
851 CleanupStack::PushL(buf); |
|
852 RBufWriteStream writeStream(*buf); |
|
853 writeStream.PushL(); |
|
854 |
|
855 // Externalize caching status |
|
856 writeStream.WriteUint8L(iServer->GetCachingStatus()); |
|
857 |
|
858 // Results are already packed in the stream |
|
859 writeStream.CommitL(); |
|
860 // -------------------------------------------------------------- |
|
861 |
|
862 // Create a heap descriptor from the buffer |
|
863 HBufC8* des = HBufC8::NewLC(buf->Size()); |
|
864 CleanupStack::Pop(des); |
|
865 TPtr8 ptr(des->Des()); |
|
866 buf->Read(0, ptr, buf->Size()); |
|
867 |
|
868 CleanupStack::PopAndDestroy(2, buf); // writestream, buf |
|
869 |
|
870 aMessage.Write(1, *des); |
|
871 aMessage.Complete(KErrNone); |
|
872 delete des; |
|
873 |
|
874 PRINT ( _L("End CCsSession::GetCachingStatusL") ); |
|
875 } |
|
876 |
|
877 // ---------------------------------------------------------------------------- |
|
878 // CCsSession::GetTotalUnreadCountL |
|
879 // Gets total unread conversation entries. |
|
880 // ---------------------------------------------------------------------------- |
|
881 void CCsSession::GetTotalUnreadCountL(const RMessage2& aMessage) |
|
882 { |
|
883 PRINT ( _L("Enter CCsSession::GetTotalUnreadCountL") ); |
|
884 |
|
885 // create a new buffer for writing into stream |
|
886 CBufFlat* buf = CBufFlat::NewL(KTinyBuffer); |
|
887 |
|
888 CleanupStack::PushL(buf); |
|
889 RBufWriteStream writeStream(*buf); |
|
890 writeStream.PushL(); |
|
891 |
|
892 CCsConversationCache* cache = iServer->ConversationCacheInterface(); |
|
893 |
|
894 // Externalize caching status |
|
895 writeStream.WriteUint32L(cache->GetTotalUnreadCount()); |
|
896 |
|
897 // Results are already packed in the stream |
|
898 writeStream.CommitL(); |
|
899 // -------------------------------------------------------------- |
|
900 |
|
901 // Create a heap descriptor from the buffer |
|
902 HBufC8* des = HBufC8::NewLC(buf->Size()); |
|
903 CleanupStack::Pop(des); |
|
904 TPtr8 ptr(des->Des()); |
|
905 buf->Read(0, ptr, buf->Size()); |
|
906 |
|
907 CleanupStack::PopAndDestroy(2, buf); // writestream, buf |
|
908 |
|
909 aMessage.Write(1, *des); |
|
910 aMessage.Complete(KErrNone); |
|
911 delete des; |
|
912 |
|
913 PRINT ( _L("End CCsSession::GetTotalUnreadCountL") ); |
|
914 } |
|
915 |
|
916 // ---------------------------------------------------------------------------- |
|
917 // CCsSession::SetConversationListChangeObserverL |
|
918 // the function to request conversation server |
|
919 // to set ConversationListChangeObserver. |
|
920 // ---------------------------------------------------------------------------- |
|
921 void CCsSession::SetConversationListChangeObserverL(const RMessage2& aMessage) |
|
922 { |
|
923 iConversationListChangeObserver = ETrue; |
|
924 aMessage.Complete(KErrNone); |
|
925 } |
|
926 |
|
927 // ---------------------------------------------------------------------------- |
|
928 // CCsSession::ResetConversationListChangeObserverL |
|
929 // the function to request conversation server |
|
930 // to reset ConversationListChangeObserver. |
|
931 // ---------------------------------------------------------------------------- |
|
932 void CCsSession::ResetConversationListChangeObserverL(const RMessage2& aMessage) |
|
933 { |
|
934 iConversationListChangeObserver = EFalse; |
|
935 aMessage.Complete(KErrNone); |
|
936 } |
|
937 |
|
938 // ---------------------------------------------------------------------------- |
|
939 // CCsSession::SetConversationChangeObserverL |
|
940 // the function to request conversation server |
|
941 // to set ConversationChangeObserver. |
|
942 // ---------------------------------------------------------------------------- |
|
943 void CCsSession::SetConversationChangeObserverL(const RMessage2& aMessage) |
|
944 { |
|
945 // Read Contact from the message |
|
946 HBufC8* buffer = HBufC8::NewLC(KBigBuffer); |
|
947 |
|
948 TPtr8 bufferPtr(buffer->Des()); |
|
949 aMessage.ReadL(0, bufferPtr); |
|
950 |
|
951 // Stream over the buffer |
|
952 RDesReadStream stream(bufferPtr); |
|
953 stream.PushL(); |
|
954 |
|
955 // Get the client conversation |
|
956 CCsClientConversation* clientConversation = CCsClientConversation::NewL(); |
|
957 CleanupStack::PushL(clientConversation); |
|
958 clientConversation->InternalizeL(stream); |
|
959 CleanupStack::Pop(clientConversation); |
|
960 |
|
961 CleanupStack::PopAndDestroy(2, buffer);//stream, buffer |
|
962 |
|
963 iMonitoredConversation = clientConversation; |
|
964 iConversationChangeObserver = ETrue; |
|
965 |
|
966 aMessage.Complete(KErrNone); |
|
967 } |
|
968 |
|
969 // ---------------------------------------------------------------------------- |
|
970 // CCsSession::ResetConversationChangeObserverL |
|
971 // the function to request conversation server |
|
972 // to reset ConversationChangeObserver. |
|
973 // ---------------------------------------------------------------------------- |
|
974 void CCsSession::ResetConversationChangeObserverL(const RMessage2& aMessage) |
|
975 { |
|
976 // Read Contact from the message |
|
977 HBufC8* buffer = HBufC8::NewLC(KBigBuffer); |
|
978 |
|
979 TPtr8 bufferPtr(buffer->Des()); |
|
980 aMessage.ReadL(0, bufferPtr); |
|
981 |
|
982 // Stream over the buffer |
|
983 RDesReadStream stream(bufferPtr); |
|
984 stream.PushL(); |
|
985 |
|
986 // Read the client conversation |
|
987 CCsClientConversation* clientConversation = CCsClientConversation::NewL(); |
|
988 CleanupStack::PushL(clientConversation); |
|
989 clientConversation->InternalizeL(stream); |
|
990 CleanupStack::Pop(clientConversation); |
|
991 |
|
992 CleanupStack::PopAndDestroy(2, buffer); //stream, buffer |
|
993 |
|
994 if (iMonitoredConversation) |
|
995 { |
|
996 delete iMonitoredConversation; |
|
997 iMonitoredConversation = NULL; |
|
998 iConversationChangeObserver = EFalse; |
|
999 } |
|
1000 |
|
1001 delete clientConversation; |
|
1002 |
|
1003 aMessage.Complete(KErrNone); |
|
1004 } |
|
1005 |
|
1006 // ---------------------------------------------------------------------------- |
|
1007 // CCsSession::SetCachingStatusObserverL |
|
1008 // the function to request conversation server |
|
1009 // to set caching status observer flag. |
|
1010 // ---------------------------------------------------------------------------- |
|
1011 void CCsSession::SetCachingStatusObserverL(const RMessage2& aMessage) |
|
1012 { |
|
1013 iCachingChangeObserver = ETrue; |
|
1014 aMessage.Complete(KErrNone); |
|
1015 } |
|
1016 |
|
1017 // ---------------------------------------------------------------------------- |
|
1018 // CCsSession::ResetCachingStatusObserverL |
|
1019 // the function to request conversation server |
|
1020 // to reset caching status observer flag. |
|
1021 // ---------------------------------------------------------------------------- |
|
1022 void CCsSession::ResetCachingStatusObserverL(const RMessage2& aMessage) |
|
1023 { |
|
1024 iCachingChangeObserver = EFalse; |
|
1025 aMessage.Complete(KErrNone); |
|
1026 } |
|
1027 |
|
1028 // ---------------------------------------------------------------------------- |
|
1029 // CCsSession::HandleNewConversationEventL |
|
1030 // the function to handles the new conversation event received from cache |
|
1031 // asynchronously |
|
1032 // ---------------------------------------------------------------------------- |
|
1033 void CCsSession::HandleNewConversationEventL( |
|
1034 CCsClientConversation* aClientConversation) |
|
1035 { |
|
1036 PRINT ( _L("Enter CCsSession::HandleNewConversationEventL") ); |
|
1037 |
|
1038 if (!iConversationChangeObserver) |
|
1039 return; |
|
1040 |
|
1041 if (aClientConversation->GetConversationEntryId() |
|
1042 != iMonitoredConversation->GetConversationEntryId()) |
|
1043 return; |
|
1044 |
|
1045 if (! (iNotifyHandling)) |
|
1046 { |
|
1047 //append in notify list |
|
1048 CCsConversationEvent* conversationEvent = CCsConversationEvent::NewL(); |
|
1049 CleanupStack::PushL(conversationEvent); |
|
1050 conversationEvent->SetClientConversationL(*aClientConversation); |
|
1051 conversationEvent->SetEvent(KConversationEventNew); |
|
1052 iEventList->AppendL(conversationEvent); |
|
1053 CleanupStack::Pop(conversationEvent); |
|
1054 } |
|
1055 else |
|
1056 { |
|
1057 // create a new buffer for writing into stream |
|
1058 CBufFlat* buf = CBufFlat::NewL(KBigBuffer); |
|
1059 CleanupStack::PushL(buf); |
|
1060 |
|
1061 RBufWriteStream writeStream(*buf); |
|
1062 writeStream.PushL(); |
|
1063 |
|
1064 //externalize ClientConversation |
|
1065 aClientConversation->ExternalizeL(writeStream); |
|
1066 |
|
1067 // Results are already packed in the stream |
|
1068 writeStream.CommitL(); |
|
1069 // -------------------------------------------------------------- |
|
1070 |
|
1071 // Create a heap descriptor from the buffer |
|
1072 HBufC8* des = HBufC8::NewLC(buf->Size()); |
|
1073 CleanupStack::Pop(des); |
|
1074 TPtr8 ptr(des->Des()); |
|
1075 buf->Read(0, ptr, buf->Size()); |
|
1076 |
|
1077 CleanupStack::PopAndDestroy(2, buf); // writestream, buf |
|
1078 |
|
1079 iAsyncReqRMessage.Write(1, *des); |
|
1080 iAsyncReqRMessage.Complete(EAddConversationEvent); |
|
1081 delete des; |
|
1082 iNotifyHandling = EFalse; |
|
1083 } |
|
1084 |
|
1085 PRINT ( _L("End CCsSession::HandleNewConversationEventL") ); |
|
1086 } |
|
1087 |
|
1088 // ---------------------------------------------------------------------------- |
|
1089 // CCsSession::HandleDeleteConversationEventL |
|
1090 // the function to handles the delete conversation event received from cache |
|
1091 // asynchronously |
|
1092 // ---------------------------------------------------------------------------- |
|
1093 void CCsSession::HandleDeleteConversationEventL( |
|
1094 CCsClientConversation* aClientConversation) |
|
1095 { |
|
1096 PRINT ( _L("Enter CCsSession::HandleDeleteConversationEventL") ); |
|
1097 |
|
1098 if (!iConversationChangeObserver) |
|
1099 return; |
|
1100 |
|
1101 if (aClientConversation->GetConversationEntryId() |
|
1102 != iMonitoredConversation->GetConversationEntryId()) |
|
1103 return; |
|
1104 |
|
1105 if (! (iNotifyHandling)) |
|
1106 { |
|
1107 //append in notify list |
|
1108 CCsConversationEvent* conversationEvent = CCsConversationEvent::NewL(); |
|
1109 CleanupStack::PushL(conversationEvent); |
|
1110 conversationEvent->SetClientConversationL(*aClientConversation); |
|
1111 conversationEvent->SetEvent(KConversationEventDelete); |
|
1112 iEventList->AppendL(conversationEvent); |
|
1113 CleanupStack::Pop(conversationEvent); |
|
1114 } |
|
1115 else |
|
1116 { |
|
1117 // create a new buffer for writing into stream |
|
1118 CBufFlat* buf = CBufFlat::NewL(KBigBuffer); |
|
1119 CleanupStack::PushL(buf); |
|
1120 |
|
1121 RBufWriteStream writeStream(*buf); |
|
1122 writeStream.PushL(); |
|
1123 |
|
1124 //externalize ClientConversation |
|
1125 aClientConversation->ExternalizeL(writeStream); |
|
1126 |
|
1127 // Results are already packed in the stream |
|
1128 writeStream.CommitL(); |
|
1129 // -------------------------------------------------------------- |
|
1130 |
|
1131 // Create a heap descriptor from the buffer |
|
1132 HBufC8* des = HBufC8::NewLC(buf->Size()); |
|
1133 CleanupStack::Pop(des); |
|
1134 TPtr8 ptr(des->Des()); |
|
1135 buf->Read(0, ptr, buf->Size()); |
|
1136 |
|
1137 CleanupStack::PopAndDestroy(2, buf); // writestream, buf |
|
1138 |
|
1139 iAsyncReqRMessage.Write(1, *des); |
|
1140 iAsyncReqRMessage.Complete(EDeleteConversationEvent); |
|
1141 delete des; |
|
1142 iNotifyHandling = EFalse; |
|
1143 } |
|
1144 |
|
1145 PRINT ( _L("End CCsSession::HandleDeleteConversationEventL") ); |
|
1146 } |
|
1147 |
|
1148 // ---------------------------------------------------------------------------- |
|
1149 // CCsSession::HandleModifyConversationEventL |
|
1150 // the function to handles the modify conversation event received from cache |
|
1151 // asynchronously |
|
1152 // ---------------------------------------------------------------------------- |
|
1153 void CCsSession::HandleModifyConversationEventL( |
|
1154 CCsClientConversation* aClientConversation) |
|
1155 { |
|
1156 PRINT ( _L("Enter CCsSession::HandleModifyConversationEventL") ); |
|
1157 |
|
1158 if (!iConversationChangeObserver) |
|
1159 return; |
|
1160 |
|
1161 if (aClientConversation->GetConversationEntryId() |
|
1162 != iMonitoredConversation->GetConversationEntryId()) |
|
1163 return; |
|
1164 |
|
1165 if (! (iNotifyHandling)) |
|
1166 { |
|
1167 //append in notify list |
|
1168 CCsConversationEvent* conversationEvent = CCsConversationEvent::NewL(); |
|
1169 CleanupStack::PushL(conversationEvent); |
|
1170 conversationEvent->SetClientConversationL(*aClientConversation); |
|
1171 conversationEvent->SetEvent(KConversationEventUpdate); |
|
1172 iEventList->AppendL(conversationEvent); |
|
1173 CleanupStack::Pop(conversationEvent); |
|
1174 } |
|
1175 else |
|
1176 { |
|
1177 // create a new buffer for writing into stream |
|
1178 CBufFlat* buf = CBufFlat::NewL(KBigBuffer); |
|
1179 CleanupStack::PushL(buf); |
|
1180 |
|
1181 RBufWriteStream writeStream(*buf); |
|
1182 writeStream.PushL(); |
|
1183 |
|
1184 //externalize ClientConversation |
|
1185 aClientConversation->ExternalizeL(writeStream); |
|
1186 |
|
1187 // Results are already packed in the stream |
|
1188 writeStream.CommitL(); |
|
1189 // -------------------------------------------------------------- |
|
1190 |
|
1191 // Create a heap descriptor from the buffer |
|
1192 HBufC8* des = HBufC8::NewLC(buf->Size()); |
|
1193 CleanupStack::Pop(des); |
|
1194 TPtr8 ptr(des->Des()); |
|
1195 buf->Read(0, ptr, buf->Size()); |
|
1196 |
|
1197 CleanupStack::PopAndDestroy(2, buf); // writestream, buf |
|
1198 |
|
1199 iAsyncReqRMessage.Write(1, *des); |
|
1200 iAsyncReqRMessage.Complete(EModifyConversationEvent); |
|
1201 delete des; |
|
1202 iNotifyHandling = EFalse; |
|
1203 } |
|
1204 |
|
1205 PRINT ( _L("End CCsSession::HandleModifyConversationEventL") ); |
|
1206 } |
|
1207 |
|
1208 // ---------------------------------------------------------------------------- |
|
1209 // CCsSession::NotifyClient |
|
1210 // The function to notify client for cache change event |
|
1211 // ---------------------------------------------------------------------------- |
|
1212 void CCsSession::NotifyClient(CCsConversationEvent* aConversationEvent) |
|
1213 { |
|
1214 if (aConversationEvent->IsNewConversationListEventSet()) |
|
1215 { |
|
1216 iAsyncReqRMessage.Complete(EAddConversationListEvent); |
|
1217 } |
|
1218 else if (aConversationEvent->IsDeleteConversationListEventSet()) |
|
1219 { |
|
1220 iAsyncReqRMessage.Complete(EDeleteConversationListEvent); |
|
1221 } |
|
1222 else if (aConversationEvent->IsUpdateConversationListEventSet()) |
|
1223 { |
|
1224 iAsyncReqRMessage.Complete(EModifyConversationListEvent); |
|
1225 } |
|
1226 else if (aConversationEvent->IsNewConversationEventSet()) |
|
1227 { |
|
1228 iAsyncReqRMessage.Complete(EAddConversationEvent); |
|
1229 } |
|
1230 else if (aConversationEvent->IsDeleteConversationEventSet()) |
|
1231 { |
|
1232 iAsyncReqRMessage.Complete(EDeleteConversationEvent); |
|
1233 } |
|
1234 else if (aConversationEvent->IsUpdateConversationEventSet()) |
|
1235 { |
|
1236 iAsyncReqRMessage.Complete(EModifyConversationEvent); |
|
1237 } |
|
1238 else if (aConversationEvent->IsRefreshConversationListEventSet()) |
|
1239 { |
|
1240 iAsyncReqRMessage.Complete(KConversationEventListRefresh); |
|
1241 } |
|
1242 else if (aConversationEvent->IsRefreshConversationEventSet()) |
|
1243 { |
|
1244 iAsyncReqRMessage.Complete(KConversationEventRefresh); |
|
1245 } |
|
1246 } |
|
1247 |
|
1248 // ---------------------------------------------------------------------------- |
|
1249 // CCsSession::HandleChangeEventL |
|
1250 // The function handles cache change events |
|
1251 // ---------------------------------------------------------------------------- |
|
1252 void CCsSession::HandleChangeEventL(CCsClientConversation* aConversation, |
|
1253 TUint32 aEvent) |
|
1254 { |
|
1255 if (aEvent & KConversationListEventNew) |
|
1256 { |
|
1257 HandleNewConversationListEventL(aConversation); |
|
1258 } |
|
1259 else if (aEvent & KConversationListEventUpdate) |
|
1260 { |
|
1261 HandleModifyConversationListEventL(aConversation); |
|
1262 } |
|
1263 else if (aEvent & KConversationListEventDelete) |
|
1264 { |
|
1265 HandleDeleteConversationListEventL(aConversation); |
|
1266 } |
|
1267 else if (aEvent & KConversationEventNew) |
|
1268 { |
|
1269 HandleNewConversationEventL(aConversation); |
|
1270 } |
|
1271 else if (aEvent & KConversationEventUpdate) |
|
1272 { |
|
1273 HandleModifyConversationEventL(aConversation); |
|
1274 } |
|
1275 else if (aEvent & KConversationEventDelete) |
|
1276 { |
|
1277 HandleDeleteConversationEventL(aConversation); |
|
1278 } |
|
1279 else if (aEvent & KConversationEventListRefresh) |
|
1280 { |
|
1281 HandleRefreshConversationListL(); |
|
1282 } |
|
1283 else if (aEvent & KConversationEventRefresh) |
|
1284 { |
|
1285 HandleRefreshConversationL(); |
|
1286 } |
|
1287 } |
|
1288 |
|
1289 // ---------------------------------------------------------------------------- |
|
1290 // CCsSession::DeleteConversationL |
|
1291 // ---------------------------------------------------------------------------- |
|
1292 void CCsSession::DeleteConversationL(const RMessage2& aMessage) |
|
1293 { |
|
1294 PRINT ( _L("Enter CCsSession::DeleteConversationL") ); |
|
1295 |
|
1296 TInt conversationId = aMessage.Int0(); |
|
1297 |
|
1298 // Delete handler |
|
1299 CCsConversationCache* cache = iServer->ConversationCacheInterface(); |
|
1300 CCsConversationDeleteHandler* deleteHandler = |
|
1301 CCsConversationDeleteHandler::NewL(cache, this); |
|
1302 |
|
1303 deleteHandler->DeleteL(conversationId); |
|
1304 aMessage.Complete(EUserDeleteConversationComplete); |
|
1305 |
|
1306 PRINT ( _L("End CCsSession::DeleteConversationL") ); |
|
1307 } |
|
1308 |
|
1309 // ---------------------------------------------------------------------------- |
|
1310 // CCsSession::DeleteComplete |
|
1311 // ---------------------------------------------------------------------------- |
|
1312 void CCsSession::DeleteComplete(CCsConversationDeleteHandler* aHandler) |
|
1313 { |
|
1314 delete aHandler; |
|
1315 } |
|
1316 |
|
1317 // ---------------------------------------------------------------------------- |
|
1318 // CCsSession::DeleteInProgress |
|
1319 // ---------------------------------------------------------------------------- |
|
1320 void CCsSession::DeleteInProgress(CCsConversationDeleteHandler* aHandler) |
|
1321 { |
|
1322 delete aHandler; |
|
1323 } |
|
1324 |
|
1325 // ---------------------------------------------------------------------------- |
|
1326 // CCsSession::HandleRefreshConversationListL |
|
1327 // ---------------------------------------------------------------------------- |
|
1328 void CCsSession::HandleRefreshConversationListL() |
|
1329 { |
|
1330 if (!iConversationListChangeObserver) |
|
1331 return; |
|
1332 |
|
1333 if (! (iNotifyHandling)) |
|
1334 { |
|
1335 // Append in notify list |
|
1336 CCsConversationEvent* conversationEvent = CCsConversationEvent::NewL(); |
|
1337 CleanupStack::PushL(conversationEvent); |
|
1338 conversationEvent->SetEvent(KConversationEventListRefresh); |
|
1339 iEventList->AppendL(conversationEvent); |
|
1340 CleanupStack::Pop(conversationEvent); |
|
1341 } |
|
1342 else |
|
1343 { |
|
1344 iAsyncReqRMessage.Complete(ERefreshConversationListEvent); |
|
1345 iNotifyHandling = EFalse; |
|
1346 } |
|
1347 } |
|
1348 |
|
1349 // ---------------------------------------------------------------------------- |
|
1350 // CCsSession::HandleRefreshConversationL |
|
1351 // ---------------------------------------------------------------------------- |
|
1352 void CCsSession::HandleRefreshConversationL() |
|
1353 { |
|
1354 if (!iConversationChangeObserver) |
|
1355 return; |
|
1356 |
|
1357 if (! (iNotifyHandling)) |
|
1358 { |
|
1359 // Append in notify list |
|
1360 CCsConversationEvent* conversationEvent = CCsConversationEvent::NewL(); |
|
1361 CleanupStack::PushL(conversationEvent); |
|
1362 conversationEvent->SetEvent(KConversationEventRefresh); |
|
1363 iEventList->AppendL(conversationEvent); |
|
1364 CleanupStack::Pop(conversationEvent); |
|
1365 } |
|
1366 else |
|
1367 { |
|
1368 iAsyncReqRMessage.Complete(ERefreshConversationEvent); |
|
1369 iNotifyHandling = EFalse; |
|
1370 } |
|
1371 } |
|
1372 |
|
1373 // ---------------------------------------------------------------------------- |
|
1374 // Get conversation id |
|
1375 // ---------------------------------------------------------------------------- |
|
1376 void CCsSession::GetConversationIdL(const RMessage2& aMessage) |
|
1377 { |
|
1378 // create a new buffer for writing into stream |
|
1379 CBufFlat* buf = CBufFlat::NewL(KTinyBuffer); |
|
1380 |
|
1381 CleanupStack::PushL(buf); |
|
1382 RBufWriteStream writeStream(*buf); |
|
1383 writeStream.PushL(); |
|
1384 |
|
1385 // Get the contact id |
|
1386 TInt contactId = aMessage.Int0(); |
|
1387 CCsConversationCache* cache = iServer->ConversationCacheInterface(); |
|
1388 TInt conversationId = cache->GetConversationIdL(contactId); |
|
1389 |
|
1390 // Externalize link |
|
1391 writeStream.WriteInt32L(conversationId); |
|
1392 |
|
1393 // Results are already packed in the stream |
|
1394 writeStream.CommitL(); |
|
1395 |
|
1396 // Create a heap descriptor from the buffer |
|
1397 HBufC8* des = HBufC8::NewLC(buf->Size()); |
|
1398 CleanupStack::Pop(des); |
|
1399 TPtr8 ptr(des->Des()); |
|
1400 buf->Read(0, ptr, buf->Size()); |
|
1401 |
|
1402 CleanupStack::PopAndDestroy(2, buf); // writestream, buf |
|
1403 |
|
1404 aMessage.Write(1, *des); |
|
1405 aMessage.Complete(EGetConversationIdComplete); |
|
1406 delete des; |
|
1407 } |
|
1408 // ---------------------------------------------------------------------------- |
|
1409 // CCsSession::GetConversationIdfromAddressL |
|
1410 // ---------------------------------------------------------------------------- |
|
1411 void CCsSession::GetConversationIdfromAddressL(const RMessage2& aMessage) |
|
1412 { |
|
1413 TInt deslen = aMessage.GetDesLength(0); |
|
1414 |
|
1415 // Copy the data into a buffer |
|
1416 RBuf buffer; |
|
1417 buffer.CreateL(deslen); |
|
1418 buffer.CleanupClosePushL(); |
|
1419 aMessage.ReadL(0,buffer,0); |
|
1420 |
|
1421 |
|
1422 // Get the contact id |
|
1423 CCsConversationCache* cache = iServer->ConversationCacheInterface(); |
|
1424 TInt conversationId = cache->GetConversationIdFromAddressL(buffer); |
|
1425 |
|
1426 // create a new buffer for writing into stream |
|
1427 CBufFlat* buf = CBufFlat::NewL(KTinyBuffer); |
|
1428 CleanupStack::PushL(buf); |
|
1429 |
|
1430 RBufWriteStream writeStream(*buf); |
|
1431 writeStream.PushL(); |
|
1432 // Externalize link |
|
1433 writeStream.WriteInt32L(conversationId); |
|
1434 |
|
1435 // Results are already packed in the stream |
|
1436 writeStream.CommitL(); |
|
1437 |
|
1438 // Create a heap descriptor from the buffer |
|
1439 HBufC8* des = HBufC8::NewLC(buf->Size()); |
|
1440 CleanupStack::Pop(des); |
|
1441 TPtr8 ptr(des->Des()); |
|
1442 buf->Read(0, ptr, buf->Size()); |
|
1443 |
|
1444 CleanupStack::PopAndDestroy(2, buf); // writestream, buf |
|
1445 CleanupStack::PopAndDestroy(&buffer); |
|
1446 |
|
1447 aMessage.Write(1, *des); |
|
1448 aMessage.Complete(EGetConversationIdFromAddressComplete); |
|
1449 delete des; |
|
1450 } |
|
1451 |
|
1452 // ---------------------------------------------------------------------------- |
|
1453 // CCsSession::MarkConversationReadL |
|
1454 // ---------------------------------------------------------------------------- |
|
1455 void CCsSession::MarkConversationReadL(const RMessage2& aMessage) |
|
1456 { |
|
1457 PRINT ( _L("Enter CCsSession::MarkConversationReadL") ); |
|
1458 |
|
1459 TInt conversationId = aMessage.Int0(); |
|
1460 |
|
1461 // Mark read handler |
|
1462 CCsConversationCache* cache = iServer->ConversationCacheInterface(); |
|
1463 CCsConversationMarkReadHandler* markHandler = |
|
1464 CCsConversationMarkReadHandler::NewL(cache, this); |
|
1465 |
|
1466 markHandler->MarkReadL(conversationId); |
|
1467 |
|
1468 aMessage.Complete(EUserMarkReadConversationComplete); |
|
1469 |
|
1470 PRINT ( _L("End CCsSession::MarkConversationReadL") ); |
|
1471 } |
|
1472 |
|
1473 // ---------------------------------------------------------------------------- |
|
1474 // CCsSession::MarkReadComplete |
|
1475 // ---------------------------------------------------------------------------- |
|
1476 void CCsSession::MarkReadComplete(CCsConversationMarkReadHandler* aHandler) |
|
1477 { |
|
1478 delete aHandler; |
|
1479 } |
|
1480 |
|
1481 //EOF |