2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "quickpanel-ui.h"
19 #include "list_util.h"
20 #include "noti_node.h"
22 static void _noti_node_free(noti_node_item *node);
24 HAPI void noti_node_create(noti_node **handle)
26 retif(handle == NULL, , "Invalid parameter!");
28 *handle = (noti_node *)malloc(sizeof(noti_node));
30 if (*handle != NULL) {
31 (*handle)->table = g_hash_table_new_full(g_direct_hash, g_direct_equal,
33 (GDestroyNotify)_noti_node_free);
35 (*handle)->n_ongoing = 0;
36 (*handle)->n_noti = 0;
42 HAPI void noti_node_destroy(noti_node **handle)
44 retif(handle == NULL, , "Invalid parameter!");
45 retif(*handle == NULL, , "Invalid parameter!");
47 g_hash_table_remove_all((*handle)->table);
48 g_hash_table_destroy((*handle)->table);
49 (*handle)->table = NULL;
55 HAPI noti_node_item *noti_node_add(noti_node *handle, notification_h noti, void *view)
58 notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
59 noti_node_item *node = NULL;
61 retif(handle == NULL || noti == NULL, NULL, "Invalid parameter!");
63 if (notification_get_id(noti, NULL, &priv_id) == NOTIFICATION_ERROR_NONE) {
64 node = malloc(sizeof(noti_node_item));
66 ERR("fail to alloc item");
73 g_hash_table_insert(handle->table, GINT_TO_POINTER(priv_id), (gpointer *)node);
75 notification_get_type(noti, ¬i_type);
77 if (noti_type == NOTIFICATION_TYPE_NOTI)
79 else if (noti_type == NOTIFICATION_TYPE_ONGOING)
88 HAPI void noti_node_remove(noti_node *handle, int priv_id)
90 notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
92 retif(handle == NULL, , "Invalid parameter!");
93 retif(handle->table == NULL, , "Invalid parameter!");
95 noti_node_item *item = noti_node_get(handle, priv_id);
98 if (item->noti != NULL) {
99 notification_get_type(item->noti, ¬i_type);
101 if (noti_type == NOTIFICATION_TYPE_NOTI)
103 else if (noti_type == NOTIFICATION_TYPE_ONGOING)
107 notification_free(item->noti);
111 if (g_hash_table_remove(handle->table, GINT_TO_POINTER(priv_id)))
113 INFO("success to remove %d", priv_id);
118 HAPI noti_node_item *noti_node_get(noti_node *handle, int priv_id)
120 retif(handle == NULL, NULL, "Invalid parameter!");
121 retif(handle->table == NULL, NULL, "Invalid parameter!");
123 return (noti_node_item *)g_hash_table_lookup
124 (handle->table, GINT_TO_POINTER(priv_id));
127 HAPI int noti_node_get_item_count(noti_node *handle, notification_type_e noti_type)
129 retif(handle == NULL, 0, "Invalid parameter!");
131 if (noti_type == NOTIFICATION_TYPE_NOTI)
132 return handle->n_noti;
133 else if (noti_type == NOTIFICATION_TYPE_ONGOING)
134 return handle->n_ongoing;
139 static void _noti_node_free(noti_node_item *node)
141 retif(node == NULL, , "Invalid parameter!");
143 DBG("item_node is freed:%p", node);