Cancel construction of GObject

2010-11-27 Thread Jaroslav Šmíd

Is it possible to cancel construction in gobject-derived class?

Lets say I have GMyObject derived from GObject. In its init function I 
need to spawn a thread. When that fails, I would like to cancel 
construction of the object (so that gobjectclass' finalize function 
would be called on the object and g_object_new would return null-pointer).


I know I can create extra function, which would call g_type_new and 
spawn the thread then and destroy the object if it fails, but I would 
like my object to be instantiable by g_object_new and not force user to 
call extra initialization function and destroy the object if it fails.

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Cancel construction of GObject

2010-11-27 Thread jcupitt
On 27 November 2010 11:14, Jaroslav Šmíd jardas...@gmail.com wrote:
 Is it possible to cancel construction in gobject-derived class?

I don't think so. Lots of code (including code inside gobject) assumes
that g_object_new() always returns a valid pointer.

I handle this by having a more complicated init system. I have
g_object_new() just doing basic mem alloc and setting up a start
state, then I let parameters be set, then I have a virtual function
called build(), which can fail, which constructs the full object.

So make a subclass of GObject for your application (MyObject?) with a
can-fail init system and make all your classes derive from that.

My code is here, if you're curious:

http://vips.svn.sourceforge.net/viewvc/vips/vips7/trunk/libvips/iofuncs/object.c?view=markup

http://vips.svn.sourceforge.net/viewvc/vips/vips7/trunk/libvips/include/vips/object.h?view=markup

John
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Cancel construction of GObject

2010-11-27 Thread Jannis Pohlmann
On Sat, 27 Nov 2010 12:14:39 +0100
Jaroslav Šmíd jardas...@gmail.com wrote:

 Is it possible to cancel construction in gobject-derived class?
 
 Lets say I have GMyObject derived from GObject. In its init function
 I need to spawn a thread. When that fails, I would like to cancel 
 construction of the object (so that gobjectclass' finalize function 
 would be called on the object and g_object_new would return
 null-pointer).

Have a look at the GInitable and GAsyncInitable interfaces.

  - Jannis
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Cancel construction of GObject

2010-11-27 Thread Jaroslav Šmíd

On 11/27/2010 05:32 PM, Jannis Pohlmann wrote:

On Sat, 27 Nov 2010 12:14:39 +0100
Jaroslav Šmídjardas...@gmail.com  wrote:


Is it possible to cancel construction in gobject-derived class?

Lets say I have GMyObject derived from GObject. In its init function
I need to spawn a thread. When that fails, I would like to cancel
construction of the object (so that gobjectclass' finalize function
would be called on the object and g_object_new would return
null-pointer).


Have a look at the GInitable and GAsyncInitable interfaces.

   - Jannis



___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Cool, thanks.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list