contentctrl_plat/adapter_customization_api/tsrc/ContactAdapter/cnsmldummydatastorewaiter.cpp
branchRCL_3
changeset 52 4f0867e42d62
parent 14 b922b9936679
equal deleted inserted replaced
51:8e7494275d3a 52:4f0867e42d62
       
     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     if ( aStoreName == KNSmlContactStoreNameForDefaultDB )
       
    90         {
       
    91         iStore.OpenL( KNSmlContactStoreNameForDefaultDB, aRelationship, iStatus );
       
    92         }
       
    93     else
       
    94         {
       
    95         iStore.OpenL( aStoreName, aRelationship, iStatus );
       
    96         }
       
    97     SetActive();
       
    98 
       
    99     if( !iWait->IsStarted() )
       
   100         {
       
   101         iWait->Start();
       
   102         }
       
   103     iOpen = ETrue;
       
   104     }
       
   105 
       
   106 TInt CNSmlDummyDataStoreWaiter::DoCommitChangeInfoL(
       
   107     const MSmlDataItemUidSet& aItems )
       
   108     {
       
   109     if( !iOpen )
       
   110         {
       
   111         User::Leave( KErrNotReady );
       
   112         }
       
   113 
       
   114     Cancel();
       
   115     iStore.DoCommitChangeInfoL( iStatus, aItems );
       
   116     SetActive();
       
   117 
       
   118     if( !iWait->IsStarted() )
       
   119         {
       
   120         iWait->Start();
       
   121         }
       
   122 
       
   123     return iStatus.Int();
       
   124     }
       
   125 
       
   126 TInt CNSmlDummyDataStoreWaiter::DoResetChangeInfoL()
       
   127     {
       
   128     if( !iOpen )
       
   129         {
       
   130         User::Leave( KErrNotReady );
       
   131         }
       
   132 
       
   133     Cancel();
       
   134     iStore.DoResetChangeInfoL( iStatus );
       
   135     SetActive();
       
   136 
       
   137     if( !iWait->IsStarted() )
       
   138         {
       
   139         iWait->Start();
       
   140         }
       
   141 
       
   142     return iStatus.Int();
       
   143     }
       
   144 
       
   145 TInt CNSmlDummyDataStoreWaiter::DoCommitChangeInfoL()
       
   146     {
       
   147     if( !iOpen )
       
   148         {
       
   149         User::Leave( KErrNotReady );
       
   150         }
       
   151 
       
   152     Cancel();
       
   153     iStore.DoCommitChangeInfoL( iStatus );
       
   154     SetActive();
       
   155 
       
   156     if( !iWait->IsStarted() )
       
   157         {
       
   158         iWait->Start();
       
   159         }
       
   160 
       
   161     return iStatus.Int();
       
   162     }
       
   163 
       
   164 // Item addition in "normal" (non-batch) mode
       
   165 TInt CNSmlDummyDataStoreWaiter::DoCreateItemL( TSmlDbItemUid& aUid,
       
   166     TInt aSize, const TDesC8& aMimeType, const TDesC8& aMimeVer )
       
   167     {
       
   168     if( !iOpen )
       
   169         {
       
   170         User::Leave( KErrNotReady );
       
   171         }
       
   172     Cancel();
       
   173     iStore.DoCreateItemL( aUid, aSize, 0, aMimeType, aMimeVer, iStatus );
       
   174 
       
   175     SetActive();
       
   176 
       
   177     if( !iWait->IsStarted() )
       
   178         {
       
   179         iWait->Start();
       
   180         }
       
   181 
       
   182     return iStatus.Int();
       
   183     }
       
   184 
       
   185 TInt CNSmlDummyDataStoreWaiter::DoCommitItemL()
       
   186     {
       
   187     if( !iOpen )
       
   188         {
       
   189         User::Leave( KErrNotReady );
       
   190         }
       
   191     Cancel();
       
   192     iStore.DoCommitItemL( iStatus );
       
   193 
       
   194     SetActive();
       
   195 
       
   196     if( !iWait->IsStarted() )
       
   197         {
       
   198         iWait->Start();
       
   199         }
       
   200 
       
   201     return iStatus.Int();
       
   202     }
       
   203 
       
   204 TInt CNSmlDummyDataStoreWaiter::DoCommitBatchL( RArray<TInt>& aResultArray )
       
   205     {
       
   206     if( !iOpen )
       
   207         {
       
   208         User::Leave( KErrNotReady );
       
   209         }
       
   210     Cancel();
       
   211     iStore.DoCommitBatchL( aResultArray, iStatus );
       
   212 
       
   213     SetActive();
       
   214 
       
   215     if( !iWait->IsStarted() )
       
   216         {
       
   217         iWait->Start();
       
   218         }
       
   219 
       
   220     return iStatus.Int();
       
   221     }
       
   222 
       
   223 void CNSmlDummyDataStoreWaiter::DoCancelBatch()
       
   224     {
       
   225     if( !iOpen )
       
   226         {
       
   227         return;
       
   228         }
       
   229     iStore.DoCancelBatch();
       
   230     }
       
   231 
       
   232 TInt CNSmlDummyDataStoreWaiter::DoOpenItemL( TSmlDbItemUid aUid,
       
   233     TBool& aFieldChange, TInt& aSize, TSmlDbItemUid& aParent,
       
   234     TDes8& aMimeType, TDes8& aMimeVer )
       
   235     {
       
   236     if( !iOpen )
       
   237         {
       
   238         User::Leave( KErrNotReady );
       
   239         }
       
   240     Cancel();
       
   241     iStore.OpenItemL( aUid, aFieldChange, aSize, aParent, aMimeType,
       
   242         aMimeVer, iStatus );
       
   243 
       
   244     SetActive();
       
   245 
       
   246     if( !iWait->IsStarted() )
       
   247         {
       
   248         iWait->Start();
       
   249         }
       
   250 
       
   251     return iStatus.Int();
       
   252     }
       
   253 
       
   254 TInt CNSmlDummyDataStoreWaiter::DoReplaceItemL( TSmlDbItemUid aUid,
       
   255     TInt aSize, TSmlDbItemUid aParent, TBool aFieldChange )
       
   256     {
       
   257     if( !iOpen )
       
   258         {
       
   259         User::Leave( KErrNotReady );
       
   260         }
       
   261     Cancel();
       
   262     iStore.ReplaceItemL( aUid, aSize, aParent, aFieldChange, iStatus );
       
   263     SetActive();
       
   264     if( !iWait->IsStarted() )
       
   265         {
       
   266         iWait->Start();
       
   267         }
       
   268     return iStatus.Int();
       
   269     }
       
   270 
       
   271 TInt CNSmlDummyDataStoreWaiter::DoDeleteItemL( TSmlDbItemUid aUid )
       
   272     {
       
   273     if( !iOpen )
       
   274         {
       
   275         User::Leave( KErrNotReady );
       
   276         }
       
   277     Cancel();
       
   278     iStore.DeleteItemL( aUid, iStatus );
       
   279 
       
   280     SetActive();
       
   281 
       
   282     if( !iWait->IsStarted() )
       
   283         {
       
   284         iWait->Start();
       
   285         }
       
   286 
       
   287     return iStatus.Int();
       
   288     }
       
   289 
       
   290 TInt CNSmlDummyDataStoreWaiter::DoDeleteAllItemsL()
       
   291     {
       
   292     if( !iOpen )
       
   293         {
       
   294         User::Leave( KErrNotReady );
       
   295         }
       
   296     Cancel();
       
   297     iStore.DeleteAllItemsL( iStatus );
       
   298 
       
   299     SetActive();
       
   300 
       
   301     if( !iWait->IsStarted() )
       
   302         {
       
   303         iWait->Start();
       
   304         }
       
   305 
       
   306     return iStatus.Int();
       
   307     }
       
   308 
       
   309 // End of file