activityfw/storage/client/src/afthumbnailrequest_p.cpp
changeset 109 e0aa398e6810
child 119 50e220be30d1
equal deleted inserted replaced
104:9b022b1f357c 109:e0aa398e6810
       
     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 <fbs.h>
       
    19 
       
    20 #include "afthumbnailrequest_p.h"
       
    21 #include "afstorageclient_p.h"
       
    22 #include "afstorageclient.h"
       
    23 #include "afentry.h"
       
    24 #include "afcmd.h"
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 /**
       
    28  * Create and initialize handler for activity thumbnail request
       
    29  * @param observer - request completion observer
       
    30  * @param session - activity client implementation
       
    31  * @param source - thumbnail source location
       
    32  * @param userData - rsponse user data
       
    33  */
       
    34 void CAfThumbnailRequestPrivate::NewLD(MAfAsyncRequestObserver &observer, 
       
    35                                        MAfAsyncSession & session,
       
    36                                        TSize resolution, 
       
    37                                        const TDesC& source,
       
    38                                        TAny* userData)
       
    39 {
       
    40     CAfThumbnailRequestPrivate* self = new(ELeave)CAfThumbnailRequestPrivate(observer, session, userData);
       
    41     CleanupStack::PushL(self);
       
    42     self->ConstructL(resolution, source);
       
    43     session.PushL(self);
       
    44     CleanupStack::Pop(self);
       
    45 }
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 /**
       
    49  * Constructor
       
    50  * @param observer - request completion observer
       
    51  * @param session - activity client implementation
       
    52  * @param userData - rsponse user data
       
    53  */
       
    54 CAfThumbnailRequestPrivate::CAfThumbnailRequestPrivate(MAfAsyncRequestObserver & observer, 
       
    55                                                        MAfAsyncSession & session,
       
    56                                                        TAny* userData)
       
    57 :
       
    58 CActive(EPriorityStandard),
       
    59 mObserver(observer),
       
    60 mSession(session),
       
    61 mUserData(userData)
       
    62 {
       
    63     CActiveScheduler::Add(this);
       
    64 }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 /**
       
    68  * Second phase constructor
       
    69  * @param resolution - requested thumbnail resolution
       
    70  * @param source - thumbnail source location
       
    71  */
       
    72 void CAfThumbnailRequestPrivate::ConstructL(TSize resolution, const TDesC& source)
       
    73 {
       
    74     mIds[0] = resolution.iWidth;
       
    75     mIds[1] = resolution.iHeight;
       
    76     CAfEntry::CopyL(mImgSrc, source);
       
    77     mSession.sendAsync(GetThumbnail, 
       
    78                        TIpcArgs(&mIds[0],&mIds[1], &mImgSrc),
       
    79                        iStatus);
       
    80     SetActive();
       
    81 }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 /**
       
    85  * Destuctor
       
    86  */
       
    87 CAfThumbnailRequestPrivate::~CAfThumbnailRequestPrivate()
       
    88 {
       
    89     Cancel();
       
    90     mImgSrc.Close();
       
    91 }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 /**
       
    95  * Cancel pending requst
       
    96  */
       
    97 void CAfThumbnailRequestPrivate::DoCancel()
       
    98 {
       
    99 }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 /**
       
   103  * Function handle request completion, copy data, forward information and destroy handler 
       
   104  */
       
   105 void CAfThumbnailRequestPrivate::RunL()
       
   106 {
       
   107     User::LeaveIfError(iStatus.Int());
       
   108     mObserver.getThumbnailRequestCompleted(iStatus.Int(), 
       
   109                                            mIds[0](), 
       
   110                                            mUserData);
       
   111     RBuf8 data;                                        
       
   112     CleanupClosePushL(data);
       
   113     mSession.getDataL((mIds[1])(), data);
       
   114     CleanupStack::PopAndDestroy(&data);
       
   115     mSession.Pop(this);
       
   116     delete this;
       
   117 }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 /**
       
   121  * Function handle request processing errors
       
   122  * @param error - error code 
       
   123  */
       
   124 TInt CAfThumbnailRequestPrivate::RunError(TInt error)
       
   125 {
       
   126     mObserver.getThumbnailRequestCompleted(error, -1, mUserData);
       
   127     mSession.Pop(this);
       
   128     delete this;
       
   129     return KErrNone;
       
   130 }
       
   131