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.
20 #include "utility/sync_util.h"
21 #include "engine-controller/queuing_rule_spec_pool.h"
23 #ifndef SYNC_AGENT_LOG
25 #define LOG_TAG "AF_EC"
28 ec_queuing_rule_spec_pool_t *ec_queuing_rule_spec_pool_alloc(sync_agent_ec_uint queuing_rule_max_cnt, ec_task_info_pool_t * task_info_pool)
32 retvm_if(task_info_pool == NULL, NULL, "ec_task_info_pool_t is NULL !!");
34 ec_queuing_rule_spec_pool_t *pool = NULL;
35 if (queuing_rule_max_cnt == 0) {
39 pool = (ec_queuing_rule_spec_pool_t *) calloc(1, sizeof(ec_queuing_rule_spec_pool_t));
44 pool->id_provider = util_create_id_provider(queuing_rule_max_cnt - 1, 12, false);
45 if (pool->id_provider == NULL) {
49 pool->queuing_rule_spec_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) sync_agent_unref_queuing_rule_spec);
50 if (pool->queuing_rule_spec_hash == NULL) {
54 pool->task_info_pool = task_info_pool;
61 ec_queuing_rule_spec_pool_free(pool);
65 void ec_queuing_rule_spec_pool_free(ec_queuing_rule_spec_pool_t * pool)
70 if (pool->id_provider != NULL) {
71 util_destroy_id_provider(pool->id_provider);
72 pool->id_provider = NULL;
74 if (pool->queuing_rule_spec_hash != NULL) {
75 g_hash_table_destroy(pool->queuing_rule_spec_hash);
76 pool->queuing_rule_spec_hash = NULL;
78 if (pool->task_info_pool != NULL) {
79 ec_task_info_pool_free(pool->task_info_pool);
80 pool->task_info_pool = NULL;
88 sync_agent_ec_error_e ec_queuing_rule_spec_pool_add_queuing_rule_spec(ec_queuing_rule_spec_pool_t * pool, sync_agent_ec_queuing_rule_spec_s * spec, sync_agent_ec_uint * queuing_rule_id)
92 retvm_if(pool == NULL, SYNC_AGENT_EC_UNKNOWN_ERROR, "ec_queuing_rule_spec_pool_t is NULL !!");
93 retvm_if(spec == NULL, SYNC_AGENT_EC_UNKNOWN_ERROR, "sync_agent_ec_queuing_rule_spec_s is NULL !!");
95 sync_agent_ec_error_e ec_error = SYNC_AGENT_EC_OK;
97 ec_task_info_pool_t *task_info_pool = pool->task_info_pool;
100 util_id_provider_error_e id_error = UTIL_ID_PROVIDER_OK;
101 sync_agent_ec_uint new_id = 0;
103 id_error = util_provide_id(pool->id_provider, &new_id);
104 if (id_error != UTIL_ID_PROVIDER_OK) {
105 if (id_error == UTIL_ID_PROVIDER_NOT_ENOUGH_ID) {
106 ec_error = SYNC_AGENT_EC_OUT_OF_FREE_ID;
108 ec_error = SYNC_AGENT_EC_UNKNOWN_ERROR;
113 /* TODO : error handling */
115 /* add queuing_rule_spec info to each task_specs */
116 ec_progress_blocking_entity_t *entity = NULL;
117 ec_task_info_t *task_info = NULL;
119 for (iter = spec->progress_blocking_entity_list; iter != NULL; iter = g_slist_next(iter)) {
120 entity = (ec_progress_blocking_entity_t *) (iter->data);
122 task_info = ec_task_info_pool_search_task_info(task_info_pool, entity->root_task_spec_id);
123 ec_error = ec_task_info_add_progress_blocking_entity(task_info, entity);
124 if (ec_error != SYNC_AGENT_EC_OK) {
126 GSList *iter2 = NULL;
127 ec_progress_blocking_entity_t *pEntity2 = NULL;
128 for (iter2 = spec->progress_blocking_entity_list; iter2 != iter; iter2 = g_slist_next(iter2)) {
129 pEntity2 = (ec_progress_blocking_entity_t *) (iter2->data);
130 ec_task_info_remove_blocking_entity(task_info, pEntity2);
133 assert(UTIL_ID_PROVIDER_OK == util_delete_id(pool->id_provider, new_id));
138 g_hash_table_insert(pool->queuing_rule_spec_hash, (gpointer) ((intptr_t)new_id), spec);
140 *queuing_rule_id = new_id;
147 sync_agent_ec_queuing_rule_spec_s *ec_queueing_rule_spec_pool_search_queuing_rule_spec(ec_queuing_rule_spec_pool_t * pool, sync_agent_ec_uint queuing_rule_id)
151 retvm_if(pool == NULL, NULL, "ec_queuing_rule_spec_pool_t is NULL !!");
153 sync_agent_ec_queuing_rule_spec_s *queuing_rule_spec = g_hash_table_lookup(pool->queuing_rule_spec_hash, (gconstpointer) ((intptr_t)queuing_rule_id));
157 return queuing_rule_spec;