2 * Copyright (c) 2000 - 2016 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.
21 #include <notification.h>
22 #include <notification_list.h>
23 #include <notification_noti.h>
24 #include <notification_debug.h>
25 #include <notification_private.h>
26 #include <notification_ipc.h>
29 struct _notification_list {
30 notification_list_h prev;
31 notification_list_h next;
36 notification_list_h _notification_list_create(void)
38 notification_list_h list = NULL;
40 list = (notification_list_h) malloc(sizeof(struct _notification_list));
42 NOTIFICATION_ERR("NO MEMORY");
54 EXPORT_API notification_list_h notification_list_get_head(notification_list_h list)
56 notification_list_h cur_list = NULL;
59 NOTIFICATION_ERR("INVALID DATA : list == NULL");
60 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
66 while (cur_list->prev != NULL)
67 cur_list = cur_list->prev;
69 set_last_result(NOTIFICATION_ERROR_NONE);
73 EXPORT_API notification_list_h notification_list_get_tail(notification_list_h list)
75 notification_list_h cur_list = NULL;
78 NOTIFICATION_ERR("INVALID DATA : list == NULL");
79 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
85 while (cur_list->next != NULL)
86 cur_list = cur_list->next;
88 set_last_result(NOTIFICATION_ERROR_NONE);
92 EXPORT_API notification_list_h notification_list_get_prev(notification_list_h list)
94 notification_list_h cur_list = NULL;
97 NOTIFICATION_ERR("INVALID DATA : list == NULL");
98 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
104 set_last_result(NOTIFICATION_ERROR_NONE);
105 return cur_list->prev;
108 EXPORT_API notification_list_h notification_list_get_next(notification_list_h list)
110 notification_list_h cur_list = NULL;
113 NOTIFICATION_ERR("INVALID DATA : list == NULL");
114 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
120 set_last_result(NOTIFICATION_ERROR_NONE);
121 return cur_list->next;
124 EXPORT_API notification_h notification_list_get_data(notification_list_h list)
126 notification_list_h cur_list = NULL;
129 NOTIFICATION_ERR("INVALID DATA : list == NULL");
130 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
136 set_last_result(NOTIFICATION_ERROR_NONE);
137 return cur_list->noti;
140 EXPORT_API notification_list_h notification_list_append(notification_list_h list,
143 notification_list_h new_list = NULL;
144 notification_list_h cur_list = NULL;
147 NOTIFICATION_ERR("INVALID DATA : data == NULL");
148 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
153 cur_list = notification_list_get_tail(list);
155 new_list = _notification_list_create();
156 if (new_list == NULL) {
157 NOTIFICATION_ERR("NO MEMORY");
158 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
162 cur_list->next = new_list;
163 new_list->prev = cur_list;
165 new_list->noti = noti;
167 cur_list = _notification_list_create();
168 if (cur_list == NULL) {
169 NOTIFICATION_ERR("NO MEMORY");
170 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
175 new_list->noti = noti;
178 set_last_result(NOTIFICATION_ERROR_NONE);
182 EXPORT_API notification_list_h notification_list_remove(notification_list_h list,
185 notification_list_h cur_list = NULL;
186 notification_list_h prev_list = NULL;
187 notification_list_h next_list = NULL;
189 cur_list = notification_list_get_head(list);
190 while (cur_list != NULL) {
191 if (cur_list->noti == noti) {
193 prev_list = cur_list->prev;
194 next_list = cur_list->next;
196 if (next_list != NULL) {
197 if (prev_list != NULL) {
198 prev_list->next = next_list;
199 next_list->prev = prev_list;
201 next_list->prev = NULL;
204 if (prev_list != NULL)
205 prev_list->next = NULL;
212 cur_list = cur_list->next;
215 if (prev_list != NULL)
216 return notification_list_get_head(prev_list);
217 else if (next_list != NULL)
223 EXPORT_API int notification_get_list(notification_type_e type,
225 notification_list_h *list)
227 notification_list_h get_list = NULL;
231 return NOTIFICATION_ERROR_INVALID_PARAMETER;
233 ret = notification_ipc_request_load_noti_grouping_list(type, count, &get_list);
234 if (ret != NOTIFICATION_ERROR_NONE)
237 if (get_list != NULL)
238 *list = notification_list_get_head(get_list);
240 return NOTIFICATION_ERROR_NONE;
243 EXPORT_API int notification_get_detail_list(const char *pkgname,
247 notification_list_h *list)
249 notification_list_h get_list = NULL;
252 if (list == NULL || pkgname == NULL)
253 return NOTIFICATION_ERROR_INVALID_PARAMETER;
256 notification_ipc_request_load_noti_detail_list(pkgname, group_id, priv_id, count,
258 if (ret != NOTIFICATION_ERROR_NONE)
261 if (get_list != NULL)
262 *list = notification_list_get_head(get_list);
264 return NOTIFICATION_ERROR_NONE;
267 EXPORT_API int notification_free_list(notification_list_h list)
269 notification_list_h cur_list = NULL;
270 notification_h noti = NULL;
273 return NOTIFICATION_ERROR_INVALID_PARAMETER;
275 cur_list = notification_list_get_head(list);
277 while (cur_list != NULL) {
278 noti = notification_list_get_data(cur_list);
279 cur_list = notification_list_remove(cur_list, noti);
281 notification_free(noti);
284 return NOTIFICATION_ERROR_NONE;