messagingappbase/smartmessaging/msgeditorutils/inc/MsgAsyncItemSaver.h
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002 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:  
       
    15 *     This is a base class for implementing asyncronous item saving.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #ifndef CMSGASYNCITEMSAVER_H
       
    22 #define CMSGASYNCITEMSAVER_H
       
    23 
       
    24 // INCLUDES
       
    25 
       
    26 #include <e32base.h>
       
    27  
       
    28 // CLASS DECLARATION
       
    29 
       
    30 /**
       
    31 * Interface for implementing the asyncronous saving operations.
       
    32 */
       
    33 class MMsgAsyncItemSaver
       
    34     {
       
    35 
       
    36     public:
       
    37         
       
    38         /**
       
    39         * Checks the status of the operation.
       
    40         * @return ETrue if the operation can be completed, EFalse
       
    41         * if the operation should continue.
       
    42         */
       
    43         virtual TBool IsComplete() const = 0;
       
    44         
       
    45         /**
       
    46         * Perform some operations and set the inner state.
       
    47         * If this leaves then RunError will be called with the
       
    48         * leave code.
       
    49         */
       
    50         virtual void ContinueOperationL() = 0;
       
    51 
       
    52         /**
       
    53         * This method is called after IsComplete() has return ETrue.
       
    54         * This method should result deleting the saver object.
       
    55         */
       
    56         virtual void CompleteOperationL() = 0;
       
    57 
       
    58         /**
       
    59         * Error handling method. If a leave occurs in ContinueOperationL
       
    60         * then this method will be called with the leave code.
       
    61         * @param aError Error code from the leave.
       
    62         * @return Error code or KErrNone if error doesn't need to be
       
    63         * handled. Returning KErrNone will continue the operation.
       
    64         */
       
    65         virtual TInt HandleError( TInt aError ) = 0;
       
    66     };
       
    67 
       
    68 /**
       
    69 * This class implements the asyncronous framework for item saving.
       
    70 */
       
    71 class CMsgAsyncItemSaver : public CActive
       
    72     {
       
    73     public: 
       
    74 
       
    75         /**
       
    76         * Constructor.
       
    77         */
       
    78         IMPORT_C CMsgAsyncItemSaver();
       
    79         
       
    80         /**
       
    81         * Destructor.
       
    82         */  
       
    83         IMPORT_C ~CMsgAsyncItemSaver();
       
    84 
       
    85         /**
       
    86          * Call this when the operation is ready to start executing.
       
    87          * Ownership of aItemSaver is not taken.
       
    88          * @param aItemSaver asyncronous item saver
       
    89          */
       
    90         IMPORT_C void StartOperation( MMsgAsyncItemSaver* aItemSaver );
       
    91 
       
    92 		/**
       
    93 		* @param aMicroseconds time to pause. By default pauses indefinitely.
       
    94 		*/
       
    95 		IMPORT_C void Pause( TInt aMicroSeconds = 0 );
       
    96 
       
    97 		IMPORT_C void Continue();
       
    98 
       
    99     protected: // from CActive
       
   100 
       
   101         void RunL();
       
   102         void DoCancel();
       
   103 	    TInt RunError(TInt aError);
       
   104 
       
   105     private: // Own
       
   106         
       
   107         /**
       
   108         * Execute the next loop.
       
   109         */
       
   110         void NextStep();
       
   111     
       
   112     private:
       
   113 
       
   114         /// Reference to the operation specific item saver.
       
   115         MMsgAsyncItemSaver* iItemSaver;
       
   116 
       
   117 		/// Saver activity state.
       
   118 		TBool iPaused;
       
   119 		RTimer iTimer;
       
   120 		TInt iPauseDelay;
       
   121     };
       
   122 
       
   123 #endif // CMSGASYNCITEMSAVER_H
       
   124 
       
   125 // End of file