messagingapp/msgappfw/server/src/ccssession.cpp
changeset 37 518b245aa84c
parent 25 84d9eb65b26f
child 48 4f501b74aeb1
equal deleted inserted replaced
25:84d9eb65b26f 37:518b245aa84c
    56 // ----------------------------------------------------------------------------
    56 // ----------------------------------------------------------------------------
    57 // CCsSession::CCsSession
    57 // CCsSession::CCsSession
    58 // Construtor
    58 // Construtor
    59 // ----------------------------------------------------------------------------
    59 // ----------------------------------------------------------------------------
    60 CCsSession::CCsSession(CCsServer* aServer) :
    60 CCsSession::CCsSession(CCsServer* aServer) :
    61     iServer(aServer)
    61     iServer(aServer),
       
    62 	    iDes(NULL),
       
    63 	    iMonitoredConversation(NULL),
       
    64 	    iBufferOverflow(EFalse),
       
    65 	    iGetConversationBufferOverflow( EFalse),
       
    66 	    iNotifyHandling(EFalse),
       
    67 	    iConversationListChangeObserver(EFalse),
       
    68 	    iConversationChangeObserver(EFalse),
       
    69 	    iCachingChangeObserver(EFalse),
       
    70 	    iReqCnt(1) //Let's start the event ID from 1    
    62 {
    71 {
    63 }
    72 }
    64 
    73 
    65 // ----------------------------------------------------------------------------
    74 // ----------------------------------------------------------------------------
    66 // CCsSession::ConstructL
    75 // CCsSession::ConstructL
    68 // ----------------------------------------------------------------------------
    77 // ----------------------------------------------------------------------------
    69 void CCsSession::ConstructL()
    78 void CCsSession::ConstructL()
    70 {
    79 {
    71     PRINT ( _L("Enter CCsSession::ConstructL") );
    80     PRINT ( _L("Enter CCsSession::ConstructL") );
    72 
    81 
    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 
    82 
    83     // initialize the event List
    83     // initialize the event List
    84     iEventList = new (ELeave) RPointerArray<CCsConversationEvent> ();
    84     iEventList = new (ELeave) RPointerArray<CCsConversationEvent> ();
    85 
    85 
    86     iReqCnt = 1; //Let's start the event ID from 1
       
    87 
       
    88     PRINT ( _L("End CCsSession::ConstructL") );
    86     PRINT ( _L("End CCsSession::ConstructL") );
    89 }
    87 }
    90 
    88 
    91 // ----------------------------------------------------------------------------
    89 // ----------------------------------------------------------------------------
    92 // CCsSession::CCsSession
    90 // CCsSession::CCsSession
    94 // ----------------------------------------------------------------------------
    92 // ----------------------------------------------------------------------------
    95 CCsSession::~CCsSession()
    93 CCsSession::~CCsSession()
    96 {
    94 {
    97     PRINT ( _L("Enter CCsSession::~CCsSession") );
    95     PRINT ( _L("Enter CCsSession::~CCsSession") );
    98 
    96 
    99     if (des)
    97     if ( iDes )
   100     {
    98         {
   101         delete des;
    99         delete iDes;
   102         des = NULL;
   100         iDes = NULL;
   103     }
   101         }
   104 
   102 		
   105     if (iEventList)
   103     if ( iEventList )
   106     {
   104         {
   107         iEventList->ResetAndDestroy();
   105         iEventList->ResetAndDestroy();
   108         iEventList->Close();
   106         iEventList->Close();
   109         delete iEventList;
   107         delete iEventList;
   110         iEventList = NULL;
   108         iEventList = NULL;
   111     }
   109     }
   131     TRAP ( errStatus, DoServiceL(aMessage) );
   129     TRAP ( errStatus, DoServiceL(aMessage) );
   132 
   130 
   133     // Check the error status returned
   131     // Check the error status returned
   134     if (errStatus != KErrNone)
   132     if (errStatus != KErrNone)
   135     {
   133     {
       
   134         // Free memory.
       
   135         if(iDes)
       
   136             {
       
   137             delete iDes;
       
   138             iDes=NULL;
       
   139             }
   136         aMessage.Complete(errStatus);
   140         aMessage.Complete(errStatus);
   137     }
   141     }
   138 }
   142 }
   139 
   143 
   140 // ----------------------------------------------------------------------------
   144 // ----------------------------------------------------------------------------
   226             
   230             
   227         case EGetConversationIdFromAddress:
   231         case EGetConversationIdFromAddress:
   228             PRINT ( _L("Received function EGetConversationIdFromAddress") )
   232             PRINT ( _L("Received function EGetConversationIdFromAddress") )
   229             GetConversationIdfromAddressL(aMessage);
   233             GetConversationIdfromAddressL(aMessage);
   230             break;
   234             break;
       
   235 
       
   236         case EGetConversationFromConversationId:
       
   237             PRINT ( _L("Received function EGetConversationFromConversationId") )
       
   238             GetConversationFromConversationIdL(aMessage);
       
   239             break;
   231 			
   240 			
   232 		case EGetConversationFromMessageId:
   241 		case EGetConversationFromMessageId:
   233             PRINT ( _L("Received function EGetConversationFromMessageId") )
   242             PRINT ( _L("Received function EGetConversationFromMessageId") )
   234             GetConversationFromMessageIdL(aMessage);
   243             GetConversationFromMessageIdL(aMessage);
   235             break;
   244             break;
   247 // CCsSession::ServiceError
   256 // CCsSession::ServiceError
   248 //
   257 //
   249 // ----------------------------------------------------------------------------
   258 // ----------------------------------------------------------------------------
   250 void CCsSession::ServiceError(const RMessage2& aMessage, TInt aError)
   259 void CCsSession::ServiceError(const RMessage2& aMessage, TInt aError)
   251 {
   260 {
       
   261     if(iDes)
       
   262         {
       
   263         delete iDes;
       
   264         iDes=NULL;
       
   265         }
   252     aMessage.Complete(aError);
   266     aMessage.Complete(aError);
   253 }
   267 }
   254 
   268 
   255 // ----------------------------------------------------------------------------
   269 // ----------------------------------------------------------------------------
   256 // CCsSession::GetConversationEntryListL
   270 // CCsSession::GetConversationEntryListL
   265 
   279 
   266     if (iBufferOverflow == EFalse)
   280     if (iBufferOverflow == EFalse)
   267     {
   281     {
   268         RPointerArray<CCsClientConversation>* ClientConversationList =
   282         RPointerArray<CCsClientConversation>* ClientConversationList =
   269                 new (ELeave) RPointerArray<CCsClientConversation> ();
   283                 new (ELeave) RPointerArray<CCsClientConversation> ();
   270 
   284         CleanupResetAndDestroyPushL(ClientConversationList);
   271         // get cache pointer
   285         // get cache pointer
   272         CCsConversationCache* cache = iServer->ConversationCacheInterface();
   286         CCsConversationCache* cache = iServer->ConversationCacheInterface();
   273 
   287 
   274         // Call cache function to get recent conversation entry list
   288         // Call cache function to get recent conversation entry list
   275         // with dispaly name for all stored conversation entry ID
   289         // with dispaly name for all stored conversation entry ID
   276         cache->GetConversationListL(ClientConversationList);
   290         cache->GetConversationListL(ClientConversationList);
   277         CleanupStack::PushL(ClientConversationList);
       
   278 
   291 
   279         //write all list data into stream
   292         //write all list data into stream
   280         // create a new buffer for writing into stream
   293         // create a new buffer for writing into stream
   281         CBufFlat* buf = CBufFlat::NewL(KBigBuffer);
   294         CBufFlat* buf = CBufFlat::NewL(KBigBuffer);
   282         CleanupStack::PushL(buf);
   295         CleanupStack::PushL(buf);
   307         // Results are already packed in the stream
   320         // Results are already packed in the stream
   308         writeStream.CommitL();
   321         writeStream.CommitL();
   309 
   322 
   310         // --------------------------------------------------------------
   323         // --------------------------------------------------------------
   311         // Create a heap descriptor from the buffer
   324         // Create a heap descriptor from the buffer
   312         des = HBufC8::NewLC(buf->Size());
   325         iDes = HBufC8::NewL(buf->Size());
   313         CleanupStack::Pop(des);
   326         TPtr8 ptr(iDes->Des());
   314         TPtr8 ptr(des->Des());
       
   315         buf->Read(0, ptr, buf->Size());
   327         buf->Read(0, ptr, buf->Size());
   316 
   328 
   317         // cleanup
   329         // Cleanup
   318         CleanupStack::PopAndDestroy(2, buf); // writestream, buf
   330         CleanupStack::PopAndDestroy(2, buf); // writestream, buf
   319         CleanupStack::Pop(ClientConversationList);
   331         
   320 
   332         // Cleanup ClientConversationList
   321         // destroy objects inside list
   333         CleanupStack::PopAndDestroy(ClientConversationList);
   322         ClientConversationList->ResetAndDestroy();
   334         }
   323         ClientConversationList->Close();
       
   324         delete ClientConversationList;
       
   325         ClientConversationList = NULL;
       
   326     }
       
   327 
   335 
   328     TInt rcevdBufferSize = aMessage.GetDesMaxLength(1);
   336     TInt rcevdBufferSize = aMessage.GetDesMaxLength(1);
   329     TInt reqdBufferSize = des->Size();
   337     TInt reqdBufferSize  = iDes->Size();
   330 
   338 
   331     PRINT1 ( _L("Received buffer size = %d"), rcevdBufferSize );
   339     PRINT1 ( _L("Received buffer size = %d"), rcevdBufferSize );
   332     PRINT1 ( _L("Required buffer size = %d"), reqdBufferSize );
   340     PRINT1 ( _L("Required buffer size = %d"), reqdBufferSize );
   333 
   341 
   334     // If the received buffer size from Client API is less than
   342     // If the received buffer size from Client API is less than
   347     else
   355     else
   348     {
   356     {
   349         PRINT ( _L("Adequate buffer received") );
   357         PRINT ( _L("Adequate buffer received") );
   350         PRINT ( _L("Packing the results in response") )
   358         PRINT ( _L("Packing the results in response") )
   351 
   359 
   352         aMessage.Write(1, *des);
   360         aMessage.Write(1, *iDes);
   353         aMessage.Complete(EGetConversationListOperationComplete);
   361         aMessage.Complete(EGetConversationListOperationComplete);
   354         iBufferOverflow = EFalse;
   362         iBufferOverflow = EFalse;
   355         delete des;
   363         delete iDes;
   356         des = NULL;
   364         iDes = NULL;
   357     }
   365         }
   358 
   366     
   359     PRINT_TIMESTAMP ("End CCsSession::GetConversationListL");
   367     PRINT_TIMESTAMP ("End CCsSession::GetConversationListL");
   360     PRINT ( _L("End CCsSession::GetConversationListL") );
   368     PRINT ( _L("End CCsSession::GetConversationListL") );
   361 }
   369 }
   362 
   370 
   363 // ----------------------------------------------------------------------------
   371 // ----------------------------------------------------------------------------
   373 
   381 
   374     if (iBufferOverflow == EFalse)
   382     if (iBufferOverflow == EFalse)
   375         {
   383         {
   376         RPointerArray<CCsClientConversation>* ClientConversationList =
   384         RPointerArray<CCsClientConversation>* ClientConversationList =
   377                 new (ELeave) RPointerArray<CCsClientConversation> ();
   385                 new (ELeave) RPointerArray<CCsClientConversation> ();
   378 
   386         CleanupResetAndDestroyPushL(ClientConversationList);
   379         // get cache pointer
   387         // get cache pointer
   380         CCsConversationCache* cache = iServer->ConversationCacheInterface();
   388         CCsConversationCache* cache = iServer->ConversationCacheInterface();
   381 
   389 
   382         // Call cache function to get recent conversation entry list
   390         // Call cache function to get recent conversation entry list
   383         // with dispaly name for all stored conversation entry ID
   391         // with dispaly name for all stored conversation entry ID
   384         cache->GetConversationUnreadListL(ClientConversationList);
   392         cache->GetConversationUnreadListL(ClientConversationList);
   385 
       
   386         CleanupStack::PushL(ClientConversationList);
       
   387 
   393 
   388         //write all list data into stream
   394         //write all list data into stream
   389         // create a new buffer for writing into stream
   395         // create a new buffer for writing into stream
   390         CBufFlat* buf = CBufFlat::NewL(KBigBuffer);
   396         CBufFlat* buf = CBufFlat::NewL(KBigBuffer);
   391         CleanupStack::PushL(buf);
   397         CleanupStack::PushL(buf);
   415         // Results are already packed in the stream
   421         // Results are already packed in the stream
   416         writeStream.CommitL();
   422         writeStream.CommitL();
   417 
   423 
   418         // --------------------------------------------------------------
   424         // --------------------------------------------------------------
   419         // Create a heap descriptor from the buffer
   425         // Create a heap descriptor from the buffer
   420         des = HBufC8::NewLC(buf->Size());
   426         iDes = HBufC8::NewL(buf->Size());
   421         CleanupStack::Pop(des);
   427         TPtr8 ptr(iDes->Des());
   422         TPtr8 ptr(des->Des());
       
   423         buf->Read(0, ptr, buf->Size());
   428         buf->Read(0, ptr, buf->Size());
   424 
   429 
   425         // cleanup
   430         // cleanup
   426         CleanupStack::PopAndDestroy(2, buf); // writestream, buf
   431         CleanupStack::PopAndDestroy(2, buf); // writestream, buf
   427         CleanupStack::Pop(ClientConversationList);
   432         CleanupStack::PopAndDestroy(ClientConversationList);
   428 
   433 
   429         // destroy objects inside list
       
   430         ClientConversationList->ResetAndDestroy();
       
   431         ClientConversationList->Close();
       
   432         delete ClientConversationList;
       
   433         ClientConversationList = NULL;
       
   434         }
   434         }
   435 
   435 
   436     TInt rcevdBufferSize = aMessage.GetDesMaxLength(1);
   436     TInt rcevdBufferSize = aMessage.GetDesMaxLength(1);
   437     TInt reqdBufferSize  = des->Size();
   437     TInt reqdBufferSize  = iDes->Size();
   438 
   438 
   439     PRINT1 ( _L("Received buffer size = %d"), rcevdBufferSize );
   439     PRINT1 ( _L("Received buffer size = %d"), rcevdBufferSize );
   440     PRINT1 ( _L("Required buffer size = %d"), reqdBufferSize );
   440     PRINT1 ( _L("Required buffer size = %d"), reqdBufferSize );
   441 
   441 
   442     if ( rcevdBufferSize < reqdBufferSize )
   442     if ( rcevdBufferSize < reqdBufferSize )
   456         PRINT ( _L("Adequate buffer received") );
   456         PRINT ( _L("Adequate buffer received") );
   457         PRINT ( _L("Packing the results in response") )
   457         PRINT ( _L("Packing the results in response") )
   458 
   458 
   459         TPckgC<TInt> overflowPackage(EFalse);
   459         TPckgC<TInt> overflowPackage(EFalse);
   460         aMessage.WriteL(0, overflowPackage);
   460         aMessage.WriteL(0, overflowPackage);
   461         aMessage.Write(1, *des);
   461         aMessage.Write(1, *iDes);
   462         aMessage.Complete(KErrNone);
   462         aMessage.Complete(KErrNone);
   463         iBufferOverflow = EFalse;
   463         iBufferOverflow = EFalse;
   464         delete des;
   464         delete iDes;
   465         des = NULL;
   465         iDes = NULL;
   466         }
   466         }
   467 
   467 
   468     PRINT_TIMESTAMP ("End CCsSession::GetConversationUnreadListL");
   468     PRINT_TIMESTAMP ("End CCsSession::GetConversationUnreadListL");
   469     PRINT ( _L("End CCsSession::GetConversationUnreadListL") );
   469     PRINT ( _L("End CCsSession::GetConversationUnreadListL") );
   470     }
   470     }
   500         ClientConversation->InternalizeL(stream);
   500         ClientConversation->InternalizeL(stream);
   501         CleanupStack::Pop(ClientConversation);
   501         CleanupStack::Pop(ClientConversation);
   502         CleanupStack::PopAndDestroy(2, buffer);//stream, buffer
   502         CleanupStack::PopAndDestroy(2, buffer);//stream, buffer
   503 
   503 
   504         CleanupStack::PushL(ClientConversation);
   504         CleanupStack::PushL(ClientConversation);
   505         RPointerArray<CCsConversationEntry>* conversationEntryList =
   505         RPointerArray<CCsConversationEntry>* conversationEntryList=
   506                 new (ELeave) RPointerArray<CCsConversationEntry> ();
   506                 new (ELeave) RPointerArray<CCsConversationEntry>(10);
   507         CleanupStack::PushL(conversationEntryList);
   507         CleanupResetAndDestroyPushL(conversationEntryList);
   508 
   508 
   509         // get conversationlist for given ClientConversation 
   509         // get conversationlist for given ClientConversation 
   510         cache->GetConversationsL(ClientConversation, conversationEntryList);
   510         cache->GetConversationsL(ClientConversation, conversationEntryList);
   511 
   511 
   512         // create a new buffer for writing into stream
   512         // create a new buffer for writing into stream
   533         // Results are already packed in the stream
   533         // Results are already packed in the stream
   534         writeStream.CommitL();
   534         writeStream.CommitL();
   535 
   535 
   536         // --------------------------------------------------------------
   536         // --------------------------------------------------------------
   537         // Create a heap descriptor from the buffer
   537         // Create a heap descriptor from the buffer
   538         des = HBufC8::NewLC(buf->Size());
   538         iDes = HBufC8::NewL(buf->Size());
   539         CleanupStack::Pop(des);
   539         TPtr8 ptr(iDes->Des());
   540         TPtr8 ptr(des->Des());
       
   541         buf->Read(0, ptr, buf->Size());
   540         buf->Read(0, ptr, buf->Size());
   542 
   541 
   543         CleanupStack::PopAndDestroy(2, buf); // writestream, buf
   542         CleanupStack::PopAndDestroy(2, buf); // writestream, buf
   544         CleanupStack::Pop(conversationEntryList);
   543      
   545 
       
   546         // Cleanup
   544         // Cleanup
   547         conversationEntryList->ResetAndDestroy();
   545         CleanupStack::PopAndDestroy(conversationEntryList);
   548         conversationEntryList->Close();
       
   549         delete conversationEntryList;
       
   550         conversationEntryList = NULL;
       
   551         CleanupStack::PopAndDestroy(ClientConversation);
   546         CleanupStack::PopAndDestroy(ClientConversation);
   552     }
   547     }
   553 
   548 
   554     TInt rcevdBufferSize = aMessage.GetDesMaxLength(1);
   549     TInt rcevdBufferSize = aMessage.GetDesMaxLength(1);
   555     TInt reqdBufferSize = des->Size();
   550     TInt reqdBufferSize  = iDes->Size();
   556 
   551 
   557     PRINT1 ( _L("Received buffer size = %d"), rcevdBufferSize );
   552     PRINT1 ( _L("Received buffer size = %d"), rcevdBufferSize );
   558     PRINT1 ( _L("Required buffer size = %d"), reqdBufferSize );
   553     PRINT1 ( _L("Required buffer size = %d"), reqdBufferSize );
   559 
   554 
   560     // If the received buffer size from Client API is less than
   555     // If the received buffer size from Client API is less than
   572     else
   567     else
   573     {
   568     {
   574         PRINT ( _L("Adequate buffer received") );
   569         PRINT ( _L("Adequate buffer received") );
   575         PRINT ( _L("Packing the results in response") )
   570         PRINT ( _L("Packing the results in response") )
   576 
   571 
   577         aMessage.Write(1, *des);
   572         aMessage.Write(1, *iDes);
   578         aMessage.Complete(EGetConversationOperationComplete);
   573         aMessage.Complete(EGetConversationOperationComplete);
   579         iGetConversationBufferOverflow = EFalse;
   574         iGetConversationBufferOverflow = EFalse;
   580         delete des;
   575         delete iDes;
   581         des = NULL;
   576         iDes = NULL;
   582     }
   577         }
   583 
   578 
   584     PRINT ( _L("End CCsSession::GetConversationsL") );
   579     PRINT ( _L("End CCsSession::GetConversationsL") );
   585 }
   580 }
   586 
   581 
   587 // ----------------------------------------------------------------------------
   582 // ----------------------------------------------------------------------------
   696         CleanupStack::PopAndDestroy(3, buf); // notifyDes, writestream, buf
   691         CleanupStack::PopAndDestroy(3, buf); // notifyDes, writestream, buf
   697         iNotifyHandling = EFalse;
   692         iNotifyHandling = EFalse;
   698     }
   693     }
   699 
   694 
   700     PRINT ( _L("End CCsSession::HandleDeleteConversationListEventL") );
   695     PRINT ( _L("End CCsSession::HandleDeleteConversationListEventL") );
       
   696 }
       
   697 
       
   698 // ----------------------------------------------------------------------------
       
   699 // CCsSession::HandlePartialDeleteConversationListEventL
       
   700 // Notify client about partial delete conversation event
       
   701 // ----------------------------------------------------------------------------
       
   702 
       
   703 void CCsSession::HandlePartialDeleteConversationListEvent(
       
   704                                                     CCsClientConversation* aClientConversation)
       
   705 {
       
   706     PRINT ( _L("Enter CCsSession::HandlePartialDeleteConversationListEvent") );
       
   707 
       
   708     if (!iConversationListChangeObserver)
       
   709         return;
       
   710     
       
   711     if (! (iNotifyHandling))
       
   712     {
       
   713         //append in notify list
       
   714         CCsConversationEvent* conversationEvent = CCsConversationEvent::NewL();
       
   715         conversationEvent->SetClientConversationL(*aClientConversation);
       
   716         CleanupStack::PushL(conversationEvent);
       
   717         conversationEvent->SetEvent(KConversationListEventPartialDelete);
       
   718         iEventList->AppendL(conversationEvent);
       
   719         CleanupStack::Pop(conversationEvent);
       
   720     }
       
   721     else
       
   722     {
       
   723         // create a new buffer for writing into stream
       
   724         CBufFlat* buf = CBufFlat::NewL(KBigBuffer);
       
   725         CleanupStack::PushL(buf);
       
   726 
       
   727         RBufWriteStream writeStream(*buf);
       
   728         writeStream.PushL();
       
   729 
       
   730         //externalize ClientConversation
       
   731         aClientConversation->ExternalizeL(writeStream);
       
   732 
       
   733         // Results are already packed in the stream
       
   734         writeStream.CommitL();
       
   735 
       
   736         // --------------------------------------------------------------
       
   737         // Create a heap descriptor from the buffer
       
   738         HBufC8* notifyDes = HBufC8::NewLC(buf->Size());
       
   739         TPtr8 ptr(notifyDes->Des());
       
   740         buf->Read(0, ptr, buf->Size());
       
   741 
       
   742         iAsyncReqRMessage.Write(1, *notifyDes);
       
   743         iAsyncReqRMessage.Complete(EPartialDeleteConversationListEvent);
       
   744         CleanupStack::PopAndDestroy(3, buf); // notifyDes, writestream, buf
       
   745         iNotifyHandling = EFalse;
       
   746     }
   701 }
   747 }
   702 
   748 
   703 // ----------------------------------------------------------------------------
   749 // ----------------------------------------------------------------------------
   704 // CCsSession::HandleModifyConversationListEventL
   750 // CCsSession::HandleModifyConversationListEventL
   705 // Notify client about update conversation event
   751 // Notify client about update conversation event
   863     // Results are already packed in the stream
   909     // Results are already packed in the stream
   864     writeStream.CommitL();
   910     writeStream.CommitL();
   865     // --------------------------------------------------------------
   911     // --------------------------------------------------------------
   866 
   912 
   867     // Create a heap descriptor from the buffer
   913     // Create a heap descriptor from the buffer
   868     HBufC8* des = HBufC8::NewLC(buf->Size());
   914     HBufC8* des = HBufC8::NewL(buf->Size());
   869     CleanupStack::Pop(des);
       
   870     TPtr8 ptr(des->Des());
   915     TPtr8 ptr(des->Des());
   871     buf->Read(0, ptr, buf->Size());
   916     buf->Read(0, ptr, buf->Size());
   872 
   917 
   873     CleanupStack::PopAndDestroy(2, buf); // writestream, buf
   918     CleanupStack::PopAndDestroy(2, buf); // writestream, buf
   874 
   919 
   902     // Results are already packed in the stream
   947     // Results are already packed in the stream
   903     writeStream.CommitL();
   948     writeStream.CommitL();
   904     // --------------------------------------------------------------
   949     // --------------------------------------------------------------
   905 
   950 
   906     // Create a heap descriptor from the buffer
   951     // Create a heap descriptor from the buffer
   907     HBufC8* des = HBufC8::NewLC(buf->Size());
   952     HBufC8* des = HBufC8::NewL(buf->Size());
   908     CleanupStack::Pop(des);
       
   909     TPtr8 ptr(des->Des());
   953     TPtr8 ptr(des->Des());
   910     buf->Read(0, ptr, buf->Size());
   954     buf->Read(0, ptr, buf->Size());
   911 
   955 
   912     CleanupStack::PopAndDestroy(2, buf); // writestream, buf
   956     CleanupStack::PopAndDestroy(2, buf); // writestream, buf
   913 
   957 
  1041     PRINT ( _L("Enter CCsSession::HandleNewConversationEventL") );
  1085     PRINT ( _L("Enter CCsSession::HandleNewConversationEventL") );
  1042 
  1086 
  1043     if (!iConversationChangeObserver)
  1087     if (!iConversationChangeObserver)
  1044         return;
  1088         return;
  1045 
  1089 
  1046     if (aClientConversation->GetConversationEntryId()
  1090     //this is check to send notif to clients for a new message
  1047             != iMonitoredConversation->GetConversationEntryId())
  1091     //1. if the client is subscribed with contact id ==> then send
  1048         return;
  1092     //2. if the client is subscribed with conv id ---> then send
  1049 
  1093     // else dont send
  1050     if (! (iNotifyHandling))
  1094     
  1051     {
  1095     if ((aClientConversation->GetContactId() == 
  1052         //append in notify list
  1096             iMonitoredConversation->GetContactId() && 
  1053         CCsConversationEvent* conversationEvent = CCsConversationEvent::NewL();
  1097             aClientConversation->GetContactId() != -1)
  1054         CleanupStack::PushL(conversationEvent);
  1098             ||(aClientConversation->GetConversationEntryId() == 
  1055         conversationEvent->SetClientConversationL(*aClientConversation);
  1099                     iMonitoredConversation->GetConversationEntryId()))
  1056         conversationEvent->SetEvent(KConversationEventNew);
  1100     {
  1057         iEventList->AppendL(conversationEvent);
  1101 
  1058         CleanupStack::Pop(conversationEvent);
  1102         if (! (iNotifyHandling))
  1059     }
  1103         {
  1060     else
  1104             //append in notify list
  1061     {
  1105             CCsConversationEvent* conversationEvent = CCsConversationEvent::NewL();
  1062         // create a new buffer for writing into stream
  1106             CleanupStack::PushL(conversationEvent);
  1063         CBufFlat* buf = CBufFlat::NewL(KBigBuffer);
  1107             conversationEvent->SetClientConversationL(*aClientConversation);
  1064         CleanupStack::PushL(buf);
  1108             conversationEvent->SetEvent(KConversationEventNew);
  1065 
  1109             iEventList->AppendL(conversationEvent);
  1066         RBufWriteStream writeStream(*buf);
  1110             CleanupStack::Pop(conversationEvent);
  1067         writeStream.PushL();
  1111         }
  1068 
  1112         else
  1069         //externalize ClientConversation
  1113         {
  1070         aClientConversation->ExternalizeL(writeStream);
  1114             // create a new buffer for writing into stream
  1071 
  1115             CBufFlat* buf = CBufFlat::NewL(KBigBuffer);
  1072         // Results are already packed in the stream
  1116             CleanupStack::PushL(buf);
  1073         writeStream.CommitL();
  1117     
  1074         // --------------------------------------------------------------
  1118             RBufWriteStream writeStream(*buf);
  1075 
  1119             writeStream.PushL();
  1076         // Create a heap descriptor from the buffer
  1120     
  1077         HBufC8* des = HBufC8::NewLC(buf->Size());
  1121             //externalize ClientConversation
  1078         CleanupStack::Pop(des);
  1122             aClientConversation->ExternalizeL(writeStream);
  1079         TPtr8 ptr(des->Des());
  1123     
  1080         buf->Read(0, ptr, buf->Size());
  1124             // Results are already packed in the stream
  1081 
  1125             writeStream.CommitL();
  1082         CleanupStack::PopAndDestroy(2, buf); // writestream, buf
  1126             // --------------------------------------------------------------
  1083 
  1127     
  1084         iAsyncReqRMessage.Write(1, *des);
  1128             // Create a heap descriptor from the buffer
  1085         iAsyncReqRMessage.Complete(EAddConversationEvent);
  1129             HBufC8* des = HBufC8::NewLC(buf->Size());
  1086         delete des;
  1130             CleanupStack::Pop(des);
  1087         iNotifyHandling = EFalse;
  1131             TPtr8 ptr(des->Des());
  1088     }
  1132             buf->Read(0, ptr, buf->Size());
  1089 
  1133     
       
  1134             CleanupStack::PopAndDestroy(2, buf); // writestream, buf
       
  1135     
       
  1136             iAsyncReqRMessage.Write(1, *des);
       
  1137             iAsyncReqRMessage.Complete(EAddConversationEvent);
       
  1138             delete des;
       
  1139             iNotifyHandling = EFalse;
       
  1140         }
       
  1141     }
  1090     PRINT ( _L("End CCsSession::HandleNewConversationEventL") );
  1142     PRINT ( _L("End CCsSession::HandleNewConversationEventL") );
  1091 }
  1143 }
  1092 
  1144 
  1093 // ----------------------------------------------------------------------------
  1145 // ----------------------------------------------------------------------------
  1094 // CCsSession::HandleDeleteConversationEventL
  1146 // CCsSession::HandleDeleteConversationEventL
  1101     PRINT ( _L("Enter CCsSession::HandleDeleteConversationEventL") );
  1153     PRINT ( _L("Enter CCsSession::HandleDeleteConversationEventL") );
  1102 
  1154 
  1103     if (!iConversationChangeObserver)
  1155     if (!iConversationChangeObserver)
  1104         return;
  1156         return;
  1105 
  1157 
  1106     if (aClientConversation->GetConversationEntryId()
  1158     if ((aClientConversation->GetContactId()
  1107             != iMonitoredConversation->GetConversationEntryId())
  1159                != iMonitoredConversation->GetContactId()) &&
       
  1160                (aClientConversation->GetConversationEntryId()
       
  1161                != iMonitoredConversation->GetConversationEntryId())
       
  1162                  )
  1108         return;
  1163         return;
  1109 
  1164 
  1110     if (! (iNotifyHandling))
  1165     if (! (iNotifyHandling))
  1111     {
  1166     {
  1112         //append in notify list
  1167         //append in notify list
  1132         // Results are already packed in the stream
  1187         // Results are already packed in the stream
  1133         writeStream.CommitL();
  1188         writeStream.CommitL();
  1134         // --------------------------------------------------------------
  1189         // --------------------------------------------------------------
  1135 
  1190 
  1136         // Create a heap descriptor from the buffer
  1191         // Create a heap descriptor from the buffer
  1137         HBufC8* des = HBufC8::NewLC(buf->Size());
  1192         HBufC8* des = HBufC8::NewL(buf->Size());
  1138         CleanupStack::Pop(des);
  1193 
  1139         TPtr8 ptr(des->Des());
  1194         TPtr8 ptr(des->Des());
  1140         buf->Read(0, ptr, buf->Size());
  1195         buf->Read(0, ptr, buf->Size());
  1141 
  1196 
  1142         CleanupStack::PopAndDestroy(2, buf); // writestream, buf
  1197         CleanupStack::PopAndDestroy(2, buf); // writestream, buf
  1143 
  1198 
  1161     PRINT ( _L("Enter CCsSession::HandleModifyConversationEventL") );
  1216     PRINT ( _L("Enter CCsSession::HandleModifyConversationEventL") );
  1162 
  1217 
  1163     if (!iConversationChangeObserver)
  1218     if (!iConversationChangeObserver)
  1164         return;
  1219         return;
  1165 
  1220 
  1166     if (aClientConversation->GetConversationEntryId()
  1221     //this is check to send notif to clients for a new message
  1167             != iMonitoredConversation->GetConversationEntryId())
  1222     //1. if the client is subscribed with contact id ==> then send
  1168         return;
  1223     //2. if the client is subscribed with conv id ---> then send
  1169 
  1224     // else dont send
  1170     if (! (iNotifyHandling))
  1225     
  1171     {
  1226     if ((aClientConversation->GetContactId() == 
  1172         //append in notify list
  1227                 iMonitoredConversation->GetContactId() && 
  1173         CCsConversationEvent* conversationEvent = CCsConversationEvent::NewL();
  1228                 aClientConversation->GetContactId() != -1)
  1174         CleanupStack::PushL(conversationEvent);
  1229                 ||(aClientConversation->GetConversationEntryId() == 
  1175         conversationEvent->SetClientConversationL(*aClientConversation);
  1230                         iMonitoredConversation->GetConversationEntryId()))
  1176         conversationEvent->SetEvent(KConversationEventUpdate);
  1231     {
  1177         iEventList->AppendL(conversationEvent);
  1232     
  1178         CleanupStack::Pop(conversationEvent);
  1233         if (! (iNotifyHandling))
  1179     }
  1234         {
  1180     else
  1235             //append in notify list
  1181     {
  1236             CCsConversationEvent* conversationEvent = CCsConversationEvent::NewL();
  1182         // create a new buffer for writing into stream
  1237             CleanupStack::PushL(conversationEvent);
  1183         CBufFlat* buf = CBufFlat::NewL(KBigBuffer);
  1238             conversationEvent->SetClientConversationL(*aClientConversation);
  1184         CleanupStack::PushL(buf);
  1239             conversationEvent->SetEvent(KConversationEventUpdate);
  1185 
  1240             iEventList->AppendL(conversationEvent);
  1186         RBufWriteStream writeStream(*buf);
  1241             CleanupStack::Pop(conversationEvent);
  1187         writeStream.PushL();
  1242         }
  1188 
  1243         else
  1189         //externalize ClientConversation
  1244         {
  1190         aClientConversation->ExternalizeL(writeStream);
  1245             // create a new buffer for writing into stream
  1191 
  1246             CBufFlat* buf = CBufFlat::NewL(KBigBuffer);
  1192         // Results are already packed in the stream
  1247             CleanupStack::PushL(buf);
  1193         writeStream.CommitL();
  1248     
  1194         // --------------------------------------------------------------
  1249             RBufWriteStream writeStream(*buf);
  1195 
  1250             writeStream.PushL();
  1196         // Create a heap descriptor from the buffer
  1251     
  1197         HBufC8* des = HBufC8::NewLC(buf->Size());
  1252             //externalize ClientConversation
  1198         CleanupStack::Pop(des);
  1253             aClientConversation->ExternalizeL(writeStream);
  1199         TPtr8 ptr(des->Des());
  1254     
  1200         buf->Read(0, ptr, buf->Size());
  1255             // Results are already packed in the stream
  1201 
  1256             writeStream.CommitL();
  1202         CleanupStack::PopAndDestroy(2, buf); // writestream, buf
  1257             // --------------------------------------------------------------
  1203 
  1258     
  1204         iAsyncReqRMessage.Write(1, *des);
  1259             // Create a heap descriptor from the buffer
  1205         iAsyncReqRMessage.Complete(EModifyConversationEvent);
  1260             HBufC8* des = HBufC8::NewL(buf->Size());
  1206         delete des;
  1261             TPtr8 ptr(des->Des());
  1207         iNotifyHandling = EFalse;
  1262             buf->Read(0, ptr, buf->Size());
  1208     }
  1263     
  1209 
  1264             CleanupStack::PopAndDestroy(2, buf); // writestream, buf
       
  1265     
       
  1266             iAsyncReqRMessage.Write(1, *des);
       
  1267             iAsyncReqRMessage.Complete(EModifyConversationEvent);
       
  1268             delete des;
       
  1269             iNotifyHandling = EFalse;
       
  1270         }
       
  1271     }
  1210     PRINT ( _L("End CCsSession::HandleModifyConversationEventL") );
  1272     PRINT ( _L("End CCsSession::HandleModifyConversationEventL") );
  1211 }
  1273 }
  1212 
  1274 
  1213 // ----------------------------------------------------------------------------
  1275 // ----------------------------------------------------------------------------
  1214 // CCsSession::NotifyClient
  1276 // CCsSession::NotifyClient
  1226     }
  1288     }
  1227     else if (aConversationEvent->IsUpdateConversationListEventSet())
  1289     else if (aConversationEvent->IsUpdateConversationListEventSet())
  1228     {
  1290     {
  1229         iAsyncReqRMessage.Complete(EModifyConversationListEvent);
  1291         iAsyncReqRMessage.Complete(EModifyConversationListEvent);
  1230     }
  1292     }
       
  1293     else if(aConversationEvent->IsPartialDeleteConversationListEventSet())
       
  1294     {
       
  1295         iAsyncReqRMessage.Complete(EPartialDeleteConversationListEvent);
       
  1296     }
  1231     else if (aConversationEvent->IsNewConversationEventSet())
  1297     else if (aConversationEvent->IsNewConversationEventSet())
  1232     {
  1298     {
  1233         iAsyncReqRMessage.Complete(EAddConversationEvent);
  1299         iAsyncReqRMessage.Complete(EAddConversationEvent);
  1234     }
  1300     }
  1235     else if (aConversationEvent->IsDeleteConversationEventSet())
  1301     else if (aConversationEvent->IsDeleteConversationEventSet())
  1266         HandleModifyConversationListEventL(aConversation);
  1332         HandleModifyConversationListEventL(aConversation);
  1267     }
  1333     }
  1268     else if (aEvent & KConversationListEventDelete)
  1334     else if (aEvent & KConversationListEventDelete)
  1269     {
  1335     {
  1270         HandleDeleteConversationListEventL(aConversation);
  1336         HandleDeleteConversationListEventL(aConversation);
       
  1337     }
       
  1338     else if(aEvent & KConversationListEventPartialDelete)
       
  1339     {
       
  1340         HandlePartialDeleteConversationListEvent(aConversation);
  1271     }
  1341     }
  1272     else if (aEvent & KConversationEventNew)
  1342     else if (aEvent & KConversationEventNew)
  1273     {
  1343     {
  1274         HandleNewConversationEventL(aConversation);
  1344         HandleNewConversationEventL(aConversation);
  1275     }
  1345     }
  1301     TInt conversationId = aMessage.Int0();
  1371     TInt conversationId = aMessage.Int0();
  1302 
  1372 
  1303     // Delete handler
  1373     // Delete handler
  1304     CCsConversationCache* cache = iServer->ConversationCacheInterface();
  1374     CCsConversationCache* cache = iServer->ConversationCacheInterface();
  1305     CCsConversationDeleteHandler* deleteHandler =
  1375     CCsConversationDeleteHandler* deleteHandler =
  1306             CCsConversationDeleteHandler::NewL(cache, this);
  1376             CCsConversationDeleteHandler::NewL(cache);
  1307 
  1377 
  1308     deleteHandler->DeleteL(conversationId);
  1378     deleteHandler->DeleteL(conversationId);
  1309     aMessage.Complete(EUserDeleteConversationComplete);
  1379     aMessage.Complete(EUserDeleteConversationComplete);
  1310 
  1380 
  1311     PRINT ( _L("End CCsSession::DeleteConversationL") );
  1381     PRINT ( _L("End CCsSession::DeleteConversationL") );
  1312 }
       
  1313 
       
  1314 // ----------------------------------------------------------------------------
       
  1315 // CCsSession::DeleteComplete
       
  1316 // ----------------------------------------------------------------------------
       
  1317 void CCsSession::DeleteComplete(CCsConversationDeleteHandler* aHandler)
       
  1318 {
       
  1319     delete aHandler;
       
  1320 }
       
  1321 
       
  1322 // ----------------------------------------------------------------------------
       
  1323 // CCsSession::DeleteInProgress
       
  1324 // ----------------------------------------------------------------------------
       
  1325 void CCsSession::DeleteInProgress(CCsConversationDeleteHandler* aHandler)
       
  1326 {
       
  1327     delete aHandler;
       
  1328 }
  1382 }
  1329 
  1383 
  1330 // ----------------------------------------------------------------------------
  1384 // ----------------------------------------------------------------------------
  1331 // CCsSession::HandleRefreshConversationListL
  1385 // CCsSession::HandleRefreshConversationListL
  1332 // ----------------------------------------------------------------------------
  1386 // ----------------------------------------------------------------------------
  1397 
  1451 
  1398     // Results are already packed in the stream
  1452     // Results are already packed in the stream
  1399     writeStream.CommitL();
  1453     writeStream.CommitL();
  1400 
  1454 
  1401     // Create a heap descriptor from the buffer
  1455     // Create a heap descriptor from the buffer
  1402     HBufC8* des = HBufC8::NewLC(buf->Size());
  1456     HBufC8* des = HBufC8::NewL(buf->Size());
  1403     CleanupStack::Pop(des);
       
  1404     TPtr8 ptr(des->Des());
  1457     TPtr8 ptr(des->Des());
  1405     buf->Read(0, ptr, buf->Size());
  1458     buf->Read(0, ptr, buf->Size());
  1406 
  1459 
  1407     CleanupStack::PopAndDestroy(2, buf); // writestream, buf
  1460     CleanupStack::PopAndDestroy(2, buf); // writestream, buf
  1408 
  1461 
  1409     aMessage.Write(1, *des);
  1462     aMessage.Write(1, *des);
  1410     aMessage.Complete(EGetConversationIdComplete);
  1463     aMessage.Complete(EGetConversationIdComplete);
       
  1464     delete des;
       
  1465 }
       
  1466 
       
  1467 void CCsSession::GetConversationFromConversationIdL(const RMessage2& aMessage)
       
  1468 {
       
  1469     // create a new buffer for writing into stream
       
  1470     CBufFlat* buf = CBufFlat::NewL(KBigBuffer);
       
  1471     CleanupStack::PushL(buf);
       
  1472 
       
  1473     RBufWriteStream writeStream(*buf);
       
  1474     writeStream.PushL();
       
  1475 
       
  1476     // Get the conversation id
       
  1477     TInt conversationId = aMessage.Int0();
       
  1478     CCsConversationCache* cache = iServer->ConversationCacheInterface();
       
  1479     CCsClientConversation* clientConv = cache->GetConversationFromConversationIdL(conversationId);
       
  1480 
       
  1481     // if no conversation exists for given message-id,
       
  1482     // create a dummy conversation and complete response
       
  1483     if(clientConv == NULL)
       
  1484     {
       
  1485         //create dummy conversation
       
  1486         clientConv = CCsClientConversation::NewL();
       
  1487         CleanupStack::PushL(clientConv);
       
  1488         clientConv->SetConversationEntryId(-1);
       
  1489         CCsConversationEntry* entry = CCsConversationEntry::NewL();
       
  1490         CleanupStack::PushL(entry);
       
  1491         entry->SetEntryId(-1);
       
  1492         clientConv->SetConversationEntryL(entry); // clone
       
  1493         CleanupStack::PopAndDestroy(entry);
       
  1494     }
       
  1495     else
       
  1496     {
       
  1497         CleanupStack::PushL(clientConv);
       
  1498     }
       
  1499 
       
  1500     // Externalize
       
  1501     clientConv->ExternalizeL(writeStream);
       
  1502 
       
  1503     // Results are already packed in the stream
       
  1504     writeStream.CommitL();
       
  1505 
       
  1506     // Create a heap descriptor from the buffer
       
  1507     HBufC8* des = HBufC8::NewL(buf->Size());
       
  1508     TPtr8 ptr(des->Des());
       
  1509     buf->Read(0, ptr, buf->Size());
       
  1510 
       
  1511     CleanupStack::PopAndDestroy(3, buf); // clientConv, writestream, buf
       
  1512 
       
  1513     aMessage.Write(1, *des);
       
  1514     aMessage.Complete(EGetConversationFromConversationIdComplete);
  1411     delete des;
  1515     delete des;
  1412 }
  1516 }
  1413 
  1517 
  1414 // ----------------------------------------------------------------------------
  1518 // ----------------------------------------------------------------------------
  1415 // GetConversationFromMessageIdL
  1519 // GetConversationFromMessageIdL
  1452     
  1556     
  1453     // Results are already packed in the stream
  1557     // Results are already packed in the stream
  1454     writeStream.CommitL();
  1558     writeStream.CommitL();
  1455     
  1559     
  1456     // Create a heap descriptor from the buffer
  1560     // Create a heap descriptor from the buffer
  1457     HBufC8* des = HBufC8::NewLC(buf->Size());
  1561     HBufC8* des = HBufC8::NewL(buf->Size());
  1458     CleanupStack::Pop(des);
       
  1459     TPtr8 ptr(des->Des());
  1562     TPtr8 ptr(des->Des());
  1460     buf->Read(0, ptr, buf->Size());
  1563     buf->Read(0, ptr, buf->Size());
  1461     
  1564     
  1462     CleanupStack::PopAndDestroy(3, buf); // conversation, writestream, buf
  1565     CleanupStack::PopAndDestroy(3, buf); // conversation, writestream, buf
  1463     
  1566     
  1495 
  1598 
  1496     // Results are already packed in the stream
  1599     // Results are already packed in the stream
  1497     writeStream.CommitL();
  1600     writeStream.CommitL();
  1498 
  1601 
  1499     // Create a heap descriptor from the buffer
  1602     // Create a heap descriptor from the buffer
  1500     HBufC8* des = HBufC8::NewLC(buf->Size());
  1603     HBufC8* des = HBufC8::NewL(buf->Size());
  1501     CleanupStack::Pop(des);
       
  1502     TPtr8 ptr(des->Des());
  1604     TPtr8 ptr(des->Des());
  1503     buf->Read(0, ptr, buf->Size());
  1605     buf->Read(0, ptr, buf->Size());
  1504  
  1606  
  1505     CleanupStack::PopAndDestroy(2, buf); // writestream, buf
  1607     CleanupStack::PopAndDestroy(2, buf); // writestream, buf
  1506     CleanupStack::PopAndDestroy(&buffer);
  1608     CleanupStack::PopAndDestroy(&buffer);
  1519 
  1621 
  1520     TInt conversationId = aMessage.Int0();
  1622     TInt conversationId = aMessage.Int0();
  1521 
  1623 
  1522     // Mark read handler
  1624     // Mark read handler
  1523     CCsConversationCache* cache = iServer->ConversationCacheInterface();
  1625     CCsConversationCache* cache = iServer->ConversationCacheInterface();
  1524     CCsConversationMarkReadHandler* markHandler = 
  1626     CCsConversationMarkReadHandler* markHandler = CCsConversationMarkReadHandler::NewL(cache);
  1525         CCsConversationMarkReadHandler::NewL(cache, this);
       
  1526 
  1627 
  1527     markHandler->MarkReadL(conversationId);
  1628     markHandler->MarkReadL(conversationId);
  1528     
  1629     
  1529     aMessage.Complete(EUserMarkReadConversationComplete);
  1630     aMessage.Complete(EUserMarkReadConversationComplete);
  1530 
  1631 
  1531     PRINT ( _L("End CCsSession::MarkConversationReadL") );
  1632     PRINT ( _L("End CCsSession::MarkConversationReadL") );
  1532 }
  1633 }
  1533 
       
  1534 // ----------------------------------------------------------------------------
       
  1535 // CCsSession::MarkReadComplete
       
  1536 // ----------------------------------------------------------------------------
       
  1537 void CCsSession::MarkReadComplete(CCsConversationMarkReadHandler* aHandler)
       
  1538 {
       
  1539     delete aHandler;
       
  1540 }
       
  1541 
       
  1542 //EOF
  1634 //EOF