00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #include "common.h"
00047
00048 #include <stdlib.h>
00049 #include <stdio.h>
00050
00051 #include "machine.h"
00052 #include "bu.h"
00053
00054
00055 void
00056 bu_hook_list_init(struct bu_hook_list *hlp)
00057 {
00058 BU_LIST_INIT(&hlp->l);
00059 hlp->hookfunc = BUHOOK_NULL;
00060 hlp->clientdata = GENPTR_NULL;
00061 }
00062
00063 void
00064 bu_add_hook(struct bu_hook_list *hlp, bu_hook_t func, genptr_t clientdata)
00065 {
00066 struct bu_hook_list *new_hook;
00067
00068 BU_GETSTRUCT(new_hook, bu_hook_list);
00069 new_hook->hookfunc = func;
00070 new_hook->clientdata = clientdata;
00071 new_hook->l.magic = BUHOOK_LIST_MAGIC;
00072 BU_LIST_APPEND(&hlp->l, &new_hook->l);
00073 }
00074
00075 void
00076 bu_delete_hook(struct bu_hook_list *hlp, bu_hook_t func, genptr_t clientdata)
00077 {
00078 struct bu_hook_list *cur = hlp;
00079
00080 for (BU_LIST_FOR(cur, bu_hook_list, &hlp->l)) {
00081 if (cur->hookfunc == func && cur->clientdata == clientdata) {
00082 struct bu_hook_list *old = BU_LIST_PLAST(bu_hook_list, cur);
00083 BU_LIST_DEQUEUE(&(cur->l));
00084 bu_free((genptr_t)cur, "bu_delete_hook");
00085 cur = old;
00086 }
00087 }
00088 }
00089
00090 void
00091 bu_call_hook(struct bu_hook_list *hlp, genptr_t buf)
00092 {
00093 struct bu_hook_list *call_hook;
00094
00095 for (BU_LIST_FOR(call_hook, bu_hook_list, &hlp->l)) {
00096 if( !(call_hook->hookfunc) ) {
00097 exit(EXIT_FAILURE);
00098 }
00099 call_hook->hookfunc(call_hook->clientdata, buf);
00100 }
00101 }
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111