40
|
1 |
/*
|
64
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
40
|
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: CSconAsyncHandler implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "sconasynchandler.h"
|
|
20 |
|
|
21 |
#include <ecom/ecom.h>
|
|
22 |
#include <SmlDataProvider.h>
|
|
23 |
#include <s32mem.h>
|
|
24 |
#include <nsmlchangefinder.h>
|
|
25 |
#include <e32cmn.h>
|
|
26 |
#include <ecom/ImplementationInformation.h>
|
|
27 |
#include <mmf/common/mmfcontrollerpluginresolver.h>
|
|
28 |
|
|
29 |
#include "sconsyncclientserver.h"
|
|
30 |
#include "sconsyncrelationship.h"
|
|
31 |
#include "scondataproviderinfo.h"
|
|
32 |
#include "debug.h"
|
|
33 |
#include "logdatastoreformat.h"
|
|
34 |
|
|
35 |
// Data Store interface implementation Uid.
|
|
36 |
// Load all plugins with this uid.
|
|
37 |
const TUid KDSEcomIFUid = {0x101F4D3A};
|
|
38 |
|
|
39 |
const TInt KDefaultExpandSize = 1024;
|
|
40 |
|
|
41 |
// one store per computer, max store count.
|
|
42 |
const TInt KMaxStoresCount = 10;
|
|
43 |
|
|
44 |
const TInt KDefaultTimeOutInMicroSeconds = 30 * 1000000; // 30 seconds
|
64
|
45 |
const TInt KDeleteAllTimeOutInMicroSeconds = 540 * 1000000; // 9 minutes
|
|
46 |
const TInt KOpenStoreTimeOutInMicroSeconds = 540 * 1000000; // 9 minutes
|
|
47 |
const TInt KResetChangeInfoTimeOutInMicroSeconds = 540 * 1000000; // 9 minutes
|
40
|
48 |
|
|
49 |
CSconAsyncHandler::~CSconAsyncHandler()
|
|
50 |
{
|
|
51 |
TRACE_FUNC_ENTRY;
|
|
52 |
Cancel();
|
|
53 |
DoCloseStore();
|
|
54 |
delete iItems;
|
|
55 |
delete iWriteData;
|
|
56 |
delete iDataStore;
|
|
57 |
delete iDataProvider;
|
|
58 |
delete iContext;
|
|
59 |
delete iStoreFormat;
|
|
60 |
iStringPool.Close();
|
|
61 |
iFs.Close();
|
|
62 |
REComSession::FinalClose();
|
|
63 |
iChunk.Close();
|
|
64 |
delete iTimeOut;
|
|
65 |
TRACE_FUNC_EXIT;
|
|
66 |
}
|
|
67 |
|
|
68 |
CSconAsyncHandler::CSconAsyncHandler(): CActive( EPriorityStandard )
|
|
69 |
{
|
|
70 |
TRACE_FUNC;
|
|
71 |
CActiveScheduler::Add( this );
|
|
72 |
}
|
|
73 |
|
|
74 |
CSconAsyncHandler* CSconAsyncHandler::NewL()
|
|
75 |
{
|
|
76 |
TRACE_FUNC;
|
|
77 |
CSconAsyncHandler* self = new(ELeave) CSconAsyncHandler();
|
|
78 |
CleanupStack::PushL( self );
|
|
79 |
self->ConstructL();
|
|
80 |
CleanupStack::Pop( self );
|
|
81 |
return self;
|
|
82 |
}
|
|
83 |
|
|
84 |
void CSconAsyncHandler::ConstructL()
|
|
85 |
{
|
|
86 |
TRACE_FUNC;
|
|
87 |
User::LeaveIfError( iFs.Connect() );
|
|
88 |
TInt err = iFs.CreatePrivatePath( EDriveC );
|
|
89 |
LOGGER_WRITE_1("CreatePrivatePath err: %d", err);
|
|
90 |
iStringPool.OpenL();
|
|
91 |
iTimeOut = CCSconTimeOut::NewL( *this );
|
|
92 |
}
|
|
93 |
|
|
94 |
// -----------------------------------------------------------------------------
|
|
95 |
// CSconAsyncHandler::HandleServiceL()
|
|
96 |
// Handles the client request
|
|
97 |
// -----------------------------------------------------------------------------
|
|
98 |
//
|
|
99 |
void CSconAsyncHandler::HandleServiceL( const RMessage2& aMessage )
|
|
100 |
{
|
|
101 |
TRACE_FUNC_ENTRY;
|
|
102 |
if ( aMessage.Function() == ECancelRequest )
|
|
103 |
{
|
|
104 |
LOGGER_WRITE("ECancelRequest");
|
|
105 |
if ( IsActive() )
|
|
106 |
{
|
|
107 |
Cancel();
|
|
108 |
LOGGER_WRITE("iMessage.Complete( KErrCancel )");
|
|
109 |
CompleteRequest( KErrCancel );
|
|
110 |
}
|
|
111 |
|
|
112 |
LOGGER_WRITE("aMessage.Complete( KErrNone )");
|
|
113 |
aMessage.Complete( KErrNone );
|
|
114 |
TRACE_FUNC_EXIT;
|
|
115 |
return;
|
|
116 |
}
|
|
117 |
|
|
118 |
iTimeOut->Start( KDefaultTimeOutInMicroSeconds );
|
|
119 |
|
|
120 |
iMessage = aMessage;
|
|
121 |
switch ( aMessage.Function() )
|
|
122 |
{
|
|
123 |
case ESendChunkHandle:
|
|
124 |
LOGGER_WRITE( "CSconSyncSession::ServiceL() : ESendChunkHandle" );
|
|
125 |
HandleChunkMessage();
|
|
126 |
break;
|
|
127 |
|
|
128 |
case EListImplementations:
|
|
129 |
LOGGER_WRITE( "CSconSyncSession::ServiceL() : EListImplementations" );
|
|
130 |
ListAllImplementationsL();
|
|
131 |
break;
|
|
132 |
|
|
133 |
case EOpenStore:
|
|
134 |
LOGGER_WRITE( "CSconSyncSession::ServiceL() : EOpenStore" );
|
|
135 |
iTimeOut->Start( KOpenStoreTimeOutInMicroSeconds );
|
|
136 |
OpenStoreL();
|
|
137 |
break;
|
|
138 |
|
|
139 |
case EOpenItem:
|
|
140 |
OpenItemL();
|
|
141 |
break;
|
|
142 |
case ECreateItem:
|
|
143 |
CreateItemL();
|
|
144 |
break;
|
|
145 |
case EReplaceItem:
|
|
146 |
ReplaceItemL();
|
|
147 |
break;
|
|
148 |
case EMoveItem:
|
|
149 |
MoveItemL();
|
|
150 |
break;
|
|
151 |
case EDeleteItem:
|
|
152 |
DeleteItemL();
|
|
153 |
break;
|
|
154 |
case ESoftDeleteItem:
|
|
155 |
SoftDeleteItemL();
|
|
156 |
break;
|
|
157 |
case EDeleteAllItems:
|
|
158 |
iTimeOut->Start( KDeleteAllTimeOutInMicroSeconds );
|
|
159 |
DeleteAllItemsL();
|
|
160 |
break;
|
|
161 |
case EReadParent:
|
|
162 |
ReadParentL();
|
|
163 |
break;
|
|
164 |
|
|
165 |
case EHasHistory:
|
|
166 |
HasHistoryL();
|
|
167 |
break;
|
|
168 |
case EAddedItems:
|
|
169 |
AddedItemsL();
|
|
170 |
break;
|
|
171 |
case EDeletedItems:
|
|
172 |
DeletedItemsL();
|
|
173 |
break;
|
|
174 |
case ESoftDeletedItems:
|
|
175 |
SoftDeletedItemsL();
|
|
176 |
break;
|
|
177 |
case EModifiedItems:
|
|
178 |
ModifiedItemsL();
|
|
179 |
break;
|
|
180 |
case EMovedItems:
|
|
181 |
MovedItemsL();
|
|
182 |
break;
|
|
183 |
case EResetChangeInfo:
|
64
|
184 |
iTimeOut->Start( KResetChangeInfoTimeOutInMicroSeconds );
|
40
|
185 |
ResetChangeInfoL();
|
|
186 |
break;
|
|
187 |
case ECommitChangeInfo:
|
|
188 |
CommitChangeInfoL();
|
|
189 |
break;
|
|
190 |
case ECloseStore:
|
|
191 |
CloseStore();
|
|
192 |
break;
|
|
193 |
case ESetSyncTimeStamp:
|
|
194 |
SetSyncTimeStampL();
|
|
195 |
break;
|
|
196 |
case EGetSyncTimeStamp:
|
|
197 |
GetSyncTimeStampL();
|
|
198 |
break;
|
|
199 |
case EExportStoreFormat:
|
|
200 |
ExportStoreFormatL();
|
|
201 |
break;
|
|
202 |
case ESetRemoteStoreFormat:
|
|
203 |
SetRemoteStoreFormatL();
|
|
204 |
break;
|
|
205 |
|
|
206 |
default:
|
|
207 |
aMessage.Complete(KErrNotSupported);
|
|
208 |
break;
|
|
209 |
}
|
|
210 |
TRACE_FUNC_EXIT;
|
|
211 |
}
|
|
212 |
|
|
213 |
|
|
214 |
void CSconAsyncHandler::RunL()
|
|
215 |
{
|
|
216 |
TRACE_FUNC_ENTRY;
|
|
217 |
LOGGER_WRITE_1("iStatus.Int(): %d", iStatus.Int());
|
|
218 |
switch ( iMessage.Function() )
|
|
219 |
{
|
|
220 |
case EOpenStore:
|
|
221 |
LOGGER_WRITE( "CSconAsyncHandler::RunL() : EOpenStore" );
|
|
222 |
CompleteRequest( iStatus.Int() );
|
|
223 |
break;
|
|
224 |
|
|
225 |
case EOpenItem:
|
|
226 |
LOGGER_WRITE( "CSconAsyncHandler::RunL() : EOpenItem" );
|
|
227 |
OpenItemCompletedL( iStatus.Int() );
|
|
228 |
break;
|
|
229 |
|
|
230 |
case ECreateItem:
|
|
231 |
LOGGER_WRITE( "CSconAsyncHandler::RunL() : ECreateItem" );
|
|
232 |
if (!iCommitInProgress)
|
|
233 |
{
|
|
234 |
// Write data to item
|
|
235 |
CreateItemCompletedL( iStatus.Int() );
|
|
236 |
}
|
|
237 |
else
|
|
238 |
{
|
|
239 |
// commit is done, all ready
|
|
240 |
LOGGER_WRITE( "CSconAsyncHandler::RunL() : ECreateItem, commit done" );
|
|
241 |
TPckg<TSmlDbItemUid> pckg(iNewItem);
|
|
242 |
iMessage.WriteL( 0, pckg, 0);
|
|
243 |
CompleteRequest( iStatus.Int() );
|
|
244 |
}
|
|
245 |
break;
|
|
246 |
|
|
247 |
case EReplaceItem:
|
|
248 |
LOGGER_WRITE( "CSconAsyncHandler::RunL() : EReplaceItem" );
|
|
249 |
if (!iCommitInProgress)
|
|
250 |
{
|
|
251 |
// Write data to item
|
|
252 |
ReplaceItemCompletedL( iStatus.Int() );
|
|
253 |
}
|
|
254 |
else
|
|
255 |
{
|
|
256 |
// commit is done, all ready
|
|
257 |
LOGGER_WRITE( "CSconAsyncHandler::RunL() : EReplaceItem, commit done" );
|
|
258 |
CompleteRequest( iStatus.Int() );
|
|
259 |
}
|
|
260 |
break;
|
|
261 |
|
|
262 |
case EMoveItem:
|
|
263 |
LOGGER_WRITE( "CSconAsyncHandler::RunL() : EMoveItem" );
|
|
264 |
CompleteRequest( iStatus.Int() );
|
|
265 |
break;
|
|
266 |
|
|
267 |
case EDeleteItem:
|
|
268 |
LOGGER_WRITE( "CSconAsyncHandler::RunL() : EDeleteItem" );
|
|
269 |
CompleteRequest( iStatus.Int() );
|
|
270 |
break;
|
|
271 |
|
|
272 |
case ESoftDeleteItem:
|
|
273 |
LOGGER_WRITE( "CSconAsyncHandler::RunL() : ESoftDeleteItem" );
|
|
274 |
CompleteRequest( iStatus.Int() );
|
|
275 |
break;
|
|
276 |
|
|
277 |
case EDeleteAllItems:
|
|
278 |
LOGGER_WRITE( "CSconAsyncHandler::RunL() : EDeleteAllItems" );
|
|
279 |
CompleteRequest( iStatus.Int() );
|
|
280 |
break;
|
|
281 |
|
|
282 |
case EReadParent:
|
|
283 |
LOGGER_WRITE( "CSconAsyncHandler::RunL() : EReadParent" );
|
|
284 |
ReadParentCompletedL( iStatus.Int() );
|
|
285 |
break;
|
|
286 |
|
|
287 |
case EResetChangeInfo:
|
|
288 |
LOGGER_WRITE( "CSconAsyncHandler::RunL() : EResetChangeInfo" );
|
|
289 |
CompleteRequest( iStatus.Int() );
|
|
290 |
break;
|
|
291 |
|
|
292 |
case ECommitChangeInfo:
|
|
293 |
LOGGER_WRITE( "CSconAsyncHandler::RunL() : ECommitChangeInfo" );
|
|
294 |
delete iItems;
|
|
295 |
iItems = NULL;
|
|
296 |
CompleteRequest( iStatus.Int() );
|
|
297 |
break;
|
|
298 |
|
|
299 |
default:
|
|
300 |
LOGGER_WRITE("Not asynchronous function")
|
|
301 |
CompleteRequest( KErrNotSupported );
|
|
302 |
break;
|
|
303 |
}
|
|
304 |
TRACE_FUNC_EXIT;
|
|
305 |
}
|
|
306 |
|
|
307 |
TInt CSconAsyncHandler::RunError(TInt aError)
|
|
308 |
{
|
|
309 |
LOGGER_WRITE_1("CSconAsyncHandler::RunError() aError: %d", aError);
|
|
310 |
delete iItems;
|
|
311 |
iItems = NULL;
|
|
312 |
delete iWriteData;
|
|
313 |
iWriteData = NULL;
|
|
314 |
|
|
315 |
if ( IsActive() )
|
|
316 |
{
|
|
317 |
LOGGER_WRITE("IsActive");
|
|
318 |
//iDataStore->CancelRequest();
|
|
319 |
Cancel();
|
|
320 |
}
|
|
321 |
|
|
322 |
if ( iDataStore && iMessage.Function() == EOpenItem )
|
|
323 |
{
|
|
324 |
LOGGER_WRITE( "CSconAsyncHandler::RunError() : EOpenItem" );
|
|
325 |
iDataStore->CloseItem();
|
|
326 |
}
|
|
327 |
|
|
328 |
CompleteRequest( aError );
|
|
329 |
aError = KErrNone;
|
|
330 |
LOGGER_WRITE_1("CSconAsyncHandler::RunError() : Return %d", aError);
|
|
331 |
return aError;
|
|
332 |
//return KErrNone;//aError;
|
|
333 |
}
|
|
334 |
|
|
335 |
void CSconAsyncHandler::DoCancel()
|
|
336 |
{
|
|
337 |
TRACE_FUNC_ENTRY;
|
|
338 |
iDataStore->CancelRequest();
|
|
339 |
iTimeOut->Cancel();
|
|
340 |
|
|
341 |
if ( iStatus == KRequestPending )
|
|
342 |
{
|
|
343 |
LOGGER_WRITE( "iStatus == KRequestPending" );
|
|
344 |
}
|
|
345 |
|
|
346 |
if ( iDataStore && iMessage.Function() == EOpenItem )
|
|
347 |
{
|
|
348 |
LOGGER_WRITE( "CSconAsyncHandler::RunError() : EOpenItem" );
|
|
349 |
iDataStore->CloseItem();
|
|
350 |
}
|
|
351 |
|
|
352 |
TRACE_FUNC_EXIT;
|
|
353 |
}
|
|
354 |
|
|
355 |
void CSconAsyncHandler::TimeOut()
|
|
356 |
{
|
|
357 |
TRACE_FUNC_ENTRY;
|
|
358 |
if ( IsActive() )
|
|
359 |
{
|
|
360 |
Cancel();
|
|
361 |
CompleteRequest( KErrCancel );
|
|
362 |
}
|
|
363 |
TRACE_FUNC_EXIT;
|
|
364 |
}
|
|
365 |
|
|
366 |
|
|
367 |
void CSconAsyncHandler::HandleChunkMessage()
|
|
368 |
{
|
|
369 |
TRACE_FUNC_ENTRY;
|
|
370 |
TInt ret ( KErrNone );
|
|
371 |
|
|
372 |
ret = iChunk.Open( iMessage, 0, EFalse );
|
|
373 |
|
|
374 |
LOGGER_WRITE_1( "CSconAsyncHandler::HandleChunkMessageL() : ret %d", ret );
|
|
375 |
CompleteRequest( ret );
|
|
376 |
}
|
|
377 |
|
|
378 |
|
|
379 |
|
|
380 |
void CSconAsyncHandler::ListAllImplementationsL()
|
|
381 |
{
|
|
382 |
TRACE_FUNC_ENTRY;
|
|
383 |
|
|
384 |
RImplInfoPtrArray implInfoArray;
|
|
385 |
CleanupResetAndDestroyPushL( implInfoArray );
|
|
386 |
REComSession::ListImplementationsL( KDSEcomIFUid, implInfoArray );
|
|
387 |
|
|
388 |
const TInt KDataproviderInfoSize = 250; // 250 bytes should be enought
|
|
389 |
TInt requiredSize = implInfoArray.Count() * KDataproviderInfoSize;
|
|
390 |
if ( iChunk.Size() < requiredSize )
|
|
391 |
{
|
|
392 |
User::LeaveIfError( iChunk.Adjust( requiredSize ) );
|
|
393 |
}
|
|
394 |
|
|
395 |
RMemWriteStream stream ( iChunk.Base(), iChunk.Size() );
|
|
396 |
CleanupClosePushL( stream );
|
|
397 |
|
|
398 |
RSconDataProviderInfoArray dpInfoArray;
|
|
399 |
CleanupResetAndDestroyPushL( dpInfoArray );
|
|
400 |
|
|
401 |
// Collect information from dataproviders
|
|
402 |
for ( TInt i=0; i < implInfoArray.Count(); i++ )
|
|
403 |
{
|
|
404 |
LOGGER_WRITE_1("implInfoArray: %d",i);
|
|
405 |
CImplementationInformation& implInfo = *implInfoArray[i];
|
|
406 |
|
|
407 |
CSmlDataProvider* dp(NULL);
|
|
408 |
TRAPD( err, dp = CSmlDataProvider::NewL( implInfo.ImplementationUid().iUid ) );
|
|
409 |
LOGGER_WRITE_2("CSmlDataProvider::NewL, uid(0x%08x) err: %d",implInfo.ImplementationUid().iUid, err );
|
|
410 |
if ( !err )
|
|
411 |
{
|
|
412 |
CleanupStack::PushL( dp );
|
|
413 |
|
|
414 |
CSconDataproviderInfo *dpInfo = CSconDataproviderInfo::NewL();
|
|
415 |
CleanupStack::PushL( dpInfo );
|
|
416 |
|
|
417 |
dpInfo->SetImplementationUid( implInfo.ImplementationUid() );
|
|
418 |
LOGGER_WRITE_1("ImplementationUid: 0x%08x", implInfo.ImplementationUid().iUid );
|
|
419 |
dpInfo->SetDisplayNameL( implInfo.DisplayName() );
|
|
420 |
LOGGER_WRITE_1("DisplayName: %S", &implInfo.DisplayName() );
|
|
421 |
|
|
422 |
dpInfo->SetDefaultStoreL( dp->DefaultStoreL() );
|
|
423 |
LOGGER_WRITE_1("DefaultStoreL: %S", &dp->DefaultStoreL() );
|
|
424 |
CDesCArray* stores = dp->ListStoresLC();
|
|
425 |
dpInfo->SetStoresL( *stores );
|
|
426 |
CleanupStack::PopAndDestroy( stores );
|
|
427 |
|
|
428 |
dpInfoArray.AppendL( dpInfo );
|
|
429 |
CleanupStack::Pop( dpInfo );
|
|
430 |
|
|
431 |
CleanupStack::PopAndDestroy( dp );
|
|
432 |
}
|
|
433 |
}
|
|
434 |
|
|
435 |
// Wrtie to stream
|
|
436 |
stream.WriteUint16L( dpInfoArray.Count() );
|
|
437 |
for ( TInt i = 0; i < dpInfoArray.Count(); i++ )
|
|
438 |
{
|
|
439 |
CSconDataproviderInfo& dpInfo = *dpInfoArray[i];
|
|
440 |
dpInfo.ExternalizeL( stream );
|
|
441 |
}
|
|
442 |
|
|
443 |
stream.CommitL();
|
|
444 |
|
|
445 |
CleanupStack::PopAndDestroy( &dpInfoArray );
|
|
446 |
CleanupStack::PopAndDestroy( &stream );
|
|
447 |
CleanupStack::PopAndDestroy( &implInfoArray );
|
|
448 |
|
|
449 |
CompleteRequest( KErrNone );
|
|
450 |
TRACE_FUNC_EXIT;
|
|
451 |
}
|
|
452 |
|
|
453 |
void CSconAsyncHandler::OpenStoreL()
|
|
454 |
{
|
|
455 |
TRACE_FUNC_ENTRY;
|
|
456 |
if ( iDataStore )
|
|
457 |
{
|
|
458 |
LOGGER_WRITE("Warning: Previous DataStore was not closed properly.");
|
|
459 |
DoCloseStore();
|
|
460 |
}
|
|
461 |
|
|
462 |
// copy data from the chunk
|
|
463 |
RMemReadStream readStream( iChunk.Base(), iChunk.Size() );
|
|
464 |
CleanupClosePushL( readStream );
|
|
465 |
|
|
466 |
TSmlDataProviderId providerId = readStream.ReadUint32L();
|
|
467 |
LOGGER_WRITE_1("providerId: 0x%08x", providerId);
|
|
468 |
|
|
469 |
TInt len = readStream.ReadUint32L();
|
|
470 |
HBufC* storeName = HBufC::NewLC(len);
|
|
471 |
TPtr storeNamePtr = storeName->Des();
|
|
472 |
readStream.ReadL(storeNamePtr, len);
|
|
473 |
LOGGER_WRITE_1("storeName: %S", &storeNamePtr);
|
|
474 |
|
|
475 |
TInt contextUid = readStream.ReadUint32L();
|
|
476 |
|
|
477 |
LOGGER_WRITE_1("contextIdentifier: 0x%08x", contextUid);
|
|
478 |
|
|
479 |
LOGGER_WRITE("Open provider");
|
|
480 |
delete iDataProvider;
|
|
481 |
iDataProvider = NULL;
|
|
482 |
iDataProvider = CSmlDataProvider::NewL( providerId );
|
|
483 |
|
|
484 |
delete iContext;
|
|
485 |
iContext = NULL;
|
|
486 |
|
|
487 |
delete iStoreFormat;
|
|
488 |
iStoreFormat = NULL;
|
|
489 |
|
|
490 |
LOGGER_WRITE("Create context");
|
|
491 |
iContext = CSconSyncRelationship::NewL( iFs, TUid::Uid(contextUid), providerId );
|
|
492 |
|
|
493 |
|
|
494 |
LOGGER_WRITE("Create NewStoreInstanceLC");
|
|
495 |
iDataStore = iDataProvider->NewStoreInstanceLC();
|
|
496 |
CleanupStack::Pop( iDataStore );
|
|
497 |
|
|
498 |
SetActive();
|
|
499 |
iStatus = KRequestPending;
|
|
500 |
LOGGER_WRITE("OpenL");
|
|
501 |
TRAPD(err, iDataStore->OpenL(storeNamePtr,*iContext, iStatus));
|
|
502 |
if ( err )
|
|
503 |
{
|
|
504 |
// we are on active state, call request completed (RunL)
|
|
505 |
LOGGER_WRITE_1("iDataStore->OpenL leaved with err: %d", err);
|
|
506 |
TRequestStatus* status = &iStatus;
|
|
507 |
User::RequestComplete( status, err );
|
|
508 |
}
|
|
509 |
|
|
510 |
CleanupStack::PopAndDestroy( storeName );
|
|
511 |
CleanupStack::PopAndDestroy( &readStream );
|
|
512 |
|
|
513 |
TRACE_FUNC_EXIT;
|
|
514 |
}
|
|
515 |
|
|
516 |
|
|
517 |
void CSconAsyncHandler::OpenItemL()
|
|
518 |
{
|
|
519 |
TRACE_FUNC_ENTRY;
|
|
520 |
LeaveIfNoInstanceL();
|
|
521 |
if ( IsActive() )
|
|
522 |
{
|
|
523 |
LOGGER_WRITE("Was still in Active");
|
|
524 |
Cancel();
|
|
525 |
}
|
|
526 |
|
|
527 |
TSmlDbItemUid itemUid = iMessage.Int0();
|
|
528 |
LOGGER_WRITE_1("Open item: %d", itemUid);
|
|
529 |
|
|
530 |
// set default values
|
|
531 |
iFieldChange = EFalse;
|
|
532 |
iSize = 0;
|
|
533 |
iParent = 0;
|
|
534 |
iMimeType.Copy(KNullDesC);
|
|
535 |
iMimeVer.Copy(KNullDesC);
|
|
536 |
|
|
537 |
SetActive();
|
|
538 |
LOGGER_WRITE("iDataStore->OpenItemL");
|
|
539 |
iStatus = KRequestPending;
|
|
540 |
TRAPD( err, iDataStore->OpenItemL(itemUid,iFieldChange,iSize,iParent,iMimeType,iMimeVer,iStatus));
|
|
541 |
if ( err )
|
|
542 |
{
|
|
543 |
// we are on active state, call request completed (RunL)
|
|
544 |
LOGGER_WRITE_1("iDataStore->OpenItemL leaved with err: %d", err);
|
|
545 |
TRequestStatus* status = &iStatus;
|
|
546 |
User::RequestComplete( status, err );
|
|
547 |
}
|
|
548 |
|
|
549 |
TRACE_FUNC_EXIT;
|
|
550 |
}
|
|
551 |
|
|
552 |
void CSconAsyncHandler::OpenItemCompletedL( TInt aError )
|
|
553 |
{
|
|
554 |
TRACE_FUNC_ENTRY;
|
|
555 |
// item opened, now read it
|
|
556 |
if ( aError )
|
|
557 |
{
|
|
558 |
CompleteRequest( aError );
|
|
559 |
return;
|
|
560 |
}
|
|
561 |
LeaveIfNoInstanceL();
|
|
562 |
|
|
563 |
LOGGER_WRITE_1("item size: %d", iSize);
|
|
564 |
|
|
565 |
TInt totalObjectSize( 0 );
|
|
566 |
totalObjectSize+= sizeof(TInt32); // data length
|
|
567 |
totalObjectSize+= iSize; // data
|
|
568 |
totalObjectSize+= sizeof(TInt8); // iFieldChange
|
|
569 |
totalObjectSize+= sizeof(TInt32); // iParent
|
|
570 |
totalObjectSize+= sizeof(TInt32); // iMimeType
|
|
571 |
totalObjectSize+= iMimeType.Length(); // iMimeType
|
|
572 |
totalObjectSize+= sizeof(TInt32); // iMimeVer
|
|
573 |
totalObjectSize+= iMimeVer.Length(); // iMimeType
|
|
574 |
|
|
575 |
LOGGER_WRITE_1("iChunk.Size(): %d", iChunk.Size());
|
|
576 |
LOGGER_WRITE_1("iChunk.MaxSize(): %d", iChunk.MaxSize());
|
|
577 |
LOGGER_WRITE_1("totalObjectSize: %d", totalObjectSize);
|
|
578 |
|
|
579 |
if ( iChunk.Size() < totalObjectSize )
|
|
580 |
{
|
|
581 |
LOGGER_WRITE("adjust chunk");
|
|
582 |
TInt err = iChunk.Adjust( totalObjectSize );
|
|
583 |
LOGGER_WRITE_1("Chunk.Adjust err: %d", err);
|
|
584 |
User::LeaveIfError( err );
|
|
585 |
}
|
|
586 |
LOGGER_WRITE_1("new Chunk size: %d", iChunk.Size());
|
|
587 |
LOGGER_WRITE_1("new ChunkMaxSize(): %d", iChunk.MaxSize());
|
|
588 |
RMemWriteStream stream ( iChunk.Base(), iChunk.Size() );
|
|
589 |
CleanupClosePushL( stream );
|
|
590 |
|
|
591 |
LOGGER_WRITE("ReadItemL");
|
|
592 |
HBufC8* tempBuf = HBufC8::NewLC(iSize);
|
|
593 |
TPtr8 tempPtr = tempBuf->Des();
|
|
594 |
|
|
595 |
TUint8* ptr = (TUint8*) tempPtr.Ptr();
|
|
596 |
|
|
597 |
TPtr8 tempPtr2( ptr, 0, iSize );
|
|
598 |
LOGGER_WRITE_1( "tempPtr2.Size(): %d", tempPtr2.Size());
|
|
599 |
iDataStore->ReadItemL( tempPtr2 );
|
|
600 |
LOGGER_WRITE("ReadItemL -ok");
|
|
601 |
|
|
602 |
LOGGER_WRITE_1("readed Length: %d", tempPtr2.Length() );
|
|
603 |
LOGGER_WRITE_1("readed Size: %d", tempPtr2.Size() );
|
|
604 |
|
|
605 |
LOGGER_WRITE8_1("iMimeType: %S", &iMimeType );
|
|
606 |
LOGGER_WRITE_1("iMimeType.Length(): %d", iMimeType.Length() );
|
|
607 |
LOGGER_WRITE_1("iMimeType Size: %d", iMimeType.Size() );
|
|
608 |
|
|
609 |
LOGGER_WRITE8_1("iMimeVer: %S", &iMimeVer );
|
|
610 |
LOGGER_WRITE_1("iMimeVer.Length(): %d", iMimeVer.Length() );
|
|
611 |
LOGGER_WRITE_1("iMimeVer Size: %d", iMimeVer.Size() );
|
|
612 |
|
|
613 |
iDataStore->CloseItem();
|
|
614 |
LOGGER_WRITE("Write to chunk");
|
|
615 |
stream.WriteInt32L( tempPtr2.Length() );
|
|
616 |
stream.WriteL( tempPtr2 );
|
|
617 |
CleanupStack::PopAndDestroy( tempBuf );
|
|
618 |
|
|
619 |
stream.WriteInt8L( (TInt)iFieldChange );
|
|
620 |
stream.WriteInt32L( iParent );
|
|
621 |
stream.WriteInt32L( iMimeType.Length() );
|
|
622 |
stream.WriteL( iMimeType );
|
|
623 |
stream.WriteInt32L( iMimeVer.Length() );
|
|
624 |
stream.WriteL( iMimeVer );
|
|
625 |
|
|
626 |
stream.CommitL();
|
|
627 |
LOGGER_WRITE("Writed ok");
|
|
628 |
CleanupStack::PopAndDestroy( &stream );
|
|
629 |
CompleteRequest( KErrNone );
|
|
630 |
TRACE_FUNC_EXIT;
|
|
631 |
}
|
|
632 |
|
|
633 |
void CSconAsyncHandler::CreateItemL()
|
|
634 |
{
|
|
635 |
TRACE_FUNC_ENTRY;
|
|
636 |
LeaveIfNoInstanceL();
|
|
637 |
iCommitInProgress = EFalse;
|
|
638 |
RMemReadStream readStream( iChunk.Base(), iChunk.Size() );
|
|
639 |
CleanupClosePushL( readStream );
|
|
640 |
|
|
641 |
TSmlDbItemUid parent = readStream.ReadUint32L();
|
|
642 |
TInt len = readStream.ReadUint32L();
|
|
643 |
readStream.ReadL(iMimeType, len);
|
|
644 |
len = readStream.ReadUint32L();
|
|
645 |
readStream.ReadL(iMimeVer, len);
|
|
646 |
len = readStream.ReadUint32L();
|
|
647 |
delete iWriteData;
|
|
648 |
iWriteData = NULL;
|
|
649 |
iWriteData = HBufC8::New(len);
|
|
650 |
TPtr8 dataPtr = iWriteData->Des();
|
|
651 |
readStream.ReadL(dataPtr, len);
|
|
652 |
CleanupStack::PopAndDestroy( &readStream );
|
|
653 |
SetActive();
|
|
654 |
iStatus = KRequestPending;
|
|
655 |
TRAPD(err, iDataStore->CreateItemL( iNewItem, dataPtr.Size(), parent, iMimeType, iMimeVer, iStatus ));
|
|
656 |
if ( err )
|
|
657 |
{
|
|
658 |
// we are on active state, call request completed (RunL)
|
|
659 |
LOGGER_WRITE_1("iDataStore->CreateItemL leaved with err: %d", err);
|
|
660 |
TRequestStatus* status = &iStatus;
|
|
661 |
User::RequestComplete( status, err );
|
|
662 |
}
|
|
663 |
TRACE_FUNC_EXIT;
|
|
664 |
}
|
|
665 |
|
|
666 |
void CSconAsyncHandler::CreateItemCompletedL( TInt aError )
|
|
667 |
{
|
|
668 |
TRACE_FUNC_ENTRY;
|
|
669 |
User::LeaveIfError( aError );
|
|
670 |
LeaveIfNoInstanceL();
|
|
671 |
// CreateItem completed, now we must write the data to the created item and commit it.
|
|
672 |
|
|
673 |
iDataStore->WriteItemL( iWriteData->Des() );
|
|
674 |
delete iWriteData;
|
|
675 |
iWriteData = NULL;
|
|
676 |
SetActive();
|
|
677 |
iStatus = KRequestPending;
|
|
678 |
TRAPD(err, iDataStore->CommitItemL( iStatus ));
|
|
679 |
if ( err )
|
|
680 |
{
|
|
681 |
// we are on active state, call request completed (RunL)
|
|
682 |
LOGGER_WRITE_1("iDataStore->CommitItemL leaved with err: %d", err);
|
|
683 |
TRequestStatus* status = &iStatus;
|
|
684 |
User::RequestComplete( status, err );
|
|
685 |
}
|
|
686 |
iCommitInProgress = ETrue;
|
|
687 |
|
|
688 |
TRACE_FUNC_EXIT;
|
|
689 |
}
|
|
690 |
|
|
691 |
void CSconAsyncHandler::ReplaceItemL()
|
|
692 |
{
|
|
693 |
TRACE_FUNC_ENTRY;
|
|
694 |
LeaveIfNoInstanceL();
|
|
695 |
|
|
696 |
iCommitInProgress = EFalse;
|
|
697 |
RMemReadStream readStream( iChunk.Base(), iChunk.Size() );
|
|
698 |
CleanupClosePushL( readStream );
|
|
699 |
|
|
700 |
TSmlDbItemUid uid = readStream.ReadUint32L();
|
|
701 |
TSmlDbItemUid parent = readStream.ReadUint32L();
|
|
702 |
TBool fieldChange = readStream.ReadUint8L();
|
|
703 |
TInt len = readStream.ReadUint32L();
|
|
704 |
delete iWriteData;
|
|
705 |
iWriteData = NULL;
|
|
706 |
iWriteData = HBufC8::New(len);
|
|
707 |
TPtr8 dataPtr = iWriteData->Des();
|
|
708 |
readStream.ReadL(dataPtr, len);
|
|
709 |
|
|
710 |
CleanupStack::PopAndDestroy( &readStream );
|
|
711 |
SetActive();
|
|
712 |
iStatus = KRequestPending;
|
|
713 |
TRAPD(err,iDataStore->ReplaceItemL( uid,dataPtr.Size(),parent,fieldChange, iStatus ));
|
|
714 |
if ( err )
|
|
715 |
{
|
|
716 |
// we are on active state, call request completed (RunL)
|
|
717 |
LOGGER_WRITE_1("iDataStore->CommitItemL leaved with err: %d", err);
|
|
718 |
TRequestStatus* status = &iStatus;
|
|
719 |
User::RequestComplete( status, err );
|
|
720 |
}
|
|
721 |
TRACE_FUNC_EXIT;
|
|
722 |
}
|
|
723 |
|
|
724 |
void CSconAsyncHandler::ReplaceItemCompletedL( TInt aError )
|
|
725 |
{
|
|
726 |
TRACE_FUNC_ENTRY;
|
|
727 |
User::LeaveIfError( aError );
|
|
728 |
LeaveIfNoInstanceL();
|
|
729 |
// CreateItem completed, now we must write the data to the created item and commit it.
|
|
730 |
|
|
731 |
iDataStore->WriteItemL( iWriteData->Des() );
|
|
732 |
delete iWriteData;
|
|
733 |
iWriteData = NULL;
|
|
734 |
|
|
735 |
SetActive();
|
|
736 |
iStatus = KRequestPending;
|
|
737 |
TRAPD(err, iDataStore->CommitItemL( iStatus ));
|
|
738 |
if ( err )
|
|
739 |
{
|
|
740 |
// we are on active state, call request completed (RunL)
|
|
741 |
LOGGER_WRITE_1("iDataStore->CommitItemL leaved with err: %d", err);
|
|
742 |
TRequestStatus* status = &iStatus;
|
|
743 |
User::RequestComplete( status, err );
|
|
744 |
}
|
|
745 |
iCommitInProgress = ETrue;
|
|
746 |
TRACE_FUNC_EXIT;
|
|
747 |
}
|
|
748 |
|
|
749 |
void CSconAsyncHandler::MoveItemL()
|
|
750 |
{
|
|
751 |
TRACE_FUNC_ENTRY;
|
|
752 |
LeaveIfNoInstanceL();
|
|
753 |
TSmlDbItemUid uid = iMessage.Int0();
|
|
754 |
TSmlDbItemUid newParent = iMessage.Int1();
|
|
755 |
LOGGER_WRITE_1( "uid: %d", uid );
|
|
756 |
LOGGER_WRITE_1( "newParent: %d", newParent );
|
|
757 |
|
|
758 |
SetActive();
|
|
759 |
iStatus = KRequestPending;
|
|
760 |
TRAPD(err, iDataStore->MoveItemL( uid, newParent, iStatus ));
|
|
761 |
if ( err )
|
|
762 |
{
|
|
763 |
// we are on active state, call request completed (RunL)
|
|
764 |
LOGGER_WRITE_1("iDataStore->MoveItemL leaved with err: %d", err);
|
|
765 |
TRequestStatus* status = &iStatus;
|
|
766 |
User::RequestComplete( status, err );
|
|
767 |
}
|
|
768 |
TRACE_FUNC_EXIT;
|
|
769 |
}
|
|
770 |
|
|
771 |
void CSconAsyncHandler::DeleteItemL()
|
|
772 |
{
|
|
773 |
TRACE_FUNC_ENTRY;
|
|
774 |
LeaveIfNoInstanceL();
|
|
775 |
|
|
776 |
TSmlDbItemUid uid = iMessage.Int0();
|
|
777 |
LOGGER_WRITE_1( "uid: %d", uid );
|
|
778 |
|
|
779 |
SetActive();
|
|
780 |
iStatus = KRequestPending;
|
|
781 |
TRAPD(err, iDataStore->DeleteItemL( uid, iStatus ));
|
|
782 |
if ( err )
|
|
783 |
{
|
|
784 |
// we are on active state, call request completed (RunL)
|
|
785 |
LOGGER_WRITE_1("iDataStore->DeleteItemL leaved with err: %d", err);
|
|
786 |
TRequestStatus* status = &iStatus;
|
|
787 |
User::RequestComplete( status, err );
|
|
788 |
}
|
|
789 |
TRACE_FUNC_EXIT;
|
|
790 |
}
|
|
791 |
|
|
792 |
void CSconAsyncHandler::SoftDeleteItemL()
|
|
793 |
{
|
|
794 |
TRACE_FUNC_ENTRY;
|
|
795 |
LeaveIfNoInstanceL();
|
|
796 |
|
|
797 |
TSmlDbItemUid uid = iMessage.Int0();
|
|
798 |
LOGGER_WRITE_1( "uid: %d", uid );
|
|
799 |
|
|
800 |
SetActive();
|
|
801 |
iStatus = KRequestPending;
|
|
802 |
TRAPD(err, iDataStore->SoftDeleteItemL( uid, iStatus ));
|
|
803 |
if ( err )
|
|
804 |
{
|
|
805 |
// we are on active state, call request completed (RunL)
|
|
806 |
LOGGER_WRITE_1("iDataStore->SoftDeleteItemL leaved with err: %d", err);
|
|
807 |
TRequestStatus* status = &iStatus;
|
|
808 |
User::RequestComplete( status, err );
|
|
809 |
}
|
|
810 |
TRACE_FUNC_EXIT;
|
|
811 |
}
|
|
812 |
|
|
813 |
void CSconAsyncHandler::DeleteAllItemsL()
|
|
814 |
{
|
|
815 |
TRACE_FUNC_ENTRY;
|
|
816 |
LeaveIfNoInstanceL();
|
|
817 |
|
|
818 |
SetActive();
|
|
819 |
iStatus = KRequestPending;
|
|
820 |
TRAPD(err, iDataStore->DeleteAllItemsL( iStatus ));
|
|
821 |
if ( err )
|
|
822 |
{
|
|
823 |
// we are on active state, call request completed (RunL)
|
|
824 |
LOGGER_WRITE_1("iDataStore->DeleteAllItemsL leaved with err: %d", err);
|
|
825 |
TRequestStatus* status = &iStatus;
|
|
826 |
User::RequestComplete( status, err );
|
|
827 |
}
|
|
828 |
TRACE_FUNC_EXIT;
|
|
829 |
}
|
|
830 |
|
|
831 |
void CSconAsyncHandler::ReadParentL()
|
|
832 |
{
|
|
833 |
TRACE_FUNC_ENTRY;
|
|
834 |
OpenItemL();
|
|
835 |
|
|
836 |
TRACE_FUNC_EXIT;
|
|
837 |
}
|
|
838 |
|
|
839 |
void CSconAsyncHandler::ReadParentCompletedL( TInt aError )
|
|
840 |
{
|
|
841 |
TRACE_FUNC_ENTRY;
|
|
842 |
// item opened, now read it
|
|
843 |
if ( aError )
|
|
844 |
{
|
|
845 |
CompleteRequest( aError );
|
|
846 |
return;
|
|
847 |
}
|
|
848 |
LeaveIfNoInstanceL();
|
|
849 |
|
|
850 |
iDataStore->CloseItem();
|
|
851 |
|
|
852 |
TPckg<TSmlDbItemUid> pckg(iParent);
|
|
853 |
iMessage.WriteL( 1, pckg, 0);
|
|
854 |
CompleteRequest( KErrNone );
|
|
855 |
TRACE_FUNC_EXIT;
|
|
856 |
}
|
|
857 |
|
|
858 |
void CSconAsyncHandler::HasHistoryL()
|
|
859 |
{
|
|
860 |
TRACE_FUNC_ENTRY;
|
|
861 |
LeaveIfNoInstanceL();
|
|
862 |
TBool hasHistory = iDataStore->HasSyncHistory();
|
|
863 |
|
|
864 |
TPckgC<TBool> pckg(hasHistory);
|
|
865 |
iMessage.WriteL( 0, pckg, 0);
|
|
866 |
CompleteRequest( KErrNone );
|
|
867 |
TRACE_FUNC_EXIT;
|
|
868 |
}
|
|
869 |
|
|
870 |
void CSconAsyncHandler::AddedItemsL()
|
|
871 |
{
|
|
872 |
TRACE_FUNC_ENTRY;
|
|
873 |
LeaveIfNoInstanceL();
|
|
874 |
const MSmlDataItemUidSet& items = iDataStore->AddedItems();
|
|
875 |
|
|
876 |
RMemWriteStream stream ( iChunk.Base(), iChunk.Size() );
|
|
877 |
CleanupClosePushL( stream );
|
|
878 |
items.ExternalizeL( stream );
|
|
879 |
CleanupStack::PopAndDestroy( &stream );
|
|
880 |
|
|
881 |
CompleteRequest( KErrNone );
|
|
882 |
TRACE_FUNC_EXIT;
|
|
883 |
}
|
|
884 |
|
|
885 |
void CSconAsyncHandler::DeletedItemsL()
|
|
886 |
{
|
|
887 |
TRACE_FUNC_ENTRY;
|
|
888 |
LeaveIfNoInstanceL();
|
|
889 |
const MSmlDataItemUidSet& items = iDataStore->DeletedItems();
|
|
890 |
|
|
891 |
RMemWriteStream stream ( iChunk.Base(), iChunk.Size() );
|
|
892 |
CleanupClosePushL( stream );
|
|
893 |
items.ExternalizeL( stream );
|
|
894 |
CleanupStack::PopAndDestroy( &stream );
|
|
895 |
|
|
896 |
CompleteRequest( KErrNone );
|
|
897 |
TRACE_FUNC_EXIT;
|
|
898 |
}
|
|
899 |
|
|
900 |
void CSconAsyncHandler::SoftDeletedItemsL()
|
|
901 |
{
|
|
902 |
TRACE_FUNC_ENTRY;
|
|
903 |
LeaveIfNoInstanceL();
|
|
904 |
const MSmlDataItemUidSet& items = iDataStore->SoftDeletedItems();
|
|
905 |
|
|
906 |
RMemWriteStream stream ( iChunk.Base(), iChunk.Size() );
|
|
907 |
CleanupClosePushL( stream );
|
|
908 |
items.ExternalizeL( stream );
|
|
909 |
CleanupStack::PopAndDestroy( &stream );
|
|
910 |
|
|
911 |
CompleteRequest( KErrNone );
|
|
912 |
TRACE_FUNC_EXIT;
|
|
913 |
}
|
|
914 |
|
|
915 |
void CSconAsyncHandler::ModifiedItemsL()
|
|
916 |
{
|
|
917 |
TRACE_FUNC_ENTRY;
|
|
918 |
LeaveIfNoInstanceL();
|
|
919 |
const MSmlDataItemUidSet& items = iDataStore->ModifiedItems();
|
|
920 |
|
|
921 |
RMemWriteStream stream ( iChunk.Base(), iChunk.Size() );
|
|
922 |
CleanupClosePushL( stream );
|
|
923 |
items.ExternalizeL( stream );
|
|
924 |
CleanupStack::PopAndDestroy( &stream );
|
|
925 |
|
|
926 |
CompleteRequest( KErrNone );
|
|
927 |
TRACE_FUNC_EXIT;
|
|
928 |
}
|
|
929 |
|
|
930 |
void CSconAsyncHandler::MovedItemsL()
|
|
931 |
{
|
|
932 |
TRACE_FUNC_ENTRY;
|
|
933 |
LeaveIfNoInstanceL();
|
|
934 |
const MSmlDataItemUidSet& items = iDataStore->MovedItems();
|
|
935 |
|
|
936 |
RMemWriteStream stream ( iChunk.Base(), iChunk.Size() );
|
|
937 |
CleanupClosePushL( stream );
|
|
938 |
items.ExternalizeL( stream );
|
|
939 |
CleanupStack::PopAndDestroy( &stream );
|
|
940 |
|
|
941 |
CompleteRequest( KErrNone );
|
|
942 |
TRACE_FUNC_EXIT;
|
|
943 |
}
|
|
944 |
|
|
945 |
void CSconAsyncHandler::ResetChangeInfoL()
|
|
946 |
{
|
|
947 |
TRACE_FUNC_ENTRY;
|
|
948 |
LeaveIfNoInstanceL();
|
|
949 |
SetActive();
|
|
950 |
iStatus = KRequestPending;
|
|
951 |
TRAPD(err, iDataStore->ResetChangeInfoL( iStatus ));
|
|
952 |
if ( err )
|
|
953 |
{
|
|
954 |
// we are on active state, call request completed (RunL)
|
|
955 |
LOGGER_WRITE_1("iDataStore->ResetChangeInfoL leaved with err: %d", err);
|
|
956 |
TRequestStatus* status = &iStatus;
|
|
957 |
User::RequestComplete( status, err );
|
|
958 |
}
|
|
959 |
TRACE_FUNC_EXIT;
|
|
960 |
}
|
|
961 |
|
|
962 |
void CSconAsyncHandler::CommitChangeInfoL()
|
|
963 |
{
|
|
964 |
TRACE_FUNC_ENTRY;
|
|
965 |
LeaveIfNoInstanceL();
|
|
966 |
RMemReadStream readStream( iChunk.Base(), iChunk.Size() );
|
|
967 |
CleanupClosePushL( readStream );
|
|
968 |
|
|
969 |
if ( iItems )
|
|
970 |
{
|
|
971 |
delete iItems;
|
|
972 |
iItems = NULL;
|
|
973 |
}
|
|
974 |
iItems = new (ELeave) CNSmlDataItemUidSet();
|
|
975 |
iItems->InternalizeL( readStream );
|
|
976 |
|
|
977 |
CleanupStack::PopAndDestroy( &readStream );
|
|
978 |
|
|
979 |
SetActive();
|
|
980 |
iStatus = KRequestPending;
|
|
981 |
TRAPD(err, iDataStore->CommitChangeInfoL( iStatus, *iItems ));
|
|
982 |
if ( err )
|
|
983 |
{
|
|
984 |
// we are on active state, call request completed (RunL)
|
|
985 |
LOGGER_WRITE_1("iDataStore->CommitChangeInfoL leaved with err: %d", err);
|
|
986 |
TRequestStatus* status = &iStatus;
|
|
987 |
User::RequestComplete( status, err );
|
|
988 |
}
|
|
989 |
TRACE_FUNC_EXIT;
|
|
990 |
}
|
|
991 |
|
|
992 |
void CSconAsyncHandler::CloseStore()
|
|
993 |
{
|
|
994 |
TRACE_FUNC_ENTRY;
|
|
995 |
DoCloseStore();
|
|
996 |
REComSession::FinalClose();
|
|
997 |
CompleteRequest( KErrNone );
|
|
998 |
TRACE_FUNC_EXIT;
|
|
999 |
}
|
|
1000 |
|
|
1001 |
void CSconAsyncHandler::SetSyncTimeStampL()
|
|
1002 |
{
|
|
1003 |
TRACE_FUNC_ENTRY;
|
|
1004 |
RMemReadStream readStream( iChunk.Base(), iChunk.Size() );
|
|
1005 |
CleanupClosePushL( readStream );
|
|
1006 |
TInt relationId = readStream.ReadInt32L();
|
|
1007 |
TInt providerId = readStream.ReadInt32L();
|
|
1008 |
CleanupStack::PopAndDestroy( &readStream );
|
|
1009 |
|
|
1010 |
CSconSyncRelationship::SetTimeStampL( iFs, TUid::Uid(relationId), providerId);
|
|
1011 |
|
|
1012 |
CompleteRequest( KErrNone );
|
|
1013 |
TRACE_FUNC_EXIT;
|
|
1014 |
}
|
|
1015 |
|
|
1016 |
void CSconAsyncHandler::GetSyncTimeStampL()
|
|
1017 |
{
|
|
1018 |
TRACE_FUNC_ENTRY;
|
|
1019 |
TInt providerId = iMessage.Int0();
|
|
1020 |
TInt relationId = iMessage.Int1();
|
|
1021 |
|
|
1022 |
TDateTime time;
|
|
1023 |
CSconSyncRelationship::GetTimeStampL( iFs, TUid::Uid(relationId), providerId, time);
|
|
1024 |
|
|
1025 |
// write timestamp
|
|
1026 |
TPckgC<TDateTime> timeBuf(time);
|
|
1027 |
iMessage.WriteL( 2, timeBuf, 0);
|
|
1028 |
|
|
1029 |
CompleteRequest( KErrNone );
|
|
1030 |
TRACE_FUNC_EXIT;
|
|
1031 |
}
|
|
1032 |
|
|
1033 |
void CSconAsyncHandler::ExportStoreFormatL()
|
|
1034 |
{
|
|
1035 |
TRACE_FUNC_ENTRY;
|
|
1036 |
LeaveIfNoInstanceL();
|
|
1037 |
if ( !iDataProvider )
|
|
1038 |
{
|
|
1039 |
User::Leave( KErrNotReady );
|
|
1040 |
}
|
|
1041 |
CBufFlat* buffer = CBufFlat::NewL( KDefaultExpandSize );
|
|
1042 |
CleanupStack::PushL( buffer );
|
|
1043 |
RBufWriteStream stream( *buffer );
|
|
1044 |
CleanupClosePushL( stream );
|
|
1045 |
|
|
1046 |
const CSmlDataStoreFormat& storeFormat = iDataProvider->StoreFormatL();
|
|
1047 |
TRAP_IGNORE( TLogDataStoreFormat::LogDataStoreFormatL( _L("iDataProvider->StoreFormatL()"), storeFormat ));
|
|
1048 |
|
|
1049 |
storeFormat.ExternalizeL( stream );
|
|
1050 |
|
|
1051 |
stream.CommitL();
|
|
1052 |
CleanupStack::PopAndDestroy( &stream );
|
|
1053 |
buffer->Compress();
|
|
1054 |
|
|
1055 |
RMemWriteStream chunkStream( iChunk.Base(), iChunk.Size() );
|
|
1056 |
CleanupClosePushL( chunkStream );
|
|
1057 |
|
|
1058 |
chunkStream.WriteInt32L( buffer->Size() );
|
|
1059 |
chunkStream.WriteL( buffer->Ptr(0), buffer->Size());
|
|
1060 |
chunkStream.CommitL();
|
|
1061 |
CleanupStack::PopAndDestroy( &chunkStream );
|
|
1062 |
|
|
1063 |
CleanupStack::PopAndDestroy( buffer );
|
|
1064 |
|
|
1065 |
CompleteRequest( KErrNone );
|
|
1066 |
TRACE_FUNC_EXIT;
|
|
1067 |
}
|
|
1068 |
|
|
1069 |
void CSconAsyncHandler::SetRemoteStoreFormatL()
|
|
1070 |
{
|
|
1071 |
TRACE_FUNC_ENTRY;
|
|
1072 |
LeaveIfNoInstanceL();
|
|
1073 |
|
|
1074 |
RMemReadStream readStream( iChunk.Base(), iChunk.Size() );
|
|
1075 |
CleanupClosePushL( readStream );
|
|
1076 |
|
|
1077 |
if ( iStoreFormat )
|
|
1078 |
{
|
|
1079 |
delete iStoreFormat;
|
|
1080 |
iStoreFormat = NULL;
|
|
1081 |
}
|
|
1082 |
iStoreFormat = CSmlDataStoreFormat::NewLC( iStringPool, readStream);
|
|
1083 |
CleanupStack::Pop( iStoreFormat );
|
|
1084 |
TRAP_IGNORE( TLogDataStoreFormat::LogDataStoreFormatL( _L("iDataProvider->SetRemoteStoreFormatL()"), *iStoreFormat ));
|
|
1085 |
iDataStore->SetRemoteStoreFormatL( *iStoreFormat );
|
|
1086 |
|
|
1087 |
CleanupStack::PopAndDestroy( &readStream );
|
|
1088 |
|
|
1089 |
CompleteRequest( KErrNone );
|
|
1090 |
TRACE_FUNC_EXIT;
|
|
1091 |
}
|
|
1092 |
|
|
1093 |
void CSconAsyncHandler::LeaveIfNoInstanceL()
|
|
1094 |
{
|
|
1095 |
if ( !iDataStore )
|
|
1096 |
{
|
|
1097 |
LOGGER_WRITE("DataStore instance was not ready, leaving KErrNotReady");
|
|
1098 |
User::Leave( KErrNotReady );
|
|
1099 |
}
|
|
1100 |
}
|
|
1101 |
|
|
1102 |
void CSconAsyncHandler::DoCloseStore()
|
|
1103 |
{
|
|
1104 |
TRACE_FUNC_ENTRY;
|
|
1105 |
delete iItems;
|
|
1106 |
iItems = NULL;
|
|
1107 |
delete iWriteData;
|
|
1108 |
iWriteData = NULL;
|
|
1109 |
if ( iDataProvider && iContext )
|
|
1110 |
{
|
|
1111 |
TInt providerId = iDataProvider->Identifier();
|
|
1112 |
TInt contextId = iContext->SyncTaskKey();
|
|
1113 |
TRAP_IGNORE( CSconSyncRelationship::SetTimeStampL( iFs, TUid::Uid(contextId), providerId) );
|
|
1114 |
}
|
|
1115 |
delete iDataStore;
|
|
1116 |
iDataStore = NULL;
|
|
1117 |
delete iDataProvider;
|
|
1118 |
iDataProvider = NULL;
|
|
1119 |
delete iContext;
|
|
1120 |
iContext = NULL;
|
|
1121 |
delete iStoreFormat;
|
|
1122 |
iStoreFormat = NULL;
|
|
1123 |
|
|
1124 |
CleanOldStoresL();
|
|
1125 |
|
|
1126 |
TRACE_FUNC_EXIT;
|
|
1127 |
}
|
|
1128 |
|
|
1129 |
void CSconAsyncHandler::CleanOldStoresL()
|
|
1130 |
{
|
|
1131 |
TRACE_FUNC_ENTRY;
|
|
1132 |
TFileName path;
|
|
1133 |
User::LeaveIfError( iFs.PrivatePath( path ) );
|
|
1134 |
CDir* dir;
|
|
1135 |
iFs.GetDir( path, KEntryAttNormal, ESortByDate, dir );
|
|
1136 |
CleanupStack::PushL( dir );
|
|
1137 |
TInt storesCount(0);
|
|
1138 |
LOGGER_WRITE_1("count: %d", dir->Count() );
|
|
1139 |
for ( TInt i=dir->Count()-1; i >= 0; i-- )
|
|
1140 |
{
|
|
1141 |
LOGGER_WRITE_1("dir[%d]", i);
|
|
1142 |
TEntry entry = (*dir)[i];
|
|
1143 |
LOGGER_WRITE_1("file: %S", &entry.iName);
|
|
1144 |
_LIT(KContextStoreName, "contextstore");
|
|
1145 |
_LIT(KTimeStoreName, "timestore");
|
|
1146 |
if ( entry.iName.Find(KContextStoreName) == 0 )
|
|
1147 |
{
|
|
1148 |
storesCount++;
|
|
1149 |
LOGGER_WRITE_1("storeNro: %d", storesCount);
|
|
1150 |
#ifdef _DEBUG
|
|
1151 |
TTime time = entry.iModified;
|
|
1152 |
TDateTime dt = time.DateTime();
|
|
1153 |
_LIT(KFormat, "%d.%d %02d:%02d");
|
|
1154 |
TFileName mod;
|
|
1155 |
mod.Format(KFormat, dt.Day()+1, dt.Month()+1, dt.Hour()+1,dt.Minute() );
|
|
1156 |
LOGGER_WRITE_1("time: %S", &mod);
|
|
1157 |
#endif
|
|
1158 |
if ( storesCount > KMaxStoresCount )
|
|
1159 |
{
|
|
1160 |
LOGGER_WRITE_1("delete contextstore: '%S'", &entry.iName );
|
|
1161 |
iFs.Delete( entry.iName );
|
|
1162 |
TFileName timeStoreFile;
|
|
1163 |
timeStoreFile = entry.iName.Right(15);
|
|
1164 |
timeStoreFile.Insert(0, KTimeStoreName);
|
|
1165 |
LOGGER_WRITE_1("delete timeStoreFile: %S", &timeStoreFile);
|
|
1166 |
iFs.Delete( timeStoreFile );
|
|
1167 |
}
|
|
1168 |
}
|
|
1169 |
|
|
1170 |
}
|
|
1171 |
CleanupStack::PopAndDestroy( dir );
|
|
1172 |
TRACE_FUNC_EXIT;
|
|
1173 |
}
|
|
1174 |
|
|
1175 |
void CSconAsyncHandler::CompleteRequest( TInt aError )
|
|
1176 |
{
|
|
1177 |
TRACE_FUNC;
|
|
1178 |
iTimeOut->Cancel();
|
|
1179 |
LOGGER_WRITE_1("iMessage.Complete( %d )", aError);
|
|
1180 |
iMessage.Complete( aError );
|
|
1181 |
}
|