activityfw/activitydatabase/hsactivitydbserver/src/afstorageasynctask.cpp
changeset 102 8b8b34fa9751
parent 100 0920c6a9b6c8
child 106 e78d6e055a5b
equal deleted inserted replaced
100:0920c6a9b6c8 102:8b8b34fa9751
     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 
       
    19 #include "afstorageasynctask.h"
       
    20 #include "activitycmd.h"
       
    21 
       
    22 _LIT(KUnsupportedStorageAsyncTask, "Unsupported async storage task");
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 //
       
    26 // -----------------------------------------------------------------------------
       
    27 //
       
    28 LOCAL_C void ReadEntryL(CAfEntry& entry, const RMessage2& msg)
       
    29 {
       
    30     RBuf8 serializedEntry;
       
    31     CleanupClosePushL(serializedEntry);
       
    32     serializedEntry.CreateL(msg.GetDesLengthL(0));
       
    33     msg.ReadL(0, serializedEntry);
       
    34     RDesReadStream reader(serializedEntry);
       
    35     CleanupClosePushL(reader);
       
    36     
       
    37     reader >> entry;
       
    38     
       
    39     CleanupStack::PopAndDestroy(&reader);
       
    40     CleanupStack::PopAndDestroy(&serializedEntry);
       
    41 }
       
    42 // -----------------------------------------------------------------------------
       
    43 /**
       
    44  * Constructor for performing 1st stage construction
       
    45  */
       
    46 CAfStorageAsyncTask::CAfStorageAsyncTask()
       
    47 {
       
    48     // No implementation required
       
    49 }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 /**
       
    53  * Destructor.
       
    54  */
       
    55 CAfStorageAsyncTask::~CAfStorageAsyncTask()
       
    56 {
       
    57     mExternalizedData.Close();
       
    58     mInternalizedData.ResetAndDestroy();
       
    59 }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 /**
       
    63  * Handle asynchronous data storage requests
       
    64  * @param taskStorage - data tasks storage
       
    65  * @param dataStorage - data storage
       
    66  * @param msg - request message
       
    67  */
       
    68 void CAfStorageAsyncTask::ExecuteLD(MAfTaskStorage& taskStorage, 
       
    69                                     CAfStorage& dataStorage, 
       
    70                                     const RMessage2& msg)
       
    71 {
       
    72     CAfStorageAsyncTask* self = new (ELeave) CAfStorageAsyncTask();
       
    73     CleanupStack::PushL(self);
       
    74     self->ExecuteL(dataStorage, msg);
       
    75     taskStorage.PushL(self);
       
    76     CleanupStack::Pop(self);
       
    77     if (EFalse == msg.IsNull()) {
       
    78         msg.Complete(KErrNone);
       
    79     }
       
    80 }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 /**
       
    84  * Interface implementation
       
    85  * @see CActivityTask::Data()
       
    86  */
       
    87 const TDesC8& CAfStorageAsyncTask::CAfStorageAsyncTask::Data() const
       
    88 {
       
    89     return mExternalizedData;
       
    90 }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 /**
       
    94  * Interface implementation
       
    95  * @see CActivityTask::BroadcastReceivedL(const RMessage2 &)
       
    96  */
       
    97 void CAfStorageAsyncTask::BroadcastReceivedL(const RMessage2& )
       
    98 {
       
    99     // No implementation required
       
   100 }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 /**
       
   104  * Handle asynchronous data storage requests
       
   105  * @param dataStorage - data storage
       
   106  * @param msg - request message
       
   107  */
       
   108 void CAfStorageAsyncTask::ExecuteL(CAfStorage& dataStorage, 
       
   109                                    const RMessage2& msg)
       
   110 {
       
   111     switch (msg.Function()) {
       
   112     case Activities:
       
   113         AllActivitiesL(dataStorage, msg);
       
   114         break;
       
   115     case ApplicationActivities:
       
   116         ApplicationActivitiesL(dataStorage, msg);
       
   117         break;
       
   118     case ApplicationActivity:
       
   119         ApplicationActivityL(dataStorage, msg);
       
   120         break;
       
   121     default:
       
   122         //this code shouldn't be called. fatal error: means wrong session implementation 
       
   123         User::Panic(KUnsupportedStorageAsyncTask, KErrGeneral);
       
   124     };
       
   125 }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 /**
       
   129  * Handle getting all activities request
       
   130  * @param dataStorage - data storage
       
   131  * @param msg - requested message
       
   132  */
       
   133 void CAfStorageAsyncTask::AllActivitiesL(CAfStorage& dataStorage, 
       
   134                                          const RMessage2& msg)
       
   135 {
       
   136     dataStorage.ActivitiesL(mInternalizedData);
       
   137     ExternalizeL();
       
   138     WriteResponseL(msg);
       
   139 }
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 /**
       
   143  * Handle getting application activities request
       
   144  * @param dataStorage - data storage
       
   145  * @param msg - requested message
       
   146  */
       
   147 void CAfStorageAsyncTask::ApplicationActivitiesL(CAfStorage& dataStorage, 
       
   148                                                  const RMessage2& msg)
       
   149 {
       
   150     CAfEntry *entry = CAfEntry::NewLC();
       
   151     ReadEntryL(*entry, msg);
       
   152     dataStorage.ActivitiesL(mInternalizedData, entry->ApplicationId());
       
   153     CleanupStack::PopAndDestroy(entry);
       
   154     ExternalizeL();
       
   155     WriteResponseL(msg);
       
   156 }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 /**
       
   160  * Handle getting application activity request
       
   161  * @param dataStorage - data storage
       
   162  * @param msg - requested message
       
   163  */
       
   164 void CAfStorageAsyncTask::ApplicationActivityL(CAfStorage& dataStorage, 
       
   165                                                const RMessage2& msg)
       
   166 {
       
   167     CAfEntry *src(CAfEntry::NewLC()) , *dst(0);
       
   168     ReadEntryL(*src, msg);
       
   169     dataStorage.ActivityL(dst, *src);
       
   170     CleanupStack::PushL(dst);
       
   171     ExternalizeL(*dst);
       
   172     CleanupStack::PopAndDestroy(dst);
       
   173     CleanupStack::PopAndDestroy(src);
       
   174     WriteResponseL(msg);
       
   175 }
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 void CAfStorageAsyncTask::ExternalizeL()
       
   179 {
       
   180     mExternalizedData << mInternalizedData;
       
   181     mInternalizedData.ResetAndDestroy();
       
   182 }
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 /**
       
   186  * Externalzie entry into output buffer
       
   187  * @param entry - source entry
       
   188  */
       
   189 void CAfStorageAsyncTask::ExternalizeL(const CAfEntry &entry)
       
   190 {
       
   191     CAfEntry::ReallocL(mExternalizedData, entry.Size());
       
   192     RDesWriteStream writer(mExternalizedData);
       
   193     CleanupClosePushL(writer);
       
   194     writer << entry;
       
   195     CleanupStack::PopAndDestroy(&writer);
       
   196 }
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 /**
       
   200  * Write response data into request message
       
   201  * @param msg - destination message
       
   202  */
       
   203 void CAfStorageAsyncTask::WriteResponseL(const RMessage2& msg)
       
   204 {
       
   205     if (EFalse == msg.IsNull()) {
       
   206         msg.WriteL(1, 
       
   207                    TPckgBuf<TInt>(mExternalizedData.Length()));//write data size
       
   208         msg.WriteL(2, 
       
   209                    TPckgBuf<CBase*>(this));//task identyfier
       
   210     }
       
   211 }
       
   212 
       
   213 // -----------------------------------------------------------------------------
       
   214 /**
       
   215  * Returns ETrue if task is related with session argument
       
   216  */
       
   217 
       
   218 TBool CAfStorageAsyncTask::IsSessionTask(const CSession2* /*session*/)
       
   219 {
       
   220 	return EFalse;
       
   221 }