landmarksui/engine/src/CLmkAOOperation.cpp
branchRCL_3
changeset 17 1fc85118c3ae
parent 16 8173571d354e
child 18 870918037e16
equal deleted inserted replaced
16:8173571d354e 17:1fc85118c3ae
     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:    LandmarksUi Content File -
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 // INCLUDE FILES
       
    26 #include "CLmkAOOperation.h"
       
    27 #include "MLmkAOOperationObserver.h"
       
    28 #include <EPos_CPosLmOperation.h>
       
    29 #include <EPos_Landmarks.h>
       
    30 
       
    31 // CONSTANTS
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CLmkAOOperation::CLmkAOOperation
       
    37 // C++ constructor can NOT contain any code, that
       
    38 // might leave.
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 EXPORT_C CLmkAOOperation::CLmkAOOperation(
       
    42     CPosLmOperation* aLmOperation,
       
    43     MLmkAOOperationObserver& aObserver,
       
    44     MLmkAOOperationObserver::TOperationTypes aType,
       
    45     TBool aProgressNote )
       
    46     : CActive( EPriorityStandard ),
       
    47       iLmOperation( aLmOperation ),
       
    48       iObserver( aObserver ),
       
    49       iType( aType ),
       
    50       iProgressNote( aProgressNote )
       
    51     {
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CLmkAOOperation::ConstructL
       
    56 // Symbian 2nd phase constructor can leave.
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 void CLmkAOOperation::ConstructL()
       
    60     {
       
    61     CActiveScheduler::Add( this );
       
    62     iTimer.CreateLocal();
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CLmkAOOperation::NewL
       
    67 // Two-phased constructor.
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 EXPORT_C CLmkAOOperation* CLmkAOOperation::NewL(
       
    71     CPosLmOperation* aLmOperation,
       
    72     MLmkAOOperationObserver& aObserver,
       
    73     MLmkAOOperationObserver::TOperationTypes aType,
       
    74     TBool aProgressNote )
       
    75     {
       
    76     CLmkAOOperation* self =
       
    77         new ( ELeave ) CLmkAOOperation( aLmOperation, aObserver,
       
    78                                        aType, aProgressNote );
       
    79 
       
    80     CleanupStack::PushL( self );
       
    81     self->ConstructL();
       
    82     CleanupStack::Pop();
       
    83 
       
    84     return self;
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CLmkAOOperation::~CLmkAOOperation
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 EXPORT_C CLmkAOOperation::~CLmkAOOperation()
       
    92     {
       
    93     iTimer.Close();
       
    94     Cancel();
       
    95     delete iLmOperation;
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CLmkAOOperation::StartOperation
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 EXPORT_C void CLmkAOOperation::StartOperation()
       
   103     {
       
   104     iLmOperation->NextStep( iStatus, iProgress );
       
   105     SetActive();
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CLmkAOOperation::StopOperation
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 EXPORT_C void CLmkAOOperation::StopOperation()
       
   113     {
       
   114     iTimer.Close();
       
   115     if (iLmOperation)
       
   116 	    {
       
   117 	    delete iLmOperation;
       
   118 	    iLmOperation = NULL;
       
   119 	    }
       
   120     }
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CLmkAOOperation::RunL
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 void CLmkAOOperation::RunL()
       
   127     {
       
   128     if ( iStatus == KPosLmOperationNotComplete || iIsTimerSet)
       
   129         {
       
   130         if ( iProgressNote && (!iIsTimerSet ))
       
   131             {
       
   132             iObserver.HandleOperationL( iType, iProgress, iStatus.Int() );
       
   133             }
       
   134         if(iLmOperation)
       
   135         	{
       
   136 	        iLmOperation->NextStep( iStatus, iProgress );
       
   137 	        iIsTimerSet = EFalse;
       
   138 	        SetActive();
       
   139         	}
       
   140         }
       
   141     else if (iStatus == KErrLocked)
       
   142         {
       
   143            iTimer.After(iStatus,1);
       
   144            iIsTimerSet = ETrue;
       
   145         SetActive();
       
   146         }
       
   147     else
       
   148         {
       
   149         /*
       
   150         * The current way, in which the active object handled is, once the HandleOperationL
       
   151         * is called, it destroys this active object inside the HandleOperationL, hence,
       
   152         * if HandleOperationL leaves, AcvtiveScheduler will try to call RunError, in turn will crash,
       
   153         * so implementer of HandleOperationL must delete the current active object after all the
       
   154         * leavable codes, also if it is required, iStatus can be set as KErrLocked by the
       
   155         * HandleOperationL code to re-issue the request in case of failures.
       
   156         */
       
   157         TRAP_IGNORE(iObserver.HandleOperationL( iType, iProgress, iStatus.Int() ));
       
   158         }
       
   159     }
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // CLmkAOOperation::DoCancel
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 void CLmkAOOperation::DoCancel()
       
   166     {
       
   167     iTimer.Close();
       
   168     if (iLmOperation)
       
   169 	    {
       
   170 	    delete iLmOperation;
       
   171 	    iLmOperation = NULL;
       
   172 	    }
       
   173     }
       
   174 
       
   175 //  End of File