activityfw/activitydatabase/hsactivitydbserver/src/activitystoragesynctask.cpp
changeset 73 4bc7b118b3df
child 80 397d00875918
equal deleted inserted replaced
66:32469d7d46ff 73:4bc7b118b3df
       
     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:
       
    15 *
       
    16 */
       
    17 #include "activitystoragesynctask.h"
       
    18 #include "activitycmd.h"
       
    19 
       
    20 _LIT(KUnsupportedStorageSyncTask, "Unsupported sync storage task");
       
    21 
       
    22 // -----------------------------------------------------------------------------
       
    23 //
       
    24 // -----------------------------------------------------------------------------
       
    25 //
       
    26 void ActivityStorageSyncTask::ExecuteL(CActivityStorage& dataStorage, const RMessage2& msg)
       
    27 {
       
    28     switch (msg.Function()) {
       
    29     case AddActivity: 
       
    30         AddActivityL(dataStorage, msg);
       
    31         break;
       
    32     case UpdateActivity:
       
    33         UpdateActivityL(dataStorage, msg);
       
    34         break;
       
    35     case RemoveActivity:
       
    36         DeleteActivityL(dataStorage, msg);
       
    37         break;
       
    38     case RemoveApplicationActivities:
       
    39         DeleteApplicationActivitiesL(dataStorage, msg);
       
    40         break;
       
    41     default:
       
    42         //this code shouldn't be called. fatal error: means wrong session implementation 
       
    43         User::Panic(KUnsupportedStorageSyncTask, KErrGeneral);
       
    44     };
       
    45     msg.Complete(KErrNone);
       
    46 }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 void ActivityStorageSyncTask::AddActivityL(CActivityStorage& dataStorage, const RMessage2& msg)
       
    53 {
       
    54     TPckgBuf<TInt> appId;
       
    55     msg.ReadL(KRequestAppIdOffset, appId);
       
    56     
       
    57     RBuf8 actId;
       
    58     CleanupClosePushL(actId);
       
    59     actId.CreateL(msg.GetDesLengthL(KRequestActOffset));
       
    60     msg.ReadL(KRequestActOffset, actId, 0);
       
    61     
       
    62     RBuf8 data;
       
    63     CleanupClosePushL(data);
       
    64     data.CreateL(msg.GetDesLengthL(KRequestData));
       
    65     msg.ReadL(KRequestData, data, 0);
       
    66     
       
    67     dataStorage.AddActivityL(appId(), actId, data);
       
    68     
       
    69     CleanupStack::PopAndDestroy(&data);
       
    70     CleanupStack::PopAndDestroy(&actId);
       
    71 }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 void ActivityStorageSyncTask::UpdateActivityL(CActivityStorage& dataStorage, const RMessage2& msg)
       
    78 {
       
    79     TPckgBuf<TInt> appId;
       
    80     msg.ReadL(KRequestAppIdOffset, appId);
       
    81     
       
    82     RBuf8 actId;
       
    83     CleanupClosePushL(actId);
       
    84     actId.CreateL(msg.GetDesLengthL(KRequestActOffset));
       
    85     msg.ReadL(KRequestActOffset, actId, 0);
       
    86     
       
    87     RBuf8 data;
       
    88     CleanupClosePushL(data);
       
    89     data.CreateL(msg.GetDesLengthL(KRequestData));
       
    90     msg.ReadL(KRequestData, data, 0);
       
    91     
       
    92     dataStorage.UpdateActivityL(appId(), actId, data);
       
    93     
       
    94     CleanupStack::PopAndDestroy(&data);
       
    95     CleanupStack::PopAndDestroy(&actId);
       
    96 }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 void ActivityStorageSyncTask::DeleteActivityL(CActivityStorage& dataStorage, const RMessage2& msg)
       
   103 {
       
   104     TPckgBuf<TInt> appId;
       
   105     msg.ReadL(KRequestAppIdOffset, appId);
       
   106     
       
   107     RBuf8 actId;
       
   108     CleanupClosePushL(actId);
       
   109     actId.CreateL(msg.GetDesLengthL(KRequestActOffset));
       
   110     msg.ReadL(KRequestActOffset, actId, 0);
       
   111     
       
   112     dataStorage.DeleteActivityL(appId(), actId);
       
   113     
       
   114     CleanupStack::PopAndDestroy(&actId);
       
   115 }
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 void ActivityStorageSyncTask::DeleteApplicationActivitiesL(CActivityStorage& dataStorage, const RMessage2& msg)
       
   122 {
       
   123     TPckgBuf<TInt> appId;
       
   124     msg.ReadL(KRequestAppIdOffset, appId);
       
   125     dataStorage.DeleteActivitiesL(appId());
       
   126 }