imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnaildecodetask.cpp
changeset 0 2014ca87e772
child 5 82749d516180
equal deleted inserted replaced
-1:000000000000 0:2014ca87e772
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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:  Task for generating new thumbnails
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <fbs.h>
       
    21 
       
    22 #include <thumbnailmanager.h>
       
    23 
       
    24 #include "thumbnaildecodetask.h"
       
    25 #include "thumbnailprovider.h"
       
    26 #include "thumbnailserver.h"
       
    27 #include "thumbnaillog.h"
       
    28 #include "thumbnailpanic.h"
       
    29 
       
    30 
       
    31 // ======== MEMBER FUNCTIONS ========
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // CThumbnailDecodeTask::CThumbnailDecodeTask()
       
    35 // C++ default constructor can NOT contain any code, that might leave.
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 CThumbnailDecodeTask::CThumbnailDecodeTask( CThumbnailTaskProcessor& aProcessor, 
       
    39         CThumbnailServer& aServer, TDesC8* aBuffer, TInt aPriority, TDisplayMode aDisplayMode): CThumbnailTask( aProcessor,
       
    40     aPriority ), iServer( aServer ), iBuffer(aBuffer), iDisplayMode(aDisplayMode)
       
    41     {
       
    42     TN_DEBUG3( "CThumbnailDecodeTask(0x%08x)::CThumbnailDecodeTask() aDisplayMode = %d", this
       
    43         , iDisplayMode);
       
    44     }
       
    45 
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // CThumbnailDecodeTask::~CThumbnailDecodeTask()
       
    49 // Destructor.
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 CThumbnailDecodeTask::~CThumbnailDecodeTask()
       
    53     {
       
    54     if ( iProvider )
       
    55         {
       
    56         iProvider->CancelGetThumbnail();
       
    57         } 
       
    58     
       
    59     iProvider = NULL;
       
    60     delete iBuffer;
       
    61     iBuffer = NULL;
       
    62     }
       
    63 
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // CThumbnailDecodeTask::StartL()
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 void CThumbnailDecodeTask::StartL()
       
    70     {
       
    71     TN_DEBUG2( "CThumbnailDecodeTask(0x%08x)::StartL()", this );
       
    72 
       
    73     CThumbnailTask::StartL();
       
    74 
       
    75     const TPtrC8 mimeType = KJpegMime();
       
    76 
       
    77     iProvider = iServer.ResolveProviderL( mimeType );
       
    78     TN_DEBUG3( "CThumbnailDecodeTask(0x%08x) -- provider UID 0x%08x", this,
       
    79         iProvider->Uid());
       
    80 
       
    81     __ASSERT_DEBUG(( iProvider ), ThumbnailPanic( EThumbnailNullPointer ));
       
    82 
       
    83     iProvider->CancelGetThumbnail();
       
    84     iProvider->Reset();
       
    85     iProvider->SetObserver( *this );
       
    86 
       
    87     iProvider->GetThumbnailL( iServer.Fs(), *iBuffer );
       
    88     }
       
    89 
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // CThumbnailDecodeTask::RunL()
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 void CThumbnailDecodeTask::RunL()
       
    96     {
       
    97     // No implementation required
       
    98     TN_DEBUG2( "CThumbnailDecodeTask(0x%08x)::RunL()", this );
       
    99     }
       
   100 
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // CThumbnailDecodeTask::DoCancel()
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 void CThumbnailDecodeTask::DoCancel()
       
   107     {
       
   108     TN_DEBUG2( "CThumbnailDecodeTask(0x%08x)::DoCancel()", this );
       
   109     if ( iProvider )
       
   110         {
       
   111         iProvider->CancelGetThumbnail();
       
   112         }
       
   113     }
       
   114 
       
   115 
       
   116 //
       
   117 // ---------------------------------------------------------------------------
       
   118 // Thumbnail provider observer callback to notify the server when
       
   119 // thumbnail has been generated.
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 void CThumbnailDecodeTask::ThumbnailProviderReady( const TInt aError,
       
   123     CFbsBitmap* aBitmap, const TSize& aOriginalSize, const TBool /*aEXIF*/, const TBool /*aPortrait*/ )
       
   124     {
       
   125     TN_DEBUG4( "CThumbnailDecodeTask(0x%08x)::ThumbnailProviderReady(aError=%d, aBitmap=0x%08x)", 
       
   126                this, aError, aBitmap );
       
   127 
       
   128     iOriginalSize = aOriginalSize;
       
   129 
       
   130     if ( aError )
       
   131         {
       
   132         delete aBitmap;
       
   133         aBitmap = NULL;
       
   134         Complete( aError );
       
   135         return;
       
   136         }
       
   137     
       
   138     if( !aBitmap )
       
   139         {
       
   140         Complete( KErrGeneral );
       
   141         return;
       
   142         }
       
   143       
       
   144     if ( iMessage.Handle())
       
   145        {
       
   146        TRAP_IGNORE(iServer.AddBitmapToPoolL( iRequestId.iSession, aBitmap ));
       
   147        const TSize bitmapSize = aBitmap->SizeInPixels();
       
   148        iBitmapHandle = aBitmap->Handle();
       
   149        aBitmap = NULL;
       
   150        
       
   151        // Complete message and pass bitmap handle to client
       
   152        TThumbnailRequestParams& params = iParamsBuf();
       
   153        TInt ret = iMessage.Read( 0, iParamsBuf );
       
   154        
       
   155        if(ret == KErrNone )
       
   156            {
       
   157            params.iBitmapHandle = iBitmapHandle;
       
   158            ret = iMessage.Write( 0, iParamsBuf );
       
   159            }
       
   160        
       
   161        Complete( ret );
       
   162        ResetMessageData();
       
   163 
       
   164        // Successfully completed the message. The client will send
       
   165        // EReleaseBitmap message later to delete the bitmap from pool.
       
   166        // CThumbnailScaleTask is no longer responsible for that.
       
   167        iBitmapHandle = 0;
       
   168        }
       
   169     else
       
   170         {
       
   171         delete aBitmap;
       
   172         aBitmap = NULL;
       
   173         }
       
   174     }
       
   175