|
1 /* |
|
2 * Copyright (c) 2002-2005 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: This is encapsulation of a background task, part of CCARequestMapper |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CCABackgroundTask.h" // Own header |
|
21 #include "MCABackgroundCallback.h" |
|
22 #include "MCABackgroundTask.h" |
|
23 |
|
24 #include <e32base.h> |
|
25 |
|
26 |
|
27 // ============================ MEMBER FUNCTIONS =============================== |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // CCABackgroundTask::NewL |
|
31 // Two-phased constructor. |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 CCABackgroundTask* CCABackgroundTask::NewL( |
|
35 MCABackgroundCallback* aParent |
|
36 , MCABackgroundTask* aBackgroundTask |
|
37 , MCABackgroundInterface::TCABackgroundTasks aTask |
|
38 , TInt aSubTasks |
|
39 ) |
|
40 { |
|
41 |
|
42 CCABackgroundTask* self = CCABackgroundTask::NewLC( aParent |
|
43 , aBackgroundTask |
|
44 , aTask |
|
45 , aSubTasks |
|
46 ); |
|
47 CleanupStack::Pop( self ); |
|
48 |
|
49 return self; |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CCABackgroundTask::NewLC |
|
54 // Two-phased constructor. |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 CCABackgroundTask* CCABackgroundTask::NewLC( |
|
58 MCABackgroundCallback* aParent |
|
59 , MCABackgroundTask* aBackgroundTask |
|
60 , MCABackgroundInterface::TCABackgroundTasks aTask |
|
61 , TInt aSubTasks |
|
62 ) |
|
63 { |
|
64 if ( aSubTasks <= 0 ) |
|
65 { |
|
66 User::Leave( KErrArgument ); |
|
67 } |
|
68 CCABackgroundTask* self = new( ELeave ) CCABackgroundTask( aParent |
|
69 , aBackgroundTask |
|
70 , aTask |
|
71 , aSubTasks |
|
72 ); |
|
73 |
|
74 CleanupStack::PushL( self ); |
|
75 self->ConstructL(); |
|
76 |
|
77 return self; |
|
78 } |
|
79 |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CCABackgroundTask::~CCABackgroundTask |
|
83 // Destructor |
|
84 // (other items were commented in a header). |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 CCABackgroundTask::~CCABackgroundTask() |
|
88 { |
|
89 if ( iIdle ) |
|
90 { |
|
91 iIdle->Cancel(); |
|
92 delete iIdle; |
|
93 } |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // CCABackgroundTask::Start |
|
98 // |
|
99 // (other items were commented in a header). |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 void CCABackgroundTask::Start() |
|
103 { |
|
104 if ( !iIdle->IsActive() ) |
|
105 { |
|
106 iIdle->Start( TCallBack( BackgroundTask, this ) ); |
|
107 } |
|
108 } |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // CCABackgroundTask::Cancel |
|
112 // |
|
113 // (other items were commented in a header). |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 void CCABackgroundTask::Cancel() |
|
117 { |
|
118 iIdle->Cancel(); |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CCABackgroundTask::Identity |
|
123 // |
|
124 // (other items were commented in a header). |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 TBool CCABackgroundTask::Identity( const CCABackgroundTask& aA |
|
128 , const CCABackgroundTask& aB |
|
129 ) |
|
130 { |
|
131 return ( aA.iTask == aB.iTask ); |
|
132 } |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // CCABackgroundTask::SubTasks |
|
136 // |
|
137 // (other items were commented in a header). |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 TInt CCABackgroundTask::SubTasks() |
|
141 { |
|
142 return iSubTasks; |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CCABackgroundTask::TaskState |
|
147 // |
|
148 // (other items were commented in a header). |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 MCABackgroundInterface::TCABackgroundStatus CCABackgroundTask::TaskState() |
|
152 { |
|
153 return iTaskState; |
|
154 } |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // CCABackgroundTask::SetTaskState |
|
158 // |
|
159 // (other items were commented in a header). |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 void CCABackgroundTask::SetTaskState( |
|
163 MCABackgroundInterface::TCABackgroundStatus aTaskState ) |
|
164 { |
|
165 iTaskState = aTaskState; |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CCABackgroundTask::More |
|
170 // |
|
171 // (other items were commented in a header). |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 TBool CCABackgroundTask::More() |
|
175 { |
|
176 if ( iSubTasks > 1 ) |
|
177 { |
|
178 iSubTasks--; |
|
179 return ETrue; |
|
180 } |
|
181 iSubTasks = 0; |
|
182 return EFalse; |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CCABackgroundTask::TaskId |
|
187 // |
|
188 // (other items were commented in a header). |
|
189 // ----------------------------------------------------------------------------- |
|
190 // |
|
191 MCABackgroundInterface::TCABackgroundTasks CCABackgroundTask::TaskId() |
|
192 { |
|
193 return iTask; |
|
194 } |
|
195 |
|
196 // ----------------------------------------------------------------------------- |
|
197 // CCABackgroundTask::BackgroundTask |
|
198 // |
|
199 // (other items were commented in a header). |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 MCABackgroundTask* CCABackgroundTask::BackgroundTask() |
|
203 { |
|
204 return iBackgroundTask; |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // CCABackgroundTask::ExecuteTaskL |
|
209 // |
|
210 // (other items were commented in a header). |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 void CCABackgroundTask::ExecuteTaskL() |
|
214 { |
|
215 iBackgroundTask->HandleBackgroundTaskL( iSubTasks ); |
|
216 } |
|
217 |
|
218 // ----------------------------------------------------------------------------- |
|
219 // CCABackgroundTask::Pending |
|
220 // |
|
221 // (other items were commented in a header). |
|
222 // ----------------------------------------------------------------------------- |
|
223 // |
|
224 TBool CCABackgroundTask::Pending() |
|
225 { |
|
226 return iIdle->IsActive(); |
|
227 } |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // CCABackgroundTask::CCABackgroundTask |
|
231 // C++ default constructor can NOT contain any code, that |
|
232 // might leave. |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 CCABackgroundTask::CCABackgroundTask( |
|
236 MCABackgroundCallback* aParent |
|
237 , MCABackgroundTask* aBackgroundTask |
|
238 , MCABackgroundInterface::TCABackgroundTasks aTask |
|
239 , TInt aSubTasks |
|
240 ) : |
|
241 iParent( aParent ), |
|
242 iBackgroundTask( aBackgroundTask ), |
|
243 iTask( aTask ), |
|
244 iSubTasks( aSubTasks ), |
|
245 iTaskState( MCABackgroundInterface::EUnknown ) |
|
246 { |
|
247 } |
|
248 |
|
249 // ----------------------------------------------------------------------------- |
|
250 // CCABackgroundTask::ConstructL |
|
251 // Symbian 2nd phase constructor can leave. |
|
252 // ----------------------------------------------------------------------------- |
|
253 // |
|
254 void CCABackgroundTask::ConstructL() |
|
255 { |
|
256 iIdle = CIdle::NewL( CActive::EPriorityIdle ); |
|
257 } |
|
258 |
|
259 // ----------------------------------------------------------------------------- |
|
260 // CCABackgroundTask::BackgroundTask |
|
261 // |
|
262 // (other items were commented in a header). |
|
263 // ----------------------------------------------------------------------------- |
|
264 // |
|
265 TInt CCABackgroundTask::BackgroundTask( TAny *aInstance ) |
|
266 { |
|
267 return static_cast<CCABackgroundTask*>( aInstance )->DoBackgroundTask(); |
|
268 } |
|
269 |
|
270 // ----------------------------------------------------------------------------- |
|
271 // CCABackgroundTask::DoBackgroundTask |
|
272 // |
|
273 // (other items were commented in a header). |
|
274 // ----------------------------------------------------------------------------- |
|
275 // |
|
276 TInt CCABackgroundTask::DoBackgroundTask() |
|
277 { |
|
278 return iParent->HandleBackgroundTask( iTask ); |
|
279 } |
|
280 |
|
281 // End of File |