connectivitymodules/SeCon/clients/syncclient/src/sconsyncclient.cpp
branchRCL_3
changeset 20 4a793f564d72
parent 18 453dfc402455
equal deleted inserted replaced
19:0aa8cc770c8a 20:4a793f564d72
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  RSconSyncSession implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "sconsyncclient.h"
       
    20 
       
    21 #include <SmlDataProvider.h>
       
    22 #include <s32mem.h>
       
    23 
       
    24 #include "sconsyncclientserver.h"
       
    25 #include "debug.h"
       
    26 
       
    27 const TInt KSConSyncChunkSize = 0xFFFF; // 65535 bytes;
       
    28 const TInt KSConSyncChunkMaxSize = 0x400000; // 4194304 bytes
       
    29 
       
    30 EXPORT_C RSconSyncSession::RSconSyncSession()
       
    31     {
       
    32     TRACE_FUNC;
       
    33     }
       
    34 
       
    35 EXPORT_C RSconSyncSession::~RSconSyncSession()
       
    36     {
       
    37     TRACE_FUNC;
       
    38     }
       
    39 
       
    40 EXPORT_C TInt RSconSyncSession::Connect()
       
    41     {
       
    42     TRACE_FUNC_ENTRY;
       
    43     TInt retryCount = 2;
       
    44     TInt error = KErrNone;
       
    45     while(retryCount)
       
    46         {
       
    47         error = CreateSession(KSconSyncServerName, TVersion(1,0,0));
       
    48         if ( error != KErrNotFound && error != KErrServerTerminated )
       
    49             {
       
    50             break;
       
    51             }
       
    52         error = StartServer();
       
    53         if( error != KErrNone && error != KErrAlreadyExists )
       
    54             {
       
    55             break;
       
    56             }
       
    57         --retryCount;
       
    58         }
       
    59     
       
    60     if ( error == KErrNone )
       
    61         {
       
    62         error = CreateAndSendChunkHandle();
       
    63         if ( error != KErrNone )
       
    64             {
       
    65             LOGGER_WRITE("CreateAndSendChunkHandle failed, close session");
       
    66             Close();
       
    67             }
       
    68         }
       
    69     TRACE_FUNC_EXIT;
       
    70     return error;
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // RSconSyncSession::Close()
       
    75 // Closes the server connection
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 EXPORT_C void RSconSyncSession::Close()
       
    79     {
       
    80     TRACE_FUNC_ENTRY;
       
    81     iChunk.Close();
       
    82     RSessionBase::Close();
       
    83     TRACE_FUNC_EXIT
       
    84     }
       
    85 
       
    86 EXPORT_C void RSconSyncSession::ListAllImplementationsL( RSconDataProviderInfoArray& aInfoArray )
       
    87     {
       
    88     TRACE_FUNC_ENTRY;
       
    89     TIpcArgs args;
       
    90     TInt ret = SendReceive ( EListImplementations, args );
       
    91     
       
    92     if ( ret != KErrNone) 
       
    93         {
       
    94         LOGGER_WRITE_1( "RSconSyncSession::ListAllImplementationsL() :\
       
    95          Send Receive failed with code %d", ret );
       
    96         User::Leave( ret );
       
    97         };
       
    98     
       
    99     // copy data from the chunk
       
   100     RMemReadStream readStream( iChunk.Base(), iChunk.Size() );
       
   101     CleanupClosePushL( readStream );
       
   102     
       
   103     TInt count( readStream.ReadUint16L() );
       
   104     LOGGER_WRITE_1("count: %d", count);
       
   105     for ( TInt i=0; i<count; i++ )
       
   106         {
       
   107         LOGGER_WRITE_1("Import[%d]", i);
       
   108         CSconDataproviderInfo *dpInfo = CSconDataproviderInfo::NewL();
       
   109         CleanupStack::PushL( dpInfo );
       
   110         
       
   111         dpInfo->InternalizeL( readStream );
       
   112         aInfoArray.AppendL( dpInfo );
       
   113         CleanupStack::Pop( dpInfo );
       
   114         }
       
   115     
       
   116     CleanupStack::PopAndDestroy( &readStream );
       
   117 
       
   118     TRACE_FUNC_EXIT;
       
   119     }
       
   120 
       
   121 EXPORT_C void RSconSyncSession::OpenDataStoreL( const TSmlDataProviderId aProviderId, const TDesC& aStoreName, TInt aContextId )
       
   122     {
       
   123     TRACE_FUNC_ENTRY;
       
   124     User::LeaveIfError( iChunk.Adjust( 
       
   125             sizeof(TInt32)
       
   126             + sizeof(TInt32)
       
   127             + aStoreName.Size()
       
   128             + sizeof(TInt) ));
       
   129     
       
   130     RMemWriteStream writeBuf( iChunk.Base(), iChunk.Size() );
       
   131     writeBuf.WriteInt32L( aProviderId );
       
   132     
       
   133     writeBuf.WriteInt32L( aStoreName.Length() );
       
   134     writeBuf.WriteL( aStoreName );
       
   135     
       
   136     writeBuf.WriteInt32L( aContextId );
       
   137 
       
   138     writeBuf.CommitL();
       
   139     writeBuf.Close();
       
   140     
       
   141     TIpcArgs args;
       
   142     TInt ret = SendReceive ( EOpenStore, args );
       
   143     
       
   144     if ( ret != KErrNone) 
       
   145         {
       
   146         LOGGER_WRITE_1( "RSconSyncSession::OpenDataStoreL() :\
       
   147          Send Receive failed with code %d", ret );
       
   148         User::Leave( ret );
       
   149         };
       
   150     TRACE_FUNC_EXIT;
       
   151     }
       
   152 
       
   153 EXPORT_C void RSconSyncSession::OpenItemL( TSmlDbItemUid aUid, TBool& aFieldChange,
       
   154         TSmlDbItemUid& aParent, TDes8& aMimeType, TDes8& aMimeVer, CBufFlat& aItemData )
       
   155     {
       
   156     TRACE_FUNC_ENTRY;
       
   157     TIpcArgs args( aUid );
       
   158     TInt ret = SendReceive ( EOpenItem, args );
       
   159     if ( ret != KErrNone) 
       
   160         {
       
   161         LOGGER_WRITE_1( "RSconSyncSession::OpenItemL() :\
       
   162          Send Receive failed with code %d", ret );
       
   163         User::Leave( ret );
       
   164         };
       
   165     
       
   166     // copy data from the chunk
       
   167     RMemReadStream readStream( iChunk.Base(), iChunk.Size() );
       
   168     CleanupClosePushL( readStream );
       
   169     TInt32 length ( 0 );
       
   170 
       
   171     aItemData.Reset();
       
   172     length = readStream.ReadInt32L();
       
   173     
       
   174     HBufC8* data = HBufC8::NewLC( length );
       
   175     TPtr8 dataPtr = data->Des();
       
   176     
       
   177     readStream.ReadL( dataPtr, length );
       
   178     aItemData.ExpandL( 0, length );
       
   179     aItemData.Write ( 0, dataPtr );
       
   180     
       
   181     CleanupStack::PopAndDestroy( data );
       
   182 
       
   183     aFieldChange = readStream.ReadInt8L();
       
   184     
       
   185     aParent = readStream.ReadInt32L();
       
   186     length = readStream.ReadInt32L();
       
   187     readStream.ReadL( aMimeType, length );
       
   188     
       
   189     length = readStream.ReadInt32L();
       
   190     readStream.ReadL( aMimeVer, length );
       
   191     
       
   192     CleanupStack::PopAndDestroy( &readStream );
       
   193     TRACE_FUNC_EXIT;
       
   194     }
       
   195 
       
   196 EXPORT_C void RSconSyncSession::CreateItemL(TSmlDbItemUid& aUid/*, TInt aSize*/,
       
   197         TSmlDbItemUid aParent, const TDesC8& aMimeType, const TDesC8& aMimeVer,
       
   198         const TDesC8& aData)
       
   199     {
       
   200     TRACE_FUNC_ENTRY;
       
   201     User::LeaveIfError( iChunk.Adjust( 
       
   202         sizeof(TInt32)
       
   203         + sizeof(TInt32)
       
   204         + aMimeType.Length()
       
   205         + sizeof(TInt32)
       
   206         + aMimeVer.Length()
       
   207         + sizeof(TInt32)
       
   208         + aData.Length() ));
       
   209     RMemWriteStream writeBuf( iChunk.Base(), iChunk.Size() );
       
   210     CleanupClosePushL( writeBuf );
       
   211     writeBuf.WriteInt32L( aParent );
       
   212     writeBuf.WriteInt32L( aMimeType.Length() );
       
   213     writeBuf.WriteL( aMimeType );
       
   214     writeBuf.WriteInt32L( aMimeVer.Length() );
       
   215     writeBuf.WriteL( aMimeVer );
       
   216     writeBuf.WriteInt32L( aData.Length() );
       
   217     writeBuf.WriteL( aData );
       
   218         
       
   219     writeBuf.CommitL();
       
   220     CleanupStack::PopAndDestroy( &writeBuf );
       
   221     
       
   222 
       
   223     
       
   224     TPckg<TSmlDbItemUid> pckg(aUid);
       
   225     iArgs = TIpcArgs( &pckg );
       
   226     
       
   227     TInt ret = SendReceive ( ECreateItem, iArgs );
       
   228     if ( ret != KErrNone) 
       
   229         {
       
   230         LOGGER_WRITE_1( "RSconSyncSession::CreateItemL() :\
       
   231          Send Receive failed with code %d", ret );
       
   232         User::Leave( ret );
       
   233         };
       
   234     LOGGER_WRITE_1("aUid: %d", aUid);
       
   235     TRACE_FUNC_EXIT;
       
   236     }
       
   237 
       
   238 EXPORT_C void RSconSyncSession::CreateItemL(TPckg<TSmlDbItemUid>& aUidPckg,
       
   239         TSmlDbItemUid aParent, const TDesC8& aMimeType, const TDesC8& aMimeVer,
       
   240         const TDesC8& aData, TRequestStatus& aStatus)
       
   241     {
       
   242     TRACE_FUNC_ENTRY;
       
   243     User::LeaveIfError( iChunk.Adjust( 
       
   244         sizeof(TInt32)
       
   245         + sizeof(TInt32)
       
   246         + aMimeType.Length()
       
   247         + sizeof(TInt32)
       
   248         + aMimeVer.Length()
       
   249         + sizeof(TInt32)
       
   250         + aData.Length() ));
       
   251     RMemWriteStream writeBuf( iChunk.Base(), iChunk.Size() );
       
   252     CleanupClosePushL( writeBuf );
       
   253     writeBuf.WriteInt32L( aParent );
       
   254     writeBuf.WriteInt32L( aMimeType.Length() );
       
   255     writeBuf.WriteL( aMimeType );
       
   256     writeBuf.WriteInt32L( aMimeVer.Length() );
       
   257     writeBuf.WriteL( aMimeVer );
       
   258     writeBuf.WriteInt32L( aData.Length() );
       
   259     writeBuf.WriteL( aData );
       
   260         
       
   261     writeBuf.CommitL();
       
   262     CleanupStack::PopAndDestroy( &writeBuf );
       
   263     
       
   264     iArgs = TIpcArgs( &aUidPckg );
       
   265     SendReceive( ECreateItem, iArgs, aStatus );
       
   266     
       
   267     TRACE_FUNC_EXIT;
       
   268     }
       
   269 
       
   270 EXPORT_C void RSconSyncSession::ReplaceItemL(TSmlDbItemUid aUid,
       
   271         TSmlDbItemUid aParent, TBool aFieldChange, const TDesC8& aData)
       
   272     {
       
   273     TRACE_FUNC_ENTRY;
       
   274     User::LeaveIfError( iChunk.Adjust( 
       
   275         sizeof(TInt32)
       
   276         + sizeof(TInt32)
       
   277         + sizeof(TInt8)
       
   278         + sizeof(TInt32)
       
   279         + aData.Length() ));
       
   280     RMemWriteStream writeBuf( iChunk.Base(), iChunk.Size() );
       
   281     CleanupClosePushL( writeBuf );
       
   282     writeBuf.WriteInt32L( aUid );
       
   283     writeBuf.WriteInt32L( aParent );
       
   284     writeBuf.WriteInt8L( aFieldChange );
       
   285     writeBuf.WriteInt32L( aData.Length() );
       
   286     writeBuf.WriteL( aData );
       
   287     writeBuf.CommitL();
       
   288     CleanupStack::PopAndDestroy( &writeBuf );
       
   289     
       
   290     TIpcArgs args;
       
   291     TInt ret = SendReceive( EReplaceItem, args );
       
   292     if ( ret != KErrNone) 
       
   293         {
       
   294         LOGGER_WRITE_1( "RSconSyncSession::ReplaceItemL() :\
       
   295          Send Receive failed with code %d", ret );
       
   296         User::Leave( ret );
       
   297         };
       
   298     TRACE_FUNC_EXIT;
       
   299     }
       
   300 
       
   301 EXPORT_C void RSconSyncSession::ReplaceItemL(TSmlDbItemUid aUid,
       
   302         TSmlDbItemUid aParent, TBool aFieldChange, const TDesC8& aData,
       
   303         TRequestStatus& aStatus)
       
   304     {
       
   305     TRACE_FUNC_ENTRY;
       
   306     User::LeaveIfError( iChunk.Adjust( 
       
   307         sizeof(TInt32)
       
   308         + sizeof(TInt32)
       
   309         + sizeof(TInt8)
       
   310         + sizeof(TInt32)
       
   311         + aData.Length() ));
       
   312     RMemWriteStream writeBuf( iChunk.Base(), iChunk.Size() );
       
   313     CleanupClosePushL( writeBuf );
       
   314     writeBuf.WriteInt32L( aUid );
       
   315     writeBuf.WriteInt32L( aParent );
       
   316     writeBuf.WriteInt8L( aFieldChange );
       
   317     writeBuf.WriteInt32L( aData.Length() );
       
   318     writeBuf.WriteL( aData );
       
   319     writeBuf.CommitL();
       
   320     CleanupStack::PopAndDestroy( &writeBuf );
       
   321     
       
   322     TIpcArgs args;
       
   323     SendReceive( EReplaceItem, args, aStatus );
       
   324     TRACE_FUNC_EXIT;
       
   325     }
       
   326 
       
   327 EXPORT_C void RSconSyncSession::MoveItemL( TSmlDbItemUid aUid, TSmlDbItemUid aNewParent )
       
   328     {
       
   329     TRACE_FUNC_ENTRY;
       
   330     
       
   331     TIpcArgs args(aUid, aNewParent);
       
   332     TInt ret = SendReceive ( EMoveItem, args );
       
   333     if ( ret != KErrNone) 
       
   334         {
       
   335         LOGGER_WRITE_1( "RSconSyncSession::MoveItemL() :\
       
   336          Send Receive failed with code %d", ret );
       
   337         User::Leave( ret );
       
   338         };
       
   339     TRACE_FUNC_EXIT;
       
   340     }
       
   341 
       
   342 EXPORT_C void RSconSyncSession::DeleteItemL( TSmlDbItemUid aUid )
       
   343     {
       
   344     TRACE_FUNC_ENTRY;
       
   345     
       
   346     TIpcArgs args( aUid );
       
   347     TInt ret = SendReceive ( EDeleteItem, args );
       
   348     if ( ret != KErrNone) 
       
   349         {
       
   350         LOGGER_WRITE_1( "RSconSyncSession::DeleteItemL() :\
       
   351          Send Receive failed with code %d", ret );
       
   352         User::Leave( ret );
       
   353         };
       
   354     TRACE_FUNC_EXIT;
       
   355     }
       
   356 
       
   357 
       
   358 EXPORT_C void RSconSyncSession::SoftDeleteItemL( TSmlDbItemUid aUid )
       
   359     {
       
   360     TRACE_FUNC_ENTRY;
       
   361     
       
   362     TIpcArgs args( aUid );
       
   363     TInt ret = SendReceive ( ESoftDeleteItem, args );
       
   364     if ( ret != KErrNone) 
       
   365         {
       
   366         LOGGER_WRITE_1( "RSconSyncSession::SoftDeleteItemL() :\
       
   367          Send Receive failed with code %d", ret );
       
   368         User::Leave( ret );
       
   369         };
       
   370     TRACE_FUNC_EXIT;
       
   371     }
       
   372 
       
   373 EXPORT_C void RSconSyncSession::DeleteAllItems( TRequestStatus& aStatus )
       
   374     {
       
   375     TRACE_FUNC_ENTRY;
       
   376     TIpcArgs args;
       
   377     SendReceive( EDeleteAllItems, args, aStatus );
       
   378     TRACE_FUNC_EXIT;
       
   379     }
       
   380 
       
   381     
       
   382 EXPORT_C TBool RSconSyncSession::HasSyncHistoryL() const
       
   383     {
       
   384     TRACE_FUNC;
       
   385     TBool history(EFalse);
       
   386     TPckg<TBool> pck(history);
       
   387     TIpcArgs args(&pck);
       
   388     TInt ret = SendReceive ( EHasHistory, args );
       
   389     User::LeaveIfError( ret );
       
   390     TRACE_FUNC_EXIT;
       
   391     return history;
       
   392     }
       
   393 
       
   394 EXPORT_C void RSconSyncSession::AddedItemsL( RArray<TSmlDbItemUid>& aItems) const
       
   395     {
       
   396     TRACE_FUNC_ENTRY;
       
   397     TIpcArgs args;
       
   398     TInt ret = SendReceive ( EAddedItems, args );
       
   399     User::LeaveIfError( ret );
       
   400     
       
   401     RMemReadStream readStream( iChunk.Base(), iChunk.Size() );
       
   402     CleanupClosePushL( readStream );
       
   403     
       
   404     aItems.Reset();
       
   405     TInt itemCount = readStream.ReadInt32L();
       
   406     for (TInt i=0; i<itemCount; i++)
       
   407         {
       
   408         aItems.AppendL( readStream.ReadInt32L() );
       
   409         }
       
   410     
       
   411     CleanupStack::PopAndDestroy( &readStream );
       
   412     
       
   413     TRACE_FUNC_EXIT;
       
   414     }
       
   415 
       
   416 EXPORT_C void RSconSyncSession::DeletedItemsL( RArray<TSmlDbItemUid>& aItems) const
       
   417     {
       
   418     TRACE_FUNC_ENTRY;
       
   419     TIpcArgs args;
       
   420     TInt ret = SendReceive ( EDeletedItems, args );
       
   421     User::LeaveIfError( ret );
       
   422     
       
   423     RMemReadStream readStream( iChunk.Base(), iChunk.Size() );
       
   424     CleanupClosePushL( readStream );
       
   425     
       
   426     aItems.Reset();
       
   427     TInt itemCount = readStream.ReadInt32L();
       
   428     for (TInt i=0; i<itemCount; i++)
       
   429         {
       
   430         aItems.AppendL( readStream.ReadInt32L() );
       
   431         }
       
   432     
       
   433     CleanupStack::PopAndDestroy( &readStream );
       
   434     
       
   435     TRACE_FUNC_EXIT;
       
   436     }
       
   437 
       
   438 EXPORT_C void RSconSyncSession::SoftDeletedItemsL( RArray<TSmlDbItemUid>& aItems) const
       
   439     {
       
   440     TRACE_FUNC_ENTRY;
       
   441     TIpcArgs args;
       
   442     TInt ret = SendReceive ( ESoftDeletedItems, args );
       
   443     User::LeaveIfError( ret );
       
   444     
       
   445     RMemReadStream readStream( iChunk.Base(), iChunk.Size() );
       
   446     CleanupClosePushL( readStream );
       
   447     
       
   448     aItems.Reset();
       
   449     TInt itemCount = readStream.ReadInt32L();
       
   450     for (TInt i=0; i<itemCount; i++)
       
   451         {
       
   452         aItems.AppendL( readStream.ReadInt32L() );
       
   453         }
       
   454     
       
   455     CleanupStack::PopAndDestroy( &readStream );
       
   456     
       
   457     TRACE_FUNC_EXIT;
       
   458     }
       
   459 
       
   460 EXPORT_C void RSconSyncSession::ModifiedItemsL( RArray<TSmlDbItemUid>& aItems) const
       
   461     {
       
   462     TRACE_FUNC_ENTRY;
       
   463     TIpcArgs args;
       
   464     TInt ret = SendReceive ( EModifiedItems, args );
       
   465     User::LeaveIfError( ret );
       
   466     
       
   467     RMemReadStream readStream( iChunk.Base(), iChunk.Size() );
       
   468     CleanupClosePushL( readStream );
       
   469     
       
   470     aItems.Reset();
       
   471     TInt itemCount = readStream.ReadInt32L();
       
   472     for (TInt i=0; i<itemCount; i++)
       
   473         {
       
   474         aItems.AppendL( readStream.ReadInt32L() );
       
   475         }
       
   476     
       
   477     CleanupStack::PopAndDestroy( &readStream );
       
   478     
       
   479     TRACE_FUNC_EXIT;
       
   480     }
       
   481 
       
   482 EXPORT_C void RSconSyncSession::MovedItemsL( RArray<TSmlDbItemUid>& aItems) const
       
   483     {
       
   484     TRACE_FUNC_ENTRY;
       
   485     TIpcArgs args;
       
   486     TInt ret = SendReceive ( EMovedItems, args );
       
   487     User::LeaveIfError( ret );
       
   488     
       
   489     RMemReadStream readStream( iChunk.Base(), iChunk.Size() );
       
   490     CleanupClosePushL( readStream );
       
   491     
       
   492     aItems.Reset();
       
   493     TInt itemCount = readStream.ReadInt32L();
       
   494     for (TInt i=0; i<itemCount; i++)
       
   495         {
       
   496         aItems.AppendL( readStream.ReadInt32L() );
       
   497         }
       
   498     
       
   499     CleanupStack::PopAndDestroy( &readStream );
       
   500     
       
   501     TRACE_FUNC_EXIT;
       
   502     }
       
   503 
       
   504 EXPORT_C void RSconSyncSession::CloseDataStore() const
       
   505     {
       
   506     TRACE_FUNC_ENTRY;
       
   507     TIpcArgs args;
       
   508     SendReceive ( ECloseStore, args );
       
   509     TRACE_FUNC_EXIT;
       
   510     }
       
   511 
       
   512 EXPORT_C void RSconSyncSession::ResetChangeInfoL()
       
   513     {
       
   514     TRACE_FUNC_ENTRY;
       
   515     TIpcArgs args;
       
   516     TInt ret = SendReceive ( EResetChangeInfo, args );
       
   517     User::LeaveIfError( ret );
       
   518     TRACE_FUNC_EXIT;
       
   519     }
       
   520 
       
   521 EXPORT_C void RSconSyncSession::CommitChangeInfoL(const RArray<TSmlDbItemUid>& aItems )
       
   522     {
       
   523     TRACE_FUNC_ENTRY;
       
   524     RMemWriteStream stream ( iChunk.Base(), iChunk.Size() );
       
   525     CleanupClosePushL( stream );
       
   526     LOGGER_WRITE_1("items count: %d", aItems.Count());
       
   527     stream.WriteInt32L( aItems.Count() );
       
   528     for (TInt i=0; i < aItems.Count(); i++ )
       
   529         {
       
   530         LOGGER_WRITE("Write item");
       
   531         stream.WriteInt32L( aItems[i] );
       
   532         }
       
   533     stream.CommitL();
       
   534     CleanupStack::PopAndDestroy( &stream );
       
   535         
       
   536     TIpcArgs args;
       
   537     TInt ret = SendReceive ( ECommitChangeInfo, args );
       
   538     User::LeaveIfError( ret );
       
   539     TRACE_FUNC_EXIT;
       
   540     }
       
   541 
       
   542 EXPORT_C void RSconSyncSession::GetSyncTimeStampL( const TSmlDataProviderId aProviderId, const TInt aContextId, TDateTime& aTimeStamp ) const
       
   543     {
       
   544     TRACE_FUNC_ENTRY;
       
   545     
       
   546     TPckg<TDateTime> timeBuf( aTimeStamp );
       
   547     TIpcArgs args( aProviderId, aContextId, &timeBuf );
       
   548     TInt ret = SendReceive ( EGetSyncTimeStamp, args );
       
   549     User::LeaveIfError( ret );
       
   550     
       
   551     TRACE_FUNC_EXIT;
       
   552     }
       
   553 
       
   554 EXPORT_C CSmlDataStoreFormat* RSconSyncSession::StoreFormatL( const RStringPool& aStringPool )
       
   555     {
       
   556     TRACE_FUNC_ENTRY;
       
   557     TIpcArgs args;
       
   558     TInt ret = SendReceive ( EExportStoreFormat, args );
       
   559     User::LeaveIfError( ret );
       
   560     
       
   561     RMemReadStream readStream( iChunk.Base(), iChunk.Size() );
       
   562     CleanupClosePushL( readStream );
       
   563     TInt len = readStream.ReadInt32L();
       
   564     LOGGER_WRITE_1("data size from server: %d", len);
       
   565     LOGGER_WRITE("CSmlDataStoreFormat::NewLC");
       
   566     CSmlDataStoreFormat* tempStoreFormat = CSmlDataStoreFormat::NewLC( aStringPool, readStream );
       
   567     LOGGER_WRITE("CSmlDataStoreFormat::NewLC -ok");
       
   568     CleanupStack::Pop( tempStoreFormat );
       
   569     
       
   570     LOGGER_WRITE("PopAndDestroy( &readStream )");
       
   571     CleanupStack::PopAndDestroy( &readStream );
       
   572     LOGGER_WRITE("return");
       
   573     TRACE_FUNC_EXIT;
       
   574     return tempStoreFormat;
       
   575     }
       
   576 
       
   577 EXPORT_C void RSconSyncSession::SetRemoteStoreFormatL( const CSmlDataStoreFormat& aServerDataStoreFormat )
       
   578     {
       
   579     TRACE_FUNC_ENTRY;
       
   580     const TInt KMaximumDataStoreFormatSize = 100000; // 100kb should be enought
       
   581     User::LeaveIfError( iChunk.Adjust( KMaximumDataStoreFormatSize ));
       
   582     
       
   583     RMemWriteStream stream ( iChunk.Base(), iChunk.Size() );
       
   584     CleanupClosePushL( stream );
       
   585     
       
   586     aServerDataStoreFormat.ExternalizeL( stream );
       
   587     
       
   588     stream.CommitL();
       
   589     CleanupStack::PopAndDestroy( &stream );
       
   590     
       
   591     TIpcArgs args;
       
   592     TInt ret = SendReceive ( ESetRemoteStoreFormat, args );
       
   593     User::LeaveIfError( ret );
       
   594     TRACE_FUNC_EXIT;
       
   595     }
       
   596 
       
   597 EXPORT_C void RSconSyncSession::CancelRequest()
       
   598     {
       
   599     TRACE_FUNC_ENTRY;
       
   600     SendReceive( ECancelRequest, TIpcArgs() );
       
   601     TRACE_FUNC_EXIT;
       
   602     }
       
   603 
       
   604 EXPORT_C TInt RSconSyncSession::GetParent( TSmlDbItemUid aUid, TSmlDbItemUid& aParent )
       
   605     {
       
   606     TRACE_FUNC_ENTRY;
       
   607     TPckg<TSmlDbItemUid> pckg(aParent);
       
   608     TIpcArgs args( aUid, &pckg );
       
   609     TInt ret = SendReceive( EReadParent, args );
       
   610     TRACE_FUNC_EXIT;
       
   611     return ret;
       
   612     }
       
   613 
       
   614 TInt RSconSyncSession::StartServer()
       
   615     {
       
   616     TRACE_FUNC_ENTRY;
       
   617     
       
   618     RProcess server;
       
   619     TInt error = server.Create(KSconSyncServerExe, KNullDesC);
       
   620     if ( error != KErrNone )
       
   621         {
       
   622         return error;
       
   623         }
       
   624     // start server and wait for signal before proceeding    
       
   625     TRequestStatus status;
       
   626     server.Rendezvous(status);
       
   627     if ( status.Int() != KRequestPending )
       
   628         {
       
   629         server.Kill(0);
       
   630         }
       
   631     else
       
   632         {
       
   633         server.Resume();
       
   634         }
       
   635     
       
   636     User::WaitForRequest( status );
       
   637     error = server.ExitType() == EExitPanic ? KErrGeneral : status.Int();
       
   638     server.Close();
       
   639     TRACE_FUNC_EXIT;
       
   640     return error;
       
   641     }
       
   642 
       
   643 // -----------------------------------------------------------------------------
       
   644 // RSconSyncSession::CreateAndSendChunkHandle()
       
   645 // Creates a chunk and sends a handle to server
       
   646 // -----------------------------------------------------------------------------
       
   647 //  
       
   648 TInt RSconSyncSession::CreateAndSendChunkHandle()
       
   649     {
       
   650     TRACE_FUNC_ENTRY;
       
   651     
       
   652     TInt err = iChunk.CreateGlobal( KNullDesC, 
       
   653                                     KSConSyncChunkSize, 
       
   654                                     KSConSyncChunkMaxSize );
       
   655     if ( err != KErrNone )
       
   656         {
       
   657         LOGGER_WRITE_1("iChunk.CreateGlobal failed, err: %d", err);
       
   658         return err;
       
   659         }                           
       
   660     TIpcArgs args;
       
   661     args.Set( 0, iChunk );
       
   662     err = SendReceive( ESendChunkHandle, args );
       
   663     
       
   664     LOGGER_WRITE_1("RSconSyncSession::CreateAndSendChunkHandle : returned: %d", err);
       
   665     return err;
       
   666     }
       
   667 
       
   668 // End of File