5 #include "../lib/array.h"
9 unsigned int hookqueuelength
;
15 for (i
=0;i
<HOOKMAX
;i
++) {
16 array_init(&(hooks
[i
]),sizeof(HookCallback
));
17 array_setlim1(&(hooks
[i
]),2);
18 array_setlim2(&(hooks
[i
]),2);
22 int registerhook(int hooknum
, HookCallback callback
) {
29 hcbs
=(HookCallback
*)(hooks
[hooknum
].content
);
30 for(i
=0;i
<hooks
[hooknum
].cursi
;i
++)
34 /* If there is a previously blanked slot, go in there */
35 for(i
=0;i
<hooks
[hooknum
].cursi
;i
++) {
42 i
=array_getfreeslot(&hooks
[hooknum
]);
43 hcbs
=(HookCallback
*)(hooks
[hooknum
].content
);
49 int deregisterhook(int hooknum
, HookCallback callback
) {
56 hcbs
=(HookCallback
*)(hooks
[hooknum
].content
);
58 for(i
=0;i
<hooks
[hooknum
].cursi
;i
++)
59 if(hcbs
[i
]==callback
) {
60 /* If there is an ongoing callback, don't actually delete from the
61 * array in case THIS hook is active */
62 if (hookqueuelength
) {
65 array_delslot(&(hooks
[hooknum
]),i
);
73 void triggerhook(int hooknum
, void *arg
) {
81 hcbs
=(HookCallback
*)(hooks
[hooknum
].content
);
82 for (i
=0;i
<hooks
[hooknum
].cursi
;i
++) {
84 (hcbs
[i
])(hooknum
, arg
);
88 if (!hookqueuelength
&& hooknum
!=HOOK_CORE_ENDOFHOOKSQUEUE
)
89 triggerhook(HOOK_CORE_ENDOFHOOKSQUEUE
, 0);