Hash :
6fbbfad4
Author :
Thomas de Grivel
Date :
2024-12-18T07:29:31
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
/* kc3
* Copyright 2022,2023,2024 kmx.io <contact@kmx.io>
*
* Permission is hereby granted to use this software granted the above
* copyright notice and this permission paragraph are included in all
* copies and substantial portions of this software.
*
* THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
* PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
#include <libkc3/assert.h>
#include <libkc3/callable.h>
#include <libkc3/eval.h>
#include <libkc3/list.h>
#include <libkc3/tag.h>
#include <libkc3/tuple.h>
#include "signal.h"
void kc3_gtk4_signal_callback (GObject *object, s_tuple *tuple)
{
s_list *args = NULL;
s_callable *callable;
s_tag tag;
s_list *tmp;
if (tuple->count != 2 ||
tuple->tag[0].type != TAG_CALLABLE) {
err_puts("kc3_gtk4_signal_callback: invalid tuple");
assert(! "kc3_gtk4_signal_callback: invalid tuple");
abort();
}
callable = tuple->tag->data.callable;
if (! callable ||
callable->type == CALLABLE_VOID) {
err_puts("kc3_gtk4_signal_callback: invalid callable");
assert(! "kc3_gtk4_signal_callback: invalid callable");
abort();
}
if (! (tmp = list_new_tag_copy(tuple->tag + 1, NULL))) {
err_puts("kc3_gtk4_signal_callback: list_new_tag_copy");
assert(! "kc3_gtk4_signal_callback: list_new_tag_copy");
abort();
}
args = tmp;
if (! (tmp = list_new_ptr(object, args))) {
err_puts("kc3_gtk4_signal_callback: list_new_tag_copy");
assert(! "kc3_gtk4_signal_callback: list_new_tag_copy");
abort();
}
args = tmp;
if (! eval_callable_call(callable, args, &tag)) {
err_puts("kc3_gtk4_signal_callback: eval_callable_call");
assert(! "kc3_gtk4_signal_callback: eval_callable_call");
abort();
}
tag_clean(&tag);
list_delete_all(args);
}
void kc3_gtk4_signal_connect (GObject **object,
const s_str *detailed_signal,
s_callable **callback,
s_tag *data)
{
s_tuple *tuple;
if (! (tuple = tuple_new(2))) {
err_puts("kc3_gtk4_signal_connect: tuple_new");
assert(! "kc3_gtk4_signal_connect: tuple_new");
abort();
}
tuple->tag->type = TAG_CALLABLE;
if (! p_callable_init_copy(&tuple->tag->data.callable, callback)) {
err_puts("kc3_gtk4_signal_connect: p_callable_init_copy");
assert(! "kc3_gtk4_signal_connect: p_callable_init_copy");
abort();
}
if (! tag_init_copy(tuple->tag + 1, data)) {
err_puts("kc3_gtk4_signal_connect: tag_init_copy");
assert(! "kc3_gtk4_signal_connect: tag_init_copy");
abort();
}
g_signal_connect(*object, detailed_signal->ptr.pchar,
G_CALLBACK(kc3_gtk4_signal_callback), tuple);
}