activityfw/storage/client/s60/src/afasyncrequest_p.cpp
changeset 104 9b022b1f357c
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 
       
    18 #include "afasyncrequest_p.h"
       
    19 #include "afstorageclient_p.h"
       
    20 #include "afstorageclient.h"
       
    21 #include "afentry.h"
       
    22 #include <fbs.h>
       
    23 #include <XQConversions>
       
    24 
       
    25 // -----------------------------------------------------------------------------
       
    26 /**
       
    27  * Create and initialize handler for anyc. activity requests
       
    28  * @param observer - request completion observer
       
    29  * @param session - activity client implementation
       
    30  * @param cmd - requested functionality
       
    31  */
       
    32 void CAfAsyncRequestPrivate::NewLD(MAfAsyncRequestObserver &observer, 
       
    33                                    RAfStorageClientImplementation & session,
       
    34                                    ActivityCmd cmd)
       
    35 {
       
    36     CAfAsyncRequestPrivate* self = new(ELeave)CAfAsyncRequestPrivate(observer, session, cmd);
       
    37     CleanupStack::PushL(self);
       
    38     self->ConstructL();
       
    39     session.PushL(self);
       
    40     CleanupStack::Pop(self);
       
    41 }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 /**
       
    45  * First phase construction
       
    46  * @param observer - request completion observer
       
    47  * @param session - activity client implementation
       
    48  * @param cmd - requested functionality
       
    49  */
       
    50 CAfAsyncRequestPrivate::CAfAsyncRequestPrivate(MAfAsyncRequestObserver & observer, 
       
    51                                                RAfStorageClientImplementation & session,
       
    52                                                ActivityCmd cmd)
       
    53 :
       
    54 CActive(EPriorityStandard),
       
    55 mObserver(observer),
       
    56 mSession(session),
       
    57 mCmd(cmd)
       
    58 {
       
    59     CActiveScheduler::Add(this);
       
    60     RProcess process;
       
    61     mIds[0] = static_cast<TInt>(process.SecureId().iId);
       
    62 }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 /**
       
    66  * Second phase construction
       
    67  */
       
    68 void CAfAsyncRequestPrivate::ConstructL()
       
    69 {
       
    70     mSession.sendAsync(mCmd, 
       
    71                        TIpcArgs(&mIds[0],&mIds[1], &mIds[2], &mIds[3]),
       
    72                        iStatus);
       
    73     SetActive();
       
    74 }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 /**
       
    78  * Destructor
       
    79  */
       
    80 CAfAsyncRequestPrivate::~CAfAsyncRequestPrivate()
       
    81 {
       
    82     Cancel();
       
    83 }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 /**
       
    87  * Cancel pending requst
       
    88  */
       
    89 void CAfAsyncRequestPrivate::DoCancel()
       
    90 {
       
    91     TRAP_IGNORE(
       
    92     switch (mCmd) {
       
    93     case WaitActivity: mSession.executeL(CancelWait); break;
       
    94     case NotifyChange: mSession.executeL(CancelNotify); break;
       
    95     }
       
    96     )
       
    97 }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 /**
       
   101  * Function handle request completion, copy data, forward information and destroy handler 
       
   102  */
       
   103 void CAfAsyncRequestPrivate::RunL()
       
   104 {
       
   105     User::LeaveIfError(iStatus.Int());
       
   106     switch (mCmd) {
       
   107     case WaitActivity:
       
   108         {
       
   109         RBuf8 data;
       
   110         CleanupClosePushL(data);
       
   111         CAfEntry::ReallocL(data, (mIds[0])());
       
   112         mSession.getDataL((mIds[3])(), data);
       
   113         mObserver.asyncRequestCompleated(iStatus.Int(), mCmd, XQConversions::s60Desc8ToQString(data));
       
   114         CleanupStack::PopAndDestroy(&data);
       
   115         break;
       
   116         }
       
   117     case NotifyChange:
       
   118         mObserver.asyncRequestCompleated(iStatus.Int(), mCmd);
       
   119         break;
       
   120     }
       
   121     mSession.Pop(this);
       
   122     delete this;
       
   123 }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 /**
       
   127  * Function handle request processing errors
       
   128  * @param error - error code 
       
   129  */
       
   130 TInt CAfAsyncRequestPrivate::RunError(TInt error)
       
   131 {
       
   132     (WaitActivity == mCmd) ? mObserver.asyncRequestCompleated(error, mCmd, QString::null) :
       
   133                              mObserver.asyncRequestCompleated(error, mCmd);
       
   134     mSession.Pop(this);
       
   135     delete this;
       
   136     return KErrNone;
       
   137 }
       
   138 
       
   139