imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnaildecodetask.cpp
changeset 54 48dd0f169f0d
parent 42 2e2a89493e2b
equal deleted inserted replaced
42:2e2a89493e2b 54:48dd0f169f0d
     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 #include "OstTraceDefinitions.h"
       
    30 #ifdef OST_TRACE_COMPILER_IN_USE
       
    31 #include "thumbnaildecodetaskTraces.h"
       
    32 #endif
       
    33 
       
    34 
       
    35 
       
    36 // ======== MEMBER FUNCTIONS ========
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // CThumbnailDecodeTask::CThumbnailDecodeTask()
       
    40 // C++ default constructor can NOT contain any code, that might leave.
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 CThumbnailDecodeTask::CThumbnailDecodeTask( CThumbnailTaskProcessor& aProcessor, 
       
    44         CThumbnailServer& aServer, TDesC8* aBuffer, TInt aPriority, TDisplayMode aDisplayMode): CThumbnailTask( aProcessor,
       
    45     aPriority ), iServer( aServer ), iBuffer(aBuffer), iDisplayMode(aDisplayMode)
       
    46     {
       
    47     TN_DEBUG3( "CThumbnailDecodeTask(0x%08x)::CThumbnailDecodeTask() aDisplayMode = %d", this
       
    48         , iDisplayMode);
       
    49     OstTrace1( TRACE_NORMAL, CTHUMBNAILDECODETASK_CTHUMBNAILDECODETASK, "CThumbnailDecodeTask::CThumbnailDecodeTask;iDisplayMode=%u", iDisplayMode );
       
    50     OstTrace1( TRACE_NORMAL, DUP1_CTHUMBNAILDECODETASK_CTHUMBNAILDECODETASK, "CThumbnailDecodeTask::CThumbnailDecodeTask;this=%o", this );
       
    51     }
       
    52 
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // CThumbnailDecodeTask::~CThumbnailDecodeTask()
       
    56 // Destructor.
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 CThumbnailDecodeTask::~CThumbnailDecodeTask()
       
    60     {
       
    61     TN_DEBUG2( "CThumbnailDecodeTask(0x%08x)::~CThumbnailDecodeTask()", this );
       
    62     OstTrace0( TRACE_NORMAL, DUP2_CTHUMBNAILDECODETASK_CTHUMBNAILDECODETASK, "CThumbnailDecodeTask::~CThumbnailDecodeTask" );
       
    63     
       
    64     if ( iProvider )
       
    65         {
       
    66         iProvider->CancelGetThumbnail();
       
    67         } 
       
    68     
       
    69     iProvider = NULL;
       
    70     delete iBuffer;
       
    71     iBuffer = NULL;
       
    72     }
       
    73 
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // CThumbnailDecodeTask::StartL()
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 void CThumbnailDecodeTask::StartL()
       
    80     {
       
    81     TN_DEBUG2( "CThumbnailDecodeTask(0x%08x)::StartL()", this );
       
    82     OstTrace1( TRACE_NORMAL, CTHUMBNAILDECODETASK_STARTL, "CThumbnailDecodeTask::StartL;this=%o", this );
       
    83 
       
    84     CThumbnailTask::StartL();
       
    85 
       
    86     const TPtrC8 mimeType = KJpegMime();
       
    87 
       
    88     iProvider = iServer.ResolveProviderL( mimeType );
       
    89     TN_DEBUG3( "CThumbnailDecodeTask(0x%08x) -- provider UID 0x%08x", this,
       
    90         iProvider->Uid());
       
    91     OstTrace1( TRACE_NORMAL, DUP1_CTHUMBNAILDECODETASK_STARTL, "CThumbnailDecodeTask::StartL;this=%o", this );
       
    92 
       
    93     __ASSERT_DEBUG(( iProvider ), ThumbnailPanic( EThumbnailNullPointer ));
       
    94 
       
    95     iProvider->CancelGetThumbnail();
       
    96     iProvider->Reset();
       
    97     iProvider->SetObserver( *this );
       
    98 
       
    99     iProvider->GetThumbnailL( iServer.Fs(), *iBuffer );
       
   100     }
       
   101 
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // CThumbnailDecodeTask::RunL()
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 void CThumbnailDecodeTask::RunL()
       
   108     {
       
   109     // No implementation required
       
   110     TN_DEBUG2( "CThumbnailDecodeTask(0x%08x)::RunL()", this );
       
   111     OstTrace1( TRACE_NORMAL, CTHUMBNAILDECODETASK_RUNL, "CThumbnailDecodeTask::RunL;this=%o", this );
       
   112     }
       
   113 
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // CThumbnailDecodeTask::DoCancel()
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 void CThumbnailDecodeTask::DoCancel()
       
   120     {
       
   121     TN_DEBUG2( "CThumbnailDecodeTask(0x%08x)::DoCancel()", this );
       
   122     OstTrace1( TRACE_NORMAL, CTHUMBNAILDECODETASK_DOCANCEL, "CThumbnailDecodeTask::DoCancel;this=%o", this );
       
   123     if ( iProvider )
       
   124         {
       
   125         iProvider->CancelGetThumbnail();
       
   126         }
       
   127     }
       
   128 
       
   129 
       
   130 //
       
   131 // ---------------------------------------------------------------------------
       
   132 // Thumbnail provider observer callback to notify the server when
       
   133 // thumbnail has been generated.
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 void CThumbnailDecodeTask::ThumbnailProviderReady( const TInt aError,
       
   137     CFbsBitmap* aBitmap, const TSize& aOriginalSize, const TBool /*aEXIF*/, const TBool /*aPortrait*/ )
       
   138     {
       
   139     TN_DEBUG4( "CThumbnailDecodeTask(0x%08x)::ThumbnailProviderReady(aError=%d, aBitmap=0x%08x)", 
       
   140                this, aError, aBitmap );
       
   141     OstTrace1( TRACE_NORMAL, CTHUMBNAILDECODETASK_THUMBNAILPROVIDERREADY, "CThumbnailDecodeTask::ThumbnailProviderReady;this=%o", this );
       
   142     OstTrace1( TRACE_NORMAL, DUP1_CTHUMBNAILDECODETASK_THUMBNAILPROVIDERREADY, "CThumbnailDecodeTask::ThumbnailProviderReady;aError=%d", aError );
       
   143     OstTrace1( TRACE_NORMAL, DUP2_CTHUMBNAILDECODETASK_THUMBNAILPROVIDERREADY, "CThumbnailDecodeTask::ThumbnailProviderReady;aBitmap=%o", aBitmap );
       
   144 
       
   145     iOriginalSize = aOriginalSize;
       
   146 
       
   147     if ( aError )
       
   148         {
       
   149         delete aBitmap;
       
   150         aBitmap = NULL;
       
   151         Complete( aError );
       
   152         return;
       
   153         }
       
   154     
       
   155     if( !aBitmap )
       
   156         {
       
   157         Complete( KErrGeneral );
       
   158         return;
       
   159         }
       
   160       
       
   161     if ( ClientThreadAlive() )
       
   162        {
       
   163        // pass bitmap handle to client
       
   164        TThumbnailRequestParams& params = iParamsBuf();
       
   165        TInt ret = iMessage.Read( 0, iParamsBuf );
       
   166        
       
   167        if(ret == KErrNone )
       
   168            {
       
   169            params.iBitmapHandle = aBitmap->Handle();
       
   170            ret = iMessage.Write( 0, iParamsBuf );
       
   171            }
       
   172        
       
   173        // add bitmap to pool
       
   174        TRAPD(err, iServer.AddBitmapToPoolL( iRequestId.iSession, aBitmap, iRequestId ) );
       
   175        if (err != KErrNone)
       
   176            {
       
   177            Complete( err );
       
   178            delete aBitmap;
       
   179            aBitmap = NULL;
       
   180            }
       
   181        else
       
   182            {
       
   183            aBitmap = NULL; // Server owns the bitmap now
       
   184        
       
   185            // Complete message
       
   186            Complete( ret );
       
   187            ResetMessageData();
       
   188            }
       
   189        }
       
   190     else
       
   191         {
       
   192         delete aBitmap;
       
   193         aBitmap = NULL;
       
   194         }
       
   195     }
       
   196