landmarks/locationlandmarks/localaccess/src/EPos_CPosLmLocalOperation.cpp
changeset 0 667063e416a2
equal deleted inserted replaced
-1:000000000000 0:667063e416a2
       
     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: A local representation of the operation class.
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    <EPos_Landmarks.h>
       
    22 #include    <EPos_LandmarksErrors.h>
       
    23 #include    "EPos_CPosLmLocalOperation.h"
       
    24 #include    "EPos_TPosOperationStatus.h"
       
    25 
       
    26 // ================= MEMBER FUNCTIONS =======================
       
    27 
       
    28 // C++ default constructor can NOT contain any code, that
       
    29 // might leave.
       
    30 //
       
    31 EXPORT_C CPosLmLocalOperation::CPosLmLocalOperation(CPosLmLocalDatabase& aDb) :
       
    32     CPosLmOperation(),
       
    33     iDb(&aDb),
       
    34     iOperationStatus(EOperationNotStarted)
       
    35     {
       
    36     }
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CPosLmLocalOperation::BaseConstructL
       
    40 //
       
    41 // (other items were commented in a header).
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 EXPORT_C void CPosLmLocalOperation::BaseConstructL()
       
    45     {
       
    46     }
       
    47 
       
    48 // Destructor
       
    49 EXPORT_C CPosLmLocalOperation::~CPosLmLocalOperation()
       
    50     {
       
    51     if (iHasDbLock)
       
    52         {
       
    53         iDb->ReleaseLock(iLockType);
       
    54         }
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CPosLmLocalOperation::NextStep
       
    59 //
       
    60 // (other items were commented in a header).
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 EXPORT_C void CPosLmLocalOperation::NextStep(
       
    64     TRequestStatus& aStatus,
       
    65     TReal32& aProgress)
       
    66     {
       
    67     if (iOperationStatus == ESyncStarted ||
       
    68         iOperationStatus == EOperationCompleted)
       
    69         {
       
    70         Panic(KPosLandmarksClientPanic, EPosInvalidOperationMode);
       
    71         }
       
    72 
       
    73     iOperationStatus = EAsyncStarted;
       
    74     aStatus = KRequestPending;
       
    75 
       
    76     TInt status = KPosLmOperationNotComplete;
       
    77 
       
    78     aProgress = iProgress;
       
    79     TRAPD(err, status = NextStepL(aProgress));
       
    80     iProgress = aProgress;
       
    81     if (err != KErrNone)
       
    82         {
       
    83         status = err;
       
    84         iOperationStatus = EOperationCompleted;
       
    85         HandleError(err);
       
    86         }
       
    87     if (status == KErrNone)
       
    88         {
       
    89         iProgress = 1.0;
       
    90         aProgress = iProgress;
       
    91         iOperationStatus = EOperationCompleted;
       
    92         HandleOperationCompleted();
       
    93         }
       
    94 
       
    95     TRequestStatus* clientStatus = &aStatus;
       
    96     User::RequestComplete(clientStatus, status);
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CPosLmLocalOperation::ExecuteL
       
   101 //
       
   102 // (other items were commented in a header).
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 EXPORT_C void CPosLmLocalOperation::ExecuteL()
       
   106     {
       
   107     if (iOperationStatus != EOperationNotStarted)
       
   108         {
       
   109         Panic(KPosLandmarksClientPanic, EPosInvalidOperationMode);
       
   110         }
       
   111 
       
   112     iOperationStatus = ESyncStarted;
       
   113 
       
   114     TInt status = KPosLmOperationNotComplete;
       
   115 
       
   116     while (status != KErrNone)
       
   117         {
       
   118         TRAPD(err, status = NextStepL(iProgress));
       
   119 
       
   120         __ASSERT_DEBUG(err != KErrNone || err == KErrNone &&
       
   121             (status == KErrNone || status == KPosLmOperationNotComplete),
       
   122             Panic(KPosLandmarksClientPanic, EPosInvalidOperationMode));
       
   123 
       
   124         if (err != KErrNone)
       
   125             {
       
   126             HandleError(err);
       
   127             User::LeaveIfError(err);
       
   128             }
       
   129 
       
   130         }
       
   131 
       
   132     iOperationStatus = EOperationCompleted;
       
   133     HandleOperationCompleted();
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CPosLmLocalOperation::HandleOperationCompleted
       
   138 //
       
   139 // (other items were commented in a header).
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 void CPosLmLocalOperation::HandleOperationCompleted()
       
   143     {
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CPosLmLocalOperation::Progress
       
   148 //
       
   149 // (other items were commented in a header).
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 TReal32 CPosLmLocalOperation::Progress()
       
   153     {
       
   154     return iProgress;
       
   155     }
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CPosLmLocalOperation::AquireLockL
       
   159 //
       
   160 // (other items were commented in a header).
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 EXPORT_C void CPosLmLocalOperation::AquireLockL(
       
   164     CPosLmLocalDatabase::TLockType aLockType)
       
   165     {
       
   166     iDb->AquireLockL(aLockType);
       
   167     iHasDbLock = ETrue;
       
   168     iLockType = aLockType;
       
   169     }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CPosLmLocalOperation::ReleaseLock
       
   173 //
       
   174 // (other items were commented in a header).
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 EXPORT_C TInt CPosLmLocalOperation::ReleaseLock()
       
   178     {
       
   179     if (iHasDbLock)
       
   180         {
       
   181         TInt status = iDb->ReleaseLock(iLockType);
       
   182         if (status == KErrNone)
       
   183             {
       
   184             iHasDbLock = EFalse;
       
   185             }
       
   186         return status;
       
   187         }
       
   188     return KErrNone;
       
   189     }
       
   190 
       
   191 //  End of File