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>
32 struct _notification_list {
33 notification_list_h prev;
34 notification_list_h next;
39 notification_list_h _notification_list_create(void)
41 notification_list_h list = NULL;
43 list = (notification_list_h) malloc(sizeof(struct _notification_list));
45 NOTIFICATION_ERR("NO MEMORY");
57 EXPORT_API notification_list_h notification_list_get_head(notification_list_h list)
59 notification_list_h cur_list = NULL;
62 NOTIFICATION_ERR("INVALID DATA : list == NULL");
63 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
69 while (cur_list->prev != NULL) {
70 cur_list = cur_list->prev;
73 set_last_result(NOTIFICATION_ERROR_NONE);
77 EXPORT_API notification_list_h notification_list_get_tail(notification_list_h list)
79 notification_list_h cur_list = NULL;
82 NOTIFICATION_ERR("INVALID DATA : list == NULL");
83 set_last_result(NOTIFICATION_ERROR_INVALID_PARAMETER);
89 while (cur_list->next != NULL) {
90 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;
218 cur_list = cur_list->next;
221 if (prev_list != NULL) {
222 return notification_list_get_head(prev_list);
223 } else if (next_list != NULL) {
230 EXPORT_API int notification_get_list(notification_type_e type,
232 notification_list_h *list)
234 notification_list_h get_list = NULL;
238 return NOTIFICATION_ERROR_INVALID_PARAMETER;
241 ret = notification_noti_get_grouping_list(type, count, &get_list);
242 if (ret != NOTIFICATION_ERROR_NONE) {
248 return NOTIFICATION_ERROR_NONE;
251 EXPORT_API int notification_get_detail_list(const char *pkgname,
255 notification_list_h *list)
257 notification_list_h get_list = NULL;
261 return NOTIFICATION_ERROR_INVALID_PARAMETER;
265 notification_noti_get_detail_list(pkgname, group_id, priv_id, count,
267 if (ret != NOTIFICATION_ERROR_NONE) {
273 return NOTIFICATION_ERROR_NONE;
276 EXPORT_API int notification_free_list(notification_list_h list)
278 notification_list_h cur_list = NULL;
279 notification_h noti = NULL;
282 return NOTIFICATION_ERROR_INVALID_PARAMETER;
285 cur_list = notification_list_get_head(list);
287 while (cur_list != NULL) {
288 noti = notification_list_get_data(cur_list);
289 cur_list = notification_list_remove(cur_list, noti);
291 notification_free(noti);
294 return NOTIFICATION_ERROR_NONE;