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: Base class for thumbnail server tasks |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <fbs.h> |
|
21 #include "thumbnailtask.h" |
|
22 #include "thumbnailtaskprocessor.h" |
|
23 #include "thumbnailprovider.h" |
|
24 #include "thumbnaillog.h" |
|
25 #include "thumbnailpanic.h" |
|
26 #include "thumbnailserversession.h" // ConvertSqlErrToE32Err() |
|
27 #include "thumbnailmanagerconstants.h" |
|
28 #include "OstTraceDefinitions.h" |
|
29 #ifdef OST_TRACE_COMPILER_IN_USE |
|
30 #include "thumbnailtaskTraces.h" |
|
31 #endif |
|
32 |
|
33 |
|
34 // ======== MEMBER FUNCTIONS ======== |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // CThumbnailTask::CThumbnailTask() |
|
38 // C++ default constructor can NOT contain any code, that might leave. |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 CThumbnailTask::CThumbnailTask( CThumbnailTaskProcessor& aProcessor, TInt |
|
42 aPriority ): CActive( EPriorityStandard ), iProcessor( aProcessor ), |
|
43 iPriority( aPriority ), iState( EIdle ) |
|
44 { |
|
45 TN_DEBUG2( "CThumbnailTask(0x%08x)::CThumbnailTask()", this); |
|
46 CActiveScheduler::Add( this ); |
|
47 } |
|
48 |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // CThumbnailTask::~CThumbnailTask() |
|
52 // Destructor. |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CThumbnailTask::~CThumbnailTask() |
|
56 { |
|
57 Cancel(); |
|
58 CancelMessage(); |
|
59 |
|
60 iClientThread.Close(); |
|
61 } |
|
62 |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // CThumbnailTask::Priority() |
|
66 // Returns priority of task. |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 TInt CThumbnailTask::Priority()const |
|
70 { |
|
71 return iPriority; |
|
72 } |
|
73 |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // CThumbnailTask::State() |
|
77 // Returns state of task. |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 CThumbnailTask::TTaskState CThumbnailTask::State()const |
|
81 { |
|
82 return iState; |
|
83 } |
|
84 |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // CThumbnailTask::StartL() |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 void CThumbnailTask::StartL() |
|
91 { |
|
92 TN_DEBUG3( "CThumbnailTask(0x%08x)::StartL() iState == %d ", this, iState ); |
|
93 OstTrace1( TRACE_NORMAL, CTHUMBNAILTASK_STARTL, "CThumbnailTask::StartL;this=%o", this ); |
|
94 OstTrace1( TRACE_NORMAL, DUP1_CTHUMBNAILTASK_STARTL, "CThumbnailTask::StartL;iState=%u", iState ); |
|
95 |
|
96 __ASSERT_DEBUG(( iState != ERunning ), ThumbnailPanic( EThumbnailAlreadyRunning )); |
|
97 iState = ERunning; |
|
98 } |
|
99 |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // CThumbnailTask::DoCancel() |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 void CThumbnailTask::DoCancel() |
|
106 { |
|
107 // No implementation required |
|
108 } |
|
109 |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // CThumbnailTask::Complete() |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 void CThumbnailTask::Complete( TInt aReason ) |
|
116 { |
|
117 TN_DEBUG4( "CThumbnailTask(0x%08x)::Complete(aReason=%d) iState was %d", |
|
118 this, aReason, iState ); |
|
119 OstTrace1( TRACE_NORMAL, CTHUMBNAILTASK_COMPLETE, "CThumbnailTask::Complete;this=%o", this ); |
|
120 OstTraceExt2( TRACE_NORMAL, DUP1_CTHUMBNAILTASK_COMPLETE, "CThumbnailTask::Complete;aReason=%d;iState=%u", aReason, iState ); |
|
121 |
|
122 if ( iState != EComplete ) |
|
123 { |
|
124 iState = EComplete; |
|
125 |
|
126 if ( ClientThreadAlive() ) |
|
127 { |
|
128 if( iMessage.Identity() == KDaemonUid ) |
|
129 { |
|
130 iProcessor.SetDaemonAsProcess(ETrue); |
|
131 } |
|
132 else |
|
133 { |
|
134 iProcessor.SetDaemonAsProcess(EFalse); |
|
135 } |
|
136 |
|
137 iMessage.Complete( CThumbnailServerSession::ConvertSqlErrToE32Err( aReason )); |
|
138 } |
|
139 |
|
140 ResetMessageData(); |
|
141 |
|
142 iProcessor.TaskComplete( this ); |
|
143 } |
|
144 } |
|
145 |
|
146 // --------------------------------------------------------------------------- |
|
147 // CThumbnailTask::Continue() |
|
148 // --------------------------------------------------------------------------- |
|
149 // |
|
150 void CThumbnailTask::Continue() |
|
151 { |
|
152 if ( iState != EComplete ) |
|
153 { |
|
154 iState = EIdle; |
|
155 } |
|
156 |
|
157 iProcessor.TaskComplete( this ); |
|
158 } |
|
159 |
|
160 // --------------------------------------------------------------------------- |
|
161 // CThumbnailTask::StartError() |
|
162 // --------------------------------------------------------------------------- |
|
163 // |
|
164 void CThumbnailTask::StartError( TInt aError ) |
|
165 { |
|
166 // This is called if StartL() left. Complete this task with an error and |
|
167 // continue processing. |
|
168 TN_DEBUG3( "CThumbnailTask(0x%08x)::StartError(aError=%d)", this, aError ); |
|
169 OstTrace1( TRACE_NORMAL, CTHUMBNAILTASK_STARTERROR, "CThumbnailTask::StartError;this=%o", this ); |
|
170 OstTrace1( TRACE_NORMAL, DUP1_CTHUMBNAILTASK_STARTERROR, "CThumbnailTask::StartError;aError=%d", aError ); |
|
171 |
|
172 Complete( aError ); |
|
173 } |
|
174 |
|
175 |
|
176 // --------------------------------------------------------------------------- |
|
177 // CThumbnailTask::ChangeTaskPriority() |
|
178 // Changes priority of the task. |
|
179 // --------------------------------------------------------------------------- |
|
180 // |
|
181 void CThumbnailTask::ChangeTaskPriority( TInt aNewPriority ) |
|
182 { |
|
183 iPriority = aNewPriority; |
|
184 } |
|
185 |
|
186 |
|
187 // --------------------------------------------------------------------------- |
|
188 // CThumbnailTask::SetMessageData() |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 void CThumbnailTask::SetMessageData( const TThumbnailServerRequestId& |
|
192 aRequestId, const RMessage2& aMessage, const RThread& aClientThread ) |
|
193 { |
|
194 iMessage = aMessage; |
|
195 iRequestId = aRequestId; |
|
196 |
|
197 if ( iMessage.Handle()) |
|
198 { |
|
199 // copy client thread handle |
|
200 iClientThread.Duplicate(aClientThread); |
|
201 } |
|
202 else |
|
203 { |
|
204 TN_DEBUG2( "CThumbnailTask(0x%08x)::ClientThreadAlive() - message null", this); |
|
205 OstTrace1( TRACE_NORMAL, CTHUMBNAILTASK_SETMESSAGEDATA, "CThumbnailTask::SetMessageData - message null;this=%o", this ); |
|
206 } |
|
207 } |
|
208 |
|
209 // --------------------------------------------------------------------------- |
|
210 // CThumbnailTask::SetMessageData() |
|
211 // --------------------------------------------------------------------------- |
|
212 // |
|
213 void CThumbnailTask::SetMessageData( const TThumbnailServerRequestId& |
|
214 aRequestId ) |
|
215 { |
|
216 iMessage = RMessage2(); |
|
217 iRequestId = aRequestId; |
|
218 } |
|
219 |
|
220 |
|
221 // --------------------------------------------------------------------------- |
|
222 // CThumbnailTask::ResetMessageData() |
|
223 // --------------------------------------------------------------------------- |
|
224 // |
|
225 void CThumbnailTask::ResetMessageData() |
|
226 { |
|
227 iMessage = RMessage2(); |
|
228 } |
|
229 |
|
230 |
|
231 // --------------------------------------------------------------------------- |
|
232 // CThumbnailTask::ResetMessageData() |
|
233 // Returns id of specific task. |
|
234 // --------------------------------------------------------------------------- |
|
235 // |
|
236 TThumbnailServerRequestId CThumbnailTask::RequestId()const |
|
237 { |
|
238 return iRequestId; |
|
239 } |
|
240 |
|
241 |
|
242 // --------------------------------------------------------------------------- |
|
243 // CThumbnailTask::CancelMessage() |
|
244 // --------------------------------------------------------------------------- |
|
245 // |
|
246 void CThumbnailTask::CancelMessage() |
|
247 { |
|
248 if ( ClientThreadAlive() ) |
|
249 { |
|
250 iMessage.Complete( KErrCancel ); |
|
251 } |
|
252 |
|
253 ResetMessageData(); |
|
254 } |
|
255 |
|
256 // --------------------------------------------------------------------------- |
|
257 // CThumbnailTask::ClientThreadAlive() |
|
258 // Checks if client thread is still alive and RMessage2 handle valid. |
|
259 // --------------------------------------------------------------------------- |
|
260 // |
|
261 TBool CThumbnailTask::ClientThreadAlive(const TBool aGetThread) |
|
262 { |
|
263 TN_DEBUG1( "CThumbnailTask::ClientThreadAlive()"); |
|
264 OstTrace0( TRACE_NORMAL, CTHUMBNAILTASK_CLIENTTHREADALIVE, "CThumbnailTask::ClientThreadAlive" ); |
|
265 |
|
266 if ( iMessage.Handle()) |
|
267 { |
|
268 if (aGetThread) |
|
269 { |
|
270 // get client thread |
|
271 TInt err = iMessage.Client( iClientThread ); |
|
272 if (err != KErrNone) |
|
273 { |
|
274 TN_DEBUG2( "CThumbnailTask(0x%08x)::ClientThreadAlive() - client thread not found", this); |
|
275 OstTrace1( TRACE_NORMAL, DUP1_CTHUMBNAILTASK_CLIENTTHREADALIVE, "CThumbnailTask::ClientThreadAlive - client thread not found;this=%o", this ); |
|
276 |
|
277 ResetMessageData(); |
|
278 |
|
279 return EFalse; |
|
280 } |
|
281 } |
|
282 |
|
283 // check if client thread alive |
|
284 TExitType exitType = iClientThread.ExitType(); |
|
285 if( exitType != EExitPending ) |
|
286 { |
|
287 TN_DEBUG2( "CThumbnailTask(0x%08x)::ClientThreadAlive() - client thread died", this); |
|
288 OstTrace1( TRACE_NORMAL, DUP2_CTHUMBNAILTASK_CLIENTTHREADALIVE, "CThumbnailTask::ClientThreadAlive - client thread died;this=%o", this ); |
|
289 |
|
290 ResetMessageData(); |
|
291 |
|
292 return EFalse; |
|
293 } |
|
294 else |
|
295 { |
|
296 // all OK |
|
297 return ETrue; |
|
298 } |
|
299 } |
|
300 else |
|
301 { |
|
302 return EFalse; |
|
303 } |
|
304 } |
|
305 |
|
306 // End of file |
|