connectivitymodules/SeCon/servers/syncserver/src/sconsyncrelationship.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:  CSconSyncRelationship implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "sconsyncrelationship.h"
       
    20 #include <s32file.h>
       
    21 #include <nsmlchangefinder.h>
       
    22 
       
    23 #include "debug.h"
       
    24 
       
    25 _LIT(KContextStore, "contextstore_0x%08x.dat");
       
    26 _LIT(KTimeStore, "timestore_0x%08x.dat");
       
    27 
       
    28 CSconSyncRelationship::~CSconSyncRelationship()
       
    29     {
       
    30     TRACE_FUNC_ENTRY;
       
    31     if ( iDictionaryStore )
       
    32         {
       
    33         iDictionaryStore->Commit();
       
    34         delete iDictionaryStore;
       
    35         }
       
    36     TRACE_FUNC_EXIT;
       
    37     }
       
    38 
       
    39 CSconSyncRelationship::CSconSyncRelationship( RFs& aFs, TUid aRelationUid, TSmlDataProviderId aProviderId )
       
    40     : iFs(aFs), iID(aRelationUid), iProviderId(aProviderId)
       
    41     {
       
    42     TRACE_FUNC;
       
    43     
       
    44     }
       
    45 
       
    46 CSconSyncRelationship* CSconSyncRelationship::NewL( RFs& aFs, TUid aRelationUid, TSmlDataProviderId aProviderId )
       
    47     {
       
    48     TRACE_FUNC_ENTRY;
       
    49     CSconSyncRelationship* self = new (ELeave) CSconSyncRelationship( aFs, aRelationUid, aProviderId );
       
    50     CleanupStack::PushL( self );
       
    51     self->ConstructL();
       
    52     CleanupStack::Pop( self );
       
    53     TRACE_FUNC_EXIT;
       
    54     return self;
       
    55     }
       
    56 
       
    57 void CSconSyncRelationship::SetTimeStampL( RFs& aFs, TUid aRelationUid, TSmlDataProviderId aId )
       
    58     {
       
    59     TRACE_FUNC_ENTRY;
       
    60     LOGGER_WRITE_1("aRelationUid: 0x%08x", aRelationUid.iUid );
       
    61     LOGGER_WRITE_1("aId: 0x%08x", aId );
       
    62     aFs.SetSessionToPrivate( EDriveC );
       
    63     TFileName file;
       
    64     file.Format(KTimeStore, aRelationUid.iUid);
       
    65     CDictionaryFileStore* dictionaryStore = CDictionaryFileStore::OpenLC(aFs, file, TUid::Uid(0x0001));
       
    66     
       
    67     RDictionaryWriteStream stream;
       
    68     stream.AssignLC( *dictionaryStore, TUid::Uid(aId) );
       
    69     
       
    70     TTime time;
       
    71     time.UniversalTime();
       
    72     
       
    73     TDateTime dateTime = time.DateTime();
       
    74     TPckgBuf<TDateTime> timeBuf(dateTime);
       
    75     
       
    76     stream.WriteL( timeBuf );
       
    77     stream.CommitL();
       
    78     
       
    79     CleanupStack::PopAndDestroy( &stream ); //AssingLC
       
    80     dictionaryStore->Commit();
       
    81     CleanupStack::PopAndDestroy( dictionaryStore );
       
    82     TRACE_FUNC_EXIT;
       
    83     }
       
    84 
       
    85 void CSconSyncRelationship::GetTimeStampL( RFs& aFs, TUid aRelationUid, TSmlDataProviderId aId, TDateTime& aTimeStamp )
       
    86     {
       
    87     TRACE_FUNC_ENTRY;
       
    88     LOGGER_WRITE_1("aRelationUid: 0x%08x", aRelationUid.iUid );
       
    89     LOGGER_WRITE_1("aId: 0x%08x", aId );
       
    90     User::LeaveIfError( aFs.SetSessionToPrivate( EDriveC ) );
       
    91     TFileName file;
       
    92     file.Format(KTimeStore, aRelationUid.iUid);
       
    93     CDictionaryFileStore* dictionaryStore = CDictionaryFileStore::OpenLC(aFs, file, TUid::Uid(0x0001));
       
    94     TBool present = dictionaryStore->IsPresentL( TUid::Uid(aId) );
       
    95     if ( !present )
       
    96         {
       
    97         LOGGER_WRITE("Stream was not present");
       
    98         User::Leave(KErrNotFound);
       
    99         }
       
   100     RDictionaryReadStream stream;
       
   101     stream.OpenLC( *dictionaryStore, TUid::Uid(aId) );
       
   102     TPckgBuf<TDateTime> timeBuf;
       
   103     stream.ReadL( timeBuf );
       
   104     aTimeStamp = timeBuf();
       
   105     CleanupStack::PopAndDestroy(); //OpenLC
       
   106     CleanupStack::PopAndDestroy( dictionaryStore );
       
   107     
       
   108     TRACE_FUNC_EXIT;
       
   109     }
       
   110 
       
   111 void CSconSyncRelationship::ConstructL()
       
   112     {
       
   113     TRACE_FUNC_ENTRY;
       
   114     iFs.SetSessionToPrivate( EDriveC );
       
   115     TFileName file;
       
   116     file.Format(KContextStore, iID.iUid);
       
   117     iDictionaryStore = CDictionaryFileStore::OpenL(
       
   118             iFs, file, TUid::Uid(0x0001));
       
   119     
       
   120     TRACE_FUNC_EXIT;
       
   121     }
       
   122 
       
   123 
       
   124 TSmlSyncTaskKey CSconSyncRelationship::SyncTaskKey() const
       
   125     {
       
   126     TRACE_FUNC;
       
   127     return static_cast<TSmlSyncTaskKey>(iID.iUid);
       
   128     }
       
   129 
       
   130 void CSconSyncRelationship::OpenReadStreamLC(RReadStream& aReadStream, TUid aStreamUid)
       
   131     {
       
   132     TRACE_FUNC_ENTRY;
       
   133     LOGGER_WRITE_1("aStreamUid: 0x%08x", aStreamUid);
       
   134     TUid streamUid(aStreamUid);
       
   135     if ( aStreamUid.iUid == KNSmlDefaultSnapshotStreamUID )
       
   136         {
       
   137         LOGGER_WRITE_1(" Default stream uid was used, use provider uid (0x%08x) as stream uid", iProviderId);
       
   138         streamUid.iUid = iProviderId;
       
   139         }
       
   140     if ( !IsStreamPresentL( streamUid ) )
       
   141         {
       
   142         LOGGER_WRITE("Stream was not present");
       
   143         User::Leave(KErrNotFound);
       
   144         }
       
   145     
       
   146         
       
   147     static_cast<RDictionaryReadStream&>(aReadStream).OpenLC(
       
   148         *iDictionaryStore, streamUid );
       
   149     TRACE_FUNC_EXIT;
       
   150     }
       
   151 
       
   152 void CSconSyncRelationship::OpenWriteStreamLC(RWriteStream& aWriteStream, TUid aStreamUid)
       
   153     {
       
   154     TRACE_FUNC_ENTRY;
       
   155     
       
   156     LOGGER_WRITE_1("aStreamUid: 0x%08x", aStreamUid);
       
   157     TUid streamUid(aStreamUid);
       
   158     if ( aStreamUid.iUid == KNSmlDefaultSnapshotStreamUID )
       
   159         {
       
   160         LOGGER_WRITE_1(" Default stream uid was used, use provider uid (0x%08x) as stream uid", iProviderId);
       
   161         streamUid.iUid = iProviderId;
       
   162         }
       
   163     static_cast<RDictionaryWriteStream&>(aWriteStream).AssignLC(
       
   164                  *iDictionaryStore, streamUid );
       
   165     TRACE_FUNC_EXIT;
       
   166     }
       
   167 
       
   168 TBool CSconSyncRelationship::IsStreamPresentL(TUid aStreamUid) const
       
   169     {
       
   170     TRACE_FUNC_ENTRY;
       
   171     LOGGER_WRITE_1("aStreamUid: 0x%08x", aStreamUid.iUid );
       
   172     TUid streamUid(aStreamUid);
       
   173     if ( aStreamUid.iUid == KNSmlDefaultSnapshotStreamUID )
       
   174         {
       
   175         LOGGER_WRITE_1(" Default stream uid was used, use provider uid (0x%08x) as stream uid", iProviderId);
       
   176         streamUid.iUid = iProviderId;
       
   177         }
       
   178     TBool present = iDictionaryStore->IsPresentL( streamUid );
       
   179     LOGGER_WRITE_1("CSconSyncRelationship::IsStreamPresentL() return: %d",(TInt)present);
       
   180     return present;
       
   181     }