4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
26 #include <notification.h>
27 #include <notification_list.h>
28 #include <notification_noti.h>
29 #include <notification_debug.h>
30 #include <notification_private.h>
31 #include <notification_ipc.h>
34 struct _notification_list {
35 notification_list_h prev;
36 notification_list_h next;
41 notification_list_h _notification_list_create(void)
43 notification_list_h list = NULL;
45 list = (notification_list_h) malloc(sizeof(struct _notification_list));
47 NOTIFICATION_ERR("NO MEMORY");
59 EXPORT_API notification_list_h notification_list_get_head(notification_list_h list)
61 notification_list_h cur_list = NULL;
64 NOTIFICATION_ERR("INVALID DATA : list == NULL");
65 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
71 while (cur_list->prev != NULL)
72 cur_list = cur_list->prev;
74 set_last_result(NOTIFICATION_ERROR_NONE);
78 EXPORT_API notification_list_h notification_list_get_tail(notification_list_h list)
80 notification_list_h cur_list = NULL;
83 NOTIFICATION_ERR("INVALID DATA : list == NULL");
84 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
90 while (cur_list->next != NULL)
91 cur_list = cur_list->next;
93 set_last_result(NOTIFICATION_ERROR_NONE);
97 EXPORT_API notification_list_h notification_list_get_prev(notification_list_h list)
99 notification_list_h cur_list = NULL;
102 NOTIFICATION_ERR("INVALID DATA : list == NULL");
103 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
109 set_last_result(NOTIFICATION_ERROR_NONE);
110 return cur_list->prev;
113 EXPORT_API notification_list_h notification_list_get_next(notification_list_h list)
115 notification_list_h cur_list = NULL;
118 NOTIFICATION_ERR("INVALID DATA : list == NULL");
119 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
125 set_last_result(NOTIFICATION_ERROR_NONE);
126 return cur_list->next;
129 EXPORT_API notification_h notification_list_get_data(notification_list_h list)
131 notification_list_h cur_list = NULL;
134 NOTIFICATION_ERR("INVALID DATA : list == NULL");
135 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
141 set_last_result(NOTIFICATION_ERROR_NONE);
142 return cur_list->noti;
145 EXPORT_API notification_list_h notification_list_append(notification_list_h list,
148 notification_list_h new_list = NULL;
149 notification_list_h cur_list = NULL;
152 NOTIFICATION_ERR("INVALID DATA : data == NULL");
153 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
158 cur_list = notification_list_get_tail(list);
160 new_list = _notification_list_create();
161 if (new_list == NULL) {
162 NOTIFICATION_ERR("NO MEMORY");
163 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
167 cur_list->next = new_list;
168 new_list->prev = cur_list;
170 new_list->noti = noti;
172 cur_list = _notification_list_create();
173 if (cur_list == NULL) {
174 NOTIFICATION_ERR("NO MEMORY");
175 set_last_result(NOTIFICATION_ERROR_OUT_OF_MEMORY);
180 new_list->noti = noti;
183 set_last_result(NOTIFICATION_ERROR_NONE);
187 EXPORT_API notification_list_h notification_list_remove(notification_list_h list,
190 notification_list_h cur_list = NULL;
191 notification_list_h prev_list = NULL;
192 notification_list_h next_list = NULL;
194 cur_list = notification_list_get_head(list);
195 while (cur_list != NULL) {
196 if (cur_list->noti == noti) {
198 prev_list = cur_list->prev;
199 next_list = cur_list->next;
201 if (next_list != NULL) {
202 if (prev_list != NULL) {
203 prev_list->next = next_list;
204 next_list->prev = prev_list;
206 next_list->prev = NULL;
209 if (prev_list != NULL)
210 prev_list->next = NULL;
217 cur_list = cur_list->next;
220 if (prev_list != NULL)
221 return notification_list_get_head(prev_list);
222 else if (next_list != NULL)
228 EXPORT_API int notification_get_list(notification_type_e type,
230 notification_list_h *list)
232 notification_list_h get_list = NULL;
236 return NOTIFICATION_ERROR_INVALID_PARAMETER;
238 ret = notification_ipc_request_load_noti_grouping_list(type, count, &get_list);
239 if (ret != NOTIFICATION_ERROR_NONE)
242 if (get_list != NULL)
243 *list = notification_list_get_head(get_list);
245 return NOTIFICATION_ERROR_NONE;
248 EXPORT_API int notification_get_detail_list(const char *pkgname,
252 notification_list_h *list)
254 notification_list_h get_list = NULL;
257 if (list == NULL || pkgname == NULL)
258 return NOTIFICATION_ERROR_INVALID_PARAMETER;
261 notification_ipc_request_load_noti_detail_list(pkgname, group_id, priv_id, count,
263 if (ret != NOTIFICATION_ERROR_NONE)
266 if (get_list != NULL)
267 *list = notification_list_get_head(get_list);
269 return NOTIFICATION_ERROR_NONE;
272 EXPORT_API int notification_free_list(notification_list_h list)
274 notification_list_h cur_list = NULL;
275 notification_h noti = NULL;
278 return NOTIFICATION_ERROR_INVALID_PARAMETER;
280 cur_list = notification_list_get_head(list);
282 while (cur_list != NULL) {
283 noti = notification_list_get_data(cur_list);
284 cur_list = notification_list_remove(cur_list, noti);
286 notification_free(noti);
289 return NOTIFICATION_ERROR_NONE;