event.h

00001 /* event.h - Event management
00002    Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
00003    Written by Stephane Carrez (stcarrez@worldnet.fr)
00004 
00005 This file is part of GEL.
00006 
00007 GEL is free software; you can redistribute it and/or modify
00008 it under the terms of the GNU General Public License as published by
00009 the Free Software Foundation; either version 2, or (at your option)
00010 any later version.
00011 
00012 GEL is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with GEL; see the file COPYING.  If not, write to
00019 the Free Software Foundation, 59 Temple Place - Suite 330,
00020 Boston, MA 02111-1307, USA.  */
00021 
00022 #ifndef _GEL_EVENT_H
00023 #define _GEL_EVENT_H
00024 
00046 struct event;
00047 struct event_callout;
00048 struct event_def;
00049 typedef struct event_def *event_type;
00050 typedef struct event event;
00051 typedef struct event_callout event_callout;
00052 
00053 extern unsigned long event_idle_counter;
00054 
00062 struct event
00063 {
00065   event_type     type;
00066 
00068   unsigned short time;
00069 
00071   unsigned short data;
00072 };
00073 
00074 typedef void (* event_handler_t) (event_callout *, event *);
00075 
00076 struct event_callout
00077 {
00078   struct event_callout *next;
00079   struct event_def     *type;
00080   event_handler_t       callback;
00081   void *data;
00082 };
00083 
00084 struct event_def
00085 {
00086   struct event_callout *callouts;
00087 };
00088 
00099 void
00100 event_initialize (event *queue, unsigned short size);
00101 
00120 void
00121 event_post (event_type type, unsigned short data);
00122 
00132 void
00133 event_add_callout (event_type type, event_callout *callout);
00134 
00137 void
00138 event_remove_callout (event_callout *callout);
00139 
00149 extern void event_register (event_type type, event_callout *callout,
00150                             event_handler_t handler, void *client_data);
00151 
00152 extern inline void
00153 event_register (event_type type, event_callout *callout,
00154                 event_handler_t handler, void *client_data)
00155 {
00156   callout->callback = handler;
00157   callout->data = client_data;
00158   event_add_callout (type, callout);
00159 }
00160 
00161 extern void event_unregister (event_callout *);
00162 
00163 extern inline void
00164 event_unregister (event_callout *callout)
00165 {
00166   event_remove_callout (callout);
00167 }
00168 
00169 extern unsigned char event_false;
00170 
00171 extern void
00172 event_loop (unsigned long tick, unsigned char *bool);
00173 
00174 extern void
00175 event_wait (unsigned long nticks, event_type type);
00176 
00179 #endif