Re: gnome-vfs API freeze items
- From: James Henstridge <james daa com au>
- To: Maciej Stachowiak <mjs noisehavoc org>
- Cc: Jonathan Blandford <jrb redhat com>, <gnome-vfs ximian com>, <gnome-2-0-list gnome org>
- Subject: Re: gnome-vfs API freeze items
- Date: Sun, 2 Sep 2001 09:26:01 +0800 (WST)
On Sat, 1 Sep 2001, Maciej Stachowiak wrote:
> > This actually needs to happen to all libraries in GNOME. I think it
> > would be good to have an API review to see if any API's are
> > inappropriate for LBs.
>
> Has it been done for libgnome* yet? Also, can you point me to
> information on how (and why) to do this?
Here is a little information on using GClosures for callbacks in a
library.
A GClosure wraps up the function, user data and destroy notify arguments
that would traditionally be used in a _full variant. The function that
takes a closure as the callback should store the closure and contain code
like the following:
if (G_CLOSURE_NEEDS_MARSHAL (closure))
g_closure_set_marshal (closure, foo_marshal_BLAH__BLAH);
This sets the closure marshal function if one hasn't already been set.
This is required for closures that wrap C functions. Your code should
call g_closure_ref() on the closure. If your function usually takes
ownership of the closure, you should call g_closure_sink() as well.
When you don't need the closure anymore, call g_closure_unref() on it.
You can invoke the closure with the g_closure_invoke() function. You need
to pass in an initialised GValue for the return_value argument, and an
array of initialised GValues (which have been filled as well) as
param_values. You can leave the invocation_hint argument as NULL.
GValue return_value = { 0 }
GValue param_values[1] = { { 0 } };
g_value_init(&return_value, G_TYPE_INT); /* for instance ... */
g_value_init(¶m_values[0], G_TYPE_OBJECT);
g_value_set_object(¶m_values[0], some_object);
g_closure_invoke(closure, return_value, 1, param_values, NULL);
g_value_unset(¶m_values[0]);
/* do something with the return_value */
g_value_unset(&return_value);
James.
--
Email: james daa com au
WWW: http://www.daa.com.au/~james/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]