meetingrequest/mrdb/src/cesmrentrycmditeratorao.cpp
changeset 0 8466d47a6819
child 16 4ce476e64c59
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: This file implements class CESMREntryCmdIteratorAO.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //INCLUDE FILES
       
    20 #include "emailtrace.h"
       
    21 #include "cesmrentrycmditeratorao.h"
       
    22 #include "cesmrcaldbmgr.h"
       
    23 
       
    24 // CONSTANTS
       
    25 /// Unnamed namespace for local definitions
       
    26 namespace {
       
    27 
       
    28 #ifdef _DEBUG
       
    29 
       
    30 // Definition text for panics
       
    31 _LIT( KESMREntryCmdIteratorTxt, "ESMRUtilsEntryCmdIterator" );
       
    32 
       
    33 // Panic code definition
       
    34 enum TESMREntryCmdIteratorPanicCode
       
    35     {
       
    36     // Entry array not empty when iterator is inactive
       
    37     EESMRUtilsEntryCmdIteratorNonEmptyArray = 1 
       
    38     };
       
    39 
       
    40 void Panic( TESMREntryCmdIteratorPanicCode aReason )
       
    41     {
       
    42     User::Panic( KESMREntryCmdIteratorTxt, aReason );
       
    43     }
       
    44 #endif
       
    45 
       
    46 }  // namespace
       
    47 
       
    48 
       
    49 // ======== MEMBER FUNCTIONS ========
       
    50 
       
    51 // ----------------------------------------------------------------------------
       
    52 // CESMREntryCmdIteratorAO::CESMREntryCmdIteratorAO
       
    53 //
       
    54 // Constructor.
       
    55 // ----------------------------------------------------------------------------
       
    56 //
       
    57 CESMREntryCmdIteratorAO::CESMREntryCmdIteratorAO(
       
    58     MESMRCalDbMgr& aDbMgr )
       
    59     : CActive( EPriorityStandard ),
       
    60       iOpCode( CMRUtils::ENoOperation ),
       
    61       iDbMgr( aDbMgr )
       
    62     {
       
    63     FUNC_LOG;
       
    64     }
       
    65     
       
    66 // ----------------------------------------------------------------------------
       
    67 // CESMREntryCmdIteratorAO::~CESMREntryCmdIteratorAO
       
    68 //
       
    69 // Destructor.
       
    70 // ----------------------------------------------------------------------------
       
    71 //        
       
    72 CESMREntryCmdIteratorAO::~CESMREntryCmdIteratorAO()
       
    73     {
       
    74     FUNC_LOG;
       
    75     Cancel();
       
    76     iCalEntryArray.Close();    
       
    77     }
       
    78     
       
    79 // ----------------------------------------------------------------------------
       
    80 // CESMREntryCmdIteratorAO::NewL
       
    81 // ----------------------------------------------------------------------------
       
    82 //
       
    83 CESMREntryCmdIteratorAO* CESMREntryCmdIteratorAO::NewL(
       
    84     MESMRCalDbMgr& aDbMgr )
       
    85 	{
       
    86     FUNC_LOG;
       
    87 	CESMREntryCmdIteratorAO* self =
       
    88 	    new( ELeave ) CESMREntryCmdIteratorAO( aDbMgr );
       
    89 	CleanupStack::PushL( self );
       
    90 	self->ConstructL();
       
    91 	CleanupStack::Pop();
       
    92 	return self;
       
    93 	}
       
    94     
       
    95 // ----------------------------------------------------------------------------
       
    96 // CESMREntryCmdIteratorAO::ConstructL
       
    97 // ----------------------------------------------------------------------------
       
    98 //    
       
    99 void CESMREntryCmdIteratorAO::ConstructL()
       
   100     {
       
   101     FUNC_LOG;
       
   102     CActiveScheduler::Add( this );
       
   103     }
       
   104 
       
   105 // ----------------------------------------------------------------------------
       
   106 // CESMREntryCmdIteratorAO::ConstructL
       
   107 // ----------------------------------------------------------------------------
       
   108 //    
       
   109 void CESMREntryCmdIteratorAO::StartCmdIterationL(
       
   110     const RPointerArray<CCalEntry>& aCalEntryArray,
       
   111     TInt aOpCode )
       
   112     {
       
   113     FUNC_LOG;
       
   114     if ( IsActive() )
       
   115         {        
       
   116         User::Leave( KErrInUse );
       
   117         }
       
   118 
       
   119     // array must be empty when we are not active:
       
   120     __ASSERT_DEBUG( iCalEntryArray.Count() == 0,
       
   121                     Panic( EESMRUtilsEntryCmdIteratorNonEmptyArray ) );
       
   122     
       
   123             
       
   124     TInt count( aCalEntryArray.Count() );
       
   125     for ( TInt i( 0 ); i < count; ++i )
       
   126         {        
       
   127         iCalEntryArray.AppendL( aCalEntryArray[i] );
       
   128         }
       
   129         
       
   130     iOpCode = aOpCode;
       
   131     
       
   132     TRequestStatus* status = &iStatus;
       
   133     User::RequestComplete( status, KErrNone );
       
   134     SetActive();
       
   135     }
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // CESMREntryCmdIteratorAO::RunL
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 void CESMREntryCmdIteratorAO::RunL()
       
   142     {
       
   143     FUNC_LOG;
       
   144     TInt lastIndex( iCalEntryArray.Count() -1 );
       
   145     if ( lastIndex < 0 )
       
   146         { // no more items, we are finished
       
   147         iDbMgr.Completed( KErrNone );
       
   148         }
       
   149     
       
   150     else
       
   151         {            
       
   152         CCalEntry* lastEntry = iCalEntryArray[lastIndex];    
       
   153         
       
   154         switch ( iOpCode )
       
   155             {
       
   156             case CMRUtils::EDeleteEntries:
       
   157                 {
       
   158                 iDbMgr.DeleteEntryCondL( *lastEntry );
       
   159                 break;
       
   160                 }
       
   161             }
       
   162             
       
   163         // The last entry was handled and can be removed from array:
       
   164         iCalEntryArray.Remove( lastIndex );
       
   165         delete lastEntry;
       
   166         
       
   167         TRequestStatus* status = &iStatus;
       
   168         User::RequestComplete( status, KErrNone );        
       
   169         SetActive();
       
   170         }
       
   171     }
       
   172 
       
   173 // -----------------------------------------------------------------------------
       
   174 // CESMREntryCmdIteratorAO::DoCancel
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 void CESMREntryCmdIteratorAO::DoCancel()
       
   178     {
       
   179     FUNC_LOG;
       
   180     iCalEntryArray.ResetAndDestroy();
       
   181     iOpCode = CMRUtils::ENoOperation;
       
   182     }
       
   183     
       
   184 // -----------------------------------------------------------------------------
       
   185 // CESMREntryCmdIteratorAO::RunError
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 TInt CESMREntryCmdIteratorAO::RunError( TInt aError )
       
   189     {
       
   190     FUNC_LOG;
       
   191     iCalEntryArray.ResetAndDestroy();    
       
   192     iDbMgr.Completed( aError );
       
   193     iOpCode = CMRUtils::ENoOperation;    
       
   194     return KErrNone;
       
   195     }
       
   196 
       
   197 // End of file
       
   198