include/muxevent.h

Go to the documentation of this file.
00001 
00002 /*
00003  * $Id: muxevent.h,v 1.1 2005/06/22 22:09:45 murrayma Exp $
00004  *
00005  * Author: Markus Stenberg <fingon@iki.fi>
00006  *
00007  *  Copyright (c) 1996 Markus Stenberg
00008  *       All rights reserved
00009  *
00010  * Created: Tue Aug 27 19:02:00 1996 fingon
00011  * Last modified: Sat Jun  6 22:20:36 1998 fingon
00012  *
00013  */
00014 
00015 #ifndef MUXEVENT_H
00016 #define MUXEVENT_H
00017 
00018 /* EVENT_DEBUG adds some useful debugging information to the structure
00019    / allows more diverse set of error messages to be shown. However,
00020    for a run-time version it's practically useless. */
00021 
00022 /* #undef EVENT_DEBUG */
00023 
00024 #define FLAG_FREE_DATA      1   /* Free the 1st data segment after execution */
00025 #define FLAG_FREE_DATA2     2   /* Free the 2nd data segment after execution */
00026 #define FLAG_ZOMBIE         4   /* Exists there just because we're too
00027                                    lazy to search for it everywhere - dud */
00028 
00029 /* ZOMBIE events aren't moved during reschedule, they instead die then.
00030    Killing them outside event_run is kinda unhealthy, therefore we set things
00031    just ZOMBIE and delete if it's convenient for us. */
00032 
00033 /* Main idea: Events are arranged as follows:
00034    - next 1-60sec (depending on present timing) each their own
00035      linked list
00036    - next hour with each min in the own linked list
00037    - next 60 hours with each hour in the own linked list
00038    - the rest in one huge 'stack', ordered according to time
00039      */
00040 
00041 /* typedef unsigned char byte; */
00042 
00043 typedef struct my_event_type {
00044     char flags;
00045     void (*function) (struct my_event_type *);
00046     void *data;
00047     void *data2;
00048     int tick;                   /* The tick this baby was first scheduled to go off */
00049     char type;
00050     struct my_event_type *next;
00051     struct my_event_type *next_in_main;
00052     struct my_event_type *prev_in_main;
00053     struct my_event_type *prev_in_type;
00054     struct my_event_type *next_in_type;
00055 } MUXEVENT;
00056 
00057 /* Some external things _do_ use this one */
00058 extern int muxevent_tick;
00059 
00060 #include "p.event.h"
00061 
00062 /* Simplified event adding is more or less irrelevant, most programs
00063    tend to make their own macros for it. This is an example,
00064    though. */
00065 #define muxevent_add_simple_arg(time,func,data) muxevent_add(time,0,0,func,data, NULL)
00066 #define muxevent_add_simple_noarg(time,func) muxevent_add(time,0,0,func,NULL, NULL)
00067 
00068 /* Macros for handling simple lists 
00069    Where it applies: a = main list, b = thing to be added, c = prev
00070    field, d = next field (c = next field in case of single-linked
00071    model */
00072 
00073 #define REMOVE_FROM_LIST(a,c,b) if (a == b ) a = b->c; else { MUXEVENT *t; \
00074 for (t=a;t->c != b;t=t->c); t->c = b->c; }
00075 #define REMOVE_FROM_BIDIR_LIST(a,c,d,b) if (b->c) b->c->d = b->d; \
00076  if (b->d) b->d->c = b->c; if (a==b) { a=b->d; if (a) a->c=NULL; }
00077 
00078 #define ADD_TO_LIST_HEAD(a,c,b) b->c = a ; a = b
00079 #define ADD_TO_BIDIR_LIST_HEAD(a,c,d,b) b->d=a ; if (a) a->c = b ; a=b ; \
00080                                         b->c=NULL
00081 
00082 
00083 /* The standard debugging macro.. Should be more or less useless
00084  because this is mostly used in daemon type of programs.  */
00085 
00086 #ifdef DEBUG
00087 #define debug(a...) printf(##a)
00088 #else
00089 #define debug(a...)
00090 #endif
00091 
00092 void muxevent_add(int time, int flags, int type, void (*func) (MUXEVENT *),
00093     void *data, void *data2);
00094 void muxevent_gothru_type_data(int type, void *data, void (*func) (MUXEVENT *));
00095 void event_gothru_type(int type, void (*func) (MUXEVENT *));
00096 
00097 
00098 
00099 /* Did I mention cproto is braindead? */
00100 
00101 #endif                          /* MUXEVENT_H */

Generated on Mon May 28 04:25:18 2007 for BattletechMUX by  doxygen 1.4.7