Search code examples
c++gtk

Get params info for any function like g_signal_query


I'm abstracting any signal with

g_signal_query(g_signal_lookup (name_of_signal, G_OBJECT_TYPE (instance_of_gtk_object)), &signal_info);

callback_object->signal_id = signal_info.signal_id;
callback_object->signal_name = signal_info.signal_name;
callback_object->itype = signal_info.itype;
callback_object->signal_flags = signal_info.signal_flags;
callback_object->return_type = signal_info.return_type;
callback_object->n_params = signal_info.n_params;
callback_object->param_types = signal_info.param_types;

[...]

closure = g_cclosure_new_swap (G_CALLBACK (connect_callback), callback_object, NULL);
int ret = g_signal_connect_closure (instance, callback_event, closure, after);

As you can see, this give-me a list of GSignalQuery with name, GType, position of argument, etc. So I create a struct and pass this to a generic function. On this function I read this struct and loop between VA list creating GValues back

Now i'm abstracting any others functions, like gtk_tree_selection_selected_foreach, GtkTreeViewRowSeparatorFunc, or any other function to a generic callback

My question: is there a way to get a list of paramters the function expecting?


Solution

  • Yes, if you use GObject introspection, which provides metadata (both in XML and in binary form) to describe a C ABI. The introspection data is commonly used by language bindings, which is essentially what you're doing.