emailservices/emailstore/base_plugin/src/baseplugindelayedops.cpp
changeset 56 15bc1d5d6267
parent 48 10eaf342f539
child 57 ae34e1715e21
equal deleted inserted replaced
51:d845db10c0d4 56:15bc1d5d6267
    21 
    21 
    22 #include "MsgStoreWritablePropertyContainer.h"
    22 #include "MsgStoreWritablePropertyContainer.h"
    23 
    23 
    24 #include "baseplugindelayedops.h"
    24 #include "baseplugindelayedops.h"
    25 #include "baseplugindelayedopsprivate.h"
    25 #include "baseplugindelayedopsprivate.h"
    26 #include "nestedao.h"
       
    27 
    26 
    28 ///////////////////////////////////////////////////
    27 ///////////////////////////////////////////////////
    29 // CDelayedOp                                    //
    28 // CDelayedOp                                    //
    30 ///////////////////////////////////////////////////
    29 ///////////////////////////////////////////////////
    31 
    30 
    49     } 
    48     } 
    50 
    49 
    51 /**
    50 /**
    52  * 
    51  * 
    53  */
    52  */
       
    53 /*public*/  void CDelayedOp::StartOp()
       
    54     {
       
    55     iStatus = KRequestPending;
       
    56     SetActive();
       
    57     TRequestStatus* pStatus = &iStatus;
       
    58     User::RequestComplete( pStatus, KErrNone );
       
    59     } 
    54 /*protected*/  CDelayedOp::CDelayedOp()
    60 /*protected*/  CDelayedOp::CDelayedOp()
    55     : CAsyncOneShot( CActive::EPriorityIdle )
    61     : CActive( CActive::EPriorityIdle )
    56     {    
    62     {    
       
    63     CActiveScheduler::Add( this );
    57     }
    64     }
    58     
    65     
    59 /**
    66 /**
    60  * 
    67  * 
    61  */
    68  */
    62 /*private virtual*/  void CDelayedOp::RunL()
    69 /*private virtual*/  void CDelayedOp::RunL()
    63     {
    70     {
    64     __LOG_ENTER_SUPPRESS( "Run" );
    71     __LOG_ENTER_SUPPRESS( "Run" );
    65     TRAPD( err, ExecuteOpL() );
    72     TBool again( EFalse );
       
    73     
       
    74     TRAPD( err, again = ExecuteOpL() );
    66     
    75     
    67     if ( KErrNone != err )
    76     if ( KErrNone != err )
    68         {
    77         {
    69         __LOG_WRITE8_FORMAT1_INFO(
    78         __LOG_WRITE8_FORMAT1_INFO(
    70             "Error while executing delayed operation: %d.", err );
    79             "Error while executing delayed operation: %d.", err );
    71         }
    80         }
    72     
    81     
    73     //self-destroy.
    82     if ( again )
    74     iManager->DequeueOp( *this );
    83         {
    75     
    84         StartOp();
    76     //Remove this from iDelayedOpReqs as well.
    85         }
    77     for ( TInt i = 0; i < iPlugin->iDelayedOpReqs.Count(); i++ )
    86     else
    78         {
    87         {
    79         if ( iPlugin->iDelayedOpReqs[i] == this )
    88         //self-destroy.
    80             {
    89         iManager->DequeueOp( *this );
    81             iPlugin->iDelayedOpReqs.Remove( i );
    90 //<qmail>		
    82             break;
    91 		    //Remove this from iDelayedOpReqs as well.
    83             }
    92 	    for ( TInt i = 0; i < iPlugin->iDelayedOpReqs.Count(); i++ )
    84         }
    93 	        {
    85     delete this;
    94 	        if ( iPlugin->iDelayedOpReqs[i] == this )
       
    95 	            {
       
    96 	            iPlugin->iDelayedOpReqs.Remove( i );
       
    97 	            break;
       
    98 	            }
       
    99 	        }
       
   100 //</qmail>			
       
   101         delete this;
       
   102         }
    86     }
   103     }
    87     
   104     
    88 /**
   105 /**
    89  * 
   106  * 
    90  */
   107  */
   136  */
   153  */
   137 /*public virtual*/ void CDelayedOpsManager::EnqueueOpL( CDelayedOp* aOp )
   154 /*public virtual*/ void CDelayedOpsManager::EnqueueOpL( CDelayedOp* aOp )
   138     {
   155     {
   139     iDelayedOps.AppendL( aOp );
   156     iDelayedOps.AppendL( aOp );
   140     aOp->SetContext( iPlugin, *this );        
   157     aOp->SetContext( iPlugin, *this );        
   141     aOp->Call();
   158     aOp->StartOp();
   142     }
   159     }
   143     
   160     
   144 /**
   161 /**
   145  * 
   162  * 
   146  */
   163  */
   244     }
   261     }
   245 
   262 
   246 /**
   263 /**
   247  * 
   264  * 
   248  */
   265  */
   249 /*public virtual*/TBool CDelayedDeleteMessagesOp::DeleteMessagesInChunksL( TInt aStartIndex )
   266 /*private*/
   250     {
   267 void CDelayedDeleteMessagesOp::ConstructL(
   251     __LOG_ENTER( "DeleteMessagesInChunksL" );
   268     const RArray<TFSMailMsgId>& aMessages )
   252     TBool done=EFalse;
   269     {
   253     TInt endIndex;
   270     __LOG_CONSTRUCT( "baseplugin", "CDelayedDeleteMessagesOp" );
   254 //<qmail>
   271             
       
   272     TInt count = aMessages.Count();
       
   273     for ( TInt i = 0; i < count; ++i )
       
   274         {
       
   275         iMessages.AppendL( aMessages[i].Id() );
       
   276         }
       
   277     }
       
   278 
       
   279 /**
       
   280  * 
       
   281  */
       
   282 /*private*/
       
   283 void CDelayedDeleteMessagesOp::ConstructL(
       
   284     TMsgStoreId aMsgId )
       
   285     {
       
   286     __LOG_CONSTRUCT( "baseplugin", "CDelayedDeleteMessagesOp" );
       
   287     iImmediateDelete = ETrue;
       
   288     iMessages.AppendL( aMsgId );
       
   289     }
       
   290 
       
   291 /**
       
   292  * 
       
   293  */
       
   294 /*private*/ CDelayedDeleteMessagesOp::CDelayedDeleteMessagesOp(
       
   295     TMsgStoreId aMailBoxId,
       
   296     TMsgStoreId aFolderId )
       
   297     :
       
   298     iMailBoxId( aMailBoxId ), iFolderId( aFolderId )
       
   299     {
       
   300     }
       
   301 
       
   302 /**
       
   303  * 
       
   304  */
       
   305 /*private*/ TBool CDelayedDeleteMessagesOp::ExecuteOpL()
       
   306     {
       
   307     __LOG_ENTER( "ExecuteOpL" );
       
   308 
       
   309     //Maximum number of messages deleted in one go
       
   310     const TInt KNumOfDeletesBeforeYield = 30;
       
   311 
       
   312     //<qmail>
   255     TInt result(KErrNone);
   313     TInt result(KErrNone);
   256     if( aStartIndex + KSizeOfChunk < iMessages.Count() )
   314 
   257         {
   315     TBool runAgain = ETrue;
   258             endIndex = aStartIndex + KSizeOfChunk;
   316     TInt endIndex = iIndex + KNumOfDeletesBeforeYield;
   259         }
   317 
   260     else
   318     if (endIndex >= iMessages.Count())
   261         {
   319         {
   262         endIndex = iMessages.Count();   
   320         endIndex = iMessages.Count();
   263         done=ETrue;
   321         runAgain = EFalse; // last time, no need to run again.
   264         }
   322         }
   265     CMailboxInfo& mailBoxInfo
   323 
   266         = GetPlugin().GetMailboxInfoL( iMailBoxId );
   324     CMailboxInfo& mailBoxInfo = GetPlugin().GetMailboxInfoL(iMailBoxId);
   267     CMsgStoreMailBox& mailBox = mailBoxInfo();
   325     CMsgStoreMailBox& mailBox = mailBoxInfo();
   268 
   326 
   269     for ( TInt i = aStartIndex; i < endIndex; ++i )
   327     for (; iIndex < endIndex; iIndex++)
   270         {
   328         {
   271         TMsgStoreId msgId = iMessages[i];
   329         TMsgStoreId msgId = iMessages[iIndex];
   272         
   330 
   273         if ( EFalse == iImmediateDelete )
   331         if (EFalse == iImmediateDelete)
   274             {
   332             {
   275             //try to find the message
   333             //try to find the message
   276             CMsgStoreMessage* theMessage = NULL;
   334             CMsgStoreMessage* theMessage = NULL;
   277             theMessage = mailBox.FetchMessageL(
   335             theMessage = mailBox.FetchMessageL(msgId, KMsgStoreInvalidId);
   278                                       msgId, KMsgStoreInvalidId ) ;
       
   279             //save parentId
   336             //save parentId
   280             TMsgStoreId msgParentId;
   337             TMsgStoreId msgParentId;
   281             msgParentId =theMessage->ParentId();
   338             msgParentId = theMessage->ParentId();
   282             //check if message is in deleted folder or not.
   339             //check if message is in deleted folder or not.
   283             if ( msgParentId != mailBoxInfo.iRootFolders.iFolders[EFSDeleted] )
   340             if (msgParentId != mailBoxInfo.iRootFolders.iFolders[EFSDeleted])
   284                 {
   341                 {
   285             	//if not in deleted items then move it there.
   342                 //if not in deleted items then move it there.
   286                 __LOG_WRITE8_FORMAT1_INFO("Moving message 0x%X to the deleted items.", msgId );
   343                 __LOG_WRITE8_FORMAT1_INFO("Moving message 0x%X to the deleted items.", msgId );
   287                 TRAP(result,mailBox.MoveMessageL(
   344                 TRAP(result,mailBox.MoveMessageL(
   288                    msgId, KMsgStoreInvalidId,
   345                                 msgId, KMsgStoreInvalidId,
   289                    mailBoxInfo.iRootFolders.iFolders[EFSDeleted] ));
   346                                 mailBoxInfo.iRootFolders.iFolders[EFSDeleted] ));
   290                 if(result == KErrNone)
   347                 if (result == KErrNone)
   291                     {
   348                     {
   292                     GetPlugin().NotifyEventL( iMailBoxId, msgId, KMsgStoreInvalidId , TFSEventMailMoved, msgParentId);
   349                     GetPlugin().NotifyEventL(iMailBoxId, msgId,
       
   350                             KMsgStoreInvalidId, TFSEventMailMoved,
       
   351                             msgParentId);
   293                     }
   352                     }
   294                 else
   353                 else
   295                     {
   354                     {
   296                     User::Leave(result);
   355                     User::Leave(result);
   297                     }
   356                     }
   298                 
   357 
   299                 }
   358                 }
   300             else
   359             else
   301                 {
   360                 {
   302                 //in deleted items, really delete it.
   361                 //in deleted items, really delete it.
   303                 __LOG_WRITE8_FORMAT1_INFO( "Deleting message 0x%X.", msgId );
   362                 __LOG_WRITE8_FORMAT1_INFO( "Deleting message 0x%X.", msgId );
   304 
   363 
   305                 delete theMessage;
   364                 delete theMessage;
   306                 TRAP(result,mailBox.DeleteMessageL( msgId, iFolderId ));
   365                 TRAP(result,mailBox.DeleteMessageL( msgId, iFolderId ));
   307                 if(result == KErrNone)
   366                 if (result == KErrNone)
   308                     {
   367                     {
   309                     GetPlugin().NotifyEventL( iMailBoxId, msgId, KMsgStoreInvalidId, TFSEventMailDeleted, iFolderId );
   368                     GetPlugin().NotifyEventL(iMailBoxId, msgId,
       
   369                             KMsgStoreInvalidId, TFSEventMailDeleted,
       
   370                             iFolderId);
   310                     }
   371                     }
   311                 else
   372                 else
   312                     {
   373                     {
   313                     User::Leave(result);
   374                     User::Leave(result);
   314                     }
   375                     }
   315                 }
   376                 }
   316             }
   377             }
   317         else
   378         else
   318             {        
   379             {
   319             TRAP(result,mailBox.DeleteMessageL( msgId, iFolderId ));
   380             TRAP(result,mailBox.DeleteMessageL( msgId, iFolderId ));
   320             if(result == KErrNone)
   381             if (result == KErrNone)
   321                 {  
   382                 {
   322                 GetPlugin().NotifyEventL( iMailBoxId, msgId, KMsgStoreInvalidId, TFSEventMailDeleted, iFolderId );
   383                 GetPlugin().NotifyEventL(iMailBoxId, msgId,
       
   384                         KMsgStoreInvalidId, TFSEventMailDeleted, iFolderId);
   323                 }
   385                 }
   324             else
   386             else
   325                 {
   387                 {
   326                 User::Leave(result);
   388                 User::Leave(result);
   327                 }
   389                 }
   328             }
   390             }
   329 //</qmail>
   391         //</qmail>
   330         }
   392         } 
   331     __LOG_EXIT;
   393 		__LOG_EXIT;
   332     return done;    
   394     return runAgain;
   333     }
       
   334 /**
       
   335  * 
       
   336  */
       
   337 /*private*/
       
   338 void CDelayedDeleteMessagesOp::ConstructL(
       
   339     const RArray<TFSMailMsgId>& aMessages )
       
   340     {
       
   341     __LOG_CONSTRUCT( "baseplugin", "CDelayedDeleteMessagesOp" );
       
   342             
       
   343     TInt count = aMessages.Count();
       
   344     for ( TInt i = 0; i < count; ++i )
       
   345         {
       
   346         iMessages.AppendL( aMessages[i].Id() );
       
   347         }
       
   348     }
       
   349 
       
   350 /**
       
   351  * 
       
   352  */
       
   353 /*private*/
       
   354 void CDelayedDeleteMessagesOp::ConstructL(
       
   355     TMsgStoreId aMsgId )
       
   356     {
       
   357     __LOG_CONSTRUCT( "baseplugin", "CDelayedDeleteMessagesOp" );
       
   358     iImmediateDelete = ETrue;
       
   359     iMessages.AppendL( aMsgId );
       
   360     }
       
   361 
       
   362 /**
       
   363  * 
       
   364  */
       
   365 /*private*/ CDelayedDeleteMessagesOp::CDelayedDeleteMessagesOp(
       
   366     TMsgStoreId aMailBoxId,
       
   367     TMsgStoreId aFolderId )
       
   368     :
       
   369     iMailBoxId( aMailBoxId ), iFolderId( aFolderId ),
       
   370     iImmediateDelete( EFalse ), iState ( EFree )
       
   371     {
       
   372     }
       
   373 
       
   374 /**
       
   375  * 
       
   376  */
       
   377 /*private*/ void CDelayedDeleteMessagesOp::ExecuteOpL()
       
   378     {
       
   379     __LOG_ENTER( "ExecuteOpL" );
       
   380     if ( iState != EFree )
       
   381         {
       
   382         //this code becomes re-entrant now because we use nested AS.
       
   383         // so if we are already authenticating, return right away.
       
   384         return;
       
   385         }
       
   386     iState=EInProgress;
       
   387     CNestedAO* nestedAO = CNestedAO::NewL( *this );
       
   388     //this is a blocking call with nested active scheduler
       
   389     //This method makes a callback periodically to DeleteMessagesInChunks
       
   390     //to delete the messages one chunk at a time
       
   391     nestedAO->DeleteMessagesAsync();
       
   392     //continue execution here
       
   393     delete nestedAO;
       
   394     iState = EFree;
       
   395     __LOG_EXIT;
       
   396     }
   395     }
   397 
   396 
   398 
   397 
   399 ///////////////////////////////////////////////////
   398 ///////////////////////////////////////////////////
   400 // CDelayedStorePropertiesOp                     //
   399 // CDelayedStorePropertiesOp                     //
   463     }
   462     }
   464 
   463 
   465 /**
   464 /**
   466  * CDelayedOp::ExecuteOpL
   465  * CDelayedOp::ExecuteOpL
   467  */
   466  */
   468 /*public virtual*/ void CDelayedSetContentOp::ExecuteOpL()
   467 /*public virtual*/ TBool CDelayedSetContentOp::ExecuteOpL()
   469     {
   468     {
   470     __LOG_ENTER( "ExecuteOpL" )
   469     __LOG_ENTER( "ExecuteOpL" )
   471 
   470 
   472     CMsgStoreMessagePart* part = FetchMessagePartLC();
   471     CMsgStoreMessagePart* part = FetchMessagePartLC();
   473 
   472 
   492             "Updated the properties of part 0x%X.", part->Id() )
   491             "Updated the properties of part 0x%X.", part->Id() )
   493         }
   492         }
   494     
   493     
   495     CleanupStack::PopAndDestroy( part );    
   494     CleanupStack::PopAndDestroy( part );    
   496     __LOG_EXIT
   495     __LOG_EXIT
       
   496     return EFalse;
   497     }
   497     }
   498 
   498 
   499 /**
   499 /**
   500  * 
   500  * 
   501  */
   501  */
   655     }
   655     }
   656 
   656 
   657 /**
   657 /**
   658  * 
   658  * 
   659  */
   659  */
   660 /*private*/ void CDelayedMessageStorerOp::ExecuteOpL()
   660 /*private*/ TBool CDelayedMessageStorerOp::ExecuteOpL()
   661     {
   661     {
   662     __LOG_ENTER( "ExecuteOpL" );
   662     __LOG_ENTER( "ExecuteOpL" );
   663    
   663    
   664     TFSProgress progress = { TFSProgress::EFSStatus_RequestCancelled, 0, 0, 0 };
   664     TFSProgress progress = { TFSProgress::EFSStatus_RequestCancelled, 0, 0, 0 };
   665     progress.iError = KErrNotFound;
   665     progress.iError = KErrNotFound;
   724 				iOperationObserver->RequestResponseL( progress, iRequestId );
   724 				iOperationObserver->RequestResponseL( progress, iRequestId );
   725 			}
   725 			}
   726     
   726     
   727     
   727     
   728     __LOG_EXIT;
   728     __LOG_EXIT;
       
   729 	return EFalse;
   729     }
   730     }
   730 
   731 
   731 
   732 
   732 /**
   733 /**
   733  * 
   734  * 
   826 
   827 
   827 
   828 
   828 /**
   829 /**
   829  * 
   830  * 
   830  */
   831  */
   831 /*private*/ void CDelayedMessageToSendOp::ExecuteOpL()
   832 /*private*/ TBool CDelayedMessageToSendOp::ExecuteOpL()
   832     {
   833     {
   833     __LOG_ENTER( "ExecuteOpL" );
   834     __LOG_ENTER( "ExecuteOpL" );
   834    
   835    
   835     TFSProgress progress = { TFSProgress::EFSStatus_RequestCancelled, 0, 0, 0 };
   836     TFSProgress progress = { TFSProgress::EFSStatus_RequestCancelled, 0, 0, 0 };
   836     progress.iError = KErrNotFound;
   837     progress.iError = KErrNotFound;
   848 			{
   849 			{
   849 				iOperationObserver->RequestResponseL( progress, iRequestId );
   850 				iOperationObserver->RequestResponseL( progress, iRequestId );
   850 			}
   851 			}
   851     
   852     
   852     __LOG_EXIT;
   853     __LOG_EXIT;
       
   854 	return EFalse;
   853     }
   855     }
   854 
   856 
   855 
   857 
   856 ///////////////////////////////////////////////////
   858 ///////////////////////////////////////////////////
   857 // CDelayedAddNewOrRemoveChildPartOp             //
   859 // CDelayedAddNewOrRemoveChildPartOp             //
   967     }
   969     }
   968 
   970 
   969 /**
   971 /**
   970  * 
   972  * 
   971  */
   973  */
   972 /*private*/ void CDelayedAddNewOrRemoveChildPartOp::ExecuteOpL()
   974 /*private*/ TBool CDelayedAddNewOrRemoveChildPartOp::ExecuteOpL()
   973     {
   975     {
   974     __LOG_ENTER( "ExecuteOpL" );
   976     __LOG_ENTER( "ExecuteOpL" );
   975     
   977     
   976     TFSProgress progress = { TFSProgress::EFSStatus_RequestCancelled, 0, 0, 0 };
   978     TFSProgress progress = { TFSProgress::EFSStatus_RequestCancelled, 0, 0, 0 };
   977     progress.iError = KErrNotFound;
   979     progress.iError = KErrNotFound;
  1008 			{
  1010 			{
  1009 				iOperationObserver->RequestResponseL( progress, iRequestId );
  1011 				iOperationObserver->RequestResponseL( progress, iRequestId );
  1010 			}
  1012 			}
  1011     
  1013     
  1012     __LOG_EXIT;
  1014     __LOG_EXIT;
       
  1015     return EFalse;
  1013     }
  1016     }
  1014 //</qmail>
  1017 //</qmail>