summaryrefslogtreecommitdiff
path: root/src/notification_list.c
blob: db28842fb77d49c6a869b15bcda97e895a1381df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*
 *  libnotification
 *
 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Contact: Jeonghoon Park <jh1979.park@samsung.com>, Youngjoo Park <yjoo93.park@samsung.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include <stdlib.h>

#include <notification.h>
#include <notification_list.h>
#include <notification_debug.h>
#include <notification_internal.h>

struct _notification_list {
	notification_list_h prev;
	notification_list_h next;

	notification_h noti;
};

notification_list_h _notification_list_create(void)
{
	notification_list_h list = NULL;

	list = (notification_list_h) malloc(sizeof(struct _notification_list));
	if (list == NULL) {
		NOTIFICATION_ERR("NO MEMORY");
		return NULL;
	}

	list->prev = NULL;
	list->next = NULL;

	list->noti = NULL;

	return list;
}

EXPORT_API notification_list_h notification_list_get_head(notification_list_h list)
{
	notification_list_h cur_list = NULL;

	if (list == NULL) {
		NOTIFICATION_ERR("INVALID DATA : list == NULL");
		return NULL;
	}

	cur_list = list;

	while (cur_list->prev != NULL) {
		cur_list = cur_list->prev;
	}

	return cur_list;
}

EXPORT_API notification_list_h notification_list_get_tail(notification_list_h list)
{
	notification_list_h cur_list = NULL;

	if (list == NULL) {
		NOTIFICATION_ERR("INVALID DATA : list == NULL");
		return NULL;
	}

	cur_list = list;

	while (cur_list->next != NULL) {
		cur_list = cur_list->next;
	}

	return cur_list;
}

EXPORT_API notification_list_h notification_list_get_prev(notification_list_h list)
{
	notification_list_h cur_list = NULL;

	if (list == NULL) {
		NOTIFICATION_ERR("INVALID DATA : list == NULL");
		return NULL;
	}

	cur_list = list;

	return cur_list->prev;
}

EXPORT_API notification_list_h notification_list_get_next(notification_list_h list)
{
	notification_list_h cur_list = NULL;

	if (list == NULL) {
		NOTIFICATION_ERR("INVALID DATA : list == NULL");
		return NULL;
	}

	cur_list = list;

	return cur_list->next;
}

EXPORT_API notification_h notification_list_get_data(notification_list_h list)
{
	notification_list_h cur_list = NULL;

	if (list == NULL) {
		NOTIFICATION_ERR("INVALID DATA : list == NULL");
		return NULL;
	}

	cur_list = list;

	return cur_list->noti;
}

EXPORT_API notification_list_h notification_list_append(notification_list_h list,
							notification_h noti)
{
	notification_list_h new_list = NULL;
	notification_list_h cur_list = NULL;

	if (noti == NULL) {
		NOTIFICATION_ERR("INVALID DATA : data == NULL");
		return NULL;
	}

	if (list != NULL) {
		cur_list = notification_list_get_tail(list);

		new_list = _notification_list_create();
		if (new_list == NULL) {
			NOTIFICATION_ERR("NO MEMORY");
			return NULL;
		}

		cur_list->next = new_list;
		new_list->prev = cur_list;

		new_list->noti = noti;
	} else {
		cur_list = _notification_list_create();
		if (cur_list == NULL) {
			NOTIFICATION_ERR("NO MEMORY");
			return NULL;
		}

		new_list = cur_list;
		new_list->noti = noti;
	}

	return new_list;
}

EXPORT_API notification_list_h notification_list_remove(notification_list_h list,
							notification_h noti)
{
	notification_list_h cur_list = NULL;
	notification_list_h prev_list = NULL;
	notification_list_h next_list = NULL;

	cur_list = notification_list_get_head(list);
	while (cur_list != NULL) {
		if (cur_list->noti == noti) {
			//remove
			prev_list = cur_list->prev;
			next_list = cur_list->next;

			if (next_list != NULL) {
				if (prev_list != NULL) {
					prev_list->next = next_list;
					next_list->prev = prev_list;
				} else {
					next_list->prev = NULL;
				}
			} else {
				if (prev_list != NULL) {
					prev_list->next = NULL;
				}
			}

			free(cur_list);
			break;
		}

		cur_list = cur_list->next;
	}

	if (prev_list != NULL) {
		return notification_list_get_head(prev_list);
	} else if (next_list != NULL) {
		return next_list;
	}

	return NULL;
}