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