|
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: Client Session for DS Host Servers |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // ------------------------------------------------------------------------------------------------ |
|
20 // Includes |
|
21 // ------------------------------------------------------------------------------------------------ |
|
22 #include <s32mem.h> |
|
23 #include <data_caging_path_literals.hrh> |
|
24 #include <f32file.h> |
|
25 |
|
26 #include <nsmlconstants.h> |
|
27 #include <nsmlunicodeconverter.h> |
|
28 #include "nsmldbcaps.h" |
|
29 #include "nsmldshostclientsession.h" |
|
30 #include "nsmldshostconstants.h" |
|
31 #include "NSmldbcapsSerializer.h" |
|
32 #include "nsmldsdpinformation.h" |
|
33 #include "nsmldshostitem.h" |
|
34 #include "nsmldsitemmodificationset.h" |
|
35 #include "nsmlfilter.h" |
|
36 |
|
37 // ------------------------------------------------------------------------------------------------ |
|
38 // Constants |
|
39 // ------------------------------------------------------------------------------------------------ |
|
40 _LIT8( KNSmlFilterTypeEXCLUSIVE, "EXCLUSIVE" ); |
|
41 _LIT8( KNSmlFilterTypeINCLUSIVE, "INCLUSIVE" ); |
|
42 _LIT8( KNSmlFilterTypeCGI, "syncml::filtertype-cgi" ); |
|
43 |
|
44 // ------------------------------------------------------------------------------------------------ |
|
45 // RNSmlDSHostClient - public methods |
|
46 // ------------------------------------------------------------------------------------------------ |
|
47 // ------------------------------------------------------------------------------------------------ |
|
48 // RNSmlDSHostClient::Connect |
|
49 // Connects client to Host Servers. |
|
50 // ------------------------------------------------------------------------------------------------ |
|
51 TInt RNSmlDSHostClient::Connect( const TDesC& aServerName, const TVersion& aVersion ) |
|
52 { |
|
53 iMode = ENSmlNormalMode; |
|
54 TInt result( CreateSession( aServerName, aVersion ) ); |
|
55 |
|
56 if ( result == KErrNotFound || result == KErrServerTerminated ) |
|
57 { |
|
58 result = LaunchServer( aServerName ); |
|
59 if ( result == KErrNone || result == KErrAlreadyExists ) |
|
60 { |
|
61 result = CreateSession( aServerName, aVersion ); |
|
62 } |
|
63 } |
|
64 return result; |
|
65 } |
|
66 |
|
67 // ------------------------------------------------------------------------------------------------ |
|
68 // RNSmlDSHostClient::Close |
|
69 // Closes connection between client and Host Server. |
|
70 // ------------------------------------------------------------------------------------------------ |
|
71 void RNSmlDSHostClient::Close() |
|
72 { |
|
73 iChunk.Close(); |
|
74 RSessionBase::Close(); |
|
75 } |
|
76 |
|
77 // ------------------------------------------------------------------------------------------------ |
|
78 // RNSmlDSHostClient::CreateChunk |
|
79 // Creates chunk that is used to transfer data between client and server. |
|
80 // ------------------------------------------------------------------------------------------------ |
|
81 TInt RNSmlDSHostClient::CreateChunk() const |
|
82 { |
|
83 return iChunk.CreateGlobal( KNullDesC, KNSmlDSHostChunkMinSize, KNSmlDSHostChunkMaxSize ); |
|
84 } |
|
85 |
|
86 // ------------------------------------------------------------------------------------------------ |
|
87 // RNSmlDSHostClient::SendChunkHandle |
|
88 // Sends Chunk handle to SyncML DS Host Servers. |
|
89 // ------------------------------------------------------------------------------------------------ |
|
90 TInt RNSmlDSHostClient::SendChunkHandle() const |
|
91 { |
|
92 TIpcArgs args; |
|
93 args.Set(0, iChunk); |
|
94 const TInt error = SendReceive( ENSmlHandleChunk, args ); |
|
95 return error; |
|
96 } |
|
97 |
|
98 // ------------------------------------------------------------------------------------------------ |
|
99 // RNSmlDSHostClient::CreateDataProvidersL |
|
100 // Creates Data Providers. |
|
101 // ------------------------------------------------------------------------------------------------ |
|
102 void RNSmlDSHostClient::CreateDataProvidersL( const RArray<TSmlDataProviderId>& aIds, RArray<TInt>& aResultArray ) |
|
103 { |
|
104 AdjustChunkIfNeededLC( sizeof( TInt32 ) * ( aIds.Count() + 1 ) ); |
|
105 RMemWriteStream writeStream( iChunk.Base(), iChunk.Size() ); |
|
106 CleanupClosePushL( writeStream ); |
|
107 writeStream.WriteInt32L( aIds.Count() ); |
|
108 |
|
109 for ( TInt i = 0; i < aIds.Count(); i++ ) |
|
110 { |
|
111 writeStream.WriteInt32L( aIds[i] ); |
|
112 } |
|
113 |
|
114 writeStream.CommitL(); |
|
115 CleanupStack::PopAndDestroy(); // writeStream |
|
116 |
|
117 User::LeaveIfError( SendReceive( ENSmlDPOpen, TIpcArgs() ) ); |
|
118 |
|
119 RMemReadStream readStream( iChunk.Base(), iChunk.Size() ); |
|
120 CleanupClosePushL( readStream ); |
|
121 TInt count( readStream.ReadInt32L() ); |
|
122 |
|
123 for ( TInt j = 0; j < count; j++ ) |
|
124 { |
|
125 aResultArray.AppendL( readStream.ReadInt32L() ); |
|
126 } |
|
127 |
|
128 CleanupStack::PopAndDestroy(2); // readStream, AdjustChunkIfNeededLC |
|
129 } |
|
130 |
|
131 // ------------------------------------------------------------------------------------------------ |
|
132 // RNSmlDSHostClient::CreateAllDataProvidersL |
|
133 // Creates all possible Data Providers. |
|
134 // ------------------------------------------------------------------------------------------------ |
|
135 void RNSmlDSHostClient::CreateAllDataProvidersL( RArray<TSmlDataProviderId>& aIds, const RArray<TSmlDataProviderId>& aExceptIds ) |
|
136 { |
|
137 AdjustChunkIfNeededLC( sizeof( TInt32 ) * ( aIds.Count() + 1 ) ); |
|
138 RMemWriteStream writeStream( iChunk.Base(), iChunk.Size() ); |
|
139 CleanupClosePushL( writeStream ); |
|
140 writeStream.WriteInt32L( aExceptIds.Count() ); |
|
141 |
|
142 for ( TInt i = 0; i < aExceptIds.Count(); i++ ) |
|
143 { |
|
144 writeStream.WriteInt32L( aExceptIds[ i ] ); |
|
145 } |
|
146 |
|
147 writeStream.CommitL(); |
|
148 CleanupStack::PopAndDestroy(); // writeStream |
|
149 |
|
150 User::LeaveIfError( SendReceive( ENSmlDPOpenExcept, TIpcArgs() ) ); |
|
151 |
|
152 RMemReadStream readStream( iChunk.Base(), iChunk.Size() ); |
|
153 CleanupClosePushL( readStream ); |
|
154 TInt count( readStream.ReadInt32L() ); |
|
155 |
|
156 for ( TInt j = 0; j < count; j++ ) |
|
157 { |
|
158 aIds.AppendL( readStream.ReadInt32L() ); |
|
159 } |
|
160 |
|
161 CleanupStack::PopAndDestroy(2); // readStream, AdjustChunkIfNeededLC |
|
162 } |
|
163 |
|
164 // ------------------------------------------------------------------------------------------------ |
|
165 // RNSmlDSHostClient::DataProviderInformationL |
|
166 // |
|
167 // ------------------------------------------------------------------------------------------------ |
|
168 TNSmlDPInformation* RNSmlDSHostClient::DataProviderInformationL( const TSmlDataProviderId aId, TInt& aResultCode ) const |
|
169 { |
|
170 TNSmlDPInformation* info = NULL; |
|
171 aResultCode = SendReceive( ENSmlDPInformation, TIpcArgs( aId ) ); |
|
172 CleanupStack::PushL( TCleanupItem ( CancelAdjust, const_cast<RNSmlDSHostClient*>( this ) ) ); |
|
173 if ( aResultCode == KErrNone ) |
|
174 { |
|
175 CNSmlDPInformation* dpi = CNSmlDPInformation::NewLC(); |
|
176 |
|
177 RMemReadStream readStream( iChunk.Base(), iChunk.Size() ); |
|
178 CleanupClosePushL( readStream ); |
|
179 dpi->InternalizeL( readStream ); |
|
180 |
|
181 CleanupStack::PopAndDestroy(); //readStream |
|
182 CleanupStack::Pop( dpi ); |
|
183 info = dpi->InformationD(); |
|
184 } |
|
185 CleanupStack::PopAndDestroy(); //CancelAdjust |
|
186 return info; |
|
187 } |
|
188 // ------------------------------------------------------------------------------------------------ |
|
189 // RNSmlDSHostClient::SupportsOperation |
|
190 // Asks if Data Provider supports some operation. |
|
191 // ------------------------------------------------------------------------------------------------ |
|
192 TBool RNSmlDSHostClient::SupportsOperationL( TUid aOpId, const TSmlDataProviderId aId, TInt& aResultCode ) const |
|
193 { |
|
194 |
|
195 RMemWriteStream writeStream( iChunk.Base(), iChunk.Size() ); |
|
196 CleanupClosePushL( writeStream ); |
|
197 writeStream.WriteInt32L( aOpId.iUid ); |
|
198 writeStream.CommitL(); |
|
199 CleanupStack::PopAndDestroy(); // writeStream |
|
200 |
|
201 TPckgBuf<TInt> pckg; |
|
202 |
|
203 aResultCode = SendReceive( ENSmlDPSupportsOperation, TIpcArgs( aId, TIpcArgs::ENothing, &pckg ) ); |
|
204 return pckg(); |
|
205 } |
|
206 |
|
207 // ------------------------------------------------------------------------------------------------ |
|
208 // RNSmlDSHostClient::StoreFormatL |
|
209 // Creates Data Store format of Data Provider. |
|
210 // ------------------------------------------------------------------------------------------------ |
|
211 CNSmlDbCaps* RNSmlDSHostClient::StoreFormatL( const TSmlDataProviderId aId, TInt& aResultCode ) |
|
212 { |
|
213 TNSmlDbCapsSerializer ser; |
|
214 CNSmlDbCaps* dbcaps = NULL; |
|
215 |
|
216 aResultCode = SendReceive( ENSmlDPStoreFormat, TIpcArgs( aId ) ); |
|
217 CleanupStack::PushL( TCleanupItem ( CancelAdjust, this ) ); |
|
218 |
|
219 if ( aResultCode == KErrNone ) |
|
220 { |
|
221 RMemReadStream readStream( iChunk.Base(), iChunk.Size() ); |
|
222 CleanupClosePushL( readStream ); |
|
223 dbcaps = ser.InternalizeL( readStream ); |
|
224 CleanupStack::PopAndDestroy(); // readStream |
|
225 } |
|
226 CleanupStack::PopAndDestroy(); //CancelAdjust |
|
227 |
|
228 return dbcaps; |
|
229 } |
|
230 |
|
231 // ------------------------------------------------------------------------------------------------ |
|
232 // RNSmlDSHostClient::ListStoresL |
|
233 // Creates list of Data Store names of Data Provider. |
|
234 // ------------------------------------------------------------------------------------------------ |
|
235 void RNSmlDSHostClient::ListStoresL( CDesCArray* aNameList, const TSmlDataProviderId aId, TInt& aResultCode ) |
|
236 { |
|
237 aNameList->Reset(); |
|
238 aResultCode = SendReceive( ENSmlDPlListStores, TIpcArgs( aId ) ); |
|
239 CleanupStack::PushL( TCleanupItem ( CancelAdjust, this ) ); |
|
240 |
|
241 if ( aResultCode == KErrNone ) |
|
242 { |
|
243 RMemReadStream readStream( iChunk.Base(), iChunk.Size() ); |
|
244 CleanupClosePushL( readStream ); |
|
245 TInt32 i(0), storeCount( readStream.ReadInt32L() ); |
|
246 |
|
247 for (; i < storeCount; i++ ) |
|
248 { |
|
249 TInt32 length( readStream.ReadInt32L() ); |
|
250 HBufC* store = HBufC::NewLC( readStream, length ); |
|
251 |
|
252 aNameList->AppendL( *store ); |
|
253 CleanupStack::PopAndDestroy( store ); |
|
254 } |
|
255 CleanupStack::PopAndDestroy(); // readStream |
|
256 } |
|
257 |
|
258 CleanupStack::PopAndDestroy(); //CancelAdjust |
|
259 } |
|
260 |
|
261 // ------------------------------------------------------------------------------------------------ |
|
262 // RNSmlDSHostClient::DefaultStoreL |
|
263 // Creates default name for Data Store of Data Provider. |
|
264 // ------------------------------------------------------------------------------------------------ |
|
265 HBufC* RNSmlDSHostClient::DefaultStoreL( const TSmlDataProviderId aId, TInt& aResultCode ) const |
|
266 { |
|
267 aResultCode = SendReceive( ENSmlDPDefaultStore, TIpcArgs( aId ) ); |
|
268 if ( aResultCode ) |
|
269 { |
|
270 return NULL; |
|
271 } |
|
272 |
|
273 RMemReadStream readStream( iChunk.Base(), iChunk.Size() ); |
|
274 CleanupClosePushL( readStream ); |
|
275 |
|
276 TInt tempLength( readStream.ReadInt32L() ); |
|
277 HBufC* tempName = HBufC::NewL( readStream, tempLength ); |
|
278 |
|
279 CleanupStack::PopAndDestroy(); // readStream |
|
280 return tempName; |
|
281 } |
|
282 |
|
283 // ------------------------------------------------------------------------------------------------ |
|
284 // RNSmlDSHostClient::SupportedServerFiltersL |
|
285 // This method returns the set of filters that can be used to send to the Sync Partner. |
|
286 // ------------------------------------------------------------------------------------------------ |
|
287 RPointerArray<CSyncMLFilter>* RNSmlDSHostClient::SupportedServerFiltersL( const TSmlDataProviderId aId, |
|
288 TSyncMLFilterMatchType& aMatchType, TSyncMLFilterChangeInfo& aChangeInfo, TInt& aResultCode ) const |
|
289 { |
|
290 TPckgBuf<TSyncMLFilterMatchType> pckg; |
|
291 |
|
292 aResultCode = SendReceive( ENSmlServerFilters, TIpcArgs( aId, TIpcArgs::ENothing, &pckg ) ); |
|
293 aMatchType = pckg(); |
|
294 |
|
295 if ( aResultCode ) |
|
296 { |
|
297 return NULL; |
|
298 } |
|
299 |
|
300 aChangeInfo = ESyncMLDefault; |
|
301 |
|
302 RPointerArray<CSyncMLFilter>* array = new ( ELeave ) RPointerArray<CSyncMLFilter>(); |
|
303 CleanupRPtrArrayPushL( array ); |
|
304 RMemReadStream readStream( iChunk.Base(), iChunk.Size() ); |
|
305 |
|
306 CleanupClosePushL( readStream ); |
|
307 InternalizeFiltersL( readStream, *array ); |
|
308 CleanupStack::PopAndDestroy(); // readStream |
|
309 CleanupStack::Pop(); //array |
|
310 |
|
311 return array; |
|
312 } |
|
313 |
|
314 // ------------------------------------------------------------------------------------------------ |
|
315 // RNSmlDSHostClient::CheckServerFiltersL |
|
316 // This method updates dynamic filters up-to-date. |
|
317 // ------------------------------------------------------------------------------------------------ |
|
318 void RNSmlDSHostClient::CheckServerFiltersL( const TSmlDataProviderId aId, RPointerArray<CSyncMLFilter>& aFilters, TSyncMLFilterChangeInfo& aChangeInfo, TInt& aResultCode ) const |
|
319 { |
|
320 TStreamBuffers* sb = StreamBufferLC(); |
|
321 sb->iWrite->WriteInt32L( aChangeInfo ); |
|
322 ExternalizeFiltersL( *sb->iWrite, aFilters ); |
|
323 sb->iWrite->CommitL(); |
|
324 |
|
325 AdjustChunkIfNeededLC( sb->iBuffer->Size() ); |
|
326 |
|
327 RMemWriteStream writeStream( iChunk.Base(), iChunk.Size() ); |
|
328 CleanupClosePushL( writeStream ); |
|
329 writeStream.WriteL( *sb->iRead ); |
|
330 writeStream.CommitL(); |
|
331 CleanupStack::PopAndDestroy(); // writeStream |
|
332 |
|
333 aResultCode = SendReceive( ENSmlUpdateServerFilters, TIpcArgs( aId ) ); |
|
334 |
|
335 RMemReadStream readStream( iChunk.Base(), iChunk.Size() ); |
|
336 CleanupClosePushL( readStream ); |
|
337 |
|
338 aChangeInfo = static_cast<TSyncMLFilterChangeInfo>( readStream.ReadInt32L() ); |
|
339 InternalizeFiltersL( readStream, aFilters ); |
|
340 CleanupStack::PopAndDestroy(3); // readStream, AdjustChunkIfNeededLC, sb |
|
341 } |
|
342 |
|
343 // ------------------------------------------------------------------------------------------------ |
|
344 // RNSmlDSHostClient::CheckSupportedServerFiltersL |
|
345 // This method checks what filters are supported by server |
|
346 // ------------------------------------------------------------------------------------------------ |
|
347 void RNSmlDSHostClient::CheckSupportedServerFiltersL( const TSmlDataProviderId aId, |
|
348 const CNSmlDbCaps& aServerDataStoreFormat, const CArrayFix<TNSmlFilterCapData>& aFilterInfoArr, |
|
349 RPointerArray<CSyncMLFilter>& aFilters, TSyncMLFilterChangeInfo& aChangeInfo, TInt& aResultCode ) const |
|
350 { |
|
351 TNSmlDbCapsSerializer ser; |
|
352 TStreamBuffers* sb = StreamBufferLC(); |
|
353 |
|
354 sb->iWrite->WriteInt32L( aChangeInfo ); |
|
355 ser.ExternalizeL( aServerDataStoreFormat, aFilterInfoArr, *sb->iWrite ); |
|
356 ExternalizeFiltersL( *sb->iWrite, aFilters ); |
|
357 sb->iWrite->CommitL(); |
|
358 |
|
359 AdjustChunkIfNeededLC( sb->iBuffer->Size() ); |
|
360 |
|
361 RMemWriteStream writeStream( iChunk.Base(), iChunk.Size() ); |
|
362 CleanupClosePushL( writeStream ); |
|
363 writeStream.WriteL( *sb->iRead ); |
|
364 writeStream.CommitL(); |
|
365 CleanupStack::PopAndDestroy(); // writeStream |
|
366 |
|
367 aResultCode = SendReceive( ENSmlCheckSupportedServerFilters, TIpcArgs( aId ) ); |
|
368 |
|
369 if ( aResultCode == KErrNone ) |
|
370 { |
|
371 RMemReadStream readStream( iChunk.Base(), iChunk.Size() ); |
|
372 CleanupClosePushL( readStream ); |
|
373 aChangeInfo = static_cast<TSyncMLFilterChangeInfo>( readStream.ReadInt32L() ); |
|
374 InternalizeFiltersL( readStream, aFilters ); |
|
375 CleanupStack::PopAndDestroy(); //readStream |
|
376 } |
|
377 |
|
378 CleanupStack::PopAndDestroy(2); //AdjustChunkIfNeededLC, sb |
|
379 } |
|
380 |
|
381 // ------------------------------------------------------------------------------------------------ |
|
382 // CNSmlDSHostClient::GetFilterL |
|
383 // Get Filters. |
|
384 // ------------------------------------------------------------------------------------------------ |
|
385 void RNSmlDSHostClient::GetFilterL( const TSmlDataProviderId aId, const TDesC& aStoreName, const RPointerArray<CSyncMLFilter>& aFilterArray, CNSmlFilter*& aFilter, TSyncMLFilterMatchType aMatchType, TInt& aResultCode ) |
|
386 { |
|
387 TStreamBuffers* sb = StreamBufferLC(); |
|
388 sb->iWrite->WriteInt32L( aMatchType ); |
|
389 ExternalizeFiltersL( *sb->iWrite, aFilterArray ); |
|
390 sb->iWrite->CommitL(); |
|
391 |
|
392 AdjustChunkIfNeededLC( sb->iBuffer->Size() ); |
|
393 |
|
394 RMemWriteStream writeStream( iChunk.Base(), iChunk.Size() ); |
|
395 CleanupClosePushL( writeStream ); |
|
396 writeStream.WriteL( *sb->iRead ); |
|
397 writeStream.CommitL(); |
|
398 CleanupStack::PopAndDestroy(); // writeStream |
|
399 |
|
400 aResultCode = SendReceive( ENSmlFilters, TIpcArgs( aId, &aStoreName ) ); |
|
401 if ( aResultCode == KErrNone ) |
|
402 { |
|
403 GetFilterFromChunkL( aFilter ); |
|
404 } |
|
405 |
|
406 CleanupStack::PopAndDestroy(2); //AdjustChunkIfNeededLC, sb |
|
407 } |
|
408 |
|
409 // ------------------------------------------------------------------------------------------------ |
|
410 // CNSmlDSHostClient::GetFilterFromChunkL |
|
411 // creates filter from chunk |
|
412 // ------------------------------------------------------------------------------------------------ |
|
413 void RNSmlDSHostClient::GetFilterFromChunkL( CNSmlFilter*& aFilter ) |
|
414 { |
|
415 RMemReadStream readStream( iChunk.Base(), iChunk.Size() ); |
|
416 CleanupClosePushL( readStream ); |
|
417 TSyncMLFilterType filterType( static_cast<TSyncMLFilterType>( readStream.ReadInt32L() ) ); |
|
418 HBufC* query = HBufC::NewLC( readStream, readStream.ReadUint32L() ); |
|
419 HBufC* recordMimeType = HBufC::NewLC( readStream, readStream.ReadUint32L() ); |
|
420 HBufC* fieldMimeType = HBufC::NewLC( readStream, readStream.ReadUint32L() ); |
|
421 |
|
422 RStringPool pool; |
|
423 pool.OpenL(); |
|
424 CleanupClosePushL( pool ); |
|
425 |
|
426 //properties |
|
427 RPointerArray<CSmlDataProperty> properties; |
|
428 CleanupStack::PushL( PtrArrCleanupItemRArr( |
|
429 CSmlDataProperty, &properties ) ); |
|
430 |
|
431 TInt count( readStream.ReadUint32L() ); |
|
432 for ( TInt i = 0; i < count; i++ ) |
|
433 { |
|
434 CSmlDataProperty* prop = CSmlDataProperty::NewLC( pool, readStream ); |
|
435 properties.AppendL( prop ); |
|
436 CleanupStack::Pop( prop ); |
|
437 } |
|
438 |
|
439 aFilter = CNSmlFilter::NewLC(); |
|
440 |
|
441 if ( filterType == ESyncMLTypeInclusive ) |
|
442 { |
|
443 aFilter->SetFilterTypeL( KNSmlFilterTypeINCLUSIVE ); |
|
444 } |
|
445 else if ( filterType == ESyncMLTypeExclusive ) |
|
446 { |
|
447 aFilter->SetFilterTypeL( KNSmlFilterTypeEXCLUSIVE ); |
|
448 } |
|
449 |
|
450 HBufC8* tmpbuf = NULL; |
|
451 NSmlUnicodeConverter::HBufC8InUTF8LC( *recordMimeType, tmpbuf ); |
|
452 aFilter->SetFilterMetaTypeL( *tmpbuf ); |
|
453 CleanupStack::PopAndDestroy(); |
|
454 NSmlUnicodeConverter::HBufC8InUTF8LC( *fieldMimeType, tmpbuf ); |
|
455 aFilter->SetFieldMetaTypeL( *tmpbuf ); |
|
456 CleanupStack::PopAndDestroy(); |
|
457 NSmlUnicodeConverter::HBufC8InUTF8LC( *query, tmpbuf ); |
|
458 aFilter->SetRecordL( KNSmlFilterTypeCGI, *tmpbuf ); |
|
459 CleanupStack::PopAndDestroy(); |
|
460 |
|
461 AddFilterPropertiesL( properties, *aFilter ); |
|
462 |
|
463 CleanupStack::Pop(); // aFilter |
|
464 CleanupStack::PopAndDestroy(6); // pool, properties, fieldMimeType, recordMimeType, query, readStream |
|
465 } |
|
466 |
|
467 // ------------------------------------------------------------------------------------------------ |
|
468 // RNSmlDSHostClient::AddFilterPropertiesL |
|
469 // ------------------------------------------------------------------------------------------------ |
|
470 void RNSmlDSHostClient::AddFilterPropertiesL( const RPointerArray<CSmlDataProperty>& properties, CNSmlFilter& aFilter ) const |
|
471 { |
|
472 TNSmlDbCapsSerializer ser; |
|
473 for ( TInt i = 0; i < properties.Count(); i++ ) |
|
474 { |
|
475 const CSmlDataProperty* prop = properties[i]; |
|
476 |
|
477 CNSmlDevInfProp* dip = aFilter.AddFieldDataPropLC( prop->Field().Name().DesC() ); |
|
478 ser.SetFromL( *prop, *dip ); |
|
479 CleanupStack::Pop(); // dip |
|
480 } |
|
481 } |
|
482 |
|
483 // ------------------------------------------------------------------------------------------------ |
|
484 // RNSmlDSHostClient::OpenL |
|
485 // Opens the data store specified by aStoreName asynchronously. |
|
486 // ------------------------------------------------------------------------------------------------ |
|
487 void RNSmlDSHostClient::OpenL( const TSmlDataProviderId aId, const TDesC& aStoreName, const TDesC& aServerId, const TDesC& aRemoteDB, TInt& aResultCode ) const |
|
488 { |
|
489 RMemWriteStream writeStream( iChunk.Base(), iChunk.Size() ); |
|
490 CleanupClosePushL( writeStream ); |
|
491 |
|
492 writeStream.WriteUint32L( aServerId.Length() ); |
|
493 writeStream << aServerId; |
|
494 writeStream.WriteUint32L( aRemoteDB.Length() ); |
|
495 writeStream << aRemoteDB; |
|
496 |
|
497 CleanupStack::PopAndDestroy(); // writeStream |
|
498 |
|
499 aResultCode = SendReceive( ENSmlDSOpen, TIpcArgs( aId, &aStoreName ) ); |
|
500 } |
|
501 |
|
502 // ------------------------------------------------------------------------------------------------ |
|
503 // RNSmlDSHostClient::CancelRequest |
|
504 // Cancel the current asynchronous request. |
|
505 // ------------------------------------------------------------------------------------------------ |
|
506 void RNSmlDSHostClient::CancelRequest( const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) const |
|
507 { |
|
508 aResultCode = SendReceive( ENSmlDSCancelRequest, TIpcArgs( aId, &aStoreName ) ); |
|
509 } |
|
510 |
|
511 // ------------------------------------------------------------------------------------------------ |
|
512 // RNSmlDSHostClient::BeginTransaction |
|
513 // Starts the transaction mode. |
|
514 // ------------------------------------------------------------------------------------------------ |
|
515 void RNSmlDSHostClient::BeginTransaction( const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) |
|
516 { |
|
517 iMode = ENSmlTransactionMode; |
|
518 aResultCode = SendReceive( ENSmlDSBeginTransaction, TIpcArgs( aId, &aStoreName ) ); |
|
519 } |
|
520 |
|
521 // ------------------------------------------------------------------------------------------------ |
|
522 // RNSmlDSHostClient::CommitTransaction |
|
523 // Method will be called at the end of a successful transaction. |
|
524 // ------------------------------------------------------------------------------------------------ |
|
525 void RNSmlDSHostClient::CommitTransaction( const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) |
|
526 { |
|
527 iMode = ENSmlNormalMode; |
|
528 aResultCode = SendReceive( ENSmlDSCommitTransaction, TIpcArgs( aId, &aStoreName ) ); |
|
529 } |
|
530 |
|
531 // ------------------------------------------------------------------------------------------------ |
|
532 // RNSmlDSHostClient::RevertTransaction |
|
533 // Method will be called to abort an ongoing transaction. |
|
534 // ------------------------------------------------------------------------------------------------ |
|
535 void RNSmlDSHostClient::RevertTransaction( const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) |
|
536 { |
|
537 iMode = ENSmlNormalMode; |
|
538 aResultCode = SendReceive( ENSmlDSRevertTransaction, TIpcArgs( aId, &aStoreName ) ); |
|
539 } |
|
540 |
|
541 // ------------------------------------------------------------------------------------------------ |
|
542 // RNSmlDSHostClient::BeginBatch |
|
543 // Starts the batch mode. |
|
544 // ------------------------------------------------------------------------------------------------ |
|
545 void RNSmlDSHostClient::BeginBatch( const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) |
|
546 { |
|
547 iMode = ENSmlBatchMode; |
|
548 iAddedUidsBuffer.Reset(); |
|
549 aResultCode = SendReceive( ENSmlDSBeginBatch, TIpcArgs( aId, &aStoreName ) ); |
|
550 } |
|
551 |
|
552 // ------------------------------------------------------------------------------------------------ |
|
553 // RNSmlDSHostClient::CommitBatchL |
|
554 // Method will be called at the end of the batch mode. |
|
555 // ------------------------------------------------------------------------------------------------ |
|
556 void RNSmlDSHostClient::CommitBatchL( RArray<TInt>& aResultArray, const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) |
|
557 { |
|
558 iMode = ENSmlNormalMode; |
|
559 |
|
560 RArray<TInt> addUids; |
|
561 CleanupClosePushL( addUids ); |
|
562 |
|
563 aResultCode = SendReceive( ENSmlDSCommitBatch, TIpcArgs( aId, &aStoreName ) ); |
|
564 CleanupStack::PushL( TCleanupItem ( CancelAdjust, this ) ); |
|
565 |
|
566 if ( aResultCode == KErrNone ) |
|
567 { |
|
568 // First read results |
|
569 RMemReadStream readStream( iChunk.Base(), iChunk.Size() ); |
|
570 CleanupClosePushL( readStream ); |
|
571 TInt resultCount( readStream.ReadInt32L() ); |
|
572 for ( TInt j = 0; j < resultCount; j++ ) |
|
573 { |
|
574 aResultArray.AppendL( readStream.ReadInt32L() ); |
|
575 } |
|
576 // Second read uids references that are added |
|
577 TInt uidsCount( readStream.ReadInt32L() ); |
|
578 for ( TInt j = 0; j < uidsCount; j++ ) |
|
579 { |
|
580 addUids.AppendL( readStream.ReadInt32L() ); |
|
581 } |
|
582 CleanupStack::PopAndDestroy(); // readStream |
|
583 |
|
584 if ( addUids.Count() != iAddedUidsBuffer.Count() ) |
|
585 { |
|
586 User::Leave( KErrUnknown ); |
|
587 } |
|
588 else |
|
589 { |
|
590 for ( TInt i = 0; i < addUids.Count(); i++ ) |
|
591 { |
|
592 *( iAddedUidsBuffer[ i ] ) = addUids[ i ]; |
|
593 } |
|
594 } |
|
595 } |
|
596 |
|
597 CleanupStack::PopAndDestroy(2); //CancelAdjust, addUids |
|
598 } |
|
599 |
|
600 // ------------------------------------------------------------------------------------------------ |
|
601 // RNSmlDSHostClient::CancelBatchL |
|
602 // Method will be called to abort an ongoing batch mode. |
|
603 // ------------------------------------------------------------------------------------------------ |
|
604 void RNSmlDSHostClient::CancelBatch( const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) |
|
605 { |
|
606 iMode = ENSmlNormalMode; |
|
607 aResultCode = SendReceive( ENSmlDSCancelBatch, TIpcArgs( aId, &aStoreName ) ); |
|
608 } |
|
609 |
|
610 // ------------------------------------------------------------------------------------------------ |
|
611 // RNSmlDSHostClient::SetRemoteDataStoreFormatL |
|
612 // Sets the Sync Partner Data Format. |
|
613 // ------------------------------------------------------------------------------------------------ |
|
614 void RNSmlDSHostClient::SetRemoteDataStoreFormatL( const CNSmlDbCaps& aServerDataStoreFormat, const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) |
|
615 { |
|
616 TNSmlDbCapsSerializer ser; |
|
617 TStreamBuffers* sb = StreamBufferLC(); |
|
618 ser.ExternalizeL( aServerDataStoreFormat, *sb->iWrite ); |
|
619 sb->iWrite->CommitL(); |
|
620 AdjustChunkIfNeededLC( sb->iBuffer->Size() ); |
|
621 RMemWriteStream writeStream( iChunk.Base(), iChunk.Size() ); |
|
622 CleanupClosePushL( writeStream ); |
|
623 writeStream.WriteL( *sb->iRead ); |
|
624 CleanupStack::PopAndDestroy(); // writeStream |
|
625 |
|
626 aResultCode = SendReceive( ENSmlDSSetDataStoreFormat, TIpcArgs( aId, &aStoreName ) ); |
|
627 CleanupStack::PopAndDestroy(2); // AdjustChunkIfNeededLC, sb |
|
628 } |
|
629 |
|
630 // ------------------------------------------------------------------------------------------------ |
|
631 // RNSmlDSHostClient::SetRemoteMaxObjectSizeL |
|
632 // Sets the SyncML server Sync Partner maximum object size. |
|
633 // ------------------------------------------------------------------------------------------------ |
|
634 void RNSmlDSHostClient::SetRemoteMaxObjectSizeL( TInt aServerMaxObjectSize, const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) const |
|
635 { |
|
636 RMemWriteStream writeStream( iChunk.Base(), iChunk.Size() ); |
|
637 CleanupClosePushL( writeStream ); |
|
638 writeStream.WriteInt32L( aServerMaxObjectSize ); |
|
639 writeStream.CommitL(); |
|
640 CleanupStack::PopAndDestroy(); // writeStream |
|
641 |
|
642 aResultCode = SendReceive( ENSmlDSRemoteMaxObjSize, TIpcArgs( aId, &aStoreName ) ); |
|
643 } |
|
644 |
|
645 // ------------------------------------------------------------------------------------------------ |
|
646 // RNSmlDSHostClient::MaxObjectSize |
|
647 // Gets the Data Store maximum object size which is reported to the SyncML partner. |
|
648 // ------------------------------------------------------------------------------------------------ |
|
649 TInt RNSmlDSHostClient::MaxObjectSize( const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) const |
|
650 { |
|
651 TPckgBuf<TInt> pckg; |
|
652 aResultCode = SendReceive( ENSmlMaxObjSize, TIpcArgs( aId, &aStoreName, &pckg ) ); |
|
653 return pckg(); |
|
654 } |
|
655 |
|
656 // ------------------------------------------------------------------------------------------------ |
|
657 // RNSmlDSHostClient::OpenItemL |
|
658 // Opens item at Data Store. |
|
659 // ------------------------------------------------------------------------------------------------ |
|
660 void RNSmlDSHostClient::OpenItemL( TSmlDbItemUid aUid, TBool& aFieldChange, TInt& aSize, TSmlDbItemUid& aParent, HBufC8*& aMimeType, HBufC8*& aMimeVer, const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) const |
|
661 { |
|
662 |
|
663 CNSmlDSHostItem* item = CNSmlDSHostItem::NewLC(); |
|
664 item->SetUid( aUid ); |
|
665 |
|
666 RMemWriteStream writeStream( iChunk.Base(), iChunk.Size() ); |
|
667 CleanupClosePushL( writeStream ); |
|
668 item->ExternalizeL( writeStream ); |
|
669 writeStream.CommitL(); |
|
670 CleanupStack::PopAndDestroy(); // writeStream |
|
671 |
|
672 aResultCode = SendReceive( ENSmlItemOpen, TIpcArgs( aId, &aStoreName ) ); |
|
673 |
|
674 if ( aResultCode == KErrNone ) |
|
675 { |
|
676 RMemReadStream readStream( iChunk.Base(), iChunk.Size() ); |
|
677 CleanupClosePushL( readStream ); |
|
678 item->InternalizeL( readStream ); |
|
679 |
|
680 CleanupStack::PopAndDestroy(); // readStream |
|
681 |
|
682 aFieldChange = item->FieldChange(); |
|
683 aSize = item->Size(); |
|
684 if ( item->ParentUid() != -2 ) |
|
685 { |
|
686 aParent = item->ParentUid(); |
|
687 } |
|
688 aMimeType = item->MimeType()->AllocLC(); |
|
689 aMimeVer = item->MimeVer()->AllocLC(); |
|
690 CleanupStack::Pop(2); //aMimeVer, aMimeType |
|
691 } |
|
692 |
|
693 CleanupStack::PopAndDestroy(); // item |
|
694 } |
|
695 |
|
696 // ------------------------------------------------------------------------------------------------ |
|
697 // RNSmlDSHostClient::CreateItemL |
|
698 // Creates new item to Data Store. |
|
699 // ------------------------------------------------------------------------------------------------ |
|
700 void RNSmlDSHostClient::CreateItemL( TSmlDbItemUid& aUid, TInt aSize, TSmlDbItemUid aParent, const TDesC8& aMimeType, const TDesC8& aMimeVer, const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) |
|
701 { |
|
702 CNSmlDSHostItem* item = CNSmlDSHostItem::NewLC(); |
|
703 item->SetUid( aUid ); |
|
704 item->SetSize( aSize ); |
|
705 item->SetParentUid( aParent ); |
|
706 item->SetMimeTypeL( aMimeType ); |
|
707 item->SetMimeVerL( aMimeVer ); |
|
708 |
|
709 RMemWriteStream writeStream( iChunk.Base(), iChunk.Size() ); |
|
710 CleanupClosePushL( writeStream ); |
|
711 item->ExternalizeL( writeStream ); |
|
712 writeStream.CommitL(); |
|
713 CleanupStack::PopAndDestroy(); // writeStream |
|
714 |
|
715 aResultCode = SendReceive( ENSmlItemCreate, TIpcArgs( aId, &aStoreName ) ); |
|
716 |
|
717 if ( aResultCode == KErrNone ) |
|
718 { |
|
719 RMemReadStream readStream( iChunk.Base(), iChunk.Size() ); |
|
720 CleanupClosePushL( readStream ); |
|
721 item->InternalizeL( readStream ); |
|
722 |
|
723 CleanupStack::PopAndDestroy(); // readStream |
|
724 |
|
725 aUid = item->Uid(); |
|
726 iAddedUidBuffer = &aUid; |
|
727 if ( iMode == ENSmlBatchMode ) |
|
728 { |
|
729 iAddedUidsBuffer.AppendL( &aUid ); |
|
730 } |
|
731 iItemState = ENSmlItemCreating; |
|
732 } |
|
733 |
|
734 CleanupStack::PopAndDestroy(); // item |
|
735 } |
|
736 |
|
737 // ------------------------------------------------------------------------------------------------ |
|
738 // RNSmlDSHostClient::ReplaceItemL |
|
739 // Replaces old item at Data Store. |
|
740 // ------------------------------------------------------------------------------------------------ |
|
741 void RNSmlDSHostClient::ReplaceItemL( TSmlDbItemUid aUid, TInt aSize, TSmlDbItemUid aParent, TBool aFieldChange, TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) |
|
742 { |
|
743 CNSmlDSHostItem* item = CNSmlDSHostItem::NewLC(); |
|
744 item->SetUid( aUid ); |
|
745 item->SetSize( aSize ); |
|
746 item->SetParentUid( aParent ); |
|
747 item->SetFieldChange( aFieldChange ); |
|
748 |
|
749 RMemWriteStream writeStream( iChunk.Base(), iChunk.Size() ); |
|
750 CleanupClosePushL( writeStream ); |
|
751 item->ExternalizeL( writeStream ); |
|
752 writeStream.CommitL(); |
|
753 CleanupStack::PopAndDestroy( 2 ); // writeStream, item |
|
754 |
|
755 aResultCode = SendReceive( ENSmlItemReplace, TIpcArgs( aId, &aStoreName ) ); |
|
756 if ( aResultCode == KErrNone ) |
|
757 { |
|
758 iItemState = ENSmlItemUpdating; |
|
759 } |
|
760 } |
|
761 |
|
762 // ------------------------------------------------------------------------------------------------ |
|
763 // RNSmlDSHostClient::ReadItemL |
|
764 // Reads data from item at Data Store. Item must be opened before this method can be called. |
|
765 // This method is called until aBuffer is not used totally or method leaves with KErrEof. |
|
766 // ------------------------------------------------------------------------------------------------ |
|
767 void RNSmlDSHostClient::ReadItemL( TDes8& aBuffer, const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) const |
|
768 { |
|
769 RMemWriteStream writeStream; |
|
770 RMemReadStream readStream; |
|
771 CleanupClosePushL( writeStream ); |
|
772 CleanupClosePushL( readStream ); |
|
773 TInt size( aBuffer.MaxSize() ); |
|
774 TInt bytesRead(0), pos(0); |
|
775 aBuffer.Zero(); |
|
776 |
|
777 do |
|
778 { |
|
779 writeStream.Open( iChunk.Base(), iChunk.Size() ); |
|
780 writeStream.WriteInt32L( size ); |
|
781 |
|
782 aResultCode = SendReceive( ENSmlItemRead, TIpcArgs( aId, &aStoreName ) ); |
|
783 if ( aResultCode != KErrNone ) |
|
784 { |
|
785 break; |
|
786 } |
|
787 |
|
788 readStream.Open( iChunk.Base(), iChunk.Size() ); |
|
789 bytesRead = readStream.ReadInt32L(); |
|
790 TInt ll( aBuffer.Length() ); |
|
791 aBuffer.SetLength( ll + bytesRead ); |
|
792 TPtr8 des = aBuffer.MidTPtr( pos ); |
|
793 readStream.ReadL( des, bytesRead ); |
|
794 pos += bytesRead; |
|
795 |
|
796 } while( size -= bytesRead ); |
|
797 |
|
798 CleanupStack::PopAndDestroy(2); //readStream, writeStream |
|
799 } |
|
800 |
|
801 // ------------------------------------------------------------------------------------------------ |
|
802 // RNSmlDSHostClient::WriteItemL |
|
803 // Writes data to item to Data Provider. CreateItemL or ReplaceItemL method must be called before |
|
804 // this method can be called. This method is called until all data to current item is written. |
|
805 // ------------------------------------------------------------------------------------------------ |
|
806 void RNSmlDSHostClient::WriteItemL( const TDesC8& aData, const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) |
|
807 { |
|
808 AdjustChunkLC( aData.Size() + sizeof( TInt32 ) ); |
|
809 |
|
810 TInt sizeOfChunk( iChunk.Size() - sizeof( TInt32 ) ); |
|
811 |
|
812 RMemWriteStream writeStream; |
|
813 CleanupClosePushL( writeStream ); |
|
814 |
|
815 TInt sizeOfData( aData.Size() ), pos(0); |
|
816 |
|
817 do |
|
818 { |
|
819 TInt size( Min<TInt>( sizeOfData, sizeOfChunk ) ); |
|
820 writeStream.Open( iChunk.Base(), iChunk.Size() ); |
|
821 |
|
822 writeStream.WriteInt32L( size ); |
|
823 writeStream.WriteL( aData.Mid( pos, size ) ); |
|
824 writeStream.CommitL(); |
|
825 aResultCode = SendReceive( ENSmlItemWrite, TIpcArgs( aId, &aStoreName ) ); |
|
826 |
|
827 if ( aResultCode != KErrNone ) |
|
828 { |
|
829 break; |
|
830 } |
|
831 |
|
832 TInt32 bytesWritten(0); |
|
833 TPckg<TInt32> bytesWrittenPckg( bytesWritten ); |
|
834 bytesWrittenPckg.Copy( iChunk.Base(), sizeof( TInt32 ) ); |
|
835 |
|
836 if ( sizeOfData <= bytesWritten ) break; |
|
837 |
|
838 sizeOfData -= bytesWritten; |
|
839 pos += bytesWritten; |
|
840 |
|
841 } while( sizeOfData > 0 ); |
|
842 |
|
843 |
|
844 CleanupStack::PopAndDestroy(2); // writeStream, AdjustChunkLC |
|
845 } |
|
846 |
|
847 // ------------------------------------------------------------------------------------------------ |
|
848 // RNSmlDSHostClient::CommitItem |
|
849 // After item is written to Data Provider it can be saved to the Data Store. |
|
850 // This method can be called just after WriteItemL method. |
|
851 // ------------------------------------------------------------------------------------------------ |
|
852 void RNSmlDSHostClient::CommitItem( const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) |
|
853 { |
|
854 TPckgBuf<TInt> pckg; |
|
855 |
|
856 if ( iItemState == ENSmlClosed || ( iItemState == ENSmlItemCreating && !iAddedUidBuffer ) ) |
|
857 { |
|
858 aResultCode = KErrArgument; |
|
859 } |
|
860 else |
|
861 { |
|
862 |
|
863 aResultCode = SendReceive( ENSmlItemCommit, TIpcArgs( aId, &aStoreName, &pckg ) ); |
|
864 |
|
865 if ( iItemState == ENSmlItemCreating ) |
|
866 { |
|
867 *iAddedUidBuffer = pckg(); |
|
868 } |
|
869 } |
|
870 |
|
871 if (aResultCode == KErrNone) |
|
872 { |
|
873 iItemState = ENSmlClosed; |
|
874 } |
|
875 } |
|
876 |
|
877 // ------------------------------------------------------------------------------------------------ |
|
878 // RNSmlDSHostClient::CloseItem |
|
879 // Closes opened item. |
|
880 // ------------------------------------------------------------------------------------------------ |
|
881 void RNSmlDSHostClient::CloseItem( const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) |
|
882 { |
|
883 aResultCode = SendReceive( ENSmlItemClose, TIpcArgs( aId, &aStoreName ) ); |
|
884 |
|
885 if (aResultCode == KErrNone) |
|
886 { |
|
887 iItemState = ENSmlClosed; |
|
888 } |
|
889 } |
|
890 |
|
891 // ------------------------------------------------------------------------------------------------ |
|
892 // RNSmlDSHostClient::MoveItemL |
|
893 // Moves item to new location. |
|
894 // ------------------------------------------------------------------------------------------------ |
|
895 void RNSmlDSHostClient::MoveItemL( TSmlDbItemUid aUid, TSmlDbItemUid aNewParent, const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) |
|
896 { |
|
897 CNSmlDSHostItem* item = CNSmlDSHostItem::NewLC(); |
|
898 item->SetUid( aUid ); |
|
899 item->SetParentUid( aNewParent ); |
|
900 |
|
901 RMemWriteStream writeStream( iChunk.Base(), iChunk.Size() ); |
|
902 CleanupClosePushL( writeStream ); |
|
903 item->ExternalizeL( writeStream ); |
|
904 writeStream.CommitL(); |
|
905 CleanupStack::PopAndDestroy( 2 ); // writeStream, item |
|
906 |
|
907 aResultCode = SendReceive( ENSmlItemMove, TIpcArgs( aId, &aStoreName ) ); |
|
908 } |
|
909 |
|
910 // ------------------------------------------------------------------------------------------------ |
|
911 // RNSmlDSHostClient::DeleteItemL |
|
912 // Deletes one item at Data Store permanently. |
|
913 // ------------------------------------------------------------------------------------------------ |
|
914 void RNSmlDSHostClient::DeleteItemL( TSmlDbItemUid aUid, const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) const |
|
915 { |
|
916 CNSmlDSHostItem* item = CNSmlDSHostItem::NewLC(); |
|
917 item->SetUid( aUid ); |
|
918 |
|
919 RMemWriteStream writeStream( iChunk.Base(), iChunk.Size() ); |
|
920 CleanupClosePushL( writeStream ); |
|
921 item->ExternalizeL( writeStream ); |
|
922 writeStream.CommitL(); |
|
923 CleanupStack::PopAndDestroy( 2 ); // writeStream, item |
|
924 |
|
925 aResultCode = SendReceive( ENSmlItemDelete, TIpcArgs( aId, &aStoreName ) ); |
|
926 } |
|
927 |
|
928 // ------------------------------------------------------------------------------------------------ |
|
929 // RNSmlDSHostClient::SoftDeleteItemL |
|
930 // Soft deletes one item at Data Store. |
|
931 // ------------------------------------------------------------------------------------------------ |
|
932 void RNSmlDSHostClient::SoftDeleteItemL( TSmlDbItemUid aUid, const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) const |
|
933 { |
|
934 CNSmlDSHostItem* item = CNSmlDSHostItem::NewLC(); |
|
935 item->SetUid( aUid ); |
|
936 |
|
937 RMemWriteStream writeStream( iChunk.Base(), iChunk.Size() ); |
|
938 CleanupClosePushL( writeStream ); |
|
939 item->ExternalizeL( writeStream ); |
|
940 writeStream.CommitL(); |
|
941 CleanupStack::PopAndDestroy( 2 ); // writeStream, item |
|
942 |
|
943 aResultCode = SendReceive( ENSmlItemSoftDelete, TIpcArgs( aId, &aStoreName ) ); |
|
944 } |
|
945 |
|
946 // ------------------------------------------------------------------------------------------------ |
|
947 // RNSmlDSHostClient::DeleteAllItems |
|
948 // Deletes all items at Data Store permanently. |
|
949 // ------------------------------------------------------------------------------------------------ |
|
950 void RNSmlDSHostClient::DeleteAllItems( const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) const |
|
951 { |
|
952 aResultCode = SendReceive( ENSmlItemDeleteAll, TIpcArgs( aId, &aStoreName ) ); |
|
953 } |
|
954 |
|
955 // ------------------------------------------------------------------------------------------------ |
|
956 // RNSmlDSHostClient::HasSyncHistory |
|
957 // Checks if the Data Store has sync history. If not then slow sync is proposed to Sync Partner. |
|
958 // ------------------------------------------------------------------------------------------------ |
|
959 TBool RNSmlDSHostClient::HasSyncHistory( const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) const |
|
960 { |
|
961 TPckgBuf<TInt> pckg; |
|
962 aResultCode = SendReceive( ENSmlDSSyncHistory, TIpcArgs( aId, &aStoreName, &pckg ) ); |
|
963 return pckg(); |
|
964 } |
|
965 |
|
966 // ------------------------------------------------------------------------------------------------ |
|
967 // RNSmlDSHostClient::AddedItemsL |
|
968 // The Data Provider returns UIDs of items that are added after previous synchronization. |
|
969 // If the Data Provider uses hierarchical synchronization then added folders must be placed |
|
970 // first (from root to leaves) to UID set and finally items. |
|
971 // ------------------------------------------------------------------------------------------------ |
|
972 void RNSmlDSHostClient::AddedItemsL( RNSmlDbItemModificationSet& aUidSet, const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) const |
|
973 { |
|
974 aResultCode = SendReceive( ENSmlDSItemsAdded, TIpcArgs( aId, &aStoreName ) ); |
|
975 CleanupStack::PushL( TCleanupItem ( CancelAdjust, const_cast<RNSmlDSHostClient*>( this ) ) ); |
|
976 if ( aResultCode == KErrNone ) |
|
977 { |
|
978 RMemReadStream readStream( iChunk.Base(), iChunk.Size() ); |
|
979 CleanupClosePushL( readStream ); |
|
980 aUidSet.InternalizeL( readStream ); |
|
981 CleanupStack::PopAndDestroy(); // readStream |
|
982 } |
|
983 |
|
984 CleanupStack::PopAndDestroy(); // CancelAdjust |
|
985 } |
|
986 |
|
987 // ------------------------------------------------------------------------------------------------ |
|
988 // RNSmlDSHostClient::DeletedItemsL |
|
989 // The Data Provider returns UIDs of items that are deleted after previous synchronization. |
|
990 // If the Data Provider uses hierarchical synchronization then deleted items must be placed |
|
991 // first to UID set and folders after items (from leaves to root). |
|
992 // ------------------------------------------------------------------------------------------------ |
|
993 void RNSmlDSHostClient::DeletedItemsL( RNSmlDbItemModificationSet& aUidSet, const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) const |
|
994 { |
|
995 aResultCode = SendReceive( ENSmlDSItemsDeleted, TIpcArgs( aId, &aStoreName ) ); |
|
996 CleanupStack::PushL( TCleanupItem ( CancelAdjust, const_cast<RNSmlDSHostClient*>( this ) ) ); |
|
997 if ( aResultCode == KErrNone ) |
|
998 { |
|
999 RMemReadStream readStream( iChunk.Base(), iChunk.Size() ); |
|
1000 CleanupClosePushL( readStream ); |
|
1001 aUidSet.InternalizeL( readStream ); |
|
1002 CleanupStack::PopAndDestroy(); // readStream |
|
1003 } |
|
1004 |
|
1005 CleanupStack::PopAndDestroy(); // CancelAdjust |
|
1006 } |
|
1007 |
|
1008 // ------------------------------------------------------------------------------------------------ |
|
1009 // RNSmlDSHostClient::SoftDeleteItemsL |
|
1010 // The Data Provider returns UIDs of items that are soft deleted after previous synchronization. |
|
1011 // If the Data Provider uses hierarchical synchronization then soft deleted items must be placed |
|
1012 // first to UID set and folders after items (from leaves to root). |
|
1013 // ------------------------------------------------------------------------------------------------ |
|
1014 void RNSmlDSHostClient::SoftDeleteItemsL( RNSmlDbItemModificationSet& aUidSet, const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) const |
|
1015 { |
|
1016 aResultCode = SendReceive( ENSmlDSItemsSofDeleted, TIpcArgs( aId, &aStoreName ) ); |
|
1017 CleanupStack::PushL( TCleanupItem ( CancelAdjust, const_cast<RNSmlDSHostClient*>( this ) ) ); |
|
1018 if ( aResultCode == KErrNone ) |
|
1019 { |
|
1020 RMemReadStream readStream( iChunk.Base(), iChunk.Size() ); |
|
1021 CleanupClosePushL( readStream ); |
|
1022 aUidSet.InternalizeL( readStream ); |
|
1023 CleanupStack::PopAndDestroy(); // readStream |
|
1024 } |
|
1025 |
|
1026 CleanupStack::PopAndDestroy(); // CancelAdjust |
|
1027 } |
|
1028 |
|
1029 // ------------------------------------------------------------------------------------------------ |
|
1030 // RNSmlDSHostClient::ModifiedItemsL |
|
1031 // The Data Provider returns UIDs of items that are modified after previous synchronization. |
|
1032 // If the Data Provider uses hierarchical synchronization then modified folders must be placed |
|
1033 // first (from root to leaves) to UID set and finally items. |
|
1034 // ------------------------------------------------------------------------------------------------ |
|
1035 void RNSmlDSHostClient::ModifiedItemsL( RNSmlDbItemModificationSet& aUidSet, const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) const |
|
1036 { |
|
1037 aResultCode = SendReceive( ENSmlDSItemsModified, TIpcArgs( aId, &aStoreName ) ); |
|
1038 CleanupStack::PushL( TCleanupItem ( CancelAdjust, const_cast<RNSmlDSHostClient*>( this ) ) ); |
|
1039 if ( aResultCode == KErrNone ) |
|
1040 { |
|
1041 RMemReadStream readStream( iChunk.Base(), iChunk.Size() ); |
|
1042 CleanupClosePushL( readStream ); |
|
1043 aUidSet.InternalizeL( readStream ); |
|
1044 CleanupStack::PopAndDestroy(); // readStream |
|
1045 } |
|
1046 |
|
1047 CleanupStack::PopAndDestroy(); // CancelAdjust |
|
1048 } |
|
1049 |
|
1050 // ------------------------------------------------------------------------------------------------ |
|
1051 // RNSmlDSHostClient::MovedItemsL |
|
1052 // The Data Provider returns UIDs of items that are moved after previous synchronization. |
|
1053 // If the Data Provider uses hierarchical synchronization then moved folders must be placed |
|
1054 // first (from root to leaves) to UID set and finally items. |
|
1055 // ------------------------------------------------------------------------------------------------ |
|
1056 void RNSmlDSHostClient::MovedItemsL( RNSmlDbItemModificationSet& aUidSet, const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) const |
|
1057 { |
|
1058 aResultCode = SendReceive( ENSmlDSItemsMoved, TIpcArgs( aId, &aStoreName ) ); |
|
1059 CleanupStack::PushL( TCleanupItem ( CancelAdjust, const_cast<RNSmlDSHostClient*>( this ) ) ); |
|
1060 if ( aResultCode == KErrNone ) |
|
1061 { |
|
1062 RMemReadStream readStream( iChunk.Base(), iChunk.Size() ); |
|
1063 CleanupClosePushL( readStream ); |
|
1064 aUidSet.InternalizeL( readStream ); |
|
1065 CleanupStack::PopAndDestroy(); // readStream |
|
1066 } |
|
1067 |
|
1068 CleanupStack::PopAndDestroy(); // CancelAdjust |
|
1069 } |
|
1070 |
|
1071 // ------------------------------------------------------------------------------------------------ |
|
1072 // RNSmlDSHostClient::AllItemsL |
|
1073 // The Data Provider returns UIDs of items that are added, deleted, modified, softdeleted |
|
1074 // or moved after previous synchronization. |
|
1075 // ------------------------------------------------------------------------------------------------ |
|
1076 void RNSmlDSHostClient::AllItemsL( RNSmlDbItemModificationSet& aUidSet, const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) const |
|
1077 { |
|
1078 aResultCode = SendReceive( ENSmlDSItemsAll, TIpcArgs( aId, &aStoreName ) ); |
|
1079 CleanupStack::PushL( TCleanupItem ( CancelAdjust, const_cast<RNSmlDSHostClient*>( this ) ) ); |
|
1080 if ( aResultCode == KErrNone ) |
|
1081 { |
|
1082 RMemReadStream readStream( iChunk.Base(), iChunk.Size() ); |
|
1083 CleanupClosePushL( readStream ); |
|
1084 aUidSet.InternalizeL( readStream ); |
|
1085 CleanupStack::PopAndDestroy(); // readStream |
|
1086 } |
|
1087 |
|
1088 CleanupStack::PopAndDestroy(); // CancelAdjust |
|
1089 } |
|
1090 |
|
1091 // ------------------------------------------------------------------------------------------------ |
|
1092 // RNSmlDSHostClient::ResetChangeInfo |
|
1093 // Reset change info from the Data Provider. The result of this method is that the Data Provider |
|
1094 // sends just ADD commands to Sync Partner. |
|
1095 // ------------------------------------------------------------------------------------------------ |
|
1096 void RNSmlDSHostClient::ResetChangeInfo( const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) const |
|
1097 { |
|
1098 aResultCode = SendReceive( ENSmlDSResetChangeInfo, TIpcArgs( aId, &aStoreName ) ); |
|
1099 } |
|
1100 |
|
1101 // ------------------------------------------------------------------------------------------------ |
|
1102 // RNSmlDSHostClient::CommitChangeInfoL |
|
1103 // This method is called after some changes are synchronized to Sync Partner. If some changes |
|
1104 // were synchronized correctly then those UIDs are included to aItems. |
|
1105 // ------------------------------------------------------------------------------------------------ |
|
1106 void RNSmlDSHostClient::CommitChangeInfoL( const MSmlDataItemUidSet& aItems, const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) |
|
1107 { |
|
1108 TStreamBuffers* sb = StreamBufferLC(); |
|
1109 aItems.ExternalizeL( *sb->iWrite ); |
|
1110 sb->iWrite->CommitL(); |
|
1111 AdjustChunkIfNeededLC( sb->iBuffer->Size() ); |
|
1112 |
|
1113 RMemWriteStream writeStream( iChunk.Base(), iChunk.Size() ); |
|
1114 CleanupClosePushL( writeStream ); |
|
1115 writeStream.WriteL( *sb->iRead ); |
|
1116 writeStream.CommitL(); |
|
1117 |
|
1118 aResultCode = SendReceive( ENSmlDSCommitChanges, TIpcArgs( aId, &aStoreName ) ); |
|
1119 CleanupStack::PopAndDestroy(3); // writeStream, AdjustChunkIfNeededLC, sb |
|
1120 } |
|
1121 |
|
1122 // ------------------------------------------------------------------------------------------------ |
|
1123 // RNSmlDSHostClient::CommitChangeInfo |
|
1124 // This method is called after some changes are synchronized to Sync Partner. This method is used if |
|
1125 // all changes were synchronized correctly. |
|
1126 // ------------------------------------------------------------------------------------------------ |
|
1127 void RNSmlDSHostClient::CommitChangeInfo( const TSmlDataProviderId aId, const TDesC& aStoreName, TInt& aResultCode ) const |
|
1128 { |
|
1129 aResultCode = SendReceive( ENSmlDSCommitAllChanges, TIpcArgs( aId, &aStoreName ) ); |
|
1130 } |
|
1131 |
|
1132 // ------------------------------------------------------------------------------------------------ |
|
1133 // RNSmlDSHostClient::UpdateServerIdL |
|
1134 // Replaces the give old server ID with new one. |
|
1135 // ------------------------------------------------------------------------------------------------ |
|
1136 void RNSmlDSHostClient::UpdateServerIdL( TDesC& aOldServerId, TDesC& aNewValue, TInt& aResultCode ) |
|
1137 { |
|
1138 AdjustChunkIfNeededLC( aOldServerId.Length() + aNewValue.Length() + 2*sizeof(TInt32) + 5 ); |
|
1139 RMemWriteStream writeStream( iChunk.Base(), iChunk.Size() ); |
|
1140 CleanupClosePushL( writeStream ); |
|
1141 |
|
1142 writeStream.WriteUint32L( aOldServerId.Length() ); |
|
1143 writeStream << aOldServerId; |
|
1144 writeStream.WriteUint32L( aNewValue.Length() ); |
|
1145 writeStream << aNewValue; |
|
1146 |
|
1147 aResultCode = SendReceive( ENSmlDSUpdateServerId, TIpcArgs() ); |
|
1148 CleanupStack::PopAndDestroy(2); // writeStream, AdjustChunkIfNeededLC |
|
1149 } |
|
1150 |
|
1151 // ------------------------------------------------------------------------------------------------ |
|
1152 // RNSmlDSHostClient - private methods |
|
1153 // ------------------------------------------------------------------------------------------------ |
|
1154 // ------------------------------------------------------------------------------------------------ |
|
1155 // RNSmlDSHostClient::LaunchServer |
|
1156 // Starts Host Server. |
|
1157 // ------------------------------------------------------------------------------------------------ |
|
1158 TInt RNSmlDSHostClient::LaunchServer( const TDesC& aServerName ) const |
|
1159 { |
|
1160 TInt result( KErrNone ); |
|
1161 |
|
1162 TParse parser; |
|
1163 if ( aServerName.Compare( KNSmlDSHostServer1Name ) == 0 ) |
|
1164 { |
|
1165 parser.Set( KNSmlDSHostServer1Exe, &KDC_PROGRAMS_DIR, NULL ); |
|
1166 } |
|
1167 else if ( aServerName.Compare( KNSmlDSHostServer2Name ) == 0 ) |
|
1168 { |
|
1169 parser.Set( KNSmlDSHostServer2Exe, &KDC_PROGRAMS_DIR, NULL ); |
|
1170 } |
|
1171 else |
|
1172 { |
|
1173 return KErrNotSupported; |
|
1174 } |
|
1175 |
|
1176 // DLL launch |
|
1177 RProcess server; |
|
1178 result = server.Create( parser.FullName(), KNullDesC ); |
|
1179 |
|
1180 // Loading failed. |
|
1181 if ( result != KErrNone ) |
|
1182 { |
|
1183 return result; |
|
1184 } |
|
1185 |
|
1186 TRequestStatus status; |
|
1187 server.Rendezvous( status ); |
|
1188 |
|
1189 if ( status != KRequestPending ) |
|
1190 { |
|
1191 server.Kill( 0 ); // abort startup |
|
1192 server.Close(); |
|
1193 return KErrGeneral; // status can be KErrNone: don't return status.Int() |
|
1194 } |
|
1195 else |
|
1196 { |
|
1197 server.Resume(); // logon OK - start the server |
|
1198 } |
|
1199 |
|
1200 User::WaitForRequest( status ); |
|
1201 |
|
1202 result = status.Int(); |
|
1203 |
|
1204 if ( status != KErrNone ) |
|
1205 { |
|
1206 server.Close(); |
|
1207 } |
|
1208 |
|
1209 return result; |
|
1210 } |
|
1211 |
|
1212 |
|
1213 // ------------------------------------------------------------------------------------------------ |
|
1214 // RNSmlDSHostClient::StreamBufferLC |
|
1215 // ------------------------------------------------------------------------------------------------ |
|
1216 RNSmlDSHostClient::TStreamBuffers* RNSmlDSHostClient::StreamBufferLC() const |
|
1217 { |
|
1218 TStreamBuffers* cleanup = new ( ELeave ) TStreamBuffers; |
|
1219 CleanupStack::PushL( TCleanupItem ( CleanupStreamBuffer, cleanup ) ); |
|
1220 cleanup->iBuffer = CBufFlat::NewL( 64 ); |
|
1221 cleanup->iWrite = new ( ELeave ) RBufWriteStream( *cleanup->iBuffer ); |
|
1222 cleanup->iRead = new ( ELeave ) RBufReadStream( *cleanup->iBuffer ); |
|
1223 return cleanup; |
|
1224 } |
|
1225 |
|
1226 // ------------------------------------------------------------------------------------------------ |
|
1227 // RNSmlDSHostClient::CleanupStreamBuffer |
|
1228 // ------------------------------------------------------------------------------------------------ |
|
1229 void RNSmlDSHostClient::CleanupStreamBuffer( TAny* aP ) |
|
1230 { |
|
1231 TStreamBuffers* cleanup = reinterpret_cast<TStreamBuffers*>( aP ); |
|
1232 |
|
1233 if ( cleanup->iWrite ) |
|
1234 { |
|
1235 cleanup->iWrite->Close(); |
|
1236 delete cleanup->iWrite; |
|
1237 } |
|
1238 |
|
1239 if ( cleanup->iRead ) |
|
1240 { |
|
1241 cleanup->iRead->Close(); |
|
1242 delete cleanup->iRead; |
|
1243 } |
|
1244 |
|
1245 delete cleanup->iBuffer; |
|
1246 delete cleanup; |
|
1247 } |
|
1248 |
|
1249 // ------------------------------------------------------------------------------------------------ |
|
1250 // RNSmlDSHostClient::AdjustChunkLC |
|
1251 // Ensures that chunk has at least required size or max size of reserved memory. |
|
1252 // ------------------------------------------------------------------------------------------------ |
|
1253 void RNSmlDSHostClient::AdjustChunkLC( TInt aRequiredSize ) const |
|
1254 { |
|
1255 const RNSmlDSHostClient* ptr = NULL; |
|
1256 |
|
1257 if ( iChunk.Size() < aRequiredSize ) |
|
1258 { |
|
1259 TInt maxSize( iChunk.MaxSize() ); |
|
1260 |
|
1261 if ( aRequiredSize > maxSize ) |
|
1262 { |
|
1263 aRequiredSize = maxSize; |
|
1264 } |
|
1265 |
|
1266 User::LeaveIfError( iChunk.Adjust( aRequiredSize ) ); |
|
1267 ptr = this; |
|
1268 } |
|
1269 |
|
1270 CleanupStack::PushL( TCleanupItem ( CancelAdjust, const_cast<RNSmlDSHostClient*>( ptr ) ) ); |
|
1271 } |
|
1272 |
|
1273 // ------------------------------------------------------------------------------------------------ |
|
1274 // RNSmlDSHostClient::AdjustChunkIfNeededLC |
|
1275 // Adjusts memory so that at least needed size is reserved. |
|
1276 // ------------------------------------------------------------------------------------------------ |
|
1277 void RNSmlDSHostClient::AdjustChunkIfNeededLC( TInt iNeededSize ) const |
|
1278 { |
|
1279 const RNSmlDSHostClient* ptr = NULL; |
|
1280 |
|
1281 if ( iChunk.Size() < iNeededSize ) |
|
1282 { |
|
1283 User::LeaveIfError( iChunk.Adjust( iNeededSize ) ); |
|
1284 ptr = this; |
|
1285 } |
|
1286 |
|
1287 CleanupStack::PushL( TCleanupItem ( CancelAdjust, const_cast<RNSmlDSHostClient*>( ptr ) ) ); |
|
1288 } |
|
1289 |
|
1290 // ------------------------------------------------------------------------------------------------ |
|
1291 // RNSmlDSHostClient::CancelAdjust |
|
1292 // restores chunk memory. |
|
1293 // ------------------------------------------------------------------------------------------------ |
|
1294 void RNSmlDSHostClient::CancelAdjust( TAny* aP ) |
|
1295 { |
|
1296 if ( aP ) |
|
1297 { |
|
1298 RNSmlDSHostClient* self = reinterpret_cast<RNSmlDSHostClient*>( aP ); |
|
1299 self->iChunk.Adjust( KNSmlDSHostChunkMinSize ); |
|
1300 } |
|
1301 } |
|
1302 |
|
1303 // ------------------------------------------------------------------------------------------------ |
|
1304 // RNSmlDSHostClient::InternalizeFiltersL |
|
1305 // Reads filters from stream. |
|
1306 // ------------------------------------------------------------------------------------------------ |
|
1307 void RNSmlDSHostClient::InternalizeFiltersL( RReadStream& aStream, RPointerArray<CSyncMLFilter>& aFilters ) const |
|
1308 { |
|
1309 aFilters.ResetAndDestroy(); |
|
1310 |
|
1311 TInt count( aStream.ReadInt32L() ); |
|
1312 |
|
1313 for ( TInt i = 0; i < count; i++ ) |
|
1314 { |
|
1315 CSyncMLFilter* filter = CSyncMLFilter::NewLC( aStream ); |
|
1316 aFilters.AppendL( filter ); |
|
1317 CleanupStack::Pop(); // filter |
|
1318 } |
|
1319 } |
|
1320 |
|
1321 // ------------------------------------------------------------------------------------------------ |
|
1322 // RNSmlDSHostClient::ExternalizeFiltersL |
|
1323 // Writes filters to stream. |
|
1324 // ------------------------------------------------------------------------------------------------ |
|
1325 void RNSmlDSHostClient::ExternalizeFiltersL( RWriteStream& aStream, const RPointerArray<CSyncMLFilter>& aFilters ) const |
|
1326 { |
|
1327 TInt count( aFilters.Count() ); |
|
1328 aStream.WriteInt32L( count ); |
|
1329 for ( TInt i(0); i < count; i++ ) |
|
1330 { |
|
1331 aFilters[i]->ExternalizeL( aStream ); |
|
1332 } |
|
1333 } |
|
1334 |
|
1335 // End of File |