imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailmdsquerytask.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 making MDS querys
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h>
       
    20 
       
    21 #include <mdeconstants.h>
       
    22 #include <thumbnailmanager.h>
       
    23 
       
    24 #include "thumbnailmdsquerytask.h"
       
    25 #include "thumbnailmanagerconstants.h"
       
    26 #include "thumbnaillog.h"
       
    27 #include "thumbnailserver.h"
       
    28 #include "OstTraceDefinitions.h"
       
    29 #ifdef OST_TRACE_COMPILER_IN_USE
       
    30 #include "thumbnailmdsquerytaskTraces.h"
       
    31 #endif
       
    32 
       
    33 
       
    34 // ======== MEMBER FUNCTIONS ========
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // CThumbnailMDSQueryTask::CThumbnailMDSQueryTask()
       
    38 // C++ default constructor can NOT contain any code, that might leave.
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 CThumbnailMDSQueryTask::CThumbnailMDSQueryTask(
       
    42         CThumbnailTaskProcessor& aProcessor, TInt aPriority, CMdESession* aMdESession, CThumbnailServer& aServer): 
       
    43         CThumbnailTask( aProcessor, aPriority ), iMdESession( aMdESession ), iQuery(NULL), 
       
    44 		iServer(aServer), iUpdateToDb(ETrue)
       
    45     {
       
    46     TN_DEBUG2( "CThumbnailMDSQueryTask(0x%08x)::CThumbnailMDSQueryTask()", this );
       
    47     OstTrace1( TRACE_NORMAL, CTHUMBNAILMDSQUERYTASK_CTHUMBNAILMDSQUERYTASK, "CThumbnailMDSQueryTask::CThumbnailMDSQueryTask;this=%o", this );
       
    48     }
       
    49 
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // CThumbnailMDSQueryTask::~CThumbnailMDSQueryTask()
       
    53 // Destructor.
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CThumbnailMDSQueryTask::~CThumbnailMDSQueryTask()
       
    57     {
       
    58     TN_DEBUG2( "CThumbnailMDSQueryTask(0x%08x)::~CThumbnailMDSQueryTask()", this);
       
    59     OstTrace1( TRACE_NORMAL, DUP1_CTHUMBNAILMDSQUERYTASK_CTHUMBNAILMDSQUERYTASK, "CThumbnailMDSQueryTask::~CThumbnailMDSQueryTask;this=%o", this );
       
    60            
       
    61     if (iQuery)
       
    62         {
       
    63         iQuery->Cancel();
       
    64         delete iQuery;
       
    65         iQuery = NULL;
       
    66         }
       
    67     }
       
    68 
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CThumbnailMDSQueryTask::HandleQueryNewResults()
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 void CThumbnailMDSQueryTask::HandleQueryNewResults( CMdEQuery& /*aQuery*/,
       
    75                                                const TInt /*aFirstNewItemIndex*/,
       
    76                                                const TInt /*aNewItemCount*/ )
       
    77     {
       
    78     // No implementation required
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CThumbnailMDSQueryTask::HandleQueryCompleted()
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 void CThumbnailMDSQueryTask::HandleQueryCompleted( CMdEQuery& /*aQuery*/, const TInt aError )
       
    86     {
       
    87     TN_DEBUG3( "CThumbnailMDSQueryTask::HandleQueryCompleted(0x%08x), aError == %d", this, aError );
       
    88     OstTrace1( TRACE_NORMAL, CTHUMBNAILMDSQUERYTASK_HANDLEQUERYCOMPLETED, "CThumbnailMDSQueryTask::HandleQueryCompleted;this=%o", this );
       
    89     OstTrace1( TRACE_NORMAL, DUP1_CTHUMBNAILMDSQUERYTASK_HANDLEQUERYCOMPLETED, "CThumbnailMDSQueryTask::HandleQueryCompleted;aError=%d", aError );
       
    90     
       
    91     
       
    92     // if no errors in query
       
    93     if (aError == KErrNone && iQuery && iQuery->Count() > 0)
       
    94         {
       
    95         if( iQueryType == EURI )
       
    96             {
       
    97             const CMdEObject* object = &iQuery->Result(0);
       
    98             
       
    99             TN_DEBUG2( "CThumbnailMDSQueryTask::HandleQueryCompleted() - URI = %S", &object->Uri() );
       
   100             OstTraceExt1( TRACE_NORMAL, DUP2_CTHUMBNAILMDSQUERYTASK_HANDLEQUERYCOMPLETED, "CThumbnailMDSQueryTask::HandleQueryCompleted;object->Uri()=%S", object->Uri() );
       
   101                             
       
   102             // return path to client side       
       
   103             if( iDelete )
       
   104                 {
       
   105                 TN_DEBUG2( "CThumbnailMDSQueryTask::HandleQueryCompleted() delete %S", &iUri );
       
   106                 OstTraceExt1( TRACE_NORMAL, DUP3_CTHUMBNAILMDSQUERYTASK_HANDLEQUERYCOMPLETED, "CThumbnailMDSQueryTask::HandleQueryCompleted - delete;iUri()=%S", iUri );
       
   107                 TRAP_IGNORE( iServer.DeleteThumbnailsL( iUri ) );
       
   108                 }
       
   109             else
       
   110                 {
       
   111                 ReturnPath(object->Uri());
       
   112                 }
       
   113             }
       
   114         else
       
   115             {
       
   116             TN_DEBUG1( "CThumbnailMDSQueryTask::HandleQueryCompleted() - Don't ever come here!" );
       
   117             OstTrace0( TRACE_NORMAL, DUP4_CTHUMBNAILMDSQUERYTASK_HANDLEQUERYCOMPLETED, "CThumbnailMDSQueryTask::HandleQueryCompleted - Don't ever come here!" );
       
   118             if (ClientThreadAlive())
       
   119                 {  
       
   120                 Complete( KErrNotFound );
       
   121                 ResetMessageData();
       
   122                 }
       
   123             __ASSERT_DEBUG((EFalse), User::Panic(_L("CThumbnailMDSQueryTask::HandleQueryCompleted()"), KErrNotSupported));
       
   124             }
       
   125         }
       
   126     else
       
   127         {
       
   128         TN_DEBUG1( "CThumbnailMDSQueryTask::HandleQueryCompleted() - No results." );
       
   129         OstTrace0( TRACE_NORMAL, DUP5_CTHUMBNAILMDSQUERYTASK_HANDLEQUERYCOMPLETED, "CThumbnailMDSQueryTask::HandleQueryCompleted - No results." );
       
   130         if(!iDelete)
       
   131             {
       
   132             if (ClientThreadAlive())
       
   133                 {  
       
   134                 Complete( KErrNotFound );
       
   135                 ResetMessageData();
       
   136                 }
       
   137             }
       
   138         }
       
   139    }
       
   140 
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // CThumbnailMDSQueryTask::StartL()
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 void CThumbnailMDSQueryTask::StartL()
       
   147     {
       
   148     TN_DEBUG2( "CThumbnailMDSQueryTask(0x%08x)::StartL()", this );
       
   149     OstTrace1( TRACE_NORMAL, CTHUMBNAILMDSQUERYTASK_STARTL, "CThumbnailMDSQueryTask::StartL;this=%o", this );
       
   150 
       
   151     CThumbnailTask::StartL();
       
   152     
       
   153     if (iMessage.Handle())
       
   154         {
       
   155         // start query
       
   156         iQuery->FindL();
       
   157         }
       
   158     else
       
   159         {
       
   160         // no point to continue
       
   161         Complete( KErrCancel );
       
   162         ResetMessageData();
       
   163         }
       
   164     }
       
   165 
       
   166 
       
   167 // ---------------------------------------------------------------------------
       
   168 // CThumbnailMDSQueryTask::RunL()
       
   169 // ---------------------------------------------------------------------------
       
   170 //
       
   171 void CThumbnailMDSQueryTask::RunL()
       
   172     {
       
   173     // No implementation required
       
   174     TN_DEBUG2( "CThumbnailMDSQueryTask(0x%08x)::RunL()", this );
       
   175     OstTrace1( TRACE_NORMAL, CTHUMBNAILMDSQUERYTASK_RUNL, "CThumbnailMDSQueryTask::RunL;this=%o", this );
       
   176     }
       
   177 
       
   178 
       
   179 // ---------------------------------------------------------------------------
       
   180 // CThumbnailMDSQueryTask::DoCancel()
       
   181 // ---------------------------------------------------------------------------
       
   182 //
       
   183 void CThumbnailMDSQueryTask::DoCancel()
       
   184     {
       
   185     TN_DEBUG2( "CThumbnailMDSQueryTask(0x%08x)::DoCancel()", this );
       
   186     OstTrace1( TRACE_NORMAL, CTHUMBNAILMDSQUERYTASK_DOCANCEL, "CThumbnailMDSQueryTask::DoCancel;this=%o", this );
       
   187     
       
   188     iQuery->Cancel();
       
   189     }
       
   190 
       
   191 // ---------------------------------------------------------------------------
       
   192 // CThumbnailMDSQueryTask::QueryPathByIdL()
       
   193 // ---------------------------------------------------------------------------
       
   194 //
       
   195 void CThumbnailMDSQueryTask::QueryPathByIdL(TThumbnailId aId, TBool aDelete)
       
   196     {
       
   197     TN_DEBUG1( "CThumbnailMDSQueryTask()::QueryPathByIdL()");
       
   198     OstTrace0( TRACE_NORMAL, CTHUMBNAILMDSQUERYTASK_QUERYPATHBYIDL, "CThumbnailMDSQueryTask::QueryPathByIdL" );
       
   199     iQueryType = EURI;
       
   200     iDelete = aDelete;
       
   201     CMdENamespaceDef* defNamespace = &iMdESession->GetDefaultNamespaceDefL();
       
   202     CMdEObjectDef& objDef = defNamespace->GetObjectDefL( MdeConstants::Object::KBaseObject );
       
   203     
       
   204     delete iQuery;
       
   205     iQuery = NULL;
       
   206     
       
   207     iQuery = iMdESession->NewObjectQueryL( *defNamespace, objDef, this );
       
   208 	
       
   209 	if(iQuery)
       
   210 		{
       
   211 	    iQuery->SetResultMode( EQueryResultModeItem );
       
   212 
       
   213     	CMdELogicCondition& rootCondition = iQuery->Conditions();
       
   214 	    rootCondition.SetOperator( ELogicConditionOperatorOr );
       
   215     
       
   216 	    // add ID condition
       
   217     	rootCondition.AddObjectConditionL( aId );
       
   218 		}
       
   219     }
       
   220 
       
   221 // ---------------------------------------------------------------------------
       
   222 // CThumbnailMDSQueryTask::ReturnPath()
       
   223 // ---------------------------------------------------------------------------
       
   224 //
       
   225 void CThumbnailMDSQueryTask::ReturnPath(const TDesC& aUri)
       
   226     {
       
   227     if ( ClientThreadAlive() )
       
   228         {
       
   229         // add path to message
       
   230         TInt ret = iMessage.Read( 0, iRequestParams );      
       
   231         if(ret == KErrNone)
       
   232             {
       
   233             TThumbnailRequestParams& params = iRequestParams();
       
   234             params.iFileName = aUri;
       
   235             ret = iMessage.Write( 0, iRequestParams );
       
   236             }
       
   237             
       
   238         // complete the message with a code from which client side
       
   239         // knows to make a new request using the path
       
   240         Complete( KThumbnailErrThumbnailNotFound );
       
   241         ResetMessageData();
       
   242         }
       
   243     }
       
   244 
       
   245 // ---------------------------------------------------------------------------
       
   246 // CThumbnailMDSQueryTask::SetUpdateToDb()
       
   247 // ---------------------------------------------------------------------------
       
   248 //
       
   249 void CThumbnailMDSQueryTask::SetUpdateToDb(const TBool& aUpdateToDb )
       
   250     {
       
   251     TN_DEBUG2( "CThumbnailMDSQueryTask()::SetCompleteTask() aUpdateToDb == %d", aUpdateToDb);
       
   252     OstTrace1( TRACE_NORMAL, CTHUMBNAILMDSQUERYTASK_SETUPDATETODB, "CThumbnailMDSQueryTask::SetUpdateToDb;aUpdateToDb=%u", aUpdateToDb );
       
   253     iUpdateToDb = aUpdateToDb;
       
   254     }