4 typedef struct _lttv_hook_closure
{
10 inline lttv_hooks
*lttv_hooks_new() {
11 return g_array_new(FALSE
, FALSE
, sizeof(lttv_hook_closure
));
14 /* MD: delete elements of the array also, but don't free pointed addresses
17 inline void lttv_hooks_destroy(lttv_hooks
*h
) {
18 g_array_free(h
, TRUE
);
21 inline void lttv_hooks_add(lttv_hooks
*h
, lttv_hook f
, void *hook_data
) {
24 /* if h is null, do nothing, or popup a warning message */
28 c
.hook_data
= hook_data
;
29 g_array_append_val(h
,c
);
33 void lttv_hooks_call(lttv_hooks
*h
, void *call_data
)
36 lttv_hook_closure
* c
;
38 for(i
= 0 ; i
< h
->len
; i
++) {
39 c
= ((lttv_hook_closure
*)h
->data
) + i
;
41 c
->hook(c
->hook_data
,call_data
);
43 g_critical("NULL hook called\n");
48 /* Sometimes different hooks need to be called based on the case. The
49 case is represented by an unsigned integer id and may represent different
50 event types, for instance. */
52 inline lttv_hooks_by_id
*lttv_hooks_by_id_new() {
53 return g_ptr_array_new();
57 inline void lttv_hooks_by_id_destroy(lttv_hooks_by_id
*h
) {
58 /* MD: delete elements of the array also */
59 g_ptr_array_free(h
, TRUE
);
63 void lttv_hooks_by_id_add(lttv_hooks_by_id
*h
, lttv_hook f
, void *hook_data
,
66 if(h
->len
< id
) g_ptr_array_set_size(h
, id
);
67 if(h
->pdata
[id
] == NULL
) h
->pdata
[id
] = lttv_hooks_new();
68 lttv_hooks_add(h
->pdata
[id
], f
, hook_data
);
71 void lttv_hooks_by_id_call(lttv_hooks_by_id
*h
, void *call_data
, unsigned int id
)
73 if(h
->len
<= id
|| h
->pdata
[id
] == NULL
) return;
74 lttv_hooks_call(h
->pdata
[id
],call_data
);
This page took 0.031319 seconds and 4 git commands to generate.