--- a/messagingapp/msgappfw/server/src/ccssession.cpp Wed Jun 23 18:09:17 2010 +0300
+++ b/messagingapp/msgappfw/server/src/ccssession.cpp Tue Jul 06 14:12:40 2010 +0300
@@ -58,7 +58,16 @@
// Construtor
// ----------------------------------------------------------------------------
CCsSession::CCsSession(CCsServer* aServer) :
- iServer(aServer)
+ iServer(aServer),
+ iDes(NULL),
+ iMonitoredConversation(NULL),
+ iBufferOverflow(EFalse),
+ iGetConversationBufferOverflow( EFalse),
+ iNotifyHandling(EFalse),
+ iConversationListChangeObserver(EFalse),
+ iConversationChangeObserver(EFalse),
+ iCachingChangeObserver(EFalse),
+ iReqCnt(1) //Let's start the event ID from 1
{
}
@@ -70,21 +79,10 @@
{
PRINT ( _L("Enter CCsSession::ConstructL") );
- iBufferOverflow = EFalse;
- iGetConversationBufferOverflow = EFalse;
- des = NULL;
-
- iNotifyHandling = EFalse;
- iConversationListChangeObserver = EFalse;
- iConversationChangeObserver = EFalse;
- iCachingChangeObserver = EFalse;
- iMonitoredConversation = NULL;
// initialize the event List
iEventList = new (ELeave) RPointerArray<CCsConversationEvent> ();
- iReqCnt = 1; //Let's start the event ID from 1
-
PRINT ( _L("End CCsSession::ConstructL") );
}
@@ -96,14 +94,14 @@
{
PRINT ( _L("Enter CCsSession::~CCsSession") );
- if (des)
- {
- delete des;
- des = NULL;
- }
-
- if (iEventList)
- {
+ if ( iDes )
+ {
+ delete iDes;
+ iDes = NULL;
+ }
+
+ if ( iEventList )
+ {
iEventList->ResetAndDestroy();
iEventList->Close();
delete iEventList;
@@ -133,6 +131,12 @@
// Check the error status returned
if (errStatus != KErrNone)
{
+ // Free memory.
+ if(iDes)
+ {
+ delete iDes;
+ iDes=NULL;
+ }
aMessage.Complete(errStatus);
}
}
@@ -228,6 +232,11 @@
PRINT ( _L("Received function EGetConversationIdFromAddress") )
GetConversationIdfromAddressL(aMessage);
break;
+
+ case EGetConversationFromConversationId:
+ PRINT ( _L("Received function EGetConversationFromConversationId") )
+ GetConversationFromConversationIdL(aMessage);
+ break;
case EGetConversationFromMessageId:
PRINT ( _L("Received function EGetConversationFromMessageId") )
@@ -249,6 +258,11 @@
// ----------------------------------------------------------------------------
void CCsSession::ServiceError(const RMessage2& aMessage, TInt aError)
{
+ if(iDes)
+ {
+ delete iDes;
+ iDes=NULL;
+ }
aMessage.Complete(aError);
}
@@ -267,14 +281,13 @@
{
RPointerArray<CCsClientConversation>* ClientConversationList =
new (ELeave) RPointerArray<CCsClientConversation> ();
-
+ CleanupResetAndDestroyPushL(ClientConversationList);
// get cache pointer
CCsConversationCache* cache = iServer->ConversationCacheInterface();
// Call cache function to get recent conversation entry list
// with dispaly name for all stored conversation entry ID
cache->GetConversationListL(ClientConversationList);
- CleanupStack::PushL(ClientConversationList);
//write all list data into stream
// create a new buffer for writing into stream
@@ -309,24 +322,19 @@
// --------------------------------------------------------------
// Create a heap descriptor from the buffer
- des = HBufC8::NewLC(buf->Size());
- CleanupStack::Pop(des);
- TPtr8 ptr(des->Des());
+ iDes = HBufC8::NewL(buf->Size());
+ TPtr8 ptr(iDes->Des());
buf->Read(0, ptr, buf->Size());
- // cleanup
+ // Cleanup
CleanupStack::PopAndDestroy(2, buf); // writestream, buf
- CleanupStack::Pop(ClientConversationList);
-
- // destroy objects inside list
- ClientConversationList->ResetAndDestroy();
- ClientConversationList->Close();
- delete ClientConversationList;
- ClientConversationList = NULL;
- }
+
+ // Cleanup ClientConversationList
+ CleanupStack::PopAndDestroy(ClientConversationList);
+ }
TInt rcevdBufferSize = aMessage.GetDesMaxLength(1);
- TInt reqdBufferSize = des->Size();
+ TInt reqdBufferSize = iDes->Size();
PRINT1 ( _L("Received buffer size = %d"), rcevdBufferSize );
PRINT1 ( _L("Required buffer size = %d"), reqdBufferSize );
@@ -349,13 +357,13 @@
PRINT ( _L("Adequate buffer received") );
PRINT ( _L("Packing the results in response") )
- aMessage.Write(1, *des);
+ aMessage.Write(1, *iDes);
aMessage.Complete(EGetConversationListOperationComplete);
iBufferOverflow = EFalse;
- delete des;
- des = NULL;
- }
-
+ delete iDes;
+ iDes = NULL;
+ }
+
PRINT_TIMESTAMP ("End CCsSession::GetConversationListL");
PRINT ( _L("End CCsSession::GetConversationListL") );
}
@@ -375,7 +383,7 @@
{
RPointerArray<CCsClientConversation>* ClientConversationList =
new (ELeave) RPointerArray<CCsClientConversation> ();
-
+ CleanupResetAndDestroyPushL(ClientConversationList);
// get cache pointer
CCsConversationCache* cache = iServer->ConversationCacheInterface();
@@ -383,8 +391,6 @@
// with dispaly name for all stored conversation entry ID
cache->GetConversationUnreadListL(ClientConversationList);
- CleanupStack::PushL(ClientConversationList);
-
//write all list data into stream
// create a new buffer for writing into stream
CBufFlat* buf = CBufFlat::NewL(KBigBuffer);
@@ -417,24 +423,18 @@
// --------------------------------------------------------------
// Create a heap descriptor from the buffer
- des = HBufC8::NewLC(buf->Size());
- CleanupStack::Pop(des);
- TPtr8 ptr(des->Des());
+ iDes = HBufC8::NewL(buf->Size());
+ TPtr8 ptr(iDes->Des());
buf->Read(0, ptr, buf->Size());
// cleanup
CleanupStack::PopAndDestroy(2, buf); // writestream, buf
- CleanupStack::Pop(ClientConversationList);
+ CleanupStack::PopAndDestroy(ClientConversationList);
- // destroy objects inside list
- ClientConversationList->ResetAndDestroy();
- ClientConversationList->Close();
- delete ClientConversationList;
- ClientConversationList = NULL;
}
TInt rcevdBufferSize = aMessage.GetDesMaxLength(1);
- TInt reqdBufferSize = des->Size();
+ TInt reqdBufferSize = iDes->Size();
PRINT1 ( _L("Received buffer size = %d"), rcevdBufferSize );
PRINT1 ( _L("Required buffer size = %d"), reqdBufferSize );
@@ -458,11 +458,11 @@
TPckgC<TInt> overflowPackage(EFalse);
aMessage.WriteL(0, overflowPackage);
- aMessage.Write(1, *des);
+ aMessage.Write(1, *iDes);
aMessage.Complete(KErrNone);
iBufferOverflow = EFalse;
- delete des;
- des = NULL;
+ delete iDes;
+ iDes = NULL;
}
PRINT_TIMESTAMP ("End CCsSession::GetConversationUnreadListL");
@@ -502,9 +502,9 @@
CleanupStack::PopAndDestroy(2, buffer);//stream, buffer
CleanupStack::PushL(ClientConversation);
- RPointerArray<CCsConversationEntry>* conversationEntryList =
- new (ELeave) RPointerArray<CCsConversationEntry> ();
- CleanupStack::PushL(conversationEntryList);
+ RPointerArray<CCsConversationEntry>* conversationEntryList=
+ new (ELeave) RPointerArray<CCsConversationEntry>(10);
+ CleanupResetAndDestroyPushL(conversationEntryList);
// get conversationlist for given ClientConversation
cache->GetConversationsL(ClientConversation, conversationEntryList);
@@ -535,24 +535,19 @@
// --------------------------------------------------------------
// Create a heap descriptor from the buffer
- des = HBufC8::NewLC(buf->Size());
- CleanupStack::Pop(des);
- TPtr8 ptr(des->Des());
+ iDes = HBufC8::NewL(buf->Size());
+ TPtr8 ptr(iDes->Des());
buf->Read(0, ptr, buf->Size());
CleanupStack::PopAndDestroy(2, buf); // writestream, buf
- CleanupStack::Pop(conversationEntryList);
-
+
// Cleanup
- conversationEntryList->ResetAndDestroy();
- conversationEntryList->Close();
- delete conversationEntryList;
- conversationEntryList = NULL;
+ CleanupStack::PopAndDestroy(conversationEntryList);
CleanupStack::PopAndDestroy(ClientConversation);
}
TInt rcevdBufferSize = aMessage.GetDesMaxLength(1);
- TInt reqdBufferSize = des->Size();
+ TInt reqdBufferSize = iDes->Size();
PRINT1 ( _L("Received buffer size = %d"), rcevdBufferSize );
PRINT1 ( _L("Required buffer size = %d"), reqdBufferSize );
@@ -574,12 +569,12 @@
PRINT ( _L("Adequate buffer received") );
PRINT ( _L("Packing the results in response") )
- aMessage.Write(1, *des);
+ aMessage.Write(1, *iDes);
aMessage.Complete(EGetConversationOperationComplete);
iGetConversationBufferOverflow = EFalse;
- delete des;
- des = NULL;
- }
+ delete iDes;
+ iDes = NULL;
+ }
PRINT ( _L("End CCsSession::GetConversationsL") );
}
@@ -701,6 +696,57 @@
}
// ----------------------------------------------------------------------------
+// CCsSession::HandlePartialDeleteConversationListEventL
+// Notify client about partial delete conversation event
+// ----------------------------------------------------------------------------
+
+void CCsSession::HandlePartialDeleteConversationListEvent(
+ CCsClientConversation* aClientConversation)
+{
+ PRINT ( _L("Enter CCsSession::HandlePartialDeleteConversationListEvent") );
+
+ if (!iConversationListChangeObserver)
+ return;
+
+ if (! (iNotifyHandling))
+ {
+ //append in notify list
+ CCsConversationEvent* conversationEvent = CCsConversationEvent::NewL();
+ conversationEvent->SetClientConversationL(*aClientConversation);
+ CleanupStack::PushL(conversationEvent);
+ conversationEvent->SetEvent(KConversationListEventPartialDelete);
+ iEventList->AppendL(conversationEvent);
+ CleanupStack::Pop(conversationEvent);
+ }
+ else
+ {
+ // create a new buffer for writing into stream
+ CBufFlat* buf = CBufFlat::NewL(KBigBuffer);
+ CleanupStack::PushL(buf);
+
+ RBufWriteStream writeStream(*buf);
+ writeStream.PushL();
+
+ //externalize ClientConversation
+ aClientConversation->ExternalizeL(writeStream);
+
+ // Results are already packed in the stream
+ writeStream.CommitL();
+
+ // --------------------------------------------------------------
+ // Create a heap descriptor from the buffer
+ HBufC8* notifyDes = HBufC8::NewLC(buf->Size());
+ TPtr8 ptr(notifyDes->Des());
+ buf->Read(0, ptr, buf->Size());
+
+ iAsyncReqRMessage.Write(1, *notifyDes);
+ iAsyncReqRMessage.Complete(EPartialDeleteConversationListEvent);
+ CleanupStack::PopAndDestroy(3, buf); // notifyDes, writestream, buf
+ iNotifyHandling = EFalse;
+ }
+}
+
+// ----------------------------------------------------------------------------
// CCsSession::HandleModifyConversationListEventL
// Notify client about update conversation event
// ----------------------------------------------------------------------------
@@ -865,8 +911,7 @@
// --------------------------------------------------------------
// Create a heap descriptor from the buffer
- HBufC8* des = HBufC8::NewLC(buf->Size());
- CleanupStack::Pop(des);
+ HBufC8* des = HBufC8::NewL(buf->Size());
TPtr8 ptr(des->Des());
buf->Read(0, ptr, buf->Size());
@@ -904,8 +949,7 @@
// --------------------------------------------------------------
// Create a heap descriptor from the buffer
- HBufC8* des = HBufC8::NewLC(buf->Size());
- CleanupStack::Pop(des);
+ HBufC8* des = HBufC8::NewL(buf->Size());
TPtr8 ptr(des->Des());
buf->Read(0, ptr, buf->Size());
@@ -1145,8 +1189,8 @@
// --------------------------------------------------------------
// Create a heap descriptor from the buffer
- HBufC8* des = HBufC8::NewLC(buf->Size());
- CleanupStack::Pop(des);
+ HBufC8* des = HBufC8::NewL(buf->Size());
+
TPtr8 ptr(des->Des());
buf->Read(0, ptr, buf->Size());
@@ -1213,8 +1257,7 @@
// --------------------------------------------------------------
// Create a heap descriptor from the buffer
- HBufC8* des = HBufC8::NewLC(buf->Size());
- CleanupStack::Pop(des);
+ HBufC8* des = HBufC8::NewL(buf->Size());
TPtr8 ptr(des->Des());
buf->Read(0, ptr, buf->Size());
@@ -1247,6 +1290,10 @@
{
iAsyncReqRMessage.Complete(EModifyConversationListEvent);
}
+ else if(aConversationEvent->IsPartialDeleteConversationListEventSet())
+ {
+ iAsyncReqRMessage.Complete(EPartialDeleteConversationListEvent);
+ }
else if (aConversationEvent->IsNewConversationEventSet())
{
iAsyncReqRMessage.Complete(EAddConversationEvent);
@@ -1288,6 +1335,10 @@
{
HandleDeleteConversationListEventL(aConversation);
}
+ else if(aEvent & KConversationListEventPartialDelete)
+ {
+ HandlePartialDeleteConversationListEvent(aConversation);
+ }
else if (aEvent & KConversationEventNew)
{
HandleNewConversationEventL(aConversation);
@@ -1402,8 +1453,7 @@
writeStream.CommitL();
// Create a heap descriptor from the buffer
- HBufC8* des = HBufC8::NewLC(buf->Size());
- CleanupStack::Pop(des);
+ HBufC8* des = HBufC8::NewL(buf->Size());
TPtr8 ptr(des->Des());
buf->Read(0, ptr, buf->Size());
@@ -1414,6 +1464,57 @@
delete des;
}
+void CCsSession::GetConversationFromConversationIdL(const RMessage2& aMessage)
+{
+ // create a new buffer for writing into stream
+ CBufFlat* buf = CBufFlat::NewL(KBigBuffer);
+ CleanupStack::PushL(buf);
+
+ RBufWriteStream writeStream(*buf);
+ writeStream.PushL();
+
+ // Get the conversation id
+ TInt conversationId = aMessage.Int0();
+ CCsConversationCache* cache = iServer->ConversationCacheInterface();
+ CCsClientConversation* clientConv = cache->GetConversationFromConversationIdL(conversationId);
+
+ // if no conversation exists for given message-id,
+ // create a dummy conversation and complete response
+ if(clientConv == NULL)
+ {
+ //create dummy conversation
+ clientConv = CCsClientConversation::NewL();
+ CleanupStack::PushL(clientConv);
+ clientConv->SetConversationEntryId(-1);
+ CCsConversationEntry* entry = CCsConversationEntry::NewL();
+ CleanupStack::PushL(entry);
+ entry->SetEntryId(-1);
+ clientConv->SetConversationEntryL(entry); // clone
+ CleanupStack::PopAndDestroy(entry);
+ }
+ else
+ {
+ CleanupStack::PushL(clientConv);
+ }
+
+ // Externalize
+ clientConv->ExternalizeL(writeStream);
+
+ // Results are already packed in the stream
+ writeStream.CommitL();
+
+ // Create a heap descriptor from the buffer
+ HBufC8* des = HBufC8::NewL(buf->Size());
+ TPtr8 ptr(des->Des());
+ buf->Read(0, ptr, buf->Size());
+
+ CleanupStack::PopAndDestroy(3, buf); // clientConv, writestream, buf
+
+ aMessage.Write(1, *des);
+ aMessage.Complete(EGetConversationFromConversationIdComplete);
+ delete des;
+}
+
// ----------------------------------------------------------------------------
// GetConversationFromMessageIdL
// ----------------------------------------------------------------------------
@@ -1457,8 +1558,7 @@
writeStream.CommitL();
// Create a heap descriptor from the buffer
- HBufC8* des = HBufC8::NewLC(buf->Size());
- CleanupStack::Pop(des);
+ HBufC8* des = HBufC8::NewL(buf->Size());
TPtr8 ptr(des->Des());
buf->Read(0, ptr, buf->Size());
@@ -1500,8 +1600,7 @@
writeStream.CommitL();
// Create a heap descriptor from the buffer
- HBufC8* des = HBufC8::NewLC(buf->Size());
- CleanupStack::Pop(des);
+ HBufC8* des = HBufC8::NewL(buf->Size());
TPtr8 ptr(des->Des());
buf->Read(0, ptr, buf->Size());