activityfw/activitydatabase/hsactivitydbserver/src/activityobservertask.cpp
changeset 103 b99b84bcd2d1
parent 83 156f692b1687
child 104 9b022b1f357c
equal deleted inserted replaced
83:156f692b1687 103:b99b84bcd2d1
     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 "activityobservertask.h"
       
    18 #include "activitycmd.h"
       
    19 
       
    20 // -----------------------------------------------------------------------------
       
    21 //
       
    22 // -----------------------------------------------------------------------------
       
    23 //
       
    24 CActivityObserverTask::CActivityObserverTask(MActivityTaskStorage& globalStorage, 
       
    25                                              MActivityTaskStorage& localStorage, 
       
    26                                              const RMessage2& msg)
       
    27 :
       
    28     mGlobalStorage(globalStorage),
       
    29     mLocalStorage(localStorage),
       
    30     mMsg(msg)
       
    31 {
       
    32     // No implementation required
       
    33 }
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CActivityObserverTask::~CActivityObserverTask()
       
    40 {
       
    41     mData.Close();
       
    42 }
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 void CActivityObserverTask::ExecuteLD(MActivityTaskStorage& globalStorage, 
       
    49                                       MActivityTaskStorage& localStorage, 
       
    50                                       const RMessage2& msg)
       
    51 {
       
    52     CActivityObserverTask *self = new(ELeave)CActivityObserverTask(globalStorage, 
       
    53                                                                    localStorage, 
       
    54                                                                    msg);
       
    55     CleanupStack::PushL(self);
       
    56     globalStorage.PushL(self);
       
    57     CleanupStack::Pop(self);
       
    58 }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 const TDesC8& CActivityObserverTask::Data() const
       
    65 {
       
    66     return mData;
       
    67 }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 void CActivityObserverTask::BroadcastReceivedL(const RMessage2& msg)
       
    74 {
       
    75     if(EFalse != mMsg.IsNull()) {
       
    76         mGlobalStorage.Pop(this);//
       
    77         mLocalStorage.Pop(this);
       
    78         delete this;
       
    79     } else if (WaitActivity == mMsg.Function() &&
       
    80                LaunchActivity == msg.Function()) {
       
    81                TPckgBuf<TInt> observerdId;
       
    82                mMsg.ReadL(KRequestAppIdOffset, observerdId);
       
    83 
       
    84         TPckgBuf<TInt> requestedId;
       
    85         msg.ReadL(KRequestAppIdOffset, requestedId);
       
    86         if (observerdId() == requestedId()) {
       
    87             if (msg.GetDesLength(KRequestActOffset) > mData.MaxLength()) {
       
    88                 mData.ReAllocL(msg.GetDesLength(1));
       
    89             }
       
    90             msg.ReadL(KRequestActOffset, mData, 0);
       
    91             WriteResponseL();
       
    92             mLocalStorage.PushL(this);
       
    93             mGlobalStorage.Pop(this);
       
    94             mMsg.Complete(KErrNone);
       
    95         }
       
    96     } else if (WaitActivity == mMsg.Function() &&
       
    97                CancelWait == msg.Function() &&
       
    98                mMsg.Session() == msg.Session()) {
       
    99         mGlobalStorage.Pop(this);
       
   100         mMsg.Complete(KErrCancel);
       
   101         delete this;
       
   102     } else if (NotifyChange == mMsg.Function() &&
       
   103                CancelNotify == msg.Function() &&
       
   104                mMsg.Session() == msg.Session()) {
       
   105         mGlobalStorage.Pop(this);
       
   106         mMsg.Complete(KErrCancel);
       
   107         delete this;
       
   108     } else if(NotifyChange == mMsg.Function() &&
       
   109               (AddActivity == msg.Function() ||
       
   110                UpdateActivity == msg.Function() ||
       
   111                RemoveActivity == msg.Function() ||
       
   112                RemoveApplicationActivities == msg.Function())){
       
   113         mMsg.Complete(KErrNone);
       
   114         mGlobalStorage.Pop(this);
       
   115         delete this;
       
   116     }
       
   117 }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 void CActivityObserverTask::WriteResponseL()
       
   124 {
       
   125     mMsg.WriteL(KResponseDataSizeOffset, TPckgBuf<TInt>(mData.Length()));//write data size
       
   126     mMsg.WriteL(KResponseIdOffset, TPckgBuf<CBase*>(this));//task identyfier
       
   127 }
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 TBool CActivityObserverTask::IsSessionTask(const CSession2* session)
       
   134 {
       
   135 	return mMsg.Session() == session ? ETrue : EFalse;
       
   136 }