messagingappbase/smartmessaging/msgeditorutils/src/MsgAsyncItemSaver.cpp
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 *     Base class for implementing asyncronous item saving.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include "MsgAsyncItemSaver.h"          // Own header
       
    24 #include "MsgEditorUtils.pan"           // MsgEditorUtils panics
       
    25 #include <e32svr.h>
       
    26 
       
    27 // ================= MEMBER FUNCTIONS =======================
       
    28 
       
    29 EXPORT_C CMsgAsyncItemSaver::CMsgAsyncItemSaver() : 
       
    30 CActive( EPriorityStandard ) // superclass constructor
       
    31     {
       
    32     }
       
    33 
       
    34 EXPORT_C CMsgAsyncItemSaver::~CMsgAsyncItemSaver()
       
    35     {
       
    36     Cancel();
       
    37     }
       
    38 
       
    39 EXPORT_C void CMsgAsyncItemSaver::StartOperation(
       
    40     MMsgAsyncItemSaver* aItemSaver )
       
    41     {
       
    42     __ASSERT_DEBUG( aItemSaver, Panic( EMEUAsynItemSaverNULL ) );
       
    43     iItemSaver = aItemSaver;
       
    44 	if (!IsAdded())
       
    45 		{
       
    46 	    CActiveScheduler::Add( this );
       
    47 		}
       
    48     NextStep();
       
    49     }
       
    50 
       
    51 EXPORT_C void CMsgAsyncItemSaver::Pause( TInt aMicroSeconds )
       
    52     {
       
    53     __ASSERT_DEBUG( iItemSaver, Panic( EMEUAsynItemSaverNULL ) );
       
    54 	iPaused = ETrue;
       
    55 	iPauseDelay = aMicroSeconds;
       
    56     }
       
    57 
       
    58 EXPORT_C void CMsgAsyncItemSaver::Continue()
       
    59     {
       
    60     __ASSERT_DEBUG( iItemSaver, Panic( EMEUAsynItemSaverNULL ) );
       
    61 	if ( iPaused )
       
    62 		{
       
    63 		iPaused = EFalse;
       
    64 		NextStep();
       
    65 		}
       
    66     }
       
    67 
       
    68 void CMsgAsyncItemSaver::RunL()
       
    69     {
       
    70     __ASSERT_DEBUG( iItemSaver, Panic( EMEUAsynItemSaverNULL ) );
       
    71 	if ( iPaused )
       
    72 		{
       
    73 		iTimer.Close();
       
    74 		iPaused = EFalse;
       
    75 		}
       
    76 
       
    77 	if ( !iItemSaver->IsComplete() )
       
    78         {
       
    79         iItemSaver->ContinueOperationL();
       
    80         NextStep();
       
    81         }
       
    82     else
       
    83         {
       
    84         iItemSaver->CompleteOperationL();
       
    85         }
       
    86     }
       
    87 
       
    88 void CMsgAsyncItemSaver::DoCancel()
       
    89     {
       
    90     // Nothing to cancel
       
    91     }
       
    92 
       
    93 TInt CMsgAsyncItemSaver::RunError(TInt aError)
       
    94     {
       
    95     TInt error = iItemSaver->HandleError( aError );
       
    96     if ( error == KErrNone )
       
    97         {
       
    98         aError = error;
       
    99         NextStep();
       
   100         }
       
   101     return aError;
       
   102     }
       
   103 
       
   104 void CMsgAsyncItemSaver::NextStep()
       
   105     {
       
   106 	if ( iPaused )
       
   107 		{
       
   108 		TInt err = iTimer.CreateLocal(); // created for this thread
       
   109 		if ( err == KErrNone )
       
   110 			{
       
   111 			iTimer.After( iStatus, iPauseDelay );
       
   112 			}
       
   113 		}
       
   114 	else
       
   115 		{
       
   116 		TRequestStatus* sp = &iStatus;
       
   117 		User::RequestComplete(sp, KErrNone);
       
   118 		}
       
   119 	SetActive();
       
   120     }
       
   121 
       
   122 //  End of File