|
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: Provides item buffering during synchronisation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "nsmldbcaps.h" |
|
21 #include "nsmldsbatchbuffer.h" |
|
22 |
|
23 // ============================ MEMBER FUNCTIONS =============================== |
|
24 |
|
25 // ----------------------------------------------------------------------------- |
|
26 // CNSmlDSBatchBuffer::CNSmlDSBatchItem::CNSmlDSBatchBuffer |
|
27 // C++ constructor. |
|
28 // ----------------------------------------------------------------------------- |
|
29 // |
|
30 CNSmlDSBatchBuffer::CNSmlDSBatchItem::CNSmlDSBatchItem() |
|
31 { |
|
32 } |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // CNSmlDSBatchBuffer::CNSmlDSBatchItem::~CNSmlDSBatchBuffer |
|
36 // Destructor. |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 CNSmlDSBatchBuffer::CNSmlDSBatchItem::~CNSmlDSBatchItem() |
|
40 { |
|
41 delete iItemData; |
|
42 delete iMimeType; |
|
43 delete iMimeVersion; |
|
44 delete iGUid; |
|
45 } |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CNSmlDSBatchBuffer::CNSmlDSBatchBuffer |
|
49 // C++ constructor. |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 CNSmlDSBatchBuffer::CNSmlDSBatchBuffer() |
|
53 { |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CNSmlDSBatchBuffer::~CNSmlDSBatchBuffer |
|
58 // Destructor. |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 CNSmlDSBatchBuffer::~CNSmlDSBatchBuffer() |
|
62 { |
|
63 iBuffer.ResetAndDestroy(); |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CNSmlDSBatchBuffer::CreateNewItemL |
|
68 // Creates a new item to the buffer. |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 void CNSmlDSBatchBuffer::CreateNewItemL( const TDesC8& aCommand ) |
|
72 { |
|
73 CNSmlDSBatchItem* newItem = new ( ELeave ) CNSmlDSBatchItem; |
|
74 |
|
75 newItem->iStatus = 0; |
|
76 newItem->iNumberOfResults = 0; |
|
77 newItem->iCommand = aCommand; |
|
78 newItem->iUid = KNullDataItemId; |
|
79 newItem->iUid = KNullDataItemId; |
|
80 newItem->iStatusEntryId = 0; |
|
81 |
|
82 iBuffer.AppendL( newItem ); |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // CNSmlDSBatchBuffer::SetStatus |
|
87 // Sets the status id of the given item. |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 void CNSmlDSBatchBuffer::SetStatus( const TInt aIndex, const TInt aStatus ) |
|
91 { |
|
92 iBuffer[aIndex]->iStatus = aStatus; |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CNSmlDSBatchBuffer::SetStatusEntryId |
|
97 // Sets the status container id of the current item. |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 void CNSmlDSBatchBuffer::SetStatusEntryId( const TInt aEntry ) |
|
101 { |
|
102 iBuffer[iBuffer.Count() - 1]->iStatusEntryId = aEntry; |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CNSmlDSBatchBuffer::Reset |
|
107 // Resets the buffer. |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 void CNSmlDSBatchBuffer::Reset() |
|
111 { |
|
112 iBuffer.ResetAndDestroy(); |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // CNSmlDSBatchBuffer::Count |
|
117 // Returns the number of items in the buffer. |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 TInt CNSmlDSBatchBuffer::Count() const |
|
121 { |
|
122 return iBuffer.Count(); |
|
123 } |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // CNSmlDSBatchBuffer::Status |
|
127 // Returns given item's status code. |
|
128 // ----------------------------------------------------------------------------- |
|
129 // |
|
130 TInt CNSmlDSBatchBuffer::Status( const TInt aIndex ) const |
|
131 { |
|
132 return iBuffer[aIndex]->iStatus; |
|
133 } |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 // CNSmlDSBatchBuffer::StatusEntryId |
|
137 // Returns given item's status container id. |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 TInt CNSmlDSBatchBuffer::StatusEntryId( const TInt aIndex ) const |
|
141 { |
|
142 return iBuffer[aIndex]->iStatusEntryId; |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CNSmlDSBatchBuffer::NumberOfResults |
|
147 // Returns the number of operations associated with the given item. |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 TInt CNSmlDSBatchBuffer::NumberOfResults( const TInt aIndex ) const |
|
151 { |
|
152 return iBuffer[aIndex]->iNumberOfResults; |
|
153 } |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 // CNSmlDSBatchBuffer::Increase |
|
157 // Increases item's operation counter by one. |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 void CNSmlDSBatchBuffer::Increase() |
|
161 { |
|
162 ++iBuffer[iBuffer.Count() - 1]->iNumberOfResults; |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CNSmlDSBatchBuffer::SetGUidL |
|
167 // Sets current item's GUID. |
|
168 // ----------------------------------------------------------------------------- |
|
169 // |
|
170 void CNSmlDSBatchBuffer::SetGUidL( const TDesC8& aGUid ) |
|
171 { |
|
172 iBuffer[iBuffer.Count() - 1]->iGUid = aGUid.AllocL(); |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // CNSmlDSBatchBuffer::Command |
|
177 // Gets given item's associated command. |
|
178 // ----------------------------------------------------------------------------- |
|
179 // |
|
180 const TDesC8& CNSmlDSBatchBuffer::Command( const TInt aIndex ) const |
|
181 { |
|
182 return iBuffer[aIndex]->iCommand; |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CNSmlDSBatchBuffer::Uid |
|
187 // Returns given item's UID. |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 TSmlDbItemUid CNSmlDSBatchBuffer::Uid( const TInt aIndex ) const |
|
191 { |
|
192 return iBuffer[aIndex]->iUid; |
|
193 } |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // CNSmlDSBatchBuffer::Uid |
|
197 // Returns a reference to the current item's UID. |
|
198 // ----------------------------------------------------------------------------- |
|
199 // |
|
200 TSmlDbItemUid& CNSmlDSBatchBuffer::Uid() const |
|
201 { |
|
202 return iBuffer[iBuffer.Count() - 1]->iUid; |
|
203 } |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // CNSmlDSBatchBuffer::GUid |
|
207 // Returns given item's GUID. |
|
208 // ----------------------------------------------------------------------------- |
|
209 // |
|
210 const TDesC8& CNSmlDSBatchBuffer::GUid( const TInt aIndex ) const |
|
211 { |
|
212 return *iBuffer[aIndex]->iGUid; |
|
213 } |
|
214 |
|
215 // ----------------------------------------------------------------------------- |
|
216 // CNSmlDSBatchBuffer::StoreItemDataL |
|
217 // Stores data to the current item. |
|
218 // ----------------------------------------------------------------------------- |
|
219 // |
|
220 void CNSmlDSBatchBuffer::StoreItemDataL( TPtrC8 aData ) |
|
221 { |
|
222 iBuffer[iBuffer.Count() - 1]->iItemData = aData.AllocL(); |
|
223 } |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // CNSmlDSBatchBuffer::ItemData |
|
227 // Returns a pointer to the given item's data. |
|
228 // ----------------------------------------------------------------------------- |
|
229 // |
|
230 TPtrC8 CNSmlDSBatchBuffer::ItemData( TInt aIndex ) const |
|
231 { |
|
232 return *iBuffer[aIndex]->iItemData; |
|
233 } |
|
234 |
|
235 // ----------------------------------------------------------------------------- |
|
236 // CNSmlDSBatchBuffer::SetParent |
|
237 // Sets current item's parent. |
|
238 // ----------------------------------------------------------------------------- |
|
239 // |
|
240 void CNSmlDSBatchBuffer::SetParent( const TSmlDbItemUid aParent ) |
|
241 { |
|
242 iBuffer[iBuffer.Count() - 1]->iParent = aParent; |
|
243 } |
|
244 |
|
245 // ----------------------------------------------------------------------------- |
|
246 // CNSmlDSBatchBuffer::Parent |
|
247 // Returns the given item's parent. |
|
248 // ----------------------------------------------------------------------------- |
|
249 // |
|
250 TSmlDbItemUid CNSmlDSBatchBuffer::Parent( const TInt aIndex ) const |
|
251 { |
|
252 return iBuffer[aIndex]->iParent; |
|
253 } |
|
254 |
|
255 // ----------------------------------------------------------------------------- |
|
256 // CNSmlDSBatchBuffer::SetMetaInformationL |
|
257 // Sets the current item's meta information. |
|
258 // ----------------------------------------------------------------------------- |
|
259 // |
|
260 void CNSmlDSBatchBuffer::SetMetaInformationL( const CNSmlDbMetaHandler* aMetaHandler ) |
|
261 { |
|
262 iBuffer[iBuffer.Count() - 1]->iMimeType = aMetaHandler->Type().AllocL(); |
|
263 iBuffer[iBuffer.Count() - 1]->iMimeVersion = aMetaHandler->Version().AllocL(); |
|
264 } |
|
265 |
|
266 // ----------------------------------------------------------------------------- |
|
267 // CNSmlDSBatchBuffer::MetaVersion |
|
268 // Returns the given item's meta version. |
|
269 // ----------------------------------------------------------------------------- |
|
270 // |
|
271 TPtrC8 CNSmlDSBatchBuffer::MimeVersion( const TInt aIndex ) const |
|
272 { |
|
273 return *iBuffer[aIndex]->iMimeVersion; |
|
274 } |
|
275 |
|
276 // ----------------------------------------------------------------------------- |
|
277 // CNSmlDSBatchBuffer::MetaVersion |
|
278 // Returns the given item's meta type. |
|
279 // ----------------------------------------------------------------------------- |
|
280 // |
|
281 TPtrC8 CNSmlDSBatchBuffer::MimeType( const TInt aIndex ) const |
|
282 { |
|
283 return *iBuffer[aIndex]->iMimeType; |
|
284 } |
|
285 |
|
286 // End of File |