12f121986606473f211a86a533c648f4d2c66e8f
4 typedef struct _LttvHookClosure
{
10 LttvHooks
*lttv_hooks_new()
12 return g_array_new(FALSE
, FALSE
, sizeof(LttvHookClosure
));
16 void lttv_hooks_destroy(LttvHooks
*h
)
18 g_array_free(h
, TRUE
);
22 void lttv_hooks_add(LttvHooks
*h
, LttvHook f
, void *hook_data
)
26 if(h
== NULL
)g_error("Null hook added");
29 c
.hook_data
= hook_data
;
30 g_array_append_val(h
,c
);
34 void lttv_hooks_add_list(LttvHooks
*h
, LttvHooks
*list
)
38 for(i
= 0 ; i
< list
->len
; i
++) {
39 g_array_append_val(h
,g_array_index(list
, LttvHookClosure
, i
));
44 void *lttv_hooks_remove(LttvHooks
*h
, LttvHook f
)
52 for(i
= 0 ; i
< h
->len
; i
++) {
53 c
= &g_array_index(h
, LttvHookClosure
, i
);
55 hook_data
= c
->hook_data
;
56 lttv_hooks_remove_by_position(h
, i
);
64 void lttv_hooks_remove_data(LttvHooks
*h
, LttvHook f
, void *hook_data
)
70 for(i
= 0 ; i
< h
->len
; i
++) {
71 c
= &g_array_index(h
, LttvHookClosure
, i
);
72 if(c
->hook
== f
&& c
->hook_data
== hook_data
) {
73 lttv_hooks_remove_by_position(h
, i
);
80 void lttv_hooks_remove_list(LttvHooks
*h
, LttvHooks
*list
)
84 LttvHookClosure
*c
, *c_list
;
86 for(i
= 0, j
= 0 ; i
< h
->len
&& j
< list
->len
;) {
87 c
= &g_array_index(h
, LttvHookClosure
, i
);
88 c_list
= &g_array_index(list
, LttvHookClosure
, j
);
89 if(c
->hook
== c_list
->hook
&& c
->hook_data
== c_list
->hook_data
) {
90 lttv_hooks_remove_by_position(h
, i
);
96 /* Normally the hooks in h are ordered as in list. If this is not the case,
100 for(; j
< list
->len
; j
++) {
101 c_list
= &g_array_index(list
, LttvHookClosure
, j
);
102 lttv_hooks_remove_data(h
, c_list
->hook
, c_list
->hook_data
);
108 unsigned lttv_hooks_number(LttvHooks
*h
)
114 void lttv_hooks_get(LttvHooks
*h
, unsigned i
, LttvHook
*f
, void **hook_data
)
118 c
= &g_array_index(h
, LttvHookClosure
, i
);
120 *hook_data
= c
->hook_data
;
124 void lttv_hooks_remove_by_position(LttvHooks
*h
, unsigned i
);
126 g_array_remove_index(h
, i
)
130 gboolean
lttv_hooks_call(LttvHooks
*h
, void *call_data
)
132 gboolean ret
= FALSE
;
137 for(i
= 0 ; i
< h
->len
; i
++) {
138 c
= &g_array_index(h
, LttvHookClosure
, i
);
139 ret
= ret
|| c
->hook(c
->hook_data
,call_data
);
146 gboolean
lttv_hooks_call_check(LttvHooks
*h
, void *call_data
)
150 for(i
= 0 ; i
< h
->len
; i
++) {
151 c
= &g_array_index(h
, LttvHookClosure
, i
);
152 if(c
->hook(c
->hook_data
,call_data
)) return TRUE
;
158 LttvHooksById
*lttv_hooks_by_id_new()
160 return g_ptr_array_new();
164 void lttv_hooks_by_id_destroy(LttvHooksById
*h
)
168 for(i
= 0 ; i
< h
->len
; i
++) {
169 if(h
->pdata
[i
] != NULL
) lttv_hooks_destroy((LttvHooks
*)(h
->pdata
[i
]));
171 g_ptr_array_free(h
, TRUE
);
175 LttvHooks
*lttv_hooks_by_id_find(LttvHooksById
*h
, unsigned id
);
177 if(h
->len
<= id
) g_ptr_array_set_size(h
, id
+ 1);
178 if(h
->pdata
[id
] == NULL
) h
->pdata
[id
] = lttv_hooks_new();
183 unsigned lttv_hooks_by_id_max_id(LttvHooksById
*h
)
189 LttvHooks
*lttv_hooks_by_id_get(LttvHooksById
*h
, unsigned id
)
191 if(id
< h
->len
) return h
->pdata
[id
];
196 void lttv_hooks_by_id_remove(LttvHooksById
*h
, unsigned id
)
198 if(id
< h
->len
&& h
->pdata
[id
] != NULL
) {
199 lttv_hooks_destroy((LttvHooks
*)h
->pdata
[id
]);
This page took 0.032434 seconds and 3 git commands to generate.