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.
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
25 #include "swfdec_function_list.h"
27 typedef struct _SwfdecFunctionListEntry SwfdecFunctionListEntry
;
28 struct _SwfdecFunctionListEntry
{
31 GDestroyNotify destroy
;
35 swfdec_function_list_clear (SwfdecFunctionList
*list
)
39 g_return_if_fail (list
!= NULL
);
41 for (walk
= list
->list
; walk
; walk
= walk
->next
) {
42 SwfdecFunctionListEntry
*entry
= walk
->data
;
44 entry
->destroy (entry
->data
);
45 g_slice_free (SwfdecFunctionListEntry
, entry
);
47 g_list_free (list
->list
);
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
);
63 entry
->destroy
= destroy
;
65 list
->list
= g_list_append (list
->list
, entry
);
69 swfdec_function_list_entry_compare (gconstpointer a
, gconstpointer b
)
71 a
= ((const SwfdecFunctionListEntry
*) a
)->data
;
72 b
= ((const SwfdecFunctionListEntry
*) b
)->data
;
82 swfdec_function_list_remove (SwfdecFunctionList
*list
, gpointer data
)
84 SwfdecFunctionListEntry entry
= { NULL
, data
, NULL
};
85 SwfdecFunctionListEntry
*e
;
88 g_return_if_fail (list
!= NULL
);
90 node
= g_list_find_custom (list
->list
, &entry
,
91 swfdec_function_list_entry_compare
);
95 g_slice_free (SwfdecFunctionListEntry
, e
);
96 list
->list
= g_list_delete_link (list
->list
, node
);
100 swfdec_function_list_execute (SwfdecFunctionList
*list
, gpointer data
)
102 SwfdecFunctionListEntry
*entry
;
105 g_return_if_fail (list
!= NULL
);
107 for (walk
= list
->list
; walk
; walk
= walk
->next
) {
109 entry
->func (entry
->data
, data
);
114 swfdec_function_list_execute_and_clear (SwfdecFunctionList
*list
, gpointer data
)
116 SwfdecFunctionListEntry
*entry
;
119 g_return_if_fail (list
!= NULL
);
123 for (walk
= old
; walk
; walk
= walk
->next
) {
125 entry
->func (entry
->data
, data
);
127 entry
->destroy (entry
->data
);
128 g_slice_free (SwfdecFunctionListEntry
, entry
);