/** * _nm_dbus_signal_connect_data: * @proxy: a #GDBusProxy * @signal_name: the D-Bus signal to connect to * @signature: (allow-none): the signal's type signature (must be a tuple) * @c_handler: the signal handler function * @data: (allow-none): data to pass to @c_handler * @destroy_data: (allow-none): closure destroy notify for @data * @connect_flags: connection flags * * Connects to the D-Bus signal @signal_name on @proxy. @c_handler must be a * void function whose first argument is a #GDBusProxy, followed by arguments * for each element of @signature, ending with a #gpointer argument for @data. * * The argument types in @c_handler correspond to the types output by * g_dbus_gvariant_to_gvalue(), except for 'ay' and 'aay'. In particular: * - both 16-bit and 32-bit integers are passed as #gint/#guint * - 'as' values are passed as #GStrv (char **) * - all other array, tuple, and dict types are passed as #GVariant * * If @signature is %NULL, then the signal's parameters will be ignored, and * @c_handler should take only the #GDBusProxy and #gpointer arguments. * * Returns: the signal handler ID, which can be used with * g_signal_handler_remove(). Beware that because of the way the signal is * connected, you will not be able to remove it with * g_signal_handlers_disconnect_by_func(), although * g_signal_handlers_disconnect_by_data() will work correctly. */ gulong _nm_dbus_signal_connect_data (GDBusProxy *proxy, const char *signal_name, const GVariantType *signature, GCallback c_handler, gpointer data, GClosureNotify destroy_data, GConnectFlags connect_flags) { NMDBusSignalData *sd; GClosure *closure; gboolean swapped = !!(connect_flags & G_CONNECT_SWAPPED); gboolean after = !!(connect_flags & G_CONNECT_AFTER); g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), 0); g_return_val_if_fail (signal_name != NULL, 0); g_return_val_if_fail (signature == NULL || g_variant_type_is_tuple (signature), 0); g_return_val_if_fail (c_handler != NULL, 0); sd = g_slice_new (NMDBusSignalData); sd->signal_name = g_strdup (signal_name); sd->signature = signature; closure = (swapped ? g_cclosure_new_swap : g_cclosure_new) (c_handler, data, destroy_data); g_closure_set_marshal (closure, g_cclosure_marshal_generic); g_closure_set_meta_marshal (closure, sd, dbus_signal_meta_marshal); g_closure_add_finalize_notifier (closure, sd, dbus_signal_data_free); return g_signal_connect_closure (proxy, "g-signal", closure, after); }
/** * g_source_set_dummy_callback: * @source: the source * * Sets a dummy callback for @source. The callback will do nothing, and * if the source expects a #gboolean return value, it will return %TRUE. * (If the source expects any other type of return value, it will return * a 0/%NULL value; whatever g_value_init() initializes a #GValue to for * that type.) * * If the source is not one of the standard GLib types, the * @closure_callback and @closure_marshal fields of the #GSourceFuncs * structure must have been filled in with pointers to appropriate * functions. */ void g_source_set_dummy_callback (GSource *source) { GClosure *closure; closure = g_closure_new_simple (sizeof (GClosure), NULL); g_closure_set_meta_marshal (closure, NULL, dummy_closure_marshal); g_source_set_closure (source, closure); }
GClosure* gjs_closure_new_for_signal(JSContext *context, JSObject *callable, const char *description, guint signal_id) { GClosure *closure; closure = gjs_closure_new(context, callable, description, FALSE); g_closure_set_meta_marshal(closure, GUINT_TO_POINTER(signal_id), closure_marshal); return closure; }
/* Takes (method_name, handler_func) pairs and connects the handlers to the * signals on skeleton, with object as the user_data, but swapped so it comes * first in the argument list, and handling the return value automatically. */ void _nm_dbus_bind_methods (gpointer object, gpointer skeleton, ...) { va_list ap; const char *method_name; char *signal_name; GCallback handler; GClosure *closure; va_start (ap, skeleton); while ( (method_name = va_arg (ap, const char *)) && (handler = va_arg (ap, GCallback))) { signal_name = signal_name_from_method_name (method_name); closure = g_cclosure_new_swap (handler, object, NULL); g_closure_set_meta_marshal (closure, NULL, _nm_dbus_method_meta_marshal); g_signal_connect_closure (skeleton, signal_name, closure, FALSE); g_free (signal_name); } va_end (ap); }