static WatchNameData * watch_name_data_new (GClosure *name_appeared_closure, GClosure *name_vanished_closure) { WatchNameData *data; data = g_new0 (WatchNameData, 1); if (name_appeared_closure != NULL) { data->name_appeared_closure = g_closure_ref (name_appeared_closure); g_closure_sink (name_appeared_closure); if (G_CLOSURE_NEEDS_MARSHAL (name_appeared_closure)) g_closure_set_marshal (name_appeared_closure, g_cclosure_marshal_generic); } if (name_vanished_closure != NULL) { data->name_vanished_closure = g_closure_ref (name_vanished_closure); g_closure_sink (name_vanished_closure); if (G_CLOSURE_NEEDS_MARSHAL (name_vanished_closure)) g_closure_set_marshal (name_vanished_closure, g_cclosure_marshal_generic); } return data; }
void dt_lua_async_call_alien_internal(const char * call_function, int line,lua_CFunction pusher,int nresults,dt_lua_finish_callback cb, void*cb_data, dt_lua_async_call_arg_type arg_type,...) { #ifdef _DEBUG dt_print(DT_DEBUG_LUA,"LUA DEBUG : %s called from %s %d\n",__FUNCTION__,call_function,line); #endif async_call_data*data = malloc(sizeof(async_call_data)); data->pusher = pusher; data->extra=NULL; data->cb = cb; data->cb_data = cb_data; data->nresults = nresults; va_list ap; va_start(ap,arg_type); dt_lua_async_call_arg_type cur_type = arg_type; while(cur_type != LUA_ASYNC_DONE){ data->extra=g_list_append(data->extra,GINT_TO_POINTER(cur_type)); switch(cur_type) { case LUA_ASYNC_TYPEID: data->extra=g_list_append(data->extra,GINT_TO_POINTER(va_arg(ap,luaA_Type))); data->extra=g_list_append(data->extra,va_arg(ap,gpointer)); break; case LUA_ASYNC_TYPEID_WITH_FREE: { data->extra=g_list_append(data->extra,GINT_TO_POINTER(va_arg(ap,luaA_Type))); data->extra=g_list_append(data->extra,va_arg(ap,gpointer)); GClosure* closure = va_arg(ap,GClosure*); g_closure_ref (closure); g_closure_sink (closure); g_closure_set_marshal(closure, g_cclosure_marshal_generic); data->extra=g_list_append(data->extra,closure); } break; case LUA_ASYNC_TYPENAME: data->extra=g_list_append(data->extra,va_arg(ap,char *)); data->extra=g_list_append(data->extra,va_arg(ap,gpointer)); break; case LUA_ASYNC_TYPENAME_WITH_FREE: { data->extra=g_list_append(data->extra,va_arg(ap,char *)); data->extra=g_list_append(data->extra,va_arg(ap,gpointer)); GClosure* closure = va_arg(ap,GClosure*); g_closure_ref (closure); g_closure_sink (closure); g_closure_set_marshal(closure, g_cclosure_marshal_generic); data->extra=g_list_append(data->extra,closure); } break; default: // should never happen g_assert(false); break; } cur_type = va_arg(ap,dt_lua_async_call_arg_type); } va_end(ap); g_async_queue_push(darktable.lua_state.alien_job_queue,(gpointer)data); g_main_context_wakeup(darktable.lua_state.context); }
static OwnNameData * own_name_data_new (GClosure *bus_acquired_closure, GClosure *name_acquired_closure, GClosure *name_lost_closure) { OwnNameData *data; data = g_new0 (OwnNameData, 1); if (bus_acquired_closure != NULL) { data->bus_acquired_closure = g_closure_ref (bus_acquired_closure); g_closure_sink (bus_acquired_closure); if (G_CLOSURE_NEEDS_MARSHAL (bus_acquired_closure)) g_closure_set_marshal (bus_acquired_closure, g_cclosure_marshal_generic); } if (name_acquired_closure != NULL) { data->name_acquired_closure = g_closure_ref (name_acquired_closure); g_closure_sink (name_acquired_closure); if (G_CLOSURE_NEEDS_MARSHAL (name_acquired_closure)) g_closure_set_marshal (name_acquired_closure, g_cclosure_marshal_generic); } if (name_lost_closure != NULL) { data->name_lost_closure = g_closure_ref (name_lost_closure); g_closure_sink (name_lost_closure); if (G_CLOSURE_NEEDS_MARSHAL (name_lost_closure)) g_closure_set_marshal (name_lost_closure, g_cclosure_marshal_generic); } return data; }
void dt_accel_rename_global(const gchar *path,const gchar *new_path) { dt_accel_t *accel; GSList * l = darktable.control->accelerator_list; char build_path[1024]; dt_accel_path_global(build_path, 1024,path); while(l) { accel = (dt_accel_t*)l->data; if(!strncmp(accel->path, build_path, 1024)) { GtkAccelKey tmp_key = *(gtk_accel_group_find(darktable.control->accelerators,find_accel_internal,accel->closure)); dt_accel_deregister_global(path); g_closure_ref(accel->closure); dt_accel_register_global(new_path,tmp_key.accel_key,tmp_key.accel_mods); dt_accel_connect_global(new_path,accel->closure); g_closure_unref(accel->closure); l = NULL; } else { l = g_slist_next(l); } } }
/* * clutter_alpha_set_closure_internal: * @alpha: a #ClutterAlpha * @closure: a #GClosure * * Sets the @closure for @alpha. This function does not * set the #ClutterAlpha:mode property and does not emit * the #GObject::notify signal for it. */ static inline void clutter_alpha_set_closure_internal (ClutterAlpha *alpha, GClosure *closure) { ClutterAlphaPrivate *priv = alpha->priv; if (priv->notify != NULL) priv->notify (priv->user_data); else if (priv->closure != NULL) g_closure_unref (priv->closure); priv->func = NULL; priv->user_data = NULL; priv->notify = NULL; if (closure == NULL) return; /* need to take ownership of the closure before sinking it */ priv->closure = g_closure_ref (closure); g_closure_sink (closure); /* set the marshaller */ if (G_CLOSURE_NEEDS_MARSHAL (closure)) { GClosureMarshal marshal = _clutter_marshal_DOUBLE__VOID; g_closure_set_marshal (priv->closure, marshal); } }
void moo_plugin_method_new (const char *name, GType ptype, GCallback method, GClosureMarshal c_marshaller, GType return_type, guint n_params, ...) { va_list args; GClosure *closure; g_return_if_fail (g_type_is_a (ptype, MOO_TYPE_PLUGIN)); g_return_if_fail (name != NULL); g_return_if_fail (method != NULL); g_return_if_fail (c_marshaller != NULL); closure = g_cclosure_new (method, NULL, NULL); g_closure_sink (g_closure_ref (closure)); va_start (args, n_params); moo_plugin_method_new_valist (name, ptype, closure, c_marshaller, return_type, n_params, args); va_end (args); g_closure_unref (closure); }
/** * thunar_clipboard_manager_paste_files: * @manager : a #XfdesktopClipboardManager. * @target_file : the #GFile of the folder to which the contents on the clipboard * should be pasted. * @widget : a #GtkWidget, on which to perform the paste or %NULL if no widget is * known. * @new_files_closure : a #GClosure to connect to the job's "new-files" signal, * which will be emitted when the job finishes with the * list of #GFile<!---->s created by the job, or * %NULL if you're not interested in the signal. * * Pastes the contents from the clipboard associated with @manager to the directory * referenced by @target_file. * Code copied and adapted from thunar-clipboard-manager.c * Copyright (c) 2005-2006 Benedikt Meurer <*****@*****.**> * Copyright (c) 2009-2011 Jannis Pohlmann <*****@*****.**> **/ void xfdesktop_clipboard_manager_paste_files (XfdesktopClipboardManager *manager, GFile *target_file, GtkWidget *widget, GClosure *new_files_closure) { XfdesktopClipboardPasteRequest *request; g_return_if_fail (XFDESKTOP_IS_CLIPBOARD_MANAGER (manager)); g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget)); /* prepare the paste request */ request = g_slice_new0 (XfdesktopClipboardPasteRequest); request->manager = g_object_ref (G_OBJECT (manager)); request->target_file = g_object_ref (target_file); request->widget = widget; /* take a reference on the closure (if any) */ if (G_LIKELY (new_files_closure != NULL)) { request->new_files_closure = new_files_closure; g_closure_ref (new_files_closure); g_closure_sink (new_files_closure); } /* get notified when the widget is destroyed prior to * completing the clipboard contents retrieval */ if (G_LIKELY (request->widget != NULL)) g_object_add_weak_pointer (G_OBJECT (request->widget), (gpointer) &request->widget); /* schedule the request */ gtk_clipboard_request_contents (manager->clipboard, manager->x_special_gnome_copied_files, xfdesktop_clipboard_manager_contents_received, request); }
/** * g_source_set_closure: * @source: the source * @closure: a #GClosure * * Set the callback for a source as a #GClosure. * * 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_closure (GSource *source, GClosure *closure) { g_return_if_fail (source != NULL); g_return_if_fail (closure != NULL); if (!source->source_funcs->closure_callback && source->source_funcs != &g_io_watch_funcs && source->source_funcs != &g_timeout_funcs && source->source_funcs != &g_idle_funcs) { g_critical (G_STRLOC ": closure can not be set on closure without GSourceFuncs::closure_callback\n"); return; } g_closure_ref (closure); g_closure_sink (closure); g_source_set_callback_indirect (source, closure, &closure_callback_funcs); if (G_CLOSURE_NEEDS_MARSHAL (closure)) { GClosureMarshal marshal = (GClosureMarshal)source->source_funcs->closure_marshal; if (!marshal) { if (source->source_funcs == &g_idle_funcs || source->source_funcs == &g_timeout_funcs) marshal = source_closure_marshal_BOOLEAN__VOID; else if (source->source_funcs == &g_io_watch_funcs) marshal = g_cclosure_marshal_BOOLEAN__FLAGS; } if (marshal) g_closure_set_marshal (closure, marshal); } }
CALLER_OWN GClosure *owl_variable_make_closure(owl_variable *v, GCallback fn, GClosureMarshal marshal) { GClosure *closure = g_cclosure_new_swap(fn, v, NULL); g_closure_set_marshal(closure,marshal); g_closure_ref(closure); g_closure_sink(closure); return closure; }
void owl_variable_dict_newvar_other(owl_vardict *vd, const char *name, const char *summary, const char *description, const char *validsettings, bool takes_on_off, GClosure *get_tostring_fn, GClosure *set_fromstring_fn) { owl_variable *var = owl_variable_newvar(OWL_VARIABLE_OTHER, name, summary, description, validsettings); var->takes_on_off = takes_on_off; var->get_tostring_fn = g_closure_ref(get_tostring_fn); g_closure_sink(get_tostring_fn); var->set_fromstring_fn = g_closure_ref(set_fromstring_fn); g_closure_sink(set_fromstring_fn); var->default_str = owl_variable_get_tostring(var); /* Note: this'll overwrite any existing variable of that name, even a C one, but it's consistent with previous behavior and commands. */ owl_variable_dict_add_variable(vd, var); }
static inline GClosure *createCppClosure(ClosureDataBase *closureData) { GClosure *closure = g_closure_new_simple(sizeof(GClosure), closureData); g_closure_set_marshal(closure, &c_marshaller); g_closure_add_finalize_notifier(closure, NULL, &closureDestroyNotify); g_closure_ref(closure); g_closure_sink(closure); return closure; }
static void test_closure (GClosure *closure) { /* try to produce high contention in closure->ref_count */ guint i = 0, n = quick_rand32() % 199; for (i = 0; i < n; i++) g_closure_ref (closure); g_closure_sink (closure); /* NOP */ for (i = 0; i < n; i++) g_closure_unref (closure); }
/* Hack. We iterate over the accel map instead of the actions, * in order to pull the parameters out of accel map entries */ static void add_accel_closure (gpointer data, const gchar *accel_path, guint accel_key, GdkModifierType accel_mods, gboolean changed) { AccelData *d = data; GtkApplicationWindow *window = d->window; GActionGroup *actions = d->actions; const gchar *path; const gchar *p; gchar *action_name; GVariant *parameter; AccelClosure *closure; if (accel_key == 0) return; if (!g_str_has_prefix (accel_path, "<GAction>/")) return; path = accel_path + strlen ("<GAction>/"); p = strchr (path, '/'); if (p) { action_name = g_strndup (path, p - path); parameter = g_variant_parse (NULL, p + 1, NULL, NULL, NULL); if (!parameter) g_warning ("Failed to parse parameter from '%s'\n", accel_path); } else { action_name = g_strdup (path); parameter = NULL; } if (g_action_group_has_action (actions, action_name)) { closure = (AccelClosure*) g_closure_new_object (sizeof (AccelClosure), g_object_ref (actions)); g_closure_set_marshal (&closure->closure, accel_activate); closure->action_name = g_strdup (action_name); closure->parameter = parameter ? g_variant_ref_sink (parameter) : NULL; window->priv->accel_closures = g_slist_prepend (window->priv->accel_closures, g_closure_ref (&closure->closure)); g_closure_sink (&closure->closure); gtk_accel_group_connect_by_path (window->priv->accels, accel_path, &closure->closure); } g_free (action_name); }
/** * g_object_bind_property_with_closures: * @source: (type GObject.Object): the source #GObject * @source_property: the property on @source to bind * @target: (type GObject.Object): the target #GObject * @target_property: the property on @target to bind * @flags: flags to pass to #GBinding * @transform_to: a #GClosure wrapping the transformation function * from the @source to the @target, or %NULL to use the default * @transform_from: a #GClosure wrapping the transformation function * from the @target to the @source, or %NULL to use the default * * Creates a binding between @source_property on @source and @target_property * on @target, allowing you to set the transformation functions to be used by * the binding. * * This function is the language bindings friendly version of * g_object_bind_property_full(), using #GClosure<!-- -->s instead of * function pointers. * * Rename to: g_object_bind_property_full * * Return value: (transfer none): the #GBinding instance representing the * binding between the two #GObject instances. The binding is released * whenever the #GBinding reference count reaches zero. * * Since: 2.26 */ GBinding * g_object_bind_property_with_closures (gpointer source, const gchar *source_property, gpointer target, const gchar *target_property, GBindingFlags flags, GClosure *transform_to, GClosure *transform_from) { TransformData *data; data = g_slice_new0 (TransformData); if (transform_to != NULL) { if (G_CLOSURE_NEEDS_MARSHAL (transform_to)) g_closure_set_marshal (transform_to, g_cclosure_marshal_BOOLEAN__BOXED_BOXED); data->transform_to_closure = g_closure_ref (transform_to); g_closure_sink (data->transform_to_closure); } if (transform_from != NULL) { if (G_CLOSURE_NEEDS_MARSHAL (transform_from)) g_closure_set_marshal (transform_from, g_cclosure_marshal_BOOLEAN__BOXED_BOXED); data->transform_from_closure = g_closure_ref (transform_from); g_closure_sink (data->transform_from_closure); } return g_object_bind_property_full (source, source_property, target, target_property, flags, transform_to != NULL ? bind_with_closures_transform_to : NULL, transform_from != NULL ? bind_with_closures_transform_from : NULL, data, bind_with_closures_free_func); }
/** * pyg_signal_class_closure_get: * * Returns the GClosure used for the class closure of signals. When * called, it will invoke the method do_signalname (for the signal * "signalname"). * * Returns: the closure. */ GClosure * pyg_signal_class_closure_get(void) { static GClosure *closure; if (closure == NULL) { closure = g_closure_new_simple(sizeof(GClosure), NULL); g_closure_set_marshal(closure, pyg_signal_class_closure_marshal); g_closure_ref(closure); g_closure_sink(closure); } return closure; }
void moo_plugin_method_newv (const char *name, GType ptype, GClosure *closure, GClosureMarshal c_marshaller, GType return_type, guint n_params, const GType *param_types) { MooPluginMeth *m; GHashTable *meths; char *norm_name; g_return_if_fail (g_type_is_a (ptype, MOO_TYPE_PLUGIN)); g_return_if_fail (name != NULL); g_return_if_fail (closure != NULL); g_return_if_fail (c_marshaller != NULL); g_return_if_fail (!n_params || param_types); norm_name = g_strdelimit (g_strdup (name), "_", '-'); meths = g_type_get_qdata (ptype, MOO_PLUGIN_METHS_QUARK); if (meths) { if (g_hash_table_lookup (meths, norm_name) != NULL) { g_warning ("method '%s' is already registered for type '%s'", name, g_type_name (ptype)); g_free (norm_name); return; } } else { meths = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) meth_free); g_type_set_qdata (ptype, MOO_PLUGIN_METHS_QUARK, meths); } m = g_new0 (MooPluginMeth, 1); m->ptype = ptype; m->return_type = return_type; m->n_params = n_params; m->param_types = n_params ? g_memdup (param_types, n_params * sizeof (GType)) : NULL; m->closure = g_closure_ref (closure); g_closure_sink (closure); g_closure_set_marshal (closure, c_marshaller); g_hash_table_insert (meths, norm_name, m); }
void _owr_get_capture_devices(OwrMediaType types, GClosure *callback) { GClosure *merger; g_return_if_fail(callback); if (G_CLOSURE_NEEDS_MARSHAL(callback)) { g_closure_set_marshal(callback, g_cclosure_marshal_generic); } merger = _owr_utils_list_closure_merger_new(callback, (GDestroyNotify) g_object_unref); if (types & OWR_MEDIA_TYPE_VIDEO) { g_closure_ref(merger); _owr_schedule_with_user_data((GSourceFunc) enumerate_video_source_devices, merger); } if (types & OWR_MEDIA_TYPE_AUDIO) { g_closure_ref(merger); _owr_schedule_with_user_data((GSourceFunc) enumerate_audio_source_devices, merger); } g_closure_unref(merger); }
/** * playerctl_player_on: * @self: an #PlayerctlPlayer * @event: the event to subscribe to * @callback: the callback to run on the event * * A convenience function for bindings to subscribe an event with a callback * * Returns: (transfer none): the #PlayerctlPlayer for chaining */ PlayerctlPlayer *playerctl_player_on(PlayerctlPlayer *self, const gchar *event, GClosure *callback, GError **err) { GError *tmp_error = NULL; if (self->priv->init_error != NULL) { g_propagate_error(err, g_error_copy(self->priv->init_error)); return self; } g_closure_ref(callback); g_closure_sink(callback); g_signal_connect_closure(self, event, callback, TRUE); return self; }
/** * g_closure_invalidate: * @closure: GClosure to invalidate * * Sets a flag on the closure to indicate that its calling * environment has become invalid, and thus causes any future * invocations of g_closure_invoke() on this @closure to be * ignored. Also, invalidation notifiers installed on the closure will * be called at this point. Note that unless you are holding a * reference to the closure yourself, the invalidation notifiers may * unref the closure and cause it to be destroyed, so if you need to * access the closure after calling g_closure_invalidate(), make sure * that you've previously called g_closure_ref(). * * Note that g_closure_invalidate() will also be called when the * reference count of a closure drops to zero (unless it has already * been invalidated before). */ void g_closure_invalidate (GClosure *closure) { g_return_if_fail (closure != NULL); if (!closure->is_invalid) { gboolean was_invalid; g_closure_ref (closure); /* preserve floating flag */ SWAP (closure, is_invalid, TRUE, &was_invalid); /* invalidate only once */ if (!was_invalid) closure_invoke_notifiers (closure, INOTIFY); g_closure_unref (closure); } }
static JSBool gjs_timeout_add(JSContext *context, JSObject *obj, uintN argc, jsval *argv, jsval *retval) { GClosure *closure; JSObject *callback; guint32 interval; guint id; /* Best I can tell, there is no way to know if argv[1] is really * callable other than to just try it. Checking whether it's a * function will not detect native objects that provide * JSClass::call, for example. */ if (!gjs_parse_args(context, "timeout_add", "uo", argc, argv, "interval", &interval, "callback", &callback)) return JS_FALSE; closure = gjs_closure_new(context, callback, "timeout"); if (closure == NULL) return JS_FALSE; g_closure_ref(closure); g_closure_sink(closure); id = g_timeout_add_full(G_PRIORITY_DEFAULT, interval, closure_source_func, closure, closure_destroy_notify); /* this is needed to remove the timeout if the JSContext is * destroyed. */ g_closure_add_invalidate_notifier(closure, GUINT_TO_POINTER(id), closure_invalidated); if (!JS_NewNumberValue(context, id, retval)) return JS_FALSE; return JS_TRUE; }
/** * clutter_binding_pool_install_action: * @pool: a #ClutterBindingPool * @action_name: the name of the action * @key_val: key symbol * @modifiers: bitmask of modifiers * @callback: (type Clutter.BindingActionFunc): function to be called * when the action is activated * @data: data to be passed to @callback * @notify: function to be called when the action is removed * from the pool * * Installs a new action inside a #ClutterBindingPool. The action * is bound to @key_val and @modifiers. * * The same action name can be used for multiple @key_val, @modifiers * pairs. * * When an action has been activated using clutter_binding_pool_activate() * the passed @callback will be invoked (with @data). * * Actions can be blocked with clutter_binding_pool_block_action() * and then unblocked using clutter_binding_pool_unblock_action(). * * Since: 1.0 */ void clutter_binding_pool_install_action (ClutterBindingPool *pool, const gchar *action_name, guint key_val, ClutterModifierType modifiers, GCallback callback, gpointer data, GDestroyNotify notify) { ClutterBindingEntry *entry; GClosure *closure; g_return_if_fail (pool != NULL); g_return_if_fail (action_name != NULL); g_return_if_fail (key_val != 0); g_return_if_fail (callback != NULL); entry = binding_pool_lookup_entry (pool, key_val, modifiers); if (G_UNLIKELY (entry)) { g_warning ("There already is an action '%s' for the given " "key symbol of %d (modifiers: %d) installed inside " "the binding pool.", entry->name, entry->key_val, entry->modifiers); return; } else entry = binding_entry_new (action_name, key_val, modifiers); closure = g_cclosure_new (callback, data, (GClosureNotify) notify); entry->closure = g_closure_ref (closure); g_closure_sink (closure); if (G_CLOSURE_NEEDS_MARSHAL (closure)) { GClosureMarshal marshal; marshal = _clutter_marshal_BOOLEAN__STRING_UINT_FLAGS; g_closure_set_marshal (closure, marshal); } pool->entries = g_slist_prepend (pool->entries, entry); g_hash_table_insert (pool->entries_hash, entry, entry); }
/** * clutter_binding_pool_override_action: * @pool: a #ClutterBindingPool * @key_val: key symbol * @modifiers: bitmask of modifiers * @callback: (type Clutter.BindingActionFunc): function to be called when the action is activated * @data: data to be passed to @callback * @notify: function to be called when the action is removed * from the pool * * Allows overriding the action for @key_val and @modifiers inside a * #ClutterBindingPool. See clutter_binding_pool_install_action(). * * When an action has been activated using clutter_binding_pool_activate() * the passed @callback will be invoked (with @data). * * Actions can be blocked with clutter_binding_pool_block_action() * and then unblocked using clutter_binding_pool_unblock_action(). * * Since: 1.0 */ void clutter_binding_pool_override_action (ClutterBindingPool *pool, guint key_val, ClutterModifierType modifiers, GCallback callback, gpointer data, GDestroyNotify notify) { ClutterBindingEntry *entry; GClosure *closure; g_return_if_fail (pool != NULL); g_return_if_fail (key_val != 0); g_return_if_fail (callback != NULL); entry = binding_pool_lookup_entry (pool, key_val, modifiers); if (G_UNLIKELY (entry == NULL)) { g_warning ("There is no action for the given key symbol " "of %d (modifiers: %d) installed inside the " "binding pool.", key_val, modifiers); return; } if (entry->closure) { g_closure_unref (entry->closure); entry->closure = NULL; } closure = g_cclosure_new (callback, data, (GClosureNotify) notify); entry->closure = g_closure_ref (closure); g_closure_sink (closure); if (G_CLOSURE_NEEDS_MARSHAL (closure)) { GClosureMarshal marshal; marshal = _clutter_marshal_BOOLEAN__STRING_UINT_FLAGS; g_closure_set_marshal (closure, marshal); } }
void terminal_accels_init (void) { guint i, j; settings_keybindings = g_settings_new (CONF_KEYS_SCHEMA); g_signal_connect (settings_keybindings, "changed", G_CALLBACK(keys_change_notify), NULL); gsettings_key_to_entry = g_hash_table_new (g_str_hash, g_str_equal); notification_group = gtk_accel_group_new (); for (i = 0; i < G_N_ELEMENTS (all_entries); ++i) { for (j = 0; j < all_entries[i].n_elements; ++j) { KeyEntry *key_entry; key_entry = &(all_entries[i].key_entry[j]); g_hash_table_insert (gsettings_key_to_entry, (gpointer) key_entry->gsettings_key, key_entry); key_entry->closure = g_closure_new_simple (sizeof (GClosure), key_entry); g_closure_ref (key_entry->closure); g_closure_sink (key_entry->closure); gtk_accel_group_connect_by_path (notification_group, I_(key_entry->accel_path), key_entry->closure); keys_change_notify (settings_keybindings, key_entry->gsettings_key, NULL); } } g_signal_connect (notification_group, "accel-changed", G_CALLBACK (accel_changed_callback), NULL); }
/** * g_closure_invoke: * @closure: a #GClosure * @return_value: a #GValue to store the return value. May be %NULL if the * callback of @closure doesn't return a value. * @n_param_values: the length of the @param_values array * @param_values: (array length=n_param_values): an array of * #GValue<!-- -->s holding the arguments on which to * invoke the callback of @closure * @invocation_hint: a context-dependent invocation hint * * Invokes the closure, i.e. executes the callback represented by the @closure. */ void g_closure_invoke (GClosure *closure, GValue /*out*/ *return_value, guint n_param_values, const GValue *param_values, gpointer invocation_hint) { g_return_if_fail (closure != NULL); g_closure_ref (closure); /* preserve floating flag */ if (!closure->is_invalid) { GClosureMarshal marshal; gpointer marshal_data; gboolean in_marshal = closure->in_marshal; g_return_if_fail (closure->marshal || closure->meta_marshal); SET (closure, in_marshal, TRUE); if (closure->meta_marshal) { marshal_data = closure->notifiers[0].data; marshal = (GClosureMarshal) closure->notifiers[0].notify; } else { marshal_data = NULL; marshal = closure->marshal; } if (!in_marshal) closure_invoke_notifiers (closure, PRE_NOTIFY); marshal (closure, return_value, n_param_values, param_values, invocation_hint, marshal_data); if (!in_marshal) closure_invoke_notifiers (closure, POST_NOTIFY); SET (closure, in_marshal, in_marshal); } g_closure_unref (closure); }
/** * g_source_set_closure: * @source: the source * @closure: a #GClosure * * Set the callback for a source as a #GClosure. * * 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_closure (GSource *source, GClosure *closure) { g_return_if_fail (source != NULL); g_return_if_fail (closure != NULL); if (!source->source_funcs->closure_callback && #ifdef G_OS_UNIX source->source_funcs != &g_unix_fd_source_funcs && source->source_funcs != &g_unix_signal_funcs && #endif source->source_funcs != &g_child_watch_funcs && source->source_funcs != &g_io_watch_funcs && source->source_funcs != &g_timeout_funcs && source->source_funcs != &g_idle_funcs) { g_critical (G_STRLOC ": closure cannot be set on GSource without GSourceFuncs::closure_callback\n"); return; } g_closure_ref (closure); g_closure_sink (closure); g_source_set_callback_indirect (source, closure, &closure_callback_funcs); g_closure_add_invalidate_notifier (closure, source, closure_invalidated); if (G_CLOSURE_NEEDS_MARSHAL (closure)) { GClosureMarshal marshal = (GClosureMarshal)source->source_funcs->closure_marshal; if (marshal) g_closure_set_marshal (closure, marshal); else if (source->source_funcs == &g_idle_funcs || #ifdef G_OS_UNIX source->source_funcs == &g_unix_signal_funcs || #endif source->source_funcs == &g_timeout_funcs) g_closure_set_marshal (closure, source_closure_marshal_BOOLEAN__VOID); else g_closure_set_marshal (closure, g_cclosure_marshal_generic); } }
static void gtk_action_init (GtkAction *action) { action->private_data = G_TYPE_INSTANCE_GET_PRIVATE (action, GTK_TYPE_ACTION, GtkActionPrivate); action->private_data->name = NULL; action->private_data->label = NULL; action->private_data->short_label = NULL; action->private_data->tooltip = NULL; action->private_data->stock_id = NULL; action->private_data->icon_name = NULL; action->private_data->visible_horizontal = TRUE; action->private_data->visible_vertical = TRUE; action->private_data->visible_overflown = TRUE; action->private_data->is_important = FALSE; action->private_data->hide_if_empty = TRUE; action->private_data->always_show_image = FALSE; action->private_data->activate_blocked = FALSE; action->private_data->sensitive = TRUE; action->private_data->visible = TRUE; action->private_data->label_set = FALSE; action->private_data->short_label_set = FALSE; action->private_data->accel_count = 0; action->private_data->accel_group = NULL; action->private_data->accel_quark = 0; action->private_data->accel_closure = g_closure_new_object (sizeof (GClosure), G_OBJECT (action)); g_closure_set_marshal (action->private_data->accel_closure, closure_accel_activate); g_closure_ref (action->private_data->accel_closure); g_closure_sink (action->private_data->accel_closure); action->private_data->action_group = NULL; action->private_data->proxies = NULL; action->private_data->gicon = NULL; }
static JSBool gjs_timeout_add_seconds(JSContext *context, JSObject *obj, uintN argc, jsval *argv, jsval *retval) { GClosure *closure; JSObject *callback; guint32 interval; guint id; /* See comment for timeout_add above */ if (!gjs_parse_args(context, "timeout_add_seconds", "uo", argc, argv, "interval", &interval, "callback", &callback)) return JS_FALSE; closure = gjs_closure_new(context, callback, "timeout_seconds"); if (closure == NULL) return JS_FALSE; g_closure_ref(closure); g_closure_sink(closure); id = g_timeout_add_seconds_full(G_PRIORITY_DEFAULT, interval, closure_source_func, closure, closure_destroy_notify); /* this is needed to remove the timeout if the JSContext is * destroyed. */ g_closure_add_invalidate_notifier(closure, GUINT_TO_POINTER(id), closure_invalidated); if (!JS_NewNumberValue(context, id, retval)) return JS_FALSE; return JS_TRUE; }
/** * e_soup_ssl_trust_connect: * @soup_message: a #SoupMessage about to be sent to the source * @source: an #ESource that uses WebDAV * * Sets up automatic SSL certificate trust handling for @soup_message using the trust * data stored in @source's WebDAV extension. If @soup_message is about to be sent on * an SSL connection with an invalid certificate, the code checks if the WebDAV * extension already has a trust response for that certificate and verifies it * with e_source_webdav_verify_ssl_trust(). If the verification fails, then * the @soup_message send also fails. * * This works by connecting to the "network-event" signal on @soup_message and * connecting to the "accept-certificate" signal on each #GTlsConnection for * which @soup_message reports a #G_SOCKET_CLIENT_TLS_HANDSHAKING event. These * handlers are torn down automatically when @soup_message is disposed. This process * is not thread-safe; it is sufficient for safety if all use of @soup_message's * session and the disposal of @soup_message occur in the same thread. * * Since: 3.16 **/ void e_soup_ssl_trust_connect (SoupMessage *soup_message, ESource *source) { ESoupSslTrustData *handler; g_return_if_fail (SOUP_IS_MESSAGE (soup_message)); g_return_if_fail (E_IS_SOURCE (source)); handler = g_malloc (sizeof (ESoupSslTrustData)); handler->soup_message = soup_message; g_object_weak_ref (G_OBJECT (soup_message), e_soup_ssl_trust_message_finalized_cb, handler); handler->source = g_object_ref (source); handler->accept_certificate_closure = g_cclosure_new (G_CALLBACK (e_soup_ssl_trust_accept_certificate_cb), handler, NULL); g_closure_ref (handler->accept_certificate_closure); g_closure_sink (handler->accept_certificate_closure); g_signal_connect ( soup_message, "network-event", G_CALLBACK (e_soup_ssl_trust_network_event_cb), handler); }
static void carbon_menu_item_update_accel_closure (CarbonMenuItem *carbon_item, GtkWidget *widget) { GtkAccelGroup *group; GtkWidget *label; get_menu_label_text (widget, &label); if (carbon_item->accel_closure) { group = gtk_accel_group_from_accel_closure (carbon_item->accel_closure); if (group) g_signal_handlers_disconnect_by_func (group, carbon_menu_item_accel_changed, widget); g_closure_unref (carbon_item->accel_closure); carbon_item->accel_closure = NULL; } if (GTK_IS_ACCEL_LABEL (label)) carbon_item->accel_closure = GTK_ACCEL_LABEL (label)->accel_closure; if (carbon_item->accel_closure) { g_closure_ref (carbon_item->accel_closure); group = gtk_accel_group_from_accel_closure (carbon_item->accel_closure); g_signal_connect_object (group, "accel-changed", G_CALLBACK (carbon_menu_item_accel_changed), widget, 0); } carbon_menu_item_update_accelerator (carbon_item, widget); }
void dt_lua_do_chunk_async_internal(const char * call_function, int line, lua_CFunction pusher,dt_lua_async_call_arg_type arg_type,...) { #ifdef _DEBUG dt_print(DT_DEBUG_LUA,"LUA DEBUG : %s called from %s %d\n",__FUNCTION__,call_function,line); #endif dt_job_t *job = dt_control_job_create(&async_callback_job, "lua: async call"); if(job) { async_call_data*data = malloc(sizeof(async_call_data)); data->pusher = pusher; data->extra=NULL; va_list ap; va_start(ap,arg_type); dt_lua_async_call_arg_type cur_type = arg_type; while(cur_type != LUA_ASYNC_DONE){ data->extra=g_list_append(data->extra,GINT_TO_POINTER(cur_type)); switch(cur_type) { case LUA_ASYNC_TYPEID: data->extra=g_list_append(data->extra,GINT_TO_POINTER(va_arg(ap,luaA_Type))); data->extra=g_list_append(data->extra,va_arg(ap,gpointer)); break; case LUA_ASYNC_TYPEID_WITH_FREE: { data->extra=g_list_append(data->extra,GINT_TO_POINTER(va_arg(ap,luaA_Type))); data->extra=g_list_append(data->extra,va_arg(ap,gpointer)); GClosure* closure = va_arg(ap,GClosure*); g_closure_ref (closure); g_closure_sink (closure); g_closure_set_marshal(closure, g_cclosure_marshal_generic); data->extra=g_list_append(data->extra,closure); } break; case LUA_ASYNC_TYPENAME: data->extra=g_list_append(data->extra,va_arg(ap,char *)); data->extra=g_list_append(data->extra,va_arg(ap,gpointer)); break; case LUA_ASYNC_TYPENAME_WITH_FREE: { data->extra=g_list_append(data->extra,va_arg(ap,char *)); data->extra=g_list_append(data->extra,va_arg(ap,gpointer)); GClosure* closure = va_arg(ap,GClosure*); g_closure_ref (closure); g_closure_sink (closure); g_closure_set_marshal(closure, g_cclosure_marshal_generic); data->extra=g_list_append(data->extra,closure); } break; default: // should never happen g_assert(false); break; } cur_type = va_arg(ap,dt_lua_async_call_arg_type); } va_end(ap); dt_control_job_set_params(job, data, async_callback_job_destructor); dt_control_add_job(darktable.control, DT_JOB_QUEUE_USER_FG, job); } }