|
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: Base classes for multi-purpose tasks. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 /** |
|
22 * @internal reviewed 30/07/2007 by Simon Brooks |
|
23 */ |
|
24 |
|
25 #ifndef C_GLXTNTASK_H |
|
26 #define C_GLXTNTASK_H |
|
27 |
|
28 #include "glxtnstd.h" |
|
29 #include <glxmediaid.h> |
|
30 #include <e32base.h> |
|
31 |
|
32 // Forward declarations |
|
33 class CGlxtnTaskManager; |
|
34 class MGlxtnThumbnailCreatorClient; |
|
35 class MGlxtnThumbnailStorage; |
|
36 |
|
37 /** |
|
38 * Base class for thumbnail tasks. |
|
39 * |
|
40 * @ingroup glx_thumbnail_creator |
|
41 */ |
|
42 NONSHARABLE_CLASS(CGlxtnTask) : public CBase |
|
43 { |
|
44 friend class CGlxtnTaskManager; |
|
45 public: |
|
46 /** |
|
47 * Different state a task can go through |
|
48 */ |
|
49 enum TState |
|
50 { |
|
51 EIdle, /**< Task is not ready to start */ |
|
52 EStarting, /**< Task is ready to start */ |
|
53 ERunning, /**< Task is currently running */ |
|
54 ECanceled, /**< Task has been cancelled, and can be deleted */ |
|
55 EComplete /**< Task has finished, and can be deleted */ |
|
56 }; |
|
57 |
|
58 public: |
|
59 CGlxtnTask(const TGlxtnTaskId& aId, const TGlxMediaId& aItemId, |
|
60 MGlxtnThumbnailStorage* aStorage); |
|
61 ~CGlxtnTask(); |
|
62 |
|
63 /** |
|
64 * Gets the current task specific state |
|
65 * @returns TState The task current state. |
|
66 */ |
|
67 inline TState State() const; |
|
68 |
|
69 /** |
|
70 * Gets the type of task this is. |
|
71 * @returns TGlxtnTaskId Task type ID. |
|
72 */ |
|
73 inline TGlxtnTaskId Id() const; |
|
74 |
|
75 /** |
|
76 * Gets the media ID of the item to which this task relates. |
|
77 * @returns TGlxMediaId Media ID. |
|
78 */ |
|
79 inline TGlxMediaId ItemId() const; |
|
80 |
|
81 /** |
|
82 * Sets the priority of the task. By default it is set to |
|
83 * EPriorityStandard. |
|
84 */ |
|
85 inline void SetPriority(TInt aPriority); |
|
86 /** |
|
87 * Gets the task priority. |
|
88 * @returns TInt Task priority. |
|
89 */ |
|
90 inline TInt Priority() const; |
|
91 |
|
92 /** |
|
93 * Get thumbnail storage for the task to use, if any. |
|
94 * @returns Pointer to thumbnail storage, or NULL if none. |
|
95 */ |
|
96 inline MGlxtnThumbnailStorage* Storage() const; |
|
97 |
|
98 /** |
|
99 * Provides a pointer to the task manager. |
|
100 * @param aManager Pointer to the task manager. |
|
101 */ |
|
102 virtual void SetManager(CGlxtnTaskManager* aManager); |
|
103 |
|
104 private: // For CGlxTaskManager only |
|
105 /** |
|
106 * Starts the task |
|
107 */ |
|
108 void StartL(TRequestStatus& aStatus); |
|
109 |
|
110 /** |
|
111 * Cancels the task |
|
112 */ |
|
113 void Cancel(); |
|
114 |
|
115 /** |
|
116 * Runs a bit of the task |
|
117 */ |
|
118 void RunL(TRequestStatus& aStatus); |
|
119 |
|
120 /** |
|
121 * Handle a leave in StartL or RunL. |
|
122 */ |
|
123 void RunError(TInt aError); |
|
124 |
|
125 protected: |
|
126 /** |
|
127 * Starts the task. |
|
128 * @param aStatus Request status for asynchronous operations |
|
129 * @returns -ETrue if the task has issued an asyncronous request. |
|
130 * CActive::SetActive() will be called in this case and the |
|
131 * task state will be ERunning. |
|
132 * -EFalse if the task has not issued a request. |
|
133 * SetActive will not be called and the task state will be |
|
134 * EComplete. |
|
135 */ |
|
136 virtual TBool DoStartL(TRequestStatus& aStatus) = 0; |
|
137 |
|
138 /** |
|
139 * Cancels the task. The task's state will be set to ECanceled. |
|
140 */ |
|
141 virtual void DoCancel() = 0; |
|
142 |
|
143 /** |
|
144 * Runs a bit of the task |
|
145 * @param aStatus Request status for asynchronous operations |
|
146 * @returns -ETrue if the task has issued an asyncronous request. |
|
147 * CActive::SetActive() will be called in this case and the |
|
148 * task state will be ERunning. |
|
149 * -EFalse if the task has not issued a request. |
|
150 * SetActive will not be called and the task state will be |
|
151 * EComplete. |
|
152 */ |
|
153 virtual TBool DoRunL(TRequestStatus& aStatus) = 0; |
|
154 |
|
155 /** |
|
156 * Handle a leave in StartL or RunL. |
|
157 * @param aError The error that occurred. |
|
158 * @returns -ETrue if the task has issued an asyncronous request. |
|
159 * CActive::SetActive() will be called in this case and the |
|
160 * task state will be ERunning. |
|
161 * -EFalse if the task has not issued a request. |
|
162 * SetActive will not be called and the task state will be |
|
163 * EComplete. |
|
164 */ |
|
165 virtual TBool DoRunError(TInt aError) = 0; |
|
166 |
|
167 protected: |
|
168 /** |
|
169 * Issues a request and sets the aStatus as KRequestPending |
|
170 * Use this to make a synchronous operation asynchronous. |
|
171 */ |
|
172 void SelfComplete(TRequestStatus& aStatus); |
|
173 |
|
174 private: |
|
175 /** Task state */ |
|
176 TState iState; |
|
177 |
|
178 /** Task id */ |
|
179 TGlxtnTaskId iId; |
|
180 |
|
181 /** Media item id */ |
|
182 TGlxMediaId iItemId; |
|
183 |
|
184 /** |
|
185 * Priority of this task. |
|
186 * The task schedule will execute tasks based on this priority |
|
187 * When this task is run, the execution priority in CActiveScheduler |
|
188 * will be this priority. (So it is comparable to priorities of active |
|
189 * objects in the system.) |
|
190 */ |
|
191 TInt iPriority; |
|
192 |
|
193 /** Thumbnail storage for the task to use (can be NULL) */ |
|
194 MGlxtnThumbnailStorage* iStorage; |
|
195 }; |
|
196 |
|
197 /** |
|
198 * Base class for thumbnail tasks which return results to a client. |
|
199 * |
|
200 * @ingroup glx_thumbnail_creator |
|
201 */ |
|
202 NONSHARABLE_CLASS(CGlxtnClientTask) : public CGlxtnTask |
|
203 { |
|
204 protected: |
|
205 CGlxtnClientTask(const TGlxtnTaskId& aId, const TGlxMediaId& aItemId, |
|
206 MGlxtnThumbnailCreatorClient& aClient); |
|
207 |
|
208 /** |
|
209 * Get the client for this task. |
|
210 */ |
|
211 inline MGlxtnThumbnailCreatorClient& Client(); |
|
212 |
|
213 private: |
|
214 /** Client for this task */ |
|
215 MGlxtnThumbnailCreatorClient& iClient; |
|
216 }; |
|
217 |
|
218 #include "glxtntask.inl" |
|
219 |
|
220 #endif // C_GLXTNTASK_H |