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.
19 #include "utility/sync_util.h"
20 #include "engine-controller/task_info_pool.h"
21 #include "engine-controller/queuing_rule_spec.h"
22 #include "engine-controller/task_spec_internal.h"
24 #ifndef SYNC_AGENT_LOG
26 #define LOG_TAG "AF_EC"
29 ec_task_info_t *ec_task_info_new(sync_agent_ec_int task_spec_id, sync_agent_ec_task_spec_s * task_spec)
33 ec_task_info_t *task_info = (ec_task_info_t *) calloc(1, sizeof(ec_task_info_t));
34 if (task_info == NULL) {
38 task_info->task_spec_id = task_spec_id;
39 task_info->progress_blocking_entity_list = NULL;
40 task_info->task_spec = ec_task_spec_ref(task_spec);
47 ec_task_info_free(task_info);
51 void ec_task_info_free(ec_task_info_t * task_info)
55 if (task_info != NULL) {
56 if (task_info->task_spec != NULL) {
57 ec_task_spec_unref(task_info->task_spec);
60 if (task_info->progress_blocking_entity_list != NULL) {
62 ec_progress_blocking_entity_t *entity = NULL;
63 for (iter = task_info->progress_blocking_entity_list; iter != NULL; iter = g_slist_next(iter)) {
64 entity = (ec_progress_blocking_entity_t *) (iter->data);
65 ec_progress_blocking_entity_unref(entity);
67 g_slist_free(task_info->progress_blocking_entity_list);
76 ec_task_info_t *ec_task_info_ref(ec_task_info_t * task_info)
80 retvm_if(task_info == NULL, NULL, "ec_task_info_t is NULL !!");
88 void ec_task_info_unref(ec_task_info_t * task_info)
97 sync_agent_ec_boolean ec_task_info_is_progress_blocking_entity_exist(ec_task_info_t * task_info, ec_progress_blocking_entity_t * entity)
101 GSList *found_node = g_slist_find(task_info->progress_blocking_entity_list, entity);
102 if (found_node != NULL) {
111 sync_agent_ec_error_e ec_task_info_add_progress_blocking_entity(ec_task_info_t * task_info, ec_progress_blocking_entity_t * entity)
115 retvm_if(task_info == NULL, SYNC_AGENT_EC_UNKNOWN_ERROR, "ec_task_info_t is NULL !!");
116 retvm_if(entity == NULL, SYNC_AGENT_EC_UNKNOWN_ERROR, "ec_progress_blocking_entity_t is NULL !!");
118 sync_agent_ec_error_e ec_error = SYNC_AGENT_EC_OK;
120 if (ec_task_info_is_progress_blocking_entity_exist(task_info, entity)) {
121 _DEBUG_INFO("task info has already same entity");
125 task_info->progress_blocking_entity_list = g_slist_prepend(task_info->progress_blocking_entity_list, entity);
126 /* TODO : error handling */
133 sync_agent_ec_error_e ec_task_info_remove_blocking_entity(ec_task_info_t * task_info, ec_progress_blocking_entity_t * entity)
137 retvm_if(task_info == NULL, SYNC_AGENT_EC_UNKNOWN_ERROR, "ec_task_info_t is NULL !!");
138 retvm_if(entity == NULL, SYNC_AGENT_EC_UNKNOWN_ERROR, "ec_progress_blocking_entity_t is NULL !!");
140 sync_agent_ec_error_e ec_error = SYNC_AGENT_EC_OK;
142 if (!ec_task_info_is_progress_blocking_entity_exist(task_info, entity)) {
143 _DEBUG_INFO("task info has no such entity");
147 task_info->progress_blocking_entity_list = g_slist_remove(task_info->progress_blocking_entity_list, entity);
154 ec_task_info_pool_t *ec_task_info_pool_alloc()
158 ec_task_info_pool_t *task_info_pool = (ec_task_info_pool_t *) calloc(1, sizeof(ec_task_info_pool_t));
159 if (task_info_pool == NULL) {
163 task_info_pool->task_info_pool = g_hash_table_new(g_direct_hash, g_direct_equal);
164 if (task_info_pool->task_info_pool == NULL) {
170 return task_info_pool;
173 ec_task_info_pool_free(task_info_pool);
177 void ec_task_info_pool_free(ec_task_info_pool_t * task_info_pool)
181 if (task_info_pool != NULL) {
182 if (task_info_pool->task_info_pool != NULL) {
183 g_hash_table_destroy(task_info_pool->task_info_pool);
184 task_info_pool->task_info_pool = NULL;
186 free(task_info_pool);
192 sync_agent_ec_boolean ec_task_info_pool_add_task_info(ec_task_info_pool_t * task_info_pool, ec_task_info_t * task_info, sync_agent_ec_boolean replace)
196 retvm_if(task_info_pool == NULL, false, "ec_task_info_pool_t is NULL !!");
197 retvm_if(task_info == NULL, false, "ec_task_info_t is NULL !!");
199 sync_agent_ec_boolean success = false;
201 GHashTable *hash = task_info_pool->task_info_pool;
203 g_hash_table_replace(hash, (gpointer) (task_info->task_spec_id), task_info); /* TODO : check free well done */
206 gpointer tmp = g_hash_table_lookup(hash, (gpointer) (task_info->task_spec_id));
210 g_hash_table_insert(hash, (gpointer) (task_info->task_spec_id), task_info);
219 sync_agent_ec_boolean ec_task_info_pool_remove_task_info(ec_task_info_pool_t * task_info_pool, sync_agent_ec_uint msg_type)
230 ec_task_info_t *ec_task_info_pool_search_task_info(ec_task_info_pool_t * task_info_pool, sync_agent_ec_uint msg_type)
234 GHashTable *hash = task_info_pool->task_info_pool;
235 ec_task_info_t *task_info = NULL;
237 task_info = (ec_task_info_t *) g_hash_table_lookup(hash, (gpointer) msg_type);