5 typedef struct _LttvHookClosure
{
11 LttvHooks
*lttv_hooks_new()
13 return g_array_new(FALSE
, FALSE
, sizeof(LttvHookClosure
));
17 void lttv_hooks_destroy(LttvHooks
*h
)
19 g_array_free(h
, TRUE
);
23 void lttv_hooks_add(LttvHooks
*h
, LttvHook f
, void *hook_data
)
27 if(h
== NULL
)g_error("Null hook added");
30 c
.hook_data
= hook_data
;
31 g_array_append_val(h
,c
);
35 void lttv_hooks_add_list(LttvHooks
*h
, LttvHooks
*list
)
39 if(list
== NULL
) return;
40 for(i
= 0 ; i
< list
->len
; i
++) {
41 g_array_append_val(h
,g_array_index(list
, LttvHookClosure
, i
));
46 void *lttv_hooks_remove(LttvHooks
*h
, LttvHook f
)
54 for(i
= 0 ; i
< h
->len
; i
++) {
55 c
= &g_array_index(h
, LttvHookClosure
, i
);
57 hook_data
= c
->hook_data
;
58 lttv_hooks_remove_by_position(h
, i
);
66 void lttv_hooks_remove_data(LttvHooks
*h
, LttvHook f
, void *hook_data
)
72 for(i
= 0 ; i
< h
->len
; i
++) {
73 c
= &g_array_index(h
, LttvHookClosure
, i
);
74 if(c
->hook
== f
&& c
->hook_data
== hook_data
) {
75 lttv_hooks_remove_by_position(h
, i
);
82 void lttv_hooks_remove_list(LttvHooks
*h
, LttvHooks
*list
)
86 LttvHookClosure
*c
, *c_list
;
88 if(list
== NULL
) return;
89 for(i
= 0, j
= 0 ; i
< h
->len
&& j
< list
->len
;) {
90 c
= &g_array_index(h
, LttvHookClosure
, i
);
91 c_list
= &g_array_index(list
, LttvHookClosure
, j
);
92 if(c
->hook
== c_list
->hook
&& c
->hook_data
== c_list
->hook_data
) {
93 lttv_hooks_remove_by_position(h
, i
);
99 /* Normally the hooks in h are ordered as in list. If this is not the case,
103 for(; j
< list
->len
; j
++) {
104 c_list
= &g_array_index(list
, LttvHookClosure
, j
);
105 lttv_hooks_remove_data(h
, c_list
->hook
, c_list
->hook_data
);
111 unsigned lttv_hooks_number(LttvHooks
*h
)
117 void lttv_hooks_get(LttvHooks
*h
, unsigned i
, LttvHook
*f
, void **hook_data
)
121 c
= &g_array_index(h
, LttvHookClosure
, i
);
123 *hook_data
= c
->hook_data
;
127 void lttv_hooks_remove_by_position(LttvHooks
*h
, unsigned i
)
129 g_array_remove_index(h
, i
);
133 gboolean
lttv_hooks_call(LttvHooks
*h
, void *call_data
)
135 gboolean ret
= FALSE
;
142 for(i
= 0 ; i
< h
->len
; i
++) {
143 c
= &g_array_index(h
, LttvHookClosure
, i
);
144 ret
= ret
|| c
->hook(c
->hook_data
,call_data
);
151 gboolean
lttv_hooks_call_check(LttvHooks
*h
, void *call_data
)
157 for(i
= 0 ; i
< h
->len
; i
++) {
158 c
= &g_array_index(h
, LttvHookClosure
, i
);
159 if(c
->hook(c
->hook_data
,call_data
)) return TRUE
;
165 LttvHooksById
*lttv_hooks_by_id_new()
167 return g_ptr_array_new();
171 void lttv_hooks_by_id_destroy(LttvHooksById
*h
)
175 for(i
= 0 ; i
< h
->len
; i
++) {
176 if(h
->pdata
[i
] != NULL
) lttv_hooks_destroy((LttvHooks
*)(h
->pdata
[i
]));
178 g_ptr_array_free(h
, TRUE
);
182 LttvHooks
*lttv_hooks_by_id_find(LttvHooksById
*h
, unsigned id
)
184 if(h
->len
<= id
) g_ptr_array_set_size(h
, id
+ 1);
185 if(h
->pdata
[id
] == NULL
) h
->pdata
[id
] = lttv_hooks_new();
190 unsigned lttv_hooks_by_id_max_id(LttvHooksById
*h
)
196 LttvHooks
*lttv_hooks_by_id_get(LttvHooksById
*h
, unsigned id
)
198 if(id
< h
->len
) return h
->pdata
[id
];
203 void lttv_hooks_by_id_remove(LttvHooksById
*h
, unsigned id
)
205 if(id
< h
->len
&& h
->pdata
[id
] != NULL
) {
206 lttv_hooks_destroy((LttvHooks
*)h
->pdata
[id
]);
This page took 0.032626 seconds and 4 git commands to generate.