activityfw/activitydatabase/hsactivitydbserver/src/afobservertask.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 "afobservertask.h"
       
    18 #include "activitycmd.h"
       
    19 
       
    20 // -----------------------------------------------------------------------------
       
    21 /**
       
    22  * Constructor for performing 1st stage construction
       
    23  * @param globalStorage - global observers storage
       
    24  * @param localStorage - local observers storage
       
    25  * @param msg - request message
       
    26  */
       
    27 CAfObserverTask::CAfObserverTask(MAfTaskStorage& globalStorage, 
       
    28                                  MAfTaskStorage& localStorage, 
       
    29                                  const RMessage2& msg)
       
    30 :
       
    31     mGlobalStorage(globalStorage),
       
    32     mLocalStorage(localStorage),
       
    33     mMsg(msg)
       
    34 {
       
    35     // No implementation required
       
    36 }
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 /**
       
    40  * Destructor.
       
    41  */
       
    42 CAfObserverTask::~CAfObserverTask()
       
    43 {
       
    44     mData.Close();
       
    45 }
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 /**
       
    49  * Handle observer request. 
       
    50  * @param globalStorage - global observers storage
       
    51  * @param localStorage - local observers storage
       
    52  * @param msg - request message
       
    53  */
       
    54 
       
    55 void CAfObserverTask::ExecuteLD(MAfTaskStorage& globalStorage, 
       
    56                                 MAfTaskStorage& localStorage, 
       
    57                                 const RMessage2& msg)
       
    58 {
       
    59     CAfObserverTask *self = new(ELeave)CAfObserverTask(globalStorage, 
       
    60                                                        localStorage, 
       
    61                                                        msg);
       
    62     CleanupStack::PushL(self);
       
    63     globalStorage.PushL(self);
       
    64     CleanupStack::Pop(self);
       
    65 }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 /**
       
    69  * Interface implementation
       
    70  * @see CActivityTask::Data()
       
    71  */
       
    72 const TDesC8& CAfObserverTask::Data() const
       
    73 {
       
    74     return mData;
       
    75 }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 /**
       
    79  * Interface implementation
       
    80  * @see CActivityTask::BroadcastReceivedL(const RMessage2&)
       
    81  */
       
    82 void CAfObserverTask::BroadcastReceivedL(const RMessage2& msg)
       
    83 {
       
    84     if(EFalse != mMsg.IsNull()) {
       
    85         mGlobalStorage.Pop(this);//
       
    86         mLocalStorage.Pop(this);
       
    87         delete this;
       
    88     } else if (WaitActivity == mMsg.Function() &&
       
    89                LaunchActivity == msg.Function()) {
       
    90                TPckgBuf<TInt> observerdId;
       
    91                mMsg.ReadL(KRequestAppIdOffset, observerdId);
       
    92 
       
    93         TPckgBuf<TInt> requestedId;
       
    94         msg.ReadL(KRequestAppIdOffset, requestedId);
       
    95         if (observerdId() == requestedId()) {
       
    96             if (msg.GetDesLength(KRequestActOffset) > mData.MaxLength()) {
       
    97                 mData.ReAllocL(msg.GetDesLength(1));
       
    98             }
       
    99             msg.ReadL(KRequestActOffset, mData, 0);
       
   100             WriteResponseL();
       
   101             mLocalStorage.PushL(this);
       
   102             mGlobalStorage.Pop(this);
       
   103             mMsg.Complete(KErrNone);
       
   104         }
       
   105     } else if (WaitActivity == mMsg.Function() &&
       
   106                CancelWait == msg.Function() &&
       
   107                mMsg.Session() == msg.Session()) {
       
   108         mGlobalStorage.Pop(this);
       
   109         mMsg.Complete(KErrCancel);
       
   110         delete this;
       
   111     } else if (NotifyChange == mMsg.Function() &&
       
   112                CancelNotify == msg.Function() &&
       
   113                mMsg.Session() == msg.Session()) {
       
   114         mGlobalStorage.Pop(this);
       
   115         mMsg.Complete(KErrCancel);
       
   116         delete this;
       
   117     } else if(NotifyChange == mMsg.Function() &&
       
   118               (AddActivity == msg.Function() ||
       
   119                UpdateActivity == msg.Function() ||
       
   120                RemoveActivity == msg.Function() ||
       
   121                RemoveApplicationActivities == msg.Function())){
       
   122         mMsg.Complete(KErrNone);
       
   123         mGlobalStorage.Pop(this);
       
   124         delete this;
       
   125     }
       
   126 }
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 /**
       
   130  * Write response data to requested message 
       
   131  */
       
   132 void CAfObserverTask::WriteResponseL()
       
   133 {
       
   134     mMsg.WriteL(KResponseDataSizeOffset, TPckgBuf<TInt>(mData.Length()));//write data size
       
   135     mMsg.WriteL(KResponseIdOffset, TPckgBuf<CBase*>(this));//task identyfier
       
   136 }
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 /**
       
   140  * Returns ETrue if task is related with session argument
       
   141  */
       
   142 TBool CAfObserverTask::IsSessionTask(const CSession2* session)
       
   143 {
       
   144     return mMsg.Session() == session ? ETrue : EFalse;
       
   145 }