Blame glib/glib/ghook.h

Packit db3073
/* GLIB - Library of useful routines for C programming
Packit db3073
 * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
Packit db3073
 *
Packit db3073
 * This library is free software; you can redistribute it and/or
Packit db3073
 * modify it under the terms of the GNU Lesser General Public
Packit db3073
 * License as published by the Free Software Foundation; either
Packit db3073
 * version 2 of the License, or (at your option) any later version.
Packit db3073
 *
Packit db3073
 * This library is distributed in the hope that it will be useful,
Packit db3073
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit db3073
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
Packit db3073
 * Lesser General Public License for more details.
Packit db3073
 *
Packit db3073
 * You should have received a copy of the GNU Lesser General Public
Packit db3073
 * License along with this library; if not, write to the
Packit db3073
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit db3073
 * Boston, MA 02111-1307, USA.
Packit db3073
 */
Packit db3073
Packit db3073
/*
Packit db3073
 * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
Packit db3073
 * file for a list of people on the GLib Team.  See the ChangeLog
Packit db3073
 * files for a list of changes.  These files are distributed with
Packit db3073
 * GLib at ftp://ftp.gtk.org/pub/gtk/.
Packit db3073
 */
Packit db3073
Packit db3073
#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
Packit db3073
#error "Only <glib.h> can be included directly."
Packit db3073
#endif
Packit db3073
Packit db3073
#ifndef __G_HOOK_H__
Packit db3073
#define __G_HOOK_H__
Packit db3073
Packit db3073
#include <glib/gmem.h>
Packit db3073
Packit db3073
G_BEGIN_DECLS
Packit db3073
Packit db3073
Packit db3073
/* --- typedefs --- */
Packit db3073
typedef struct _GHook		GHook;
Packit db3073
typedef struct _GHookList	GHookList;
Packit db3073
Packit db3073
typedef gint		(*GHookCompareFunc)	(GHook		*new_hook,
Packit db3073
						 GHook		*sibling);
Packit db3073
typedef gboolean	(*GHookFindFunc)	(GHook		*hook,
Packit db3073
						 gpointer	 data);
Packit db3073
typedef void		(*GHookMarshaller)	(GHook		*hook,
Packit db3073
						 gpointer	 marshal_data);
Packit db3073
typedef gboolean	(*GHookCheckMarshaller)	(GHook		*hook,
Packit db3073
						 gpointer	 marshal_data);
Packit db3073
typedef void		(*GHookFunc)		(gpointer	 data);
Packit db3073
typedef gboolean	(*GHookCheckFunc)	(gpointer	 data);
Packit db3073
typedef void		(*GHookFinalizeFunc)	(GHookList      *hook_list,
Packit db3073
						 GHook          *hook);
Packit db3073
typedef enum
Packit db3073
{
Packit db3073
  G_HOOK_FLAG_ACTIVE	    = 1 << 0,
Packit db3073
  G_HOOK_FLAG_IN_CALL	    = 1 << 1,
Packit db3073
  G_HOOK_FLAG_MASK	    = 0x0f
Packit db3073
} GHookFlagMask;
Packit db3073
#define G_HOOK_FLAG_USER_SHIFT	(4)
Packit db3073
Packit db3073
Packit db3073
/* --- structures --- */
Packit db3073
struct _GHookList
Packit db3073
{
Packit db3073
  gulong	    seq_id;
Packit db3073
  guint		    hook_size : 16;
Packit db3073
  guint		    is_setup : 1;
Packit db3073
  GHook		   *hooks;
Packit db3073
  gpointer	    dummy3;
Packit db3073
  GHookFinalizeFunc finalize_hook;
Packit db3073
  gpointer	    dummy[2];
Packit db3073
};
Packit db3073
struct _GHook
Packit db3073
{
Packit db3073
  gpointer	 data;
Packit db3073
  GHook		*next;
Packit db3073
  GHook		*prev;
Packit db3073
  guint		 ref_count;
Packit db3073
  gulong	 hook_id;
Packit db3073
  guint		 flags;
Packit db3073
  gpointer	 func;
Packit db3073
  GDestroyNotify destroy;
Packit db3073
};
Packit db3073
Packit db3073
Packit db3073
/* --- macros --- */
Packit db3073
#define	G_HOOK(hook)			((GHook*) (hook))
Packit db3073
#define	G_HOOK_FLAGS(hook)		(G_HOOK (hook)->flags)
Packit db3073
#define	G_HOOK_ACTIVE(hook)		((G_HOOK_FLAGS (hook) & \
Packit db3073
					  G_HOOK_FLAG_ACTIVE) != 0)
Packit db3073
#define	G_HOOK_IN_CALL(hook)		((G_HOOK_FLAGS (hook) & \
Packit db3073
					  G_HOOK_FLAG_IN_CALL) != 0)
Packit db3073
#define G_HOOK_IS_VALID(hook)		(G_HOOK (hook)->hook_id != 0 && \
Packit db3073
					 (G_HOOK_FLAGS (hook) & \
Packit db3073
                                          G_HOOK_FLAG_ACTIVE))
