2 * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "quickpanel-ui.h"
21 #include "list_util.h"
22 #include "noti_node.h"
24 static void _noti_node_free(noti_node_item *node);
26 HAPI void noti_node_create(noti_node **handle)
28 retif(handle == NULL, , "Invalid parameter!");
30 *handle = (noti_node *)malloc(sizeof(noti_node));
32 if (*handle != NULL) {
33 (*handle)->table = g_hash_table_new_full(g_direct_hash, g_direct_equal,
35 (GDestroyNotify)_noti_node_free);
37 (*handle)->n_ongoing = 0;
38 (*handle)->n_noti = 0;
44 HAPI void noti_node_destroy(noti_node **handle)
46 retif(handle == NULL, , "Invalid parameter!");
47 retif(*handle == NULL, , "Invalid parameter!");
49 g_hash_table_remove_all((*handle)->table);
50 g_hash_table_destroy((*handle)->table);
51 (*handle)->table = NULL;
57 HAPI noti_node_item *noti_node_add(noti_node *handle, notification_h noti, void *view)
60 notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
61 noti_node_item *node = NULL;
63 retif(handle == NULL || noti == NULL, NULL, "Invalid parameter!");
65 if (notification_get_id(noti, NULL, &priv_id) == NOTIFICATION_ERROR_NONE) {
66 node = malloc(sizeof(noti_node_item));
68 ERR("fail to alloc item");
75 g_hash_table_insert(handle->table, GINT_TO_POINTER(priv_id), (gpointer *)node);
77 notification_get_type(noti, ¬i_type);
79 if (noti_type == NOTIFICATION_TYPE_NOTI)
81 else if (noti_type == NOTIFICATION_TYPE_ONGOING)
84 DBG("n_noti = [%d] n_ongoing = [%d]", handle->n_noti, handle->n_ongoing);
91 HAPI void noti_node_remove(noti_node *handle, int priv_id)
93 notification_type_e noti_type = NOTIFICATION_TYPE_NONE;
95 retif(handle == NULL, , "Invalid parameter!");
96 retif(handle->table == NULL, , "Invalid parameter!");
98 noti_node_item *item = noti_node_get(handle, priv_id);
101 if (item->noti != NULL) {
102 notification_get_type(item->noti, ¬i_type);
104 if (noti_type == NOTIFICATION_TYPE_NOTI)
106 else if (noti_type == NOTIFICATION_TYPE_ONGOING)
110 notification_free(item->noti);
114 if (g_hash_table_remove(handle->table, GINT_TO_POINTER(priv_id)))
116 DBG("success to remove %d", priv_id);
121 HAPI void noti_node_remove_all(noti_node *handle)
123 retif(handle == NULL, , "Invalid parameter!");
124 retif(handle->table == NULL, , "Invalid parameter!");
126 g_hash_table_remove_all(handle->table);
128 handle->n_ongoing = 0;
129 DBG("all the nodes are removed");
132 HAPI noti_node_item *noti_node_get(noti_node *handle, int priv_id)
134 retif(handle == NULL, NULL, "Invalid parameter!");
135 retif(handle->table == NULL, NULL, "Invalid parameter!");
137 return (noti_node_item *)g_hash_table_lookup
138 (handle->table, GINT_TO_POINTER(priv_id));
141 HAPI int noti_node_get_item_count(noti_node *handle, notification_type_e noti_type)
143 retif(handle == NULL, 0, "Invalid parameter!");
145 DBG("n_noti %d , n_ongoing %d ", handle->n_noti, handle->n_ongoing);
147 if (noti_type == NOTIFICATION_TYPE_NOTI)
148 return handle->n_noti;
149 else if (noti_type == NOTIFICATION_TYPE_ONGOING)
150 return handle->n_ongoing;
151 else if (noti_type == NOTIFICATION_TYPE_NONE)
152 return handle->n_noti + handle->n_ongoing;
157 static void _noti_node_free(noti_node_item *node)
159 retif(node == NULL, , "Invalid parameter!");
161 DBG("item_node is freed:%p", node);