Split glib.h into many header files mostly according to the resp.
[platform/upstream/glib.git] / glib / ghook.h
1 /* GLIB - Library of useful routines for C programming
2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
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 Public
15  * 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
20 /*
21  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GLib Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
25  */
26
27 #ifndef __G_HOOK_H__
28 #define __G_HOOK_H__
29
30 #include <gmem.h>
31
32 G_BEGIN_DECLS
33
34 typedef struct _GHook           GHook;
35 typedef struct _GHookList       GHookList;
36
37 typedef gint            (*GHookCompareFunc)     (GHook          *new_hook,
38                                                  GHook          *sibling);
39 typedef gboolean        (*GHookFindFunc)        (GHook          *hook,
40                                                  gpointer        data);
41 typedef void            (*GHookMarshaller)      (GHook          *hook,
42                                                  gpointer        data);
43 typedef gboolean        (*GHookCheckMarshaller) (GHook          *hook,
44                                                  gpointer        data);
45 typedef void            (*GHookFunc)            (gpointer        data);
46 typedef gboolean        (*GHookCheckFunc)       (gpointer        data);
47 typedef void            (*GHookFreeFunc)        (GHookList      *hook_list,
48                                                  GHook          *hook);
49
50 /* Callback maintenance functions
51  */
52 #define G_HOOK_FLAG_USER_SHIFT  (4)
53 typedef enum
54 {
55   G_HOOK_FLAG_ACTIVE    = 1 << 0,
56   G_HOOK_FLAG_IN_CALL   = 1 << 1,
57   G_HOOK_FLAG_MASK      = 0x0f
58 } GHookFlagMask;
59
60 #define G_HOOK_DEFERRED_DESTROY ((GHookFreeFunc) 0x01)
61
62 struct _GHookList
63 {
64   guint          seq_id;
65   guint          hook_size;
66   guint          is_setup : 1;
67   GHook         *hooks;
68   GMemChunk     *hook_memchunk;
69   GHookFreeFunc  hook_free; /* virtual function */
70   GHookFreeFunc  hook_destroy; /* virtual function */
71 };
72
73 struct _GHook
74 {
75   gpointer       data;
76   GHook         *next;
77   GHook         *prev;
78   guint          ref_count;
79   guint          hook_id;
80   guint          flags;
81   gpointer       func;
82   GDestroyNotify destroy;
83 };
84
85 #define G_HOOK_ACTIVE(hook)             ((((GHook*) hook)->flags & \
86                                           G_HOOK_FLAG_ACTIVE) != 0)
87 #define G_HOOK_IN_CALL(hook)            ((((GHook*) hook)->flags & \
88                                           G_HOOK_FLAG_IN_CALL) != 0)
89 #define G_HOOK_IS_VALID(hook)           (((GHook*) hook)->hook_id != 0 && \
90                                          G_HOOK_ACTIVE (hook))
91 #define G_HOOK_IS_UNLINKED(hook)        (((GHook*) hook)->next == NULL && \
92                                          ((GHook*) hook)->prev == NULL && \
93                                          ((GHook*) hook)->hook_id == 0 && \
94                                          ((GHook*) hook)->ref_count == 0)
95
96 void     g_hook_list_init               (GHookList              *hook_list,
97                                          guint                   hook_size);
98 void     g_hook_list_clear              (GHookList              *hook_list);
99 GHook*   g_hook_alloc                   (GHookList              *hook_list);
100 void     g_hook_free                    (GHookList              *hook_list,
101                                          GHook                  *hook);
102 void     g_hook_ref                     (GHookList              *hook_list,
103                                          GHook                  *hook);
104 void     g_hook_unref                   (GHookList              *hook_list,
105                                          GHook                  *hook);
106 gboolean g_hook_destroy                 (GHookList              *hook_list,
107                                          guint                   hook_id);
108 void     g_hook_destroy_link            (GHookList              *hook_list,
109                                          GHook                  *hook);
110 void     g_hook_prepend                 (GHookList              *hook_list,
111                                          GHook                  *hook);
112 void     g_hook_insert_before           (GHookList              *hook_list,
113                                          GHook                  *sibling,
114                                          GHook                  *hook);
115 void     g_hook_insert_sorted           (GHookList              *hook_list,
116                                          GHook                  *hook,
117                                          GHookCompareFunc        func);
118 GHook*   g_hook_get                     (GHookList              *hook_list,
119                                          guint                   hook_id);
120 GHook*   g_hook_find                    (GHookList              *hook_list,
121                                          gboolean                need_valids,
122                                          GHookFindFunc           func,
123                                          gpointer                data);
124 GHook*   g_hook_find_data               (GHookList              *hook_list,
125                                          gboolean                need_valids,
126                                          gpointer                data);
127 GHook*   g_hook_find_func               (GHookList              *hook_list,
128                                          gboolean                need_valids,
129                                          gpointer                func);
130 GHook*   g_hook_find_func_data          (GHookList              *hook_list,
131                                          gboolean                need_valids,
132                                          gpointer                func,
133                                          gpointer                data);
134 /* return the first valid hook, and increment its reference count */
135 GHook*   g_hook_first_valid             (GHookList              *hook_list,
136                                          gboolean                may_be_in_call);
137 /* return the next valid hook with incremented reference count, and
138  * decrement the reference count of the original hook
139  */
140 GHook*   g_hook_next_valid              (GHookList              *hook_list,
141                                          GHook                  *hook,
142                                          gboolean                may_be_in_call);
143
144 /* GHookCompareFunc implementation to insert hooks sorted by their id */
145 gint     g_hook_compare_ids             (GHook                  *new_hook,
146                                          GHook                  *sibling);
147
148 /* convenience macros */
149 #define  g_hook_append( hook_list, hook )  \
150      g_hook_insert_before ((hook_list), NULL, (hook))
151
152 /* invoke all valid hooks with the (*GHookFunc) signature.
153  */
154 void     g_hook_list_invoke             (GHookList              *hook_list,
155                                          gboolean                may_recurse);
156 /* invoke all valid hooks with the (*GHookCheckFunc) signature,
157  * and destroy the hook if FALSE is returned.
158  */
159 void     g_hook_list_invoke_check       (GHookList              *hook_list,
160                                          gboolean                may_recurse);
161 /* invoke a marshaller on all valid hooks.
162  */
163 void     g_hook_list_marshal            (GHookList              *hook_list,
164                                          gboolean                may_recurse,
165                                          GHookMarshaller         marshaller,
166                                          gpointer                data);
167 void     g_hook_list_marshal_check      (GHookList              *hook_list,
168                                          gboolean                may_recurse,
169                                          GHookCheckMarshaller    marshaller,
170                                          gpointer                data);
171
172 G_END_DECLS
173
174 #endif /* __G_HOOK_H__ */
175