activityfw/storage/server/src/afstoragesynctask.cpp
changeset 104 9b022b1f357c
child 107 b34d53f6acdf
equal deleted inserted replaced
103:b99b84bcd2d1 104:9b022b1f357c
       
     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 <s32mem.h>
       
    18 #include <fbs.h>
       
    19 #include <bautils.h>
       
    20 
       
    21 #include "afstoragesynctask.h"
       
    22 #include "afcmd.h"
       
    23 #include "afentry.h"
       
    24 
       
    25 _LIT(KUnsupportedStorageSyncTask, "Unsupported sync storage task");
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 /**
       
    29  * Handle synchronous data storage requests
       
    30  * @param dataStorage - data storage
       
    31  * @param msg - request message
       
    32  */
       
    33 void AfStorageSyncTask::ExecuteL(MAfTaskStorage& observers,
       
    34                                  CAfStorage& dataStorage, 
       
    35                                  const RMessage2& msg)
       
    36 {
       
    37     switch (msg.Function()) {
       
    38     case AddActivity: 
       
    39         AddActivityL(dataStorage, msg);
       
    40         break;
       
    41     case UpdateActivity:
       
    42         UpdateActivityL(dataStorage, msg);
       
    43         break;
       
    44     case RemoveActivity:
       
    45         DeleteActivityL(dataStorage, msg);
       
    46         break;
       
    47     case RemoveApplicationActivities:
       
    48         DeleteApplicationActivitiesL(dataStorage, msg);
       
    49         break;
       
    50     default:
       
    51         //this code shouldn't be called. fatal error: means wrong session implementation 
       
    52         User::Panic(KUnsupportedStorageSyncTask, KErrGeneral);
       
    53     };
       
    54     msg.Complete(KErrNone);
       
    55     NotifyChangeL(observers, msg);
       
    56 }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 /**
       
    60  * Handle adding new activity.
       
    61  * @param dataStorage - data storage
       
    62  * @param msg - request message
       
    63  */
       
    64 void AfStorageSyncTask::AddActivityL(CAfStorage& dataStorage, 
       
    65                                      const RMessage2& msg)
       
    66 {
       
    67     //Read message and bitmap handle
       
    68     TPckgBuf<TInt> bitmapHdl(0);
       
    69     CAfEntry *entry = CAfEntry::NewLC(msg);
       
    70     msg.ReadL(1, bitmapHdl);
       
    71     
       
    72     RBuf thumbnailPath;
       
    73     CleanupClosePushL(thumbnailPath);
       
    74     dataStorage.ThumbnailPathL(thumbnailPath, 
       
    75                    dataStorage.Fs(), 
       
    76                    entry->ApplicationId(), 
       
    77                    entry->ActivityId(),
       
    78                    entry->Flags() & CAfEntry::Persistent);
       
    79     CreateThumbnailL(thumbnailPath, bitmapHdl());
       
    80     entry->SetImageSrcL(thumbnailPath);
       
    81     dataStorage.AddActivityL(*entry);
       
    82     CleanupStack::PopAndDestroy(&thumbnailPath);
       
    83     
       
    84     CleanupStack::PopAndDestroy(entry);
       
    85 }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 /**
       
    89  * Handle updating existing activiy
       
    90  * @param dataStorage - data storage
       
    91  * @param msg - request message
       
    92  */
       
    93 void AfStorageSyncTask::UpdateActivityL(CAfStorage& dataStorage, 
       
    94                                         const RMessage2& msg)
       
    95 {
       
    96     TPckgBuf<TInt> bitmapHdl(0);
       
    97     CAfEntry *entry = CAfEntry::NewLC(msg);
       
    98     msg.ReadL(1, bitmapHdl);
       
    99         
       
   100     RBuf thumbnailPath;
       
   101     CleanupClosePushL(thumbnailPath);
       
   102     DeleteActivityScreenshotL(dataStorage, 
       
   103                     entry->ApplicationId(), 
       
   104                     entry->ActivityId());
       
   105     
       
   106     dataStorage.ThumbnailPathL(thumbnailPath, 
       
   107                    dataStorage.Fs(), 
       
   108                    entry->ApplicationId(), 
       
   109                    entry->ActivityId(),
       
   110                    entry->Flags() & CAfEntry::Persistent);
       
   111     CreateThumbnailL(thumbnailPath, bitmapHdl());
       
   112     entry->SetImageSrcL(thumbnailPath);
       
   113     dataStorage.UpdateActivityL(*entry);
       
   114     CleanupStack::PopAndDestroy(&thumbnailPath);
       
   115     CleanupStack::PopAndDestroy(entry);
       
   116 }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 /**
       
   120  * Handle removing activity.
       
   121  * @param dataStorage - data storage
       
   122  * @param msg - request message
       
   123  */
       
   124 void AfStorageSyncTask::DeleteActivityL(CAfStorage& dataStorage, 
       
   125                                         const RMessage2& msg)
       
   126 {
       
   127     CAfEntry *entry = CAfEntry::NewLC(msg);
       
   128     dataStorage.DeleteActivityL(*entry);
       
   129     DeleteActivityScreenshotL(dataStorage, 
       
   130                         entry->ApplicationId(), 
       
   131                         entry->ActivityId());
       
   132     CleanupStack::PopAndDestroy(entry);
       
   133 }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 /**
       
   137  * Handle removing activity.
       
   138  * @param dataStorage - data storage
       
   139  * @param msg - request message
       
   140  */
       
   141 void AfStorageSyncTask::DeleteActivityScreenshotL(CAfStorage& dataStorage,
       
   142                                     TInt uid, 
       
   143                                     const TDesC &activityName)
       
   144 {
       
   145     RBuf thumbnailPath;
       
   146     CleanupClosePushL(thumbnailPath);
       
   147     dataStorage.ThumbnailPathL(thumbnailPath, 
       
   148                    dataStorage.Fs(), 
       
   149                    uid, 
       
   150                    activityName,
       
   151                    TRUE);
       
   152     dataStorage.Fs().Delete(thumbnailPath);
       
   153     thumbnailPath.Zero();
       
   154     dataStorage.ThumbnailPathL(thumbnailPath, 
       
   155                        dataStorage.Fs(), 
       
   156                        uid, 
       
   157                        activityName,
       
   158                        FALSE);
       
   159     dataStorage.Fs().Delete(thumbnailPath);
       
   160     thumbnailPath.Zero(); 
       
   161     CleanupStack::PopAndDestroy(&thumbnailPath);
       
   162 }
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 /**
       
   166  * Handle removing all application activities.
       
   167  * @param dataStorage - data storage
       
   168  * @param msg - request message
       
   169  */
       
   170 void AfStorageSyncTask::DeleteApplicationActivitiesL(CAfStorage& dataStorage, 
       
   171                                                      const RMessage2& msg)
       
   172 {
       
   173     CAfEntry *entry = CAfEntry::NewLC(msg);
       
   174     dataStorage.DeleteActivitiesL(*entry);
       
   175     CleanupStack::PopAndDestroy(entry);
       
   176 }
       
   177 
       
   178 // -----------------------------------------------------------------------------
       
   179 //
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 void AfStorageSyncTask::NotifyChangeL(MAfTaskStorage& observers,
       
   183                                       const RMessage2& msg)
       
   184 {
       
   185     const RPointerArray<CAfTask> &table(observers.StorageData());
       
   186     for (TInt iter(table.Count() - 1); 0 <= iter; --iter) {
       
   187         table[iter]->BroadcastReceivedL(msg);
       
   188     }
       
   189 }
       
   190 
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 void AfStorageSyncTask::CreateThumbnailL(const TDesC &path, TInt hdl)
       
   196 {
       
   197     if (0 >= hdl) {
       
   198         User::Leave(KErrCorrupt);
       
   199     }
       
   200     CFbsBitmap *bitmap = new (ELeave) CFbsBitmap;
       
   201     CleanupStack::PushL(bitmap);
       
   202     User::LeaveIfError(bitmap->Duplicate(hdl));
       
   203     User::LeaveIfError(bitmap->Save(path));
       
   204     CleanupStack::PopAndDestroy(bitmap);
       
   205 }