contentctrl_plat/ds_contact_adapter_customization_api/tsrc/ContactsAdapter/cnsmldummydatastorewaiter.cpp
branchRCL_3
changeset 24 8e7494275d3a
equal deleted inserted replaced
23:2bb96f4ecad8 24:8e7494275d3a
       
     1 /*
       
     2 * Copyright (c) 2009 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:  Source code file for datastorewaiter helper class.
       
    15 *
       
    16 */
       
    17 
       
    18 //  CLASS HEADER
       
    19 #include "cnsmldummydatastorewaiter.h"
       
    20 
       
    21 // INTERNAL INCLUDES
       
    22 #include "nsmldummydatastore.h"
       
    23 
       
    24 //  EXTERNAL INCLUDES
       
    25 #include <eunitmacros.h>
       
    26 
       
    27 // CONSTANTS
       
    28 
       
    29 
       
    30 // --- Constructors & destructors --------------------------------------------
       
    31 CNSmlDummyDataStoreWaiter* CNSmlDummyDataStoreWaiter::NewL(
       
    32         CNSmlDummyDataStore& aStore )
       
    33     {
       
    34     CNSmlDummyDataStoreWaiter* self =
       
    35         CNSmlDummyDataStoreWaiter::NewLC( aStore );
       
    36     CleanupStack::Pop( self );
       
    37 
       
    38     return self;
       
    39     }
       
    40 
       
    41 CNSmlDummyDataStoreWaiter* CNSmlDummyDataStoreWaiter::NewLC(
       
    42     CNSmlDummyDataStore& aStore )
       
    43     {
       
    44     CNSmlDummyDataStoreWaiter* self =
       
    45         new ( ELeave ) CNSmlDummyDataStoreWaiter( aStore );
       
    46     CleanupStack::PushL( self );
       
    47     self->ConstructL();
       
    48 
       
    49     return self;
       
    50     }
       
    51 
       
    52 CNSmlDummyDataStoreWaiter::~CNSmlDummyDataStoreWaiter()
       
    53     {
       
    54     Cancel();
       
    55     delete iWait;
       
    56     iOpen = EFalse;
       
    57     }
       
    58 
       
    59 CNSmlDummyDataStoreWaiter::CNSmlDummyDataStoreWaiter(
       
    60     CNSmlDummyDataStore& aStore ):
       
    61     CActive( EPriorityNormal ), iStore( aStore ), iOpen( EFalse )
       
    62     {
       
    63 
       
    64     }
       
    65 
       
    66 void CNSmlDummyDataStoreWaiter::ConstructL()
       
    67     {
       
    68     CActiveScheduler::Add( this );
       
    69     iWait = new ( ELeave ) CActiveSchedulerWait();
       
    70     }
       
    71 
       
    72 // --- From CActive ----------------------------------------------------------
       
    73 void CNSmlDummyDataStoreWaiter::DoCancel()
       
    74     {
       
    75     iStore.CancelRequest();
       
    76     }
       
    77 
       
    78 void CNSmlDummyDataStoreWaiter::RunL()
       
    79     {
       
    80     iWait->AsyncStop();
       
    81     }
       
    82 
       
    83 // --- Test methods -----------------------------------------------------------
       
    84 
       
    85 void CNSmlDummyDataStoreWaiter::OpenStoreL( MSmlSyncRelationship& aRelationship, 
       
    86     const TDesC& /*aStoreName*/ )
       
    87     {
       
    88     Cancel();
       
    89     iStore.OpenL( _L("C:Contacts.cdb"), aRelationship, iStatus );
       
    90     SetActive();
       
    91 
       
    92     if( !iWait->IsStarted() )
       
    93         {
       
    94         iWait->Start();
       
    95         }
       
    96     iOpen = ETrue;
       
    97     }
       
    98 
       
    99 TInt CNSmlDummyDataStoreWaiter::DoCommitChangeInfoL(
       
   100     const MSmlDataItemUidSet& aItems )
       
   101     {
       
   102     if( !iOpen )
       
   103         {
       
   104         User::Leave( KErrNotReady );
       
   105         }
       
   106 
       
   107     Cancel();
       
   108     iStore.DoCommitChangeInfoL( iStatus, aItems );
       
   109     SetActive();
       
   110 
       
   111     if( !iWait->IsStarted() )
       
   112         {
       
   113         iWait->Start();
       
   114         }
       
   115 
       
   116     return iStatus.Int();
       
   117     }
       
   118 
       
   119 TInt CNSmlDummyDataStoreWaiter::DoResetChangeInfoL()
       
   120     {
       
   121     if( !iOpen )
       
   122         {
       
   123         User::Leave( KErrNotReady );
       
   124         }
       
   125 
       
   126     Cancel();
       
   127     iStore.DoResetChangeInfoL( iStatus );
       
   128     SetActive();
       
   129 
       
   130     if( !iWait->IsStarted() )
       
   131         {
       
   132         iWait->Start();
       
   133         }
       
   134 
       
   135     return iStatus.Int();
       
   136     }
       
   137 
       
   138 TInt CNSmlDummyDataStoreWaiter::DoCommitChangeInfoL()
       
   139     {
       
   140     if( !iOpen )
       
   141         {
       
   142         User::Leave( KErrNotReady );
       
   143         }
       
   144 
       
   145     Cancel();
       
   146     iStore.DoCommitChangeInfoL( iStatus );
       
   147     SetActive();
       
   148 
       
   149     if( !iWait->IsStarted() )
       
   150         {
       
   151         iWait->Start();
       
   152         }
       
   153 
       
   154     return iStatus.Int();
       
   155     }
       
   156 
       
   157 // Item addition in "normal" (non-batch) mode
       
   158 TInt CNSmlDummyDataStoreWaiter::DoCreateItemL( TSmlDbItemUid& aUid,
       
   159     TInt aSize, const TDesC8& aMimeType, const TDesC8& aMimeVer )
       
   160     {
       
   161     if( !iOpen )
       
   162         {
       
   163         User::Leave( KErrNotReady );
       
   164         }
       
   165     Cancel();
       
   166     iStore.DoCreateItemL( aUid, aSize, 0, aMimeType, aMimeVer, iStatus );
       
   167 
       
   168     SetActive();
       
   169 
       
   170     if( !iWait->IsStarted() )
       
   171         {
       
   172         iWait->Start();
       
   173         }
       
   174 
       
   175     return iStatus.Int();
       
   176     }
       
   177 
       
   178 TInt CNSmlDummyDataStoreWaiter::DoCommitItemL()
       
   179     {
       
   180     if( !iOpen )
       
   181         {
       
   182         User::Leave( KErrNotReady );
       
   183         }
       
   184     Cancel();
       
   185     iStore.DoCommitItemL( iStatus );
       
   186 
       
   187     SetActive();
       
   188 
       
   189     if( !iWait->IsStarted() )
       
   190         {
       
   191         iWait->Start();
       
   192         }
       
   193 
       
   194     return iStatus.Int();
       
   195     }
       
   196 
       
   197 TInt CNSmlDummyDataStoreWaiter::DoCommitBatchL( RArray<TInt>& aResultArray )
       
   198     {
       
   199     if( !iOpen )
       
   200         {
       
   201         User::Leave( KErrNotReady );
       
   202         }
       
   203     Cancel();
       
   204     iStore.DoCommitBatchL( aResultArray, iStatus );
       
   205 
       
   206     SetActive();
       
   207 
       
   208     if( !iWait->IsStarted() )
       
   209         {
       
   210         iWait->Start();
       
   211         }
       
   212 
       
   213     return iStatus.Int();
       
   214     }
       
   215 
       
   216 void CNSmlDummyDataStoreWaiter::DoCancelBatch()
       
   217     {
       
   218     if( !iOpen )
       
   219         {
       
   220         return;
       
   221         }
       
   222     iStore.DoCancelBatch();
       
   223     }
       
   224 
       
   225 TInt CNSmlDummyDataStoreWaiter::DoOpenItemL( TSmlDbItemUid aUid,
       
   226     TBool& aFieldChange, TInt& aSize, TSmlDbItemUid& aParent,
       
   227     TDes8& aMimeType, TDes8& aMimeVer )
       
   228     {
       
   229     if( !iOpen )
       
   230         {
       
   231         User::Leave( KErrNotReady );
       
   232         }
       
   233     Cancel();
       
   234     iStore.OpenItemL( aUid, aFieldChange, aSize, aParent, aMimeType,
       
   235         aMimeVer, iStatus );
       
   236 
       
   237     SetActive();
       
   238 
       
   239     if( !iWait->IsStarted() )
       
   240         {
       
   241         iWait->Start();
       
   242         }
       
   243 
       
   244     return iStatus.Int();
       
   245     }
       
   246 
       
   247 TInt CNSmlDummyDataStoreWaiter::DoReplaceItemL( TSmlDbItemUid aUid,
       
   248     TInt aSize, TSmlDbItemUid aParent, TBool aFieldChange )
       
   249     {
       
   250     if( !iOpen )
       
   251         {
       
   252         User::Leave( KErrNotReady );
       
   253         }
       
   254     Cancel();
       
   255     iStore.ReplaceItemL( aUid, aSize, aParent, aFieldChange, iStatus );
       
   256     SetActive();
       
   257     if( !iWait->IsStarted() )
       
   258         {
       
   259         iWait->Start();
       
   260         }
       
   261     return iStatus.Int();
       
   262     }
       
   263 
       
   264 TInt CNSmlDummyDataStoreWaiter::DoDeleteItemL( TSmlDbItemUid aUid )
       
   265     {
       
   266     if( !iOpen )
       
   267         {
       
   268         User::Leave( KErrNotReady );
       
   269         }
       
   270     Cancel();
       
   271     iStore.DeleteItemL( aUid, iStatus );
       
   272 
       
   273     SetActive();
       
   274 
       
   275     if( !iWait->IsStarted() )
       
   276         {
       
   277         iWait->Start();
       
   278         }
       
   279 
       
   280     return iStatus.Int();
       
   281     }
       
   282 
       
   283 TInt CNSmlDummyDataStoreWaiter::DoDeleteAllItemsL()
       
   284     {
       
   285     if( !iOpen )
       
   286         {
       
   287         User::Leave( KErrNotReady );
       
   288         }
       
   289     Cancel();
       
   290     iStore.DeleteAllItemsL( iStatus );
       
   291 
       
   292     SetActive();
       
   293 
       
   294     if( !iWait->IsStarted() )
       
   295         {
       
   296         iWait->Start();
       
   297         }
       
   298 
       
   299     return iStatus.Int();
       
   300     }
       
   301 
       
   302 // End of file