remove left-over usages of an anonymous GBoxed typedef.
[platform/upstream/glib.git] / gobject / gobjectnotifyqueue.c
1 /* GObject - GLib Type, Object, Parameter and Signal Library
2  * Copyright (C) 1998-1999, 2000-2001 Tim Janik and Red Hat, Inc.
3  *
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 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.
13  *
14  * You should have received a copy of the GNU Lesser General
15  * Public License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19 #ifndef __G_NOTIFY_H__
20 #define __G_NOTIFY_H__
21
22 #include        <gobject/gobject.h>
23
24 G_BEGIN_DECLS
25
26
27 /* --- typedefs --- */
28 typedef struct _GObjectNotifyContext          GObjectNotifyContext;
29 typedef struct _GObjectNotifyQueue            GObjectNotifyQueue;
30 typedef void (*GObjectNotifyQueueDispatcher) (GObject     *object,
31                                               guint        n_pspecs,
32                                               GParamSpec **pspecs);
33
34
35 /* --- structures --- */
36 struct _GObjectNotifyContext
37 {
38   GQuark                       quark_notify_queue;
39   GObjectNotifyQueueDispatcher dispatcher;
40   GTrashStack                 *nqueue_trash;
41 };
42 struct _GObjectNotifyQueue
43 {
44   GObjectNotifyContext *context;
45   GSList               *pspecs;
46   guint                 n_pspecs;
47   guint                 freeze_count;
48 };
49
50
51 /* --- functions --- */
52 static void
53 g_object_notify_queue_free (gpointer data)
54 {
55   GObjectNotifyQueue *nqueue = data;
56
57   g_slist_free (nqueue->pspecs);
58   g_trash_stack_push (&nqueue->context->nqueue_trash, nqueue);
59 }
60
61 static inline GObjectNotifyQueue*
62 g_object_notify_queue_freeze (GObject              *object,
63                               GObjectNotifyContext *context)
64 {
65   GObjectNotifyQueue *nqueue;
66
67   nqueue = g_datalist_id_get_data (&object->qdata, context->quark_notify_queue);
68   if (!nqueue)
69     {
70       nqueue = g_trash_stack_pop (&context->nqueue_trash);
71       if (!nqueue)
72         {
73           guint i;
74
75           nqueue = g_new (GObjectNotifyQueue, 16);
76           for (i = 0; i < 15; i++)
77             g_trash_stack_push (&context->nqueue_trash, nqueue++);
78         }
79       memset (nqueue, 0, sizeof (*nqueue));
80       nqueue->context = context;
81       g_datalist_id_set_data_full (&object->qdata, context->quark_notify_queue,
82                                    nqueue, g_object_notify_queue_free);
83     }
84   nqueue->freeze_count++;
85
86   return nqueue;
87 }
88
89 static inline void
90 g_object_notify_queue_thaw (GObject            *object,
91                             GObjectNotifyQueue *nqueue)
92 {
93   GObjectNotifyContext *context = nqueue->context;
94   GParamSpec *pspecs_mem[16], **pspecs, **free_me = NULL;
95   GSList *slist;
96   guint n_pspecs = 0;
97
98   g_return_if_fail (nqueue->freeze_count > 0);
99
100   nqueue->freeze_count--;
101   if (nqueue->freeze_count)
102     return;
103   g_return_if_fail (object->ref_count > 0);
104
105   pspecs = nqueue->n_pspecs > 16 ? free_me = g_new (GParamSpec*, nqueue->n_pspecs) : pspecs_mem;
106   for (slist = nqueue->pspecs; slist; slist = slist->next)
107     {
108       GParamSpec *pspec = slist->data;
109       gint i = 0;
110
111       /* dedup, make pspecs in the list unique */
112     redo_dedup_check:
113       if (pspecs[i] == pspec)
114         continue;
115       if (++i < n_pspecs)
116         goto redo_dedup_check;
117
118       pspecs[n_pspecs++] = pspec;
119     }
120   g_datalist_id_set_data (&object->qdata, context->quark_notify_queue, NULL);
121
122   if (n_pspecs)
123     context->dispatcher (object, n_pspecs, pspecs);
124   g_free (free_me);
125 }
126
127 static inline void
128 g_object_notify_queue_clear (GObject            *object,
129                              GObjectNotifyQueue *nqueue)
130 {
131   g_return_if_fail (nqueue->freeze_count > 0);
132
133   g_slist_free (nqueue->pspecs);
134   nqueue->pspecs = NULL;
135   nqueue->n_pspecs = 0;
136 }
137
138 static inline void
139 g_object_notify_queue_add (GObject            *object,
140                            GObjectNotifyQueue *nqueue,
141                            GParamSpec         *pspec)
142 {
143   if (pspec->flags & G_PARAM_READABLE)
144     {
145       /* we do the deduping in _thaw */
146       nqueue->pspecs = g_slist_prepend (nqueue->pspecs, pspec);
147       nqueue->n_pspecs++;
148     }
149 }
150
151 static inline GObjectNotifyQueue*
152 g_object_notify_queue_from_object (GObject              *object,
153                                    GObjectNotifyContext *context)
154 {
155   return g_datalist_id_get_data (&object->qdata, context->quark_notify_queue);
156 }
157
158
159 G_END_DECLS
160
161 #endif /* __G_OBJECT_H__ */