3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
23 #include "engine-controller/param.h"
24 #include "engine-controller/param_internal.h"
25 #include "engine-controller/task_spec.h"
26 #include "engine-controller/task_cancel_info.h"
27 #include "engine-controller/message.h"
28 #include "engine-controller/task_info_pool.h"
29 #include "utility/fw_ref.h"
33 * @brief Defines engine controller task APIs
36 /** @addtogroup engine_controller
41 * @brief Structure for task
43 typedef struct ec_task_s ec_task_t;
46 * @brief Structure for task
49 sync_agent_ec_int ref_count; /**< Reference count */
51 sync_agent_ec_task_error_e task_error; /**< Task error */
53 ec_task_info_t *task_info; /**< Task information */
54 GSList *progress_blocking_realized_entity_list; /**< containing ec_progress_blocking_realized_entity_t* */
55 GSList *current_node_in_progress_blocking_entity_list; /**< containing ec_n_ary_tree_node_with_flag_t* */
57 sync_agent_ec_task_spec_s *task_spec; /**< Task spec */
58 sync_agent_util_ref_object_s *request_msg; /**< Request message(containing ec_request_msg_t*) */
60 ec_task_cancel_info_t *cancel_information; /**< Cancel information */
61 sync_agent_ec_param_param_s **param_array; /**< Parameter array */
63 /* information of dynamic case */
64 sync_agent_ec_int dynamic_case; /**< dynamic case(only use when task spec is dynamic) */
66 /* information of parent link */
67 ec_task_t *parent_task; /**< Parent task */
68 sync_agent_ec_int child_task_index_in_parent_task; /**< Child task index in parent task */
70 /* information of child link */
71 ec_task_t **child_task_array; /**< Child task array */
73 sync_agent_ec_uint cnt_left_child_task_to_finish; /**< Left child task count to finish */
75 sync_agent_ec_uint *current_child_task_control_flow_in_degree_array; /**< Current child task control flow in degree array */
77 struct timeval create_time; /**< Create time */
78 struct timeval run_time; /**< Run time */
79 struct timeval finish_time; /**< Finish time */
83 * @brief Construct progress_blocking_realized_entity_list
84 * @param[in] task_info ec_task_info_t
85 * @return progress_blocking_realized_entity_list on success, NULL on fail
86 * @retval progress_blocking_realized_entity_list Successful
89 GSList *ec_task_construct_progress_blocking_realized_entity_list(ec_task_info_t * task_info);
92 * @brief Allocate root task
93 * @param[in] task_spec sync_agent_ec_task_spec_s
94 * @param[in] request_msg ec_request_msg_t
95 * @param[in] task_info_pool ec_task_info_pool_t
96 * @return ec_task_t on success, NULL on fail
97 * @retval root task Successful
100 ec_task_t *ec_task_alloc_root_task(sync_agent_ec_task_spec_s * task_spec, ec_request_msg_t * request_msg, ec_task_info_pool_t * task_info_pool);
103 * @brief Allocate child task
104 * @param[in] parent_task ec_task_t
105 * @param[in] child_index sync_agent_ec_int
106 * @return ec_task_t on success, NULL on fail
107 * @retval child task Successful
110 ec_task_t *ec_task_alloc_child_task(ec_task_t * parent_task, sync_agent_ec_int child_index);
113 * @brief Increase task reference count
114 * @param[in] task ec_task_t
115 * @return ec_task_t on success, NULL on fail
116 * @retval task Successful
118 ec_task_t *ec_task_ref_task(ec_task_t * task);
121 * @brief Decrease task reference count
122 * @param[in] task ec_task_t
124 void ec_task_unref_task(ec_task_t * task);
127 * @brief Check that inputted task is simple task or not
128 * @param[in] task ec_task_t
129 * @return true on success, false on fail
130 * @retval true Simple task
131 * @retval false Others
133 sync_agent_ec_boolean ec_task_is_simple_task(ec_task_t * task);
136 * @brief Check that inputted task is container task or not
137 * @param[in] task ec_task_t
138 * @return true on success, false on fail
139 * @retval true Container task
140 * @retval false Others
142 sync_agent_ec_boolean ec_task_is_container_task(ec_task_t * task);
145 * @brief Check that inputted task is root task or not
146 * @param[in] task ec_task_t
147 * @return true on success, false on fail
148 * @retval true Root task
149 * @retval false Others
151 sync_agent_ec_boolean ec_task_is_root_task(ec_task_t * task);
154 * @brief Get parameter count
155 * @param[in] task ec_task_t
156 * @return Parameter count
158 sync_agent_ec_int ec_task_get_param_cnt(ec_task_t * task);
161 * @brief Get output parameter information
162 * @param[in] task ec_task_t
163 * @param[out] pOutput_param_cnt output parameter count
164 * @param[out] pOutput_param_index_array output parameter index array
165 * @return true on success, false on fail
166 * @retval true Successful
169 sync_agent_ec_int ec_task_get_output_param_info(ec_task_t * task, sync_agent_ec_int * pOutput_param_cnt, sync_agent_ec_int ** pOutput_param_index_array);
172 * @brief Get child task count
173 * @param[in] task ec_task_t
174 * @return Child task count
176 sync_agent_ec_uint ec_task_get_child_task_cnt(ec_task_t * task);
179 * @brief Get parent task
180 * @param[in] task ec_task_t
181 * @return parent task on success, NULL on fail
182 * @retval parent task Successful
185 ec_task_t *ec_task_get_parent_task(ec_task_t * task);
188 * @brief Get child index in parent task
189 * @param[in] task ec_task_t
190 * @return child index
192 sync_agent_ec_int ec_task_get_child_index_in_parent_task(ec_task_t * task);
195 * @brief Set task error
196 * @param[in] task ec_task_t
197 * @param[in] task_error sync_agent_ec_task_error_e
199 void ec_task_set_task_error(ec_task_t * task, sync_agent_ec_task_error_e task_error);
202 * @brief Check same task error
203 * @param[in] task ec_task_t
204 * @param[in] task_error sync_agent_ec_task_error_e
205 * @return true on success, false on fail
206 * @retval true same task
207 * @retval false not same task
209 sync_agent_ec_boolean ec_task_check_same_task_error(ec_task_t * task, sync_agent_ec_task_error_e task_error);
212 * @brief Check inputted task is not yet run
213 * @param[in] task ec_task_t
214 * @return true on success, false on fail
215 * @retval true not run
216 * @retval false already run
218 sync_agent_ec_boolean ec_task_is_not_yet_run(ec_task_t * task);
221 * @brief Request cancel
222 * @param[in] task ec_task_t
224 void ec_task_do_cancellation(ec_task_t * task);
227 * @brief Call task finish callback
228 * @param[in] task ec_task_t
230 void ec_task_call_task_finish_callback(ec_task_t * task);
233 * @brief Remove control flow
234 * @param[in] parent_task ec_task_t
235 * @param[in] from_task_index from index
236 * @param[in] to_task_index to index
238 void ec_task_remove_control_flow(ec_task_t * parent_task, sync_agent_ec_int from_task_index, sync_agent_ec_int to_task_index);
241 * @brief Set left child to run
242 * @param[in] parent_task ec_task_t
243 * @param[in] number left child count
245 void ec_task_set_left_child_to_run(ec_task_t * parent_task, sync_agent_ec_uint number);
248 * @brief Check inputted parent task has no more left child to run
249 * @param[in] parent_task ec_task_t
250 * @return true on success, false on fail
251 * @retval true no more child to run
252 * @retval false child task left
254 sync_agent_ec_boolean ec_task_is_left_child_to_run_zero(ec_task_t * parent_task);
257 * @brief Decrease left child to run
258 * @param[in] parent_task ec_task_t
260 void ec_task_decrease_left_child_to_run(ec_task_t * parent_task);
263 * @brief check inputted parent task is EC_TASK_DONE
264 * @param[in] parent_task ec_task_t
265 * @return true on success, false on fail
266 * @retval true EC_TASK_DONE
267 * @retval false others
269 sync_agent_ec_boolean ec_task_is_parent_EC_TASK_DONE(ec_task_t * parent_task);
272 * @brief Collect parent task output parameter
273 * @param[in] parent_task ec_task_t
275 void ec_task_collect_parent_task_output_parameter(ec_task_t * parent_task);
278 * @brief Collect firstly runnable child tasks
279 * @param[in] parent_task ec_task_t
280 * @return runnable child tasks on success, false on fail
281 * @retval runnable child tasks Successful
284 GSList *ec_collect_firstly_runnable_child_tasks(ec_task_t * parent_task);
287 * @brief Collect become runnable child tasks by remove control flow
288 * @param[in] parent_task ec_task_t
289 * @param[in] from_child_task_index child task index
290 * @return runnable child tasks on success, false on fail
291 * @retval runnable child tasks Successful
294 GSList *ec_collect_become_runnable_child_tasks_by_remove_control_flow(ec_task_t * parent_task, sync_agent_ec_int from_child_task_index);
297 * @brief Run simple task
298 * @param[in] pSimple_task ec_task_t
299 * @return SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS on success, otherwise error value
300 * @retval SYNC_AGENT_EC_TASK_ERROR_RUN_SUCCESS Successful
301 * @retval SYNC_AGENT_EC_TASK_ERROR_CANCELED Fail
303 sync_agent_ec_task_error_e ec_task_run_simple_task(ec_task_t * pSimple_task);
306 * @brief Add pending task list of first progress blocking realized entity
307 * @remarks return true if pending is done
308 * @param[in] task ec_task_t
309 * @return true on success, false on fail
310 * @retval true Successful
313 sync_agent_ec_boolean ec_task_add_pending_task_list_of_first_progress_blocking_realized_entity(ec_task_t * task);
316 * @brief Update progress blocking realized entity and pop if possible
317 * @param[in] task ec_task_t
319 void ec_task_update_progress_blocking_realized_entity_and_pop_if_possible(ec_task_t * task);
322 * @brief Structure for progress blocking realized entity
324 typedef struct ec_progress_blocking_realized_entity_s ec_progress_blocking_realized_entity_t;
327 * @brief Structure for progress blocking realized entity
329 struct ec_progress_blocking_realized_entity_s {
330 sync_agent_ec_uint left_progress_blocking_element_cnt; /**< Left progress blocking element count */
332 ec_progress_blocking_entity_t *entity; /**< Blocking entity */
333 GSList *pending_task_list; /**< Pending task list(containing ec_task_t*) */
337 * @brief Create ec_progress_blocking_realized_entity_t
338 * @param[in] entity ec_progress_blocking_entity_t
339 * @return progress blocking realized entity on success, NULL on fail
340 * @retval ec_progress_blocking_realized_entity_t Successful
343 ec_progress_blocking_realized_entity_t *ec_progress_blocking_realized_entity_new(ec_progress_blocking_entity_t * entity);
346 * @brief Free ec_progress_blocking_realized_entity_t
347 * @param[in] realized_entity ec_progress_blocking_realized_entity_t
349 void ec_progress_blocking_realized_entity_free(ec_progress_blocking_realized_entity_t * realized_entity);
352 * @brief Restart pending task
353 * @param[in] realized_entity ec_progress_blocking_realized_entity_t
355 void ec_progress_blocking_realized_entity_restart_pending_task(ec_progress_blocking_realized_entity_t * realized_entity);
358 * @brief Add pending task
359 * @param[in] entity ec_progress_blocking_realized_entity_t
360 * @param[in] pending_task ec_task_t
362 void ec_progress_blocking_realized_entity_add_pending_task(ec_progress_blocking_realized_entity_t * entity, ec_task_t * pending_task);
365 * @brief Update progress blocking realized entity and test left progress blocking element count
366 * @remarks return true when left_progress_blocking_element_cnt are updated and become zero
367 * @param[in] realized_entity ec_progress_blocking_realized_entity_t
368 * @param[in] current_node ec_n_ary_tree_node_with_flag_t
369 * @param[in] task ec_task_t
370 * @return true on success, false on fail
371 * @retval true Successful
374 sync_agent_ec_boolean ec_progress_blocking_realized_entity_update_and_test_left_progress_blocking_element_cnt(ec_progress_blocking_realized_entity_t * realized_entity, ec_n_ary_tree_node_with_flag_t * current_node, ec_task_t * task);
377 * @brief Check left progress blocking element count
378 * @remarks return true when left_progress_blocking_element_cnt are updated and become zero
379 * @param[in] realized_entity ec_progress_blocking_realized_entity_t
380 * @return true on success, false on fail
381 * @retval true Successful
384 sync_agent_ec_boolean ec_progress_blocking_realized_entity_is_zero_left_progress_blocking_element_cnt(ec_progress_blocking_realized_entity_t * realized_entity);