5 #include "../lib/array.h"
10 unsigned int hookqueuelength
;
16 for (i
=0;i
<HOOKMAX
;i
++) {
17 array_init(&(hooks
[i
]),sizeof(HookCallback
));
18 array_setlim1(&(hooks
[i
]),2);
19 array_setlim2(&(hooks
[i
]),2);
23 int registerhook(int hooknum
, HookCallback callback
) {
30 hcbs
=(HookCallback
*)(hooks
[hooknum
].content
);
31 for(i
=0;i
<hooks
[hooknum
].cursi
;i
++)
35 /* If there is a previously blanked slot, go in there */
36 for(i
=0;i
<hooks
[hooknum
].cursi
;i
++) {
43 i
=array_getfreeslot(&hooks
[hooknum
]);
44 hcbs
=(HookCallback
*)(hooks
[hooknum
].content
);
50 int registerpriorityhook(int hooknum
, HookCallback callback
, long priority
) {
51 Error("core", ERR_WARNING
, "Priority hook system not loaded.");
53 return registerhook(hooknum
, callback
);
56 int deregisterhook(int hooknum
, HookCallback callback
) {
63 hcbs
=(HookCallback
*)(hooks
[hooknum
].content
);
65 for(i
=0;i
<hooks
[hooknum
].cursi
;i
++)
66 if(hcbs
[i
]==callback
) {
67 /* If there is an ongoing callback, don't actually delete from the
68 * array in case THIS hook is active */
69 if (hookqueuelength
) {
72 array_delslot(&(hooks
[hooknum
]),i
);
80 void triggerhook(int hooknum
, void *arg
) {
88 hcbs
=(HookCallback
*)(hooks
[hooknum
].content
);
89 for (i
=0;i
<hooks
[hooknum
].cursi
;i
++) {
91 (hcbs
[i
])(hooknum
, arg
);
95 if (!hookqueuelength
&& hooknum
!=HOOK_CORE_ENDOFHOOKSQUEUE
)
96 triggerhook(HOOK_CORE_ENDOFHOOKSQUEUE
, 0);