fix build for --disable-gtk-doc
[swfdec.git] / swfdec / swfdec_function_list.c
blob0b29b590246feb6d0f7511c16ba32eb8a2564b0c
1 /* Swfdec
2 * Copyright (C) 2008 Benjamin Otte <otte@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
24 #include <string.h>
25 #include "swfdec_function_list.h"
27 typedef struct _SwfdecFunctionListEntry SwfdecFunctionListEntry;
28 struct _SwfdecFunctionListEntry {
29 GFunc func;
30 gpointer data;
31 GDestroyNotify destroy;
34 void
35 swfdec_function_list_clear (SwfdecFunctionList *list)
37 GList *walk;
39 g_return_if_fail (list != NULL);
41 for (walk = list->list; walk; walk = walk->next) {
42 SwfdecFunctionListEntry *entry = walk->data;
43 if (entry->destroy)
44 entry->destroy (entry->data);
45 g_slice_free (SwfdecFunctionListEntry, entry);
47 g_list_free (list->list);
48 list->list = NULL;
51 void
52 swfdec_function_list_add (SwfdecFunctionList *list, GFunc func,
53 gpointer data, GDestroyNotify destroy)
55 SwfdecFunctionListEntry *entry;
57 g_return_if_fail (list != NULL);
58 g_return_if_fail (func);
60 entry = g_slice_new (SwfdecFunctionListEntry);
61 entry->func = func;
62 entry->data = data;
63 entry->destroy = destroy;
65 list->list = g_list_append (list->list, entry);
68 static int
69 swfdec_function_list_entry_compare (gconstpointer a, gconstpointer b)
71 a = ((const SwfdecFunctionListEntry *) a)->data;
72 b = ((const SwfdecFunctionListEntry *) b)->data;
74 if (a < b)
75 return -1;
76 if (a > b)
77 return 1;
78 return 0;
81 void
82 swfdec_function_list_remove (SwfdecFunctionList *list, gpointer data)
84 SwfdecFunctionListEntry entry = { NULL, data, NULL };
85 SwfdecFunctionListEntry *e;
86 GList *node;
88 g_return_if_fail (list != NULL);
90 node = g_list_find_custom (list->list, &entry,
91 swfdec_function_list_entry_compare);
92 e = node->data;
93 if (e->destroy)
94 e->destroy (data);
95 g_slice_free (SwfdecFunctionListEntry, e);
96 list->list = g_list_delete_link (list->list, node);
99 void
100 swfdec_function_list_execute (SwfdecFunctionList *list, gpointer data)
102 SwfdecFunctionListEntry *entry;
103 GList *walk;
105 g_return_if_fail (list != NULL);
107 for (walk = list->list; walk; walk = walk->next) {
108 entry = walk->data;
109 entry->func (entry->data, data);
113 void
114 swfdec_function_list_execute_and_clear (SwfdecFunctionList *list, gpointer data)
116 SwfdecFunctionListEntry *entry;
117 GList *old, *walk;
119 g_return_if_fail (list != NULL);
121 old = list->list;
122 list->list = NULL;
123 for (walk = old; walk; walk = walk->next) {
124 entry = walk->data;
125 entry->func (entry->data, data);
126 if (entry->destroy)
127 entry->destroy (entry->data);
128 g_slice_free (SwfdecFunctionListEntry, entry);
130 g_list_free (old);