|
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: array for storing dataproviders and datastores. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <s32mem.h> |
|
21 #include <nsmldebug.h> |
|
22 |
|
23 #include "nsmldshostconstants.h" |
|
24 #include "Nsmldsasyncrequesthandler.h" |
|
25 #include "Nsmldsdataproviderarray.h" |
|
26 |
|
27 #ifdef __HOST_SERVER_MTEST__ |
|
28 #include "../../stif/DSHostServerTest/inc/fakedataprovider.h" |
|
29 #else |
|
30 #include <SmlDataProvider.h> |
|
31 #endif |
|
32 |
|
33 // CONSTANTS |
|
34 _LIT( KNSmlPanicCategory, " Host Server Session\\Changed items fetcher " ); |
|
35 |
|
36 // ======================================= MEMBER FUNCTIONS ======================================= |
|
37 |
|
38 // ------------------------------------------------------------------------------------------------ |
|
39 // CNSmlDSChangedItemsFetcher::NewLC |
|
40 // ------------------------------------------------------------------------------------------------ |
|
41 CNSmlDSChangedItemsFetcher* CNSmlDSChangedItemsFetcher::NewLC( CNSmlDSHostSession* aSession, |
|
42 TNSmlDSDataStoreElement* aDSItem, |
|
43 const RMessage2& aMessage, |
|
44 RequestFinishedFunction aReqFinishedFunc ) |
|
45 { |
|
46 CNSmlDSChangedItemsFetcher* self = new ( ELeave ) CNSmlDSChangedItemsFetcher( |
|
47 aSession, aDSItem, aMessage, aReqFinishedFunc ); |
|
48 CleanupStack::PushL( self ); |
|
49 self->ConstructL(); |
|
50 return self; |
|
51 } |
|
52 |
|
53 // ------------------------------------------------------------------------------------------------ |
|
54 // CNSmlDSChangedItemsFetcher::~CNSmlDSChangedItemsFetcher |
|
55 // ------------------------------------------------------------------------------------------------ |
|
56 CNSmlDSChangedItemsFetcher::~CNSmlDSChangedItemsFetcher() |
|
57 { |
|
58 if (iChangedItems) |
|
59 { |
|
60 iChangedItems->Close(); |
|
61 delete iChangedItems; |
|
62 } |
|
63 } |
|
64 |
|
65 // ------------------------------------------------------------------------------------------------ |
|
66 // CNSmlDSChangedItemsFetcher::FetchAllChangedItemsL |
|
67 // ------------------------------------------------------------------------------------------------ |
|
68 void CNSmlDSChangedItemsFetcher::FetchAllChangedItemsL() |
|
69 { |
|
70 AddToSchedulerL(); |
|
71 SetActive(); |
|
72 TRequestStatus* status = &iStatus; |
|
73 User::RequestComplete( status, KErrNone ); |
|
74 } |
|
75 |
|
76 // ------------------------------------------------------------------------------------------------ |
|
77 // CNSmlDSChangedItemsFetcher::CNSmlDSChangedItemsFetcher |
|
78 // ------------------------------------------------------------------------------------------------ |
|
79 CNSmlDSChangedItemsFetcher::CNSmlDSChangedItemsFetcher( CNSmlDSHostSession* aSession, |
|
80 TNSmlDSDataStoreElement* aDSItem, |
|
81 const RMessage2& aMessage, |
|
82 RequestFinishedFunction aReqFinishedFunc ) : |
|
83 CNSmlDSAsyncRequestHandler( EPriorityLow, aSession, aDSItem, aMessage ), |
|
84 iChangedItems( NULL ) |
|
85 { |
|
86 iNextModsToFetch = TNSmlDbItemModification::ENSmlDbItemAdd; |
|
87 iReqFinishedFunc = aReqFinishedFunc; |
|
88 ASSERT( iReqFinishedFunc != NULL ); |
|
89 ASSERT( iDSItem != NULL ); |
|
90 } |
|
91 |
|
92 // ------------------------------------------------------------------------------------------------ |
|
93 // CNSmlDSChangedItemsFetcher::ConstructL |
|
94 // ------------------------------------------------------------------------------------------------ |
|
95 void CNSmlDSChangedItemsFetcher::ConstructL() |
|
96 { |
|
97 iChangedItems = new ( ELeave ) RNSmlDbItemModificationSet(); |
|
98 } |
|
99 |
|
100 // ------------------------------------------------------------------------------------------------ |
|
101 // CNSmlDSChangedItemsFetcher::DoCancel |
|
102 // No need to do anything. Here to prevent base class DoCancel from getting called. |
|
103 // ------------------------------------------------------------------------------------------------ |
|
104 void CNSmlDSChangedItemsFetcher::DoCancel() |
|
105 { |
|
106 |
|
107 } |
|
108 |
|
109 // ------------------------------------------------------------------------------------------------ |
|
110 // CNSmlDSChangedItemsFetcher::RunL |
|
111 // ------------------------------------------------------------------------------------------------ |
|
112 void CNSmlDSChangedItemsFetcher::RunL() |
|
113 { |
|
114 CSmlDataStore* ds = iDSItem->iDataStore; |
|
115 TBool fetchFinished( EFalse ); |
|
116 TNSmlDbItemModification::TNSmlDbItemModificationType |
|
117 toNextModsToFetch( TNSmlDbItemModification::ENSmlDbItemAdd ); |
|
118 const MSmlDataItemUidSet* dius = NULL; |
|
119 |
|
120 //Order of items must be preserved for hierarchy sync. |
|
121 //1.Add, 2.Replace, 3.Move, 4.SoftDelete, 5.Delete. |
|
122 switch( iNextModsToFetch ) |
|
123 { |
|
124 case TNSmlDbItemModification::ENSmlDbItemAdd: |
|
125 { |
|
126 dius = &ds->AddedItems(); |
|
127 toNextModsToFetch = TNSmlDbItemModification::ENSmlDbItemModify; |
|
128 break; |
|
129 } |
|
130 case TNSmlDbItemModification::ENSmlDbItemDelete: |
|
131 { |
|
132 dius = &ds->DeletedItems(); |
|
133 fetchFinished = ETrue; |
|
134 break; |
|
135 } |
|
136 case TNSmlDbItemModification::ENSmlDbItemSoftDelete: |
|
137 { |
|
138 dius = &ds->SoftDeletedItems(); |
|
139 toNextModsToFetch = TNSmlDbItemModification::ENSmlDbItemDelete; |
|
140 break; |
|
141 } |
|
142 case TNSmlDbItemModification::ENSmlDbItemMove: |
|
143 { |
|
144 dius = &ds->MovedItems(); |
|
145 toNextModsToFetch = TNSmlDbItemModification::ENSmlDbItemSoftDelete; |
|
146 break; |
|
147 } |
|
148 case TNSmlDbItemModification::ENSmlDbItemModify: |
|
149 { |
|
150 dius = &ds->ModifiedItems(); |
|
151 toNextModsToFetch = TNSmlDbItemModification::ENSmlDbItemMove; |
|
152 break; |
|
153 } |
|
154 default: |
|
155 User::Panic( KNSmlPanicCategory, KErrUnknown ); |
|
156 } |
|
157 |
|
158 TInt status = KErrNone; |
|
159 |
|
160 if ( dius ) |
|
161 { |
|
162 iChangedItems->AddGroupL( *dius, iNextModsToFetch ); |
|
163 } |
|
164 |
|
165 if ( fetchFinished ) |
|
166 { |
|
167 TRAP( status, ( *iSession.*iReqFinishedFunc )( this ) ); |
|
168 |
|
169 iMessage.Complete( status ); |
|
170 delete this; |
|
171 } |
|
172 else |
|
173 { |
|
174 iNextModsToFetch = toNextModsToFetch; |
|
175 SetActive(); |
|
176 TRequestStatus* rstatus = &iStatus; |
|
177 User::RequestComplete( rstatus, KErrNone ); |
|
178 } |
|
179 } |
|
180 |
|
181 // End of File |