|
1 /* |
|
2 * Copyright (c) 2005-2006 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 the License "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 wlan engine operations |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "core_operation_base.h" |
|
20 #include "core_server.h" |
|
21 #include "core_sub_operation_load_drivers.h" |
|
22 #include "am_debug.h" |
|
23 |
|
24 // ======== MEMBER FUNCTIONS ======== |
|
25 |
|
26 // --------------------------------------------------------------------------- |
|
27 // --------------------------------------------------------------------------- |
|
28 // |
|
29 core_operation_base_c::core_operation_base_c( |
|
30 core_operation_type_e type, |
|
31 u32_t request_id, |
|
32 core_server_c* server, |
|
33 abs_core_driverif_c* drivers, |
|
34 abs_core_server_callback_c* adaptation, |
|
35 u32_t feature_flags ) : |
|
36 request_id_m( request_id ), |
|
37 server_m( server ), |
|
38 drivers_m( drivers ), |
|
39 adaptation_m( adaptation ), |
|
40 is_executing_m( false_t ), |
|
41 is_canceling_m( false_t ), |
|
42 operation_state_m( core_base_state_init ), |
|
43 sub_operation_m( NULL ), |
|
44 failure_reason_m( core_error_cancel ), |
|
45 operation_type_m( type ), |
|
46 feature_flags_m( feature_flags ) |
|
47 { |
|
48 DEBUG1( "core_operation_base_c::core_operation_base_c() (%08X)", |
|
49 this ); |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 core_operation_base_c::~core_operation_base_c() |
|
56 { |
|
57 DEBUG1( "core_operation_base_c::~core_operation_base_c() (%08X)", |
|
58 this ); |
|
59 |
|
60 delete sub_operation_m; |
|
61 sub_operation_m = NULL; |
|
62 server_m = NULL; |
|
63 drivers_m = NULL; |
|
64 adaptation_m = NULL; |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 core_error_e core_operation_base_c::start_operation() |
|
71 { |
|
72 DEBUG1( "core_operation_base_c::start_operation() (%08X)", |
|
73 this ); |
|
74 |
|
75 is_executing_m = true_t; |
|
76 return continue_operation( core_error_ok ); |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 core_error_e core_operation_base_c::continue_operation( |
|
83 core_error_e request_status ) |
|
84 { |
|
85 DEBUG1( "core_operation_base_c::continue_operation() (%08X)", |
|
86 this ); |
|
87 bool_t is_sub_operation_canceled( false_t ); |
|
88 |
|
89 /** |
|
90 * If we have pending sub-operation, this continue must be for it. |
|
91 */ |
|
92 if ( sub_operation_m ) |
|
93 { |
|
94 core_error_e ret = sub_operation_m->continue_operation( request_status ); |
|
95 if ( ret == core_error_request_pending ) |
|
96 { |
|
97 DEBUG( "core_operation_base_c::continue_operation() - sub-operation still pending" ); |
|
98 return ret; |
|
99 } |
|
100 |
|
101 delete sub_operation_m; |
|
102 sub_operation_m = NULL; |
|
103 |
|
104 if ( ret == core_error_ok ) |
|
105 { |
|
106 DEBUG( "core_operation_base_c::continue_operation() - sub-operation completed successfully" ); |
|
107 } |
|
108 else if ( is_canceling_m ) |
|
109 { |
|
110 DEBUG( "core_operation_base_c::continue_operation() - sub-operation user cancel completed" ); |
|
111 is_sub_operation_canceled = true_t; |
|
112 } |
|
113 else |
|
114 { |
|
115 DEBUG1( "core_operation_base_c::continue_operation() - sub-operation failed with %u", |
|
116 ret ); |
|
117 failure_reason_m = ret; |
|
118 |
|
119 return cancel_operation(); |
|
120 } |
|
121 } |
|
122 |
|
123 /** |
|
124 * Handle user cancel for operations that haven't overridden the user cancel method. |
|
125 */ |
|
126 if ( operation_state_m == core_base_state_user_cancel ) |
|
127 { |
|
128 DEBUG( "core_operation_base_c::continue_operation() - user cancel complete" ); |
|
129 ASSERT( is_canceling_m ); |
|
130 |
|
131 return core_error_cancel; |
|
132 } |
|
133 |
|
134 /** |
|
135 * This continue is for this operation. |
|
136 * |
|
137 * If a sub-operation has just completed its user cancel, ignore the return |
|
138 * value. |
|
139 */ |
|
140 if ( !is_sub_operation_canceled && |
|
141 request_status != core_error_ok ) |
|
142 { |
|
143 DEBUG1( "core_operation_base_c::continue_operation() - request failed with %u", |
|
144 request_status ); |
|
145 failure_reason_m = request_status; |
|
146 |
|
147 return cancel_operation(); |
|
148 } |
|
149 |
|
150 switch ( operation_state_m ) |
|
151 { |
|
152 case core_base_state_init: |
|
153 { |
|
154 operation_state_m = core_base_state_next; |
|
155 |
|
156 if ( is_flags( core_base_flag_drivers_needed ) && |
|
157 !server_m->get_core_settings().is_driver_loaded() ) |
|
158 { |
|
159 DEBUG( "core_operation_base_c::continue_operation() - drivers required" ); |
|
160 |
|
161 operation_state_m = core_base_state_load_drivers; |
|
162 |
|
163 core_operation_base_c* operation = new core_sub_operation_load_drivers_c( |
|
164 request_id_m, server_m, drivers_m, adaptation_m ); |
|
165 return run_sub_operation( operation ); |
|
166 } |
|
167 |
|
168 return next_state(); |
|
169 } |
|
170 case core_base_state_load_drivers: |
|
171 { |
|
172 DEBUG( "core_operation_base_c::continue_operation() - drivers loaded successfully" ); |
|
173 |
|
174 operation_state_m = core_base_state_next; |
|
175 |
|
176 return next_state(); |
|
177 } |
|
178 default: |
|
179 { |
|
180 core_error_e ret = next_state(); |
|
181 |
|
182 /** |
|
183 * Always return an error code when the operation completes |
|
184 * after user cancel. |
|
185 */ |
|
186 if( is_canceling_m && |
|
187 ret != core_error_request_pending ) |
|
188 { |
|
189 DEBUG( "core_operation_base_c::continue_operation() - completing user canceled operation with core_error_cancel" ); |
|
190 |
|
191 return core_error_cancel; |
|
192 } |
|
193 |
|
194 return ret; |
|
195 } |
|
196 } |
|
197 } |
|
198 |
|
199 // --------------------------------------------------------------------------- |
|
200 // --------------------------------------------------------------------------- |
|
201 // |
|
202 core_error_e core_operation_base_c::cancel_operation() |
|
203 { |
|
204 DEBUG1( "core_operation_base_c::cancel_operation() (%08X)", |
|
205 this ); |
|
206 |
|
207 /** |
|
208 * If we have pending sub-operation, it must be canceled first. |
|
209 */ |
|
210 if ( sub_operation_m ) |
|
211 { |
|
212 core_error_e ret = sub_operation_m->cancel_operation(); |
|
213 if ( ret == core_error_request_pending ) |
|
214 { |
|
215 DEBUG( "core_operation_base_c::cancel_operation() - sub-operation cancel pending" ); |
|
216 return ret; |
|
217 } |
|
218 |
|
219 delete sub_operation_m; |
|
220 sub_operation_m = NULL; |
|
221 } |
|
222 |
|
223 /** |
|
224 * If the cancel occurs during the base operation state machine, fail the operation |
|
225 * immediately without making the main state machine handle the failure. |
|
226 */ |
|
227 if ( operation_state_m < core_base_state_next ) |
|
228 { |
|
229 DEBUG( "core_operation_base_c::cancel_operation() - canceling using base operation cancel()" ); |
|
230 |
|
231 return core_operation_base_c::cancel(); |
|
232 } |
|
233 |
|
234 return cancel(); |
|
235 } |
|
236 |
|
237 // --------------------------------------------------------------------------- |
|
238 // --------------------------------------------------------------------------- |
|
239 // |
|
240 void core_operation_base_c::user_cancel_operation( |
|
241 bool_t do_graceful_cancel ) |
|
242 { |
|
243 DEBUG1( "core_operation_base_c::user_cancel_operation() (%08X)", |
|
244 this ); |
|
245 |
|
246 /** |
|
247 * Prevent double canceling. |
|
248 */ |
|
249 if ( is_canceling_m ) |
|
250 { |
|
251 DEBUG( "core_operation_base_c::user_cancel_operation() - canceling already in progress" ); |
|
252 |
|
253 return; |
|
254 } |
|
255 |
|
256 /** |
|
257 * If we have pending sub-operation, it must be canceled first. |
|
258 */ |
|
259 if ( sub_operation_m ) |
|
260 { |
|
261 sub_operation_m->user_cancel_operation( do_graceful_cancel ); |
|
262 } |
|
263 |
|
264 is_canceling_m = true_t; |
|
265 |
|
266 /** |
|
267 * If the user cancel occurs during the base operation state machine, fail the operation |
|
268 * immediately without making the main state machine handle the user cancel. |
|
269 */ |
|
270 if ( operation_state_m < core_base_state_next ) |
|
271 { |
|
272 DEBUG( "core_operation_base_c::user_cancel_operation() - canceling using base operation user_cancel()" ); |
|
273 |
|
274 core_operation_base_c::user_cancel( do_graceful_cancel ); |
|
275 return; |
|
276 } |
|
277 |
|
278 user_cancel( do_graceful_cancel ); |
|
279 } |
|
280 |
|
281 // --------------------------------------------------------------------------- |
|
282 // --------------------------------------------------------------------------- |
|
283 // |
|
284 u32_t core_operation_base_c::request_id() const |
|
285 { |
|
286 return request_id_m; |
|
287 } |
|
288 |
|
289 // --------------------------------------------------------------------------- |
|
290 // --------------------------------------------------------------------------- |
|
291 // |
|
292 core_operation_type_e core_operation_base_c::operation_type() const |
|
293 { |
|
294 return operation_type_m; |
|
295 } |
|
296 |
|
297 // --------------------------------------------------------------------------- |
|
298 // --------------------------------------------------------------------------- |
|
299 // |
|
300 bool_t core_operation_base_c::is_executing() const |
|
301 { |
|
302 return is_executing_m; |
|
303 } |
|
304 |
|
305 // --------------------------------------------------------------------------- |
|
306 // --------------------------------------------------------------------------- |
|
307 // |
|
308 bool_t core_operation_base_c::is_flags( |
|
309 u32_t feature_flags ) const |
|
310 { |
|
311 if ( feature_flags_m & feature_flags ) |
|
312 { |
|
313 return true_t; |
|
314 } |
|
315 |
|
316 return false_t; |
|
317 } |
|
318 |
|
319 // --------------------------------------------------------------------------- |
|
320 // --------------------------------------------------------------------------- |
|
321 // |
|
322 core_error_e core_operation_base_c::cancel() |
|
323 { |
|
324 DEBUG( "core_operation_base_c::cancel() " ); |
|
325 |
|
326 return failure_reason_m; |
|
327 } |
|
328 |
|
329 // --------------------------------------------------------------------------- |
|
330 // --------------------------------------------------------------------------- |
|
331 // |
|
332 void core_operation_base_c::user_cancel( |
|
333 bool_t /* do_graceful_cancel */ ) |
|
334 { |
|
335 DEBUG( "core_operation_base_c::user_cancel()" ); |
|
336 |
|
337 operation_state_m = core_base_state_user_cancel; |
|
338 } |
|
339 |
|
340 // --------------------------------------------------------------------------- |
|
341 // --------------------------------------------------------------------------- |
|
342 // |
|
343 core_error_e core_operation_base_c::goto_state( |
|
344 u32_t state ) |
|
345 { |
|
346 operation_state_m = state; |
|
347 |
|
348 return next_state(); |
|
349 } |
|
350 |
|
351 // --------------------------------------------------------------------------- |
|
352 // --------------------------------------------------------------------------- |
|
353 // |
|
354 core_error_e core_operation_base_c::run_sub_operation( |
|
355 core_operation_base_c* sub_operation ) |
|
356 { |
|
357 DEBUG( "core_operation_base_c::run_sub_operation() " ); |
|
358 |
|
359 ASSERT( !sub_operation_m ); |
|
360 sub_operation_m = sub_operation; |
|
361 |
|
362 if ( !sub_operation_m ) |
|
363 { |
|
364 DEBUG( "core_operation_base_c::run_sub_operation() - sub-operation creation failed" ); |
|
365 failure_reason_m = core_error_no_memory; |
|
366 |
|
367 return cancel_operation(); |
|
368 } |
|
369 |
|
370 core_error_e ret = sub_operation_m->start_operation(); |
|
371 if ( ret == core_error_request_pending ) |
|
372 { |
|
373 DEBUG( "core_operation_base_c::run_sub_operation() - sub-operation still pending" ); |
|
374 return ret; |
|
375 } |
|
376 |
|
377 delete sub_operation_m; |
|
378 sub_operation_m = NULL; |
|
379 |
|
380 if ( ret != core_error_ok ) |
|
381 { |
|
382 DEBUG1( "core_operation_base_c::run_sub_operation() - sub-operation failed with %u", |
|
383 ret ); |
|
384 failure_reason_m = ret; |
|
385 |
|
386 return cancel_operation(); |
|
387 } |
|
388 |
|
389 DEBUG( "core_operation_base_c::run_sub_operation() - sub-operation completed successfully" ); |
|
390 |
|
391 return continue_operation( ret ); |
|
392 } |
|
393 |
|
394 // --------------------------------------------------------------------------- |
|
395 // --------------------------------------------------------------------------- |
|
396 // |
|
397 core_error_e core_operation_base_c::run_sub_operation( |
|
398 core_operation_base_c* sub_operation, |
|
399 u32_t state ) |
|
400 { |
|
401 operation_state_m = state; |
|
402 |
|
403 return run_sub_operation( sub_operation ); |
|
404 } |
|
405 |
|
406 // --------------------------------------------------------------------------- |
|
407 // --------------------------------------------------------------------------- |
|
408 // |
|
409 core_error_e core_operation_base_c::asynch_goto( |
|
410 u32_t state, |
|
411 u32_t delay ) |
|
412 { |
|
413 operation_state_m = state; |
|
414 |
|
415 server_m->schedule_operation_timer( |
|
416 delay ); |
|
417 |
|
418 return core_error_request_pending; |
|
419 } |
|
420 |
|
421 // --------------------------------------------------------------------------- |
|
422 // --------------------------------------------------------------------------- |
|
423 // |
|
424 void core_operation_base_c::asynch_default_user_cancel() |
|
425 { |
|
426 DEBUG( "core_operation_base_c::asynch_default_user_cancel()" ); |
|
427 |
|
428 server_m->cancel_operation_timer(); |
|
429 |
|
430 asynch_goto( core_base_state_user_cancel ); |
|
431 } |