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_critical("lttv_hooks_destroy()");
20 g_array_free(h
, TRUE
);
24 void lttv_hooks_add(LttvHooks
*h
, LttvHook f
, void *hook_data
)
28 if(h
== NULL
)g_error("Null hook added");
31 c
.hook_data
= hook_data
;
32 g_array_append_val(h
,c
);
36 void lttv_hooks_add_list(LttvHooks
*h
, LttvHooks
*list
)
40 if(list
== NULL
) return;
41 for(i
= 0 ; i
< list
->len
; i
++) {
42 g_array_append_val(h
,g_array_index(list
, LttvHookClosure
, i
));
47 void *lttv_hooks_remove(LttvHooks
*h
, LttvHook f
)
55 for(i
= 0 ; i
< h
->len
; i
++) {
56 c
= &g_array_index(h
, LttvHookClosure
, i
);
58 hook_data
= c
->hook_data
;
59 lttv_hooks_remove_by_position(h
, i
);
67 void lttv_hooks_remove_data(LttvHooks
*h
, LttvHook f
, void *hook_data
)
73 for(i
= 0 ; i
< h
->len
; i
++) {
74 c
= &g_array_index(h
, LttvHookClosure
, i
);
75 if(c
->hook
== f
&& c
->hook_data
== hook_data
) {
76 lttv_hooks_remove_by_position(h
, i
);
83 void lttv_hooks_remove_list(LttvHooks
*h
, LttvHooks
*list
)
87 LttvHookClosure
*c
, *c_list
;
89 if(list
== NULL
) return;
90 for(i
= 0, j
= 0 ; i
< h
->len
&& j
< list
->len
;) {
91 c
= &g_array_index(h
, LttvHookClosure
, i
);
92 c_list
= &g_array_index(list
, LttvHookClosure
, j
);
93 if(c
->hook
== c_list
->hook
&& c
->hook_data
== c_list
->hook_data
) {
94 lttv_hooks_remove_by_position(h
, i
);
100 /* Normally the hooks in h are ordered as in list. If this is not the case,
104 for(; j
< list
->len
; j
++) {
105 c_list
= &g_array_index(list
, LttvHookClosure
, j
);
106 lttv_hooks_remove_data(h
, c_list
->hook
, c_list
->hook_data
);
112 unsigned lttv_hooks_number(LttvHooks
*h
)
118 void lttv_hooks_get(LttvHooks
*h
, unsigned i
, LttvHook
*f
, void **hook_data
)
122 c
= &g_array_index(h
, LttvHookClosure
, i
);
124 *hook_data
= c
->hook_data
;
128 void lttv_hooks_remove_by_position(LttvHooks
*h
, unsigned i
)
130 g_array_remove_index(h
, i
);
134 gboolean
lttv_hooks_call(LttvHooks
*h
, void *call_data
)
136 gboolean ret
, sum_ret
= FALSE
;
143 for(i
= 0 ; i
< h
->len
; i
++) {
144 c
= &g_array_index(h
, LttvHookClosure
, i
);
145 ret
= c
->hook(c
->hook_data
,call_data
);
146 sum_ret
= sum_ret
|| ret
;
153 gboolean
lttv_hooks_call_check(LttvHooks
*h
, void *call_data
)
159 for(i
= 0 ; i
< h
->len
; i
++) {
160 c
= &g_array_index(h
, LttvHookClosure
, i
);
161 if(c
->hook(c
->hook_data
,call_data
)) return TRUE
;
167 LttvHooksById
*lttv_hooks_by_id_new()
169 return g_ptr_array_new();
173 void lttv_hooks_by_id_destroy(LttvHooksById
*h
)
177 for(i
= 0 ; i
< h
->len
; i
++) {
178 if(h
->pdata
[i
] != NULL
) lttv_hooks_destroy((LttvHooks
*)(h
->pdata
[i
]));
180 g_ptr_array_free(h
, TRUE
);
184 LttvHooks
*lttv_hooks_by_id_find(LttvHooksById
*h
, unsigned id
)
186 if(h
->len
<= id
) g_ptr_array_set_size(h
, id
+ 1);
187 if(h
->pdata
[id
] == NULL
) h
->pdata
[id
] = lttv_hooks_new();
192 unsigned lttv_hooks_by_id_max_id(LttvHooksById
*h
)
198 LttvHooks
*lttv_hooks_by_id_get(LttvHooksById
*h
, unsigned id
)
200 if(id
< h
->len
) return h
->pdata
[id
];
205 void lttv_hooks_by_id_remove(LttvHooksById
*h
, unsigned id
)
207 if(id
< h
->len
&& h
->pdata
[id
] != NULL
) {
208 lttv_hooks_destroy((LttvHooks
*)h
->pdata
[id
]);
This page took 0.033176 seconds and 4 git commands to generate.