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.
18 #include <assert.h> /* TODO : replace with framework assert */
21 #include "utility/sync_util.h"
22 #include "engine-controller/graph_edge_pool.h"
23 #include "engine-controller/hash_set.h"
25 #ifndef SYNC_AGENT_LOG
27 #define LOG_TAG "AF_EC"
30 struct ec_graph_edge_pool_s {
31 GHashTable *from_graph_node_hash; /* containing ec_hash_set_t* to_graph_nodes */
34 ec_graph_edge_pool_t *ec_graph_edge_pool_new(void)
38 ec_graph_edge_pool_t *pool = (ec_graph_edge_pool_t *) calloc(1, sizeof(ec_graph_edge_pool_t));
43 pool->from_graph_node_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
44 if (pool->from_graph_node_hash == NULL) {
53 ec_graph_edge_pool_free(pool);
57 void ec_graph_edge_pool_free(ec_graph_edge_pool_t * pool)
62 if (pool->from_graph_node_hash != NULL) {
63 g_hash_table_destroy(pool->from_graph_node_hash);
71 /* return add success or not */
72 /* if already exist edge added, then return false */
73 sync_agent_ec_boolean ec_graph_edge_pool_add_edge(ec_graph_edge_pool_t * pool, sync_agent_ec_constpointer from_node, sync_agent_ec_constpointer to_node)
77 sync_agent_ec_boolean add_success = false;
78 ec_hash_set_t *to_node_set = NULL;
80 to_node_set = g_hash_table_lookup(pool->from_graph_node_hash, from_node);
81 if (to_node_set == NULL) {
82 to_node_set = ec_hash_set_create();
83 if (to_node_set == NULL) {
86 g_hash_table_insert(pool->from_graph_node_hash, (gpointer) from_node, (gpointer) to_node_set);
89 add_success = ec_hash_set_add(to_node_set, to_node);
96 GList *ec_graph_edge_pool_query_to_node_list(ec_graph_edge_pool_t * pool, sync_agent_ec_constpointer from_node)
100 retvm_if(pool == NULL, NULL, "ec_graph_edge_pool_t is NULL !!");
102 GList *to_nodes_list = NULL;
104 ec_hash_set_t *to_node_set = NULL;
105 to_node_set = g_hash_table_lookup(pool->from_graph_node_hash, from_node);
106 if (to_node_set == NULL) {
110 to_nodes_list = ec_hash_set_get_element_list(to_node_set);
116 return to_nodes_list;