photosgallery/collectionframework/thumbnailcreator/inc/glxtntaskmanager.h
changeset 0 4e91876724a2
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     1 /*
       
     2 * Copyright (c) 2008-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:    Task manager for multiple tasks. Allows asynchronosity and 
       
    15 *                tracking/callback for long running tasks.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 /**
       
    23  * @internal reviewed 30/07/2007 by Simon Brooks
       
    24  */
       
    25 
       
    26 #ifndef C_GLXTNTASKMANAGER_H
       
    27 #define C_GLXTNTASKMANAGER_H
       
    28 
       
    29 #include "glxtnstd.h"
       
    30 #include <glxmediaid.h>
       
    31 #include <e32base.h>
       
    32 
       
    33 // Forward declarations
       
    34 class CGlxtnTask;
       
    35 class MGlxtnThumbnailStorage;
       
    36 
       
    37 /**
       
    38  * Active object which maintains a priority queue of long running tasks, and
       
    39  * provides callback upon task completion or error.
       
    40  *
       
    41  * The highest priority task in the queue which has @ref CGlxtnTask::TState "state"
       
    42  * EStarting is started and the task manager's RunL then delegates to the task's
       
    43  * RunL until the task is complete, or is cancelled.  The task is then deleted
       
    44  * and another task is started, if any are ready to start.
       
    45  *
       
    46  * The task manager's DoCancel and RunError methods also delegate to the current
       
    47  * task, if any.
       
    48  *
       
    49  * @ingroup glx_thumbnail_creator
       
    50  */
       
    51 NONSHARABLE_CLASS(CGlxtnTaskManager) : public CActive
       
    52     {
       
    53 public:
       
    54 	enum TExecutionOrder
       
    55 		{
       
    56 		ELastOut,	// Old tasks with the same priority get executed before the new task
       
    57 		EFirstOut	// New task gets executed before other tasks with the same priority
       
    58 		};
       
    59 public:
       
    60     /**
       
    61      * Static constructor.
       
    62      */
       
    63     static CGlxtnTaskManager* NewL();
       
    64     
       
    65     /**
       
    66      * Destructor.
       
    67      */
       
    68     ~CGlxtnTaskManager();
       
    69     
       
    70 public:
       
    71     /**
       
    72      * @returns CVieTask task at an index
       
    73      */
       
    74 
       
    75     inline CGlxtnTask* Task(TInt aIndex) const { return iTasks[aIndex]; };
       
    76 
       
    77      /**
       
    78       * Returns the highest priority task with the id.
       
    79       * If there are multiple tasks with same id and priority, 
       
    80       * returns the one of those that will be executed first 
       
    81       */
       
    82    	CGlxtnTask* Task(const TGlxtnTaskId& aId) const;
       
    83 
       
    84     /**
       
    85      * Adds a task to the task list.  If no task is currently running, the task
       
    86      * is started.
       
    87      *
       
    88      * @param aTask Task to add.  Takes ownership, task is deleted if a leave occurs.
       
    89      *
       
    90      * @param aExecutionOrder -if ELastOut, the tast gets added to the bottom 
       
    91      *					  	  of the queue of the tasks with the same priority 
       
    92      * 					      as the new tasks. This means that the task is 
       
    93      *						  executed after the previously added tasks (with 
       
    94      *						  same priority) have been run.
       
    95      *						  -if EFirstOut, the task gets added to the top,
       
    96      *						  and will be executed before the other tasks
       
    97      *						  with the same priority (unless more tasks added 
       
    98      *						  later, of course)
       
    99      */
       
   100     void AddTaskL(CGlxtnTask* aTask, TExecutionOrder aExecutionOrder = ELastOut);
       
   101 
       
   102     /**
       
   103      * Cancel all tasks relating to a given media item.
       
   104      * @param aItemId ID of media item.
       
   105      */
       
   106     void CancelTasks(const TGlxMediaId& aItemId);
       
   107 
       
   108     /**
       
   109      * Cancel all tasks using a given storage.
       
   110      * @param aClient Reference to thumbnail storage.
       
   111      */
       
   112     void CancelTasks(MGlxtnThumbnailStorage* aStorage);
       
   113 
       
   114     /**
       
   115      * Gets the total task count
       
   116      *
       
   117      * @return TInt task count
       
   118      */
       
   119     inline TInt TaskCount() const { return iTasks.Count(); };
       
   120 
       
   121 protected:
       
   122     /**
       
   123      * Constructors
       
   124      */
       
   125     CGlxtnTaskManager();
       
   126     void ConstructL(); 
       
   127 
       
   128 private: // From CActive
       
   129 	void RunL();		
       
   130 	void DoCancel();
       
   131     TInt RunError(TInt aError);
       
   132 
       
   133 private:
       
   134     /**
       
   135      * Issue a self-completing request causing RunL to be called.
       
   136      */
       
   137     void AsyncRun();
       
   138 
       
   139 private:
       
   140     /**
       
   141      * Task list in priority order
       
   142      */
       
   143     RPointerArray<CGlxtnTask> iTasks;
       
   144     
       
   145     /**
       
   146      * Task that is currently being run.
       
   147      */
       
   148     CGlxtnTask* iCurrentTask;
       
   149     };
       
   150 
       
   151 #endif // C_GLXTNTASKMANAGER_H