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