pushmtm/MtmCliSrvSrc/PushMtmGcOperation.cpp
changeset 32 92a061761a7b
parent 0 84ad3b177aa3
equal deleted inserted replaced
31:868cceedabd3 32:92a061761a7b
    21 
    21 
    22 #include "PushMtmGcOperation.h"
    22 #include "PushMtmGcOperation.h"
    23 #include "PushMtmCliSrvPanic.h"
    23 #include "PushMtmCliSrvPanic.h"
    24 #include "PushMtmUtil.h"
    24 #include "PushMtmUtil.h"
    25 #include "PushMtmLog.h"
    25 #include "PushMtmLog.h"
    26 #include <CSIPushMsgEntry.h>
    26 #include <push/CSIPushMsgEntry.h>
    27 #include <msvids.h>
    27 #include <msvids.h>
    28 
    28 
    29 // ================= MEMBER FUNCTIONS =======================
    29 // ================= MEMBER FUNCTIONS =======================
    30 
    30 
    31 // ---------------------------------------------------------
    31 // ---------------------------------------------------------
    36                                 CMsvSession& aSession,
    36                                 CMsvSession& aSession,
    37                                 TMsvId aFolderId,
    37                                 TMsvId aFolderId,
    38                                 TRequestStatus& aObserverRequestStatus )
    38                                 TRequestStatus& aObserverRequestStatus )
    39     {
    39     {
    40     PUSHLOG_ENTERFN("CPushMtmGcOperation::NewL")
    40     PUSHLOG_ENTERFN("CPushMtmGcOperation::NewL")
    41     
    41 
    42     CPushMtmGcOperation* self = new (ELeave) CPushMtmGcOperation
    42     CPushMtmGcOperation* self = new (ELeave) CPushMtmGcOperation
    43         ( aSession, aFolderId, aObserverRequestStatus );
    43         ( aSession, aFolderId, aObserverRequestStatus );
    44     CleanupStack::PushL( self );
    44     CleanupStack::PushL( self );
    45     self->ConstructL();
    45     self->ConstructL();
    46     CleanupStack::Pop(); // self
    46     CleanupStack::Pop(); // self
    47     
    47 
    48     PUSHLOG_LEAVEFN("CPushMtmGcOperation::NewL")
    48     PUSHLOG_LEAVEFN("CPushMtmGcOperation::NewL")
    49     return self;
    49     return self;
    50     }
    50     }
    51 
    51 
    52 // ---------------------------------------------------------
    52 // ---------------------------------------------------------
    54 // ---------------------------------------------------------
    54 // ---------------------------------------------------------
    55 //
    55 //
    56 CPushMtmGcOperation::~CPushMtmGcOperation()
    56 CPushMtmGcOperation::~CPushMtmGcOperation()
    57     {
    57     {
    58     PUSHLOG_ENTERFN("CPushMtmGcOperation::~CPushMtmGcOperation")
    58     PUSHLOG_ENTERFN("CPushMtmGcOperation::~CPushMtmGcOperation")
    59     
    59 
    60     Cancel();
    60     Cancel();
    61     delete iEntrySel;
    61     delete iEntrySel;
    62     delete iEntryWrapper;
    62     delete iEntryWrapper;
    63     delete iUtil;
    63     delete iUtil;
    64     
    64 
    65     PUSHLOG_LEAVEFN("CPushMtmGcOperation::~CPushMtmGcOperation")
    65     PUSHLOG_LEAVEFN("CPushMtmGcOperation::~CPushMtmGcOperation")
    66     }
    66     }
    67 
    67 
    68 // ---------------------------------------------------------
    68 // ---------------------------------------------------------
    69 // CPushMtmGcOperation::DoSyncL
    69 // CPushMtmGcOperation::DoSyncL
    70 // ---------------------------------------------------------
    70 // ---------------------------------------------------------
    71 //
    71 //
    72 void CPushMtmGcOperation::DoSyncL()
    72 void CPushMtmGcOperation::DoSyncL()
    73     {
    73     {
    74     PUSHLOG_ENTERFN("CPushMtmGcOperation::DoSyncL")
    74     PUSHLOG_ENTERFN("CPushMtmGcOperation::DoSyncL")
    75     
    75 
    76     InitL();
    76     InitL();
    77     
    77 
    78     for ( iCurrentIndex = 0; iCurrentIndex < iCount; ++iCurrentIndex )
    78     for ( iCurrentIndex = 0; iCurrentIndex < iCount; ++iCurrentIndex )
    79         {
    79         {
    80         // iCurrentIndex indicate the current entry in the selection.
    80         // iCurrentIndex indicate the current entry in the selection.
    81         GcCurrentL();
    81         GcCurrentL();
    82         }
    82         }
    83 
    83 
    84     // Release unnecessary resources.
    84     // Release unnecessary resources.
    85     delete iEntrySel;
    85     delete iEntrySel;
    86     iEntrySel = NULL;
    86     iEntrySel = NULL;
    87     
    87 
    88     PUSHLOG_LEAVEFN("CPushMtmGcOperation::DoSyncL")
    88     PUSHLOG_LEAVEFN("CPushMtmGcOperation::DoSyncL")
    89     }
    89     }
    90 
    90 
    91 // ---------------------------------------------------------
    91 // ---------------------------------------------------------
    92 // CPushMtmGcOperation::CPushMtmGcOperation
    92 // CPushMtmGcOperation::CPushMtmGcOperation
    93 // ---------------------------------------------------------
    93 // ---------------------------------------------------------
    94 //
    94 //
    95 CPushMtmGcOperation::CPushMtmGcOperation( CMsvSession& aSession, 
    95 CPushMtmGcOperation::CPushMtmGcOperation( CMsvSession& aSession,
    96                                           TMsvId aFolderId, 
    96                                           TMsvId aFolderId,
    97                                           TRequestStatus& aObserverRequestStatus ) 
    97                                           TRequestStatus& aObserverRequestStatus )
    98 :   CPushMtmOperation( aSession, KMsvNullIndexEntryId, aObserverRequestStatus ), 
    98 :   CPushMtmOperation( aSession, KMsvNullIndexEntryId, aObserverRequestStatus ),
    99     iState( EInit ), iFolderId( aFolderId ), iCurrentIndex( 0 )
    99     iState( EInit ), iFolderId( aFolderId ), iCurrentIndex( 0 )
   100     {
   100     {
   101     }
   101     }
   102 
   102 
   103 // ---------------------------------------------------------
   103 // ---------------------------------------------------------
   114 // ---------------------------------------------------------
   114 // ---------------------------------------------------------
   115 //
   115 //
   116 void CPushMtmGcOperation::InitL()
   116 void CPushMtmGcOperation::InitL()
   117     {
   117     {
   118     PUSHLOG_ENTERFN("CPushMtmGcOperation::InitL")
   118     PUSHLOG_ENTERFN("CPushMtmGcOperation::InitL")
   119     
   119 
   120     if ( !iUtil )
   120     if ( !iUtil )
   121         {
   121         {
   122         iUtil = CPushMtmUtil::NewL( iMsvSession );
   122         iUtil = CPushMtmUtil::NewL( iMsvSession );
   123         }
   123         }
   124 
   124 
   150     // We need a wrapper only if there is entry to delete.
   150     // We need a wrapper only if there is entry to delete.
   151     if ( iCount && !iEntryWrapper )
   151     if ( iCount && !iEntryWrapper )
   152         {
   152         {
   153         iEntryWrapper = CSIPushMsgEntry::NewL();
   153         iEntryWrapper = CSIPushMsgEntry::NewL();
   154         }
   154         }
   155         
   155 
   156     PUSHLOG_LEAVEFN("CPushMtmGcOperation::InitL")
   156     PUSHLOG_LEAVEFN("CPushMtmGcOperation::InitL")
   157     }
   157     }
   158 
   158 
   159 // ---------------------------------------------------------
   159 // ---------------------------------------------------------
   160 // CPushMtmGcOperation::GcCurrentL
   160 // CPushMtmGcOperation::GcCurrentL
   161 // ---------------------------------------------------------
   161 // ---------------------------------------------------------
   162 //
   162 //
   163 void CPushMtmGcOperation::GcCurrentL()
   163 void CPushMtmGcOperation::GcCurrentL()
   164     {
   164     {
   165     PUSHLOG_ENTERFN("CPushMtmGcOperation::GcCurrentL")
   165     PUSHLOG_ENTERFN("CPushMtmGcOperation::GcCurrentL")
   166     
   166 
   167     PUSHLOG_WRITE_FORMAT(" iCurrentIndex: %d",iCurrentIndex)
   167     PUSHLOG_WRITE_FORMAT(" iCurrentIndex: %d",iCurrentIndex)
   168     TMsvId entryId( iEntrySel->At(iCurrentIndex) );
   168     TMsvId entryId( iEntrySel->At(iCurrentIndex) );
   169 
   169 
   170 #ifdef _DEBUG
   170 #ifdef _DEBUG
   171     TMsvEntry tEntry;
   171     TMsvEntry tEntry;
   172     TMsvId dummyService;
   172     TMsvId dummyService;
   173     User::LeaveIfError
   173     User::LeaveIfError
   174         ( iMsvSession.GetEntry( entryId, dummyService, tEntry ) );
   174         ( iMsvSession.GetEntry( entryId, dummyService, tEntry ) );
   175 
   175 
   176     __ASSERT_DEBUG( tEntry.iMtm == KUidMtmWapPush && 
   176     __ASSERT_DEBUG( tEntry.iMtm == KUidMtmWapPush &&
   177                     tEntry.iBioType == KUidWapPushMsgSI.iUid, 
   177                     tEntry.iBioType == KUidWapPushMsgSI.iUid,
   178                     CliSrvPanic( EPushMtmCliSrvPanBadType ) );
   178                     CliSrvPanic( EPushMtmCliSrvPanBadType ) );
   179 #endif // _DEBUG
   179 #endif // _DEBUG
   180 
   180 
   181     iEntryWrapper->RetrieveL( iMsvSession, entryId );
   181     iEntryWrapper->RetrieveL( iMsvSession, entryId );
   182     // Check expiration if expiration time was set.
   182     // Check expiration if expiration time was set.
   186 	    today.UniversalTime();
   186 	    today.UniversalTime();
   187         if ( iEntryWrapper->Expires() < today )
   187         if ( iEntryWrapper->Expires() < today )
   188 		    {
   188 		    {
   189 		    PUSHLOG_WRITE(" Expired")
   189 		    PUSHLOG_WRITE(" Expired")
   190             // The message has expired. Delete it.
   190             // The message has expired. Delete it.
   191             CMsvEntry* cParent = 
   191             CMsvEntry* cParent =
   192                 iMsvSession.GetEntryL( iEntryWrapper->Entry().Parent() );
   192                 iMsvSession.GetEntryL( iEntryWrapper->Entry().Parent() );
   193             CleanupStack::PushL( cParent );
   193             CleanupStack::PushL( cParent );
   194             // Delete the message.
   194             // Delete the message.
   195             cParent->DeleteL( entryId );
   195             cParent->DeleteL( entryId );
   196             CleanupStack::PopAndDestroy(); // cParent
   196             CleanupStack::PopAndDestroy(); // cParent
   197             }
   197             }
   198         }
   198         }
   199         
   199 
   200     PUSHLOG_LEAVEFN("CPushMtmGcOperation::GcCurrentL")
   200     PUSHLOG_LEAVEFN("CPushMtmGcOperation::GcCurrentL")
   201     }
   201     }
   202 
   202 
   203 // ---------------------------------------------------------
   203 // ---------------------------------------------------------
   204 // CPushMtmGcOperation::RunL
   204 // CPushMtmGcOperation::RunL
   205 // ---------------------------------------------------------
   205 // ---------------------------------------------------------
   206 //
   206 //
   207 void CPushMtmGcOperation::RunL()
   207 void CPushMtmGcOperation::RunL()
   208     {
   208     {
   209     PUSHLOG_ENTERFN("CPushMtmGcOperation::RunL")
   209     PUSHLOG_ENTERFN("CPushMtmGcOperation::RunL")
   210     
   210 
   211     if ( iState == EInit )
   211     if ( iState == EInit )
   212         {
   212         {
   213         InitL();
   213         InitL();
   214         if ( !iCount )
   214         if ( !iCount )
   215             {
   215             {
   223             InvokeRun();
   223             InvokeRun();
   224             }
   224             }
   225         }
   225         }
   226     else if ( iState == EGarbageCollecting )
   226     else if ( iState == EGarbageCollecting )
   227         {
   227         {
   228         __ASSERT_DEBUG( iCount, 
   228         __ASSERT_DEBUG( iCount,
   229             CliSrvPanic( EPushMtmCliSrvPanEmptySelection ) );
   229             CliSrvPanic( EPushMtmCliSrvPanEmptySelection ) );
   230         // iCurrentIndex indicate the current entry in the selection.
   230         // iCurrentIndex indicate the current entry in the selection.
   231         GcCurrentL();
   231         GcCurrentL();
   232         if ( ++iCurrentIndex < iCount )
   232         if ( ++iCurrentIndex < iCount )
   233             {
   233             {
   241             SignalObserver( KErrNone );
   241             SignalObserver( KErrNone );
   242             }
   242             }
   243         }
   243         }
   244     else
   244     else
   245         {
   245         {
   246         __ASSERT_DEBUG( EFalse, 
   246         __ASSERT_DEBUG( EFalse,
   247             CliSrvPanic( EPushMtmCliSrvPanCommandNotSupported ) );
   247             CliSrvPanic( EPushMtmCliSrvPanCommandNotSupported ) );
   248         }
   248         }
   249         
   249 
   250     PUSHLOG_LEAVEFN("CPushMtmGcOperation::RunL")
   250     PUSHLOG_LEAVEFN("CPushMtmGcOperation::RunL")
   251     }
   251     }
   252 
   252 
   253 // ---------------------------------------------------------
   253 // ---------------------------------------------------------
   254 // CPushMtmGcOperation::DoCancel
   254 // CPushMtmGcOperation::DoCancel
   255 // ---------------------------------------------------------
   255 // ---------------------------------------------------------
   256 //
   256 //
   257 void CPushMtmGcOperation::DoCancel()
   257 void CPushMtmGcOperation::DoCancel()
   258     {
   258     {
   259     PUSHLOG_ENTERFN("CPushMtmGcOperation::DoCancel")
   259     PUSHLOG_ENTERFN("CPushMtmGcOperation::DoCancel")
   260     
   260 
   261     CPushMtmOperation::DoCancel();
   261     CPushMtmOperation::DoCancel();
   262     
   262 
   263     PUSHLOG_LEAVEFN("CPushMtmGcOperation::DoCancel")
   263     PUSHLOG_LEAVEFN("CPushMtmGcOperation::DoCancel")
   264     }
   264     }
   265 
   265 
   266 // ---------------------------------------------------------
   266 // ---------------------------------------------------------
   267 // CPushMtmGcOperation::RunError
   267 // CPushMtmGcOperation::RunError
   269 //
   269 //
   270 TInt CPushMtmGcOperation::RunError( TInt aError )
   270 TInt CPushMtmGcOperation::RunError( TInt aError )
   271     {
   271     {
   272     PUSHLOG_ENTERFN("CPushMtmGcOperation::RunError")
   272     PUSHLOG_ENTERFN("CPushMtmGcOperation::RunError")
   273     PUSHLOG_WRITE_FORMAT(" aError: %d",aError)
   273     PUSHLOG_WRITE_FORMAT(" aError: %d",aError)
   274     
   274 
   275     TBool doContinue( EFalse );
   275     TBool doContinue( EFalse );
   276 
   276 
   277     PUSHLOG_WRITE_FORMAT(" iState: %d",iState)
   277     PUSHLOG_WRITE_FORMAT(" iState: %d",iState)
   278     if ( iState == EInit )
   278     if ( iState == EInit )
   279         {
   279         {
   293                 }
   293                 }
   294             }
   294             }
   295         }
   295         }
   296     else
   296     else
   297         {
   297         {
   298         __ASSERT_DEBUG( EFalse, 
   298         __ASSERT_DEBUG( EFalse,
   299             CliSrvPanic( EPushMtmCliSrvPanCommandNotSupported ) );
   299             CliSrvPanic( EPushMtmCliSrvPanCommandNotSupported ) );
   300         }
   300         }
   301 
   301 
   302     TInt ret = KErrNone;
   302     TInt ret = KErrNone;
   303     if ( doContinue )
   303     if ( doContinue )