Packit db3073
#define G_HOOK_IS_UNLINKED(hook)	(G_HOOK (hook)->next == NULL && \
Packit db3073
					 G_HOOK (hook)->prev == NULL && \
Packit db3073
					 G_HOOK (hook)->hook_id == 0 && \
Packit db3073
					 G_HOOK (hook)->ref_count == 0)
Packit db3073
Packit db3073
Packit db3073
/* --- prototypes --- */
Packit db3073
/* callback maintenance functions */
Packit db3073
void	 g_hook_list_init		(GHookList		*hook_list,
Packit db3073
					 guint			 hook_size);
Packit db3073
void	 g_hook_list_clear		(GHookList		*hook_list);
Packit db3073
GHook*	 g_hook_alloc			(GHookList		*hook_list);
Packit db3073
void	 g_hook_free			(GHookList		*hook_list,
Packit db3073
					 GHook			*hook);
Packit db3073
GHook *	 g_hook_ref			(GHookList		*hook_list,
Packit db3073
					 GHook			*hook);
Packit db3073
void	 g_hook_unref			(GHookList		*hook_list,
Packit db3073
					 GHook			*hook);
Packit db3073
gboolean g_hook_destroy			(GHookList		*hook_list,
Packit db3073
					 gulong			 hook_id);
Packit db3073
void	 g_hook_destroy_link		(GHookList		*hook_list,
Packit db3073
					 GHook			*hook);
Packit db3073
void	 g_hook_prepend			(GHookList		*hook_list,
Packit db3073
					 GHook			*hook);
Packit db3073
void	 g_hook_insert_before		(GHookList		*hook_list,
Packit db3073
					 GHook			*sibling,
Packit db3073
					 GHook			*hook);
Packit db3073
void	 g_hook_insert_sorted		(GHookList		*hook_list,
Packit db3073
					 GHook			*hook,
Packit db3073
					 GHookCompareFunc	 func);
Packit db3073
GHook*	 g_hook_get			(GHookList		*hook_list,
Packit db3073
					 gulong			 hook_id);
Packit db3073
GHook*	 g_hook_find			(GHookList		*hook_list,
Packit db3073
					 gboolean		 need_valids,
Packit db3073
					 GHookFindFunc		 func,
Packit db3073
					 gpointer		 data);
Packit db3073
GHook*	 g_hook_find_data		(GHookList		*hook_list,
Packit db3073
					 gboolean		 need_valids,
Packit db3073
					 gpointer		 data);
Packit db3073
GHook*	 g_hook_find_func		(GHookList		*hook_list,
Packit db3073
					 gboolean		 need_valids,
Packit db3073
					 gpointer		 func);
Packit db3073
GHook*	 g_hook_find_func_data		(GHookList		*hook_list,
Packit db3073
					 gboolean		 need_valids,
Packit db3073
					 gpointer		 func,
Packit db3073
					 gpointer		 data);
Packit db3073
/* return the first valid hook, and increment its reference count */
Packit db3073
GHook*	 g_hook_first_valid		(GHookList		*hook_list,
Packit db3073
					 gboolean		 may_be_in_call);
Packit db3073
/* return the next valid hook with incremented reference count, and
Packit db3073
 * decrement the reference count of the original hook
Packit db3073
 */
Packit db3073
GHook*	 g_hook_next_valid		(GHookList		*hook_list,
Packit db3073
					 GHook			*hook,
Packit db3073
					 gboolean		 may_be_in_call);
Packit db3073
/* GHookCompareFunc implementation to insert hooks sorted by their id */
Packit db3073
gint	 g_hook_compare_ids		(GHook			*new_hook,
Packit db3073
					 GHook			*sibling);
Packit db3073
/* convenience macros */
Packit db3073
#define	 g_hook_append( hook_list, hook )  \
Packit db3073
     g_hook_insert_before ((hook_list), NULL, (hook))
Packit db3073
/* invoke all valid hooks with the (*GHookFunc) signature.
Packit db3073
 */
Packit db3073
void	 g_hook_list_invoke		(GHookList		*hook_list,
Packit db3073
					 gboolean		 may_recurse);
Packit db3073
/* invoke all valid hooks with the (*GHookCheckFunc) signature,
Packit db3073
 * and destroy the hook if FALSE is returned.
Packit db3073
 */
Packit db3073
void	 g_hook_list_invoke_check	(GHookList		*hook_list,
Packit db3073
					 gboolean		 may_recurse);
Packit db3073
/* invoke a marshaller on all valid hooks.
Packit db3073
 */
Packit db3073
void	 g_hook_list_marshal		(GHookList		*hook_list,
Packit db3073
					 gboolean		 may_recurse,
Packit db3073
					 GHookMarshaller	 marshaller,
Packit db3073
					 gpointer		 marshal_data);
Packit db3073
void	 g_hook_list_marshal_check	(GHookList		*hook_list,
Packit db3073
					 gboolean		 may_recurse,
Packit db3073
					 GHookCheckMarshaller	 marshaller,
Packit db3073
					 gpointer		 marshal_data);
Packit db3073
Packit db3073
G_END_DECLS
Packit db3073
Packit db3073
#endif /* __G_HOOK_H__ */