2008-10-15 22:09:22 +02:00
|
|
|
/* abstract base class for all vips objects
|
|
|
|
*
|
|
|
|
* Edited from nip's base class, 15/10/08
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright (C) 1991-2003 The National Gallery
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
#define DEBUG
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif /*HAVE_CONFIG_H*/
|
|
|
|
#include <vips/intl.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <vips/vips.h>
|
|
|
|
#include <vips/internal.h>
|
|
|
|
|
|
|
|
#ifdef WITH_DMALLOC
|
|
|
|
#include <dmalloc.h>
|
|
|
|
#endif /*WITH_DMALLOC*/
|
|
|
|
|
|
|
|
/* Our signals.
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
SIG_DESTROY, /* End lifetime */
|
2008-10-16 16:08:12 +02:00
|
|
|
SIG_CHANGED, /* VipsObject has changed somehow */
|
2008-10-15 22:09:22 +02:00
|
|
|
SIG_LAST
|
|
|
|
};
|
|
|
|
|
|
|
|
static GObjectClass *parent_class = NULL;
|
|
|
|
|
2008-10-16 16:08:12 +02:00
|
|
|
static guint vips_object_signals[SIG_LAST] = { 0 };
|
2008-10-15 22:09:22 +02:00
|
|
|
|
|
|
|
/* Don't emit "destroy" immediately, do it from the _dispose handler.
|
|
|
|
*/
|
|
|
|
void *
|
2008-10-16 16:08:12 +02:00
|
|
|
vips_object_destroy( VipsObject *vips_object )
|
2008-10-15 22:09:22 +02:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2008-10-16 16:08:12 +02:00
|
|
|
printf( "vips_object_destroy: " );
|
|
|
|
vips_object_print( vips_object );
|
2008-10-15 22:09:22 +02:00
|
|
|
#endif /*DEBUG*/
|
|
|
|
|
2008-10-16 16:08:12 +02:00
|
|
|
if( !vips_object->in_destruction )
|
|
|
|
g_object_run_dispose( G_OBJECT( vips_object ) );
|
2008-10-15 22:09:22 +02:00
|
|
|
|
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2008-10-16 16:08:12 +02:00
|
|
|
vips_object_changed( VipsObject *vips_object )
|
2008-10-15 22:09:22 +02:00
|
|
|
{
|
2008-10-16 16:08:12 +02:00
|
|
|
g_return_val_if_fail( vips_object != NULL, NULL );
|
|
|
|
g_return_val_if_fail( VIPS_IS_OBJECT( vips_object ), NULL );
|
2008-10-15 22:09:22 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2008-10-16 16:08:12 +02:00
|
|
|
printf( "vips_object_changed: " );
|
|
|
|
vips_object_print( vips_object );
|
2008-10-15 22:09:22 +02:00
|
|
|
#endif /*DEBUG*/
|
|
|
|
|
2008-10-16 16:08:12 +02:00
|
|
|
g_signal_emit( G_OBJECT( vips_object ),
|
|
|
|
vips_object_signals[SIG_CHANGED], 0 );
|
2008-10-15 22:09:22 +02:00
|
|
|
|
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-16 16:08:12 +02:00
|
|
|
vips_object_dispose( GObject *gobject )
|
2008-10-15 22:09:22 +02:00
|
|
|
{
|
2008-10-16 16:08:12 +02:00
|
|
|
VipsObject *vips_object = VIPS_OBJECT( gobject );
|
2008-10-15 22:09:22 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2008-10-16 16:08:12 +02:00
|
|
|
printf( "vips_object_dispose: " );
|
|
|
|
vips_object_print( vips_object );
|
2008-10-15 22:09:22 +02:00
|
|
|
#endif /*DEBUG*/
|
|
|
|
|
2008-10-16 16:08:12 +02:00
|
|
|
if( !vips_object->in_destruction ) {
|
|
|
|
vips_object->in_destruction = TRUE;
|
|
|
|
g_signal_emit( G_OBJECT( vips_object ),
|
|
|
|
vips_object_signals[SIG_DESTROY], 0 );
|
|
|
|
vips_object->in_destruction = FALSE;
|
2008-10-15 22:09:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS( parent_class )->dispose( gobject );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-16 16:08:12 +02:00
|
|
|
vips_object_finalize( GObject *gobject )
|
2008-10-15 22:09:22 +02:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2008-10-16 16:08:12 +02:00
|
|
|
VipsObject *vips_object = VIPS_OBJECT( gobject );
|
2008-10-15 22:09:22 +02:00
|
|
|
|
2008-10-16 16:08:12 +02:00
|
|
|
printf( "vips_object_finalize: " );
|
|
|
|
vips_object_print( vips_object );
|
2008-10-15 22:09:22 +02:00
|
|
|
#endif /*DEBUG*/
|
|
|
|
|
|
|
|
/* Unlike GTK, we allow floating objects to be finalized. Handy if a
|
2008-10-16 16:08:12 +02:00
|
|
|
* _new() fails. So don't assert( !vips_object->floating );
|
2008-10-15 22:09:22 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
G_OBJECT_CLASS( parent_class )->finalize( gobject );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-16 16:08:12 +02:00
|
|
|
vips_object_real_destroy( VipsObject *vips_object )
|
2008-10-15 22:09:22 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-16 16:08:12 +02:00
|
|
|
vips_object_real_changed( VipsObject *vips_object )
|
2008-10-15 22:09:22 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-16 16:08:12 +02:00
|
|
|
vips_object_class_init( VipsObjectClass *class )
|
2008-10-15 22:09:22 +02:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
|
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent( class );
|
|
|
|
|
2008-10-16 16:08:12 +02:00
|
|
|
gobject_class->dispose = vips_object_dispose;
|
|
|
|
gobject_class->finalize = vips_object_finalize;
|
2008-10-15 22:09:22 +02:00
|
|
|
|
2008-10-16 16:08:12 +02:00
|
|
|
class->destroy = vips_object_real_destroy;
|
|
|
|
class->changed = vips_object_real_changed;
|
2008-10-15 22:09:22 +02:00
|
|
|
|
2008-10-16 16:08:12 +02:00
|
|
|
vips_object_signals[SIG_DESTROY] = g_signal_new( "destroy",
|
2008-10-15 22:09:22 +02:00
|
|
|
G_TYPE_FROM_CLASS( gobject_class ),
|
|
|
|
G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
|
2008-10-16 16:08:12 +02:00
|
|
|
G_STRUCT_OFFSET( VipsObjectClass, destroy ),
|
2008-10-15 22:09:22 +02:00
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0 );
|
2008-10-16 16:08:12 +02:00
|
|
|
vips_object_signals[SIG_CHANGED] = g_signal_new( "changed",
|
2008-10-15 22:09:22 +02:00
|
|
|
G_OBJECT_CLASS_TYPE( gobject_class ),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
2008-10-16 16:08:12 +02:00
|
|
|
G_STRUCT_OFFSET( VipsObjectClass, changed ),
|
2008-10-15 22:09:22 +02:00
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-16 16:08:12 +02:00
|
|
|
vips_object_init( VipsObject *vips_object )
|
2008-10-15 22:09:22 +02:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2008-10-16 16:08:12 +02:00
|
|
|
printf( "vips_object_init: " );
|
|
|
|
vips_object_print( vips_object );
|
2008-10-15 22:09:22 +02:00
|
|
|
#endif /*DEBUG*/
|
|
|
|
|
2008-10-16 16:08:12 +02:00
|
|
|
vips_object->floating = TRUE;
|
|
|
|
vips_object->in_destruction = FALSE;
|
2008-10-15 22:09:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GType
|
2008-10-16 16:08:12 +02:00
|
|
|
vips_object_get_type( void )
|
2008-10-15 22:09:22 +02:00
|
|
|
{
|
2008-10-16 16:08:12 +02:00
|
|
|
static GType vips_object_type = 0;
|
2008-10-15 22:09:22 +02:00
|
|
|
|
2008-10-16 16:08:12 +02:00
|
|
|
if( !vips_object_type ) {
|
2008-10-15 22:09:22 +02:00
|
|
|
static const GTypeInfo info = {
|
2008-10-16 16:08:12 +02:00
|
|
|
sizeof( VipsObjectClass ),
|
2008-10-15 22:09:22 +02:00
|
|
|
NULL, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
2008-10-16 16:08:12 +02:00
|
|
|
(GClassInitFunc) vips_object_class_init,
|
2008-10-15 22:09:22 +02:00
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
2008-10-16 16:08:12 +02:00
|
|
|
sizeof( VipsObject ),
|
2008-10-15 22:09:22 +02:00
|
|
|
32, /* n_preallocs */
|
2008-10-16 16:08:12 +02:00
|
|
|
(GInstanceInitFunc) vips_object_init,
|
2008-10-15 22:09:22 +02:00
|
|
|
};
|
|
|
|
|
2008-10-16 16:08:12 +02:00
|
|
|
vips_object_type = g_type_register_static( G_TYPE_OBJECT,
|
|
|
|
"VipsObject", &info, 0 );
|
2008-10-15 22:09:22 +02:00
|
|
|
}
|
|
|
|
|
2008-10-16 16:08:12 +02:00
|
|
|
return( vips_object_type );
|
2008-10-15 22:09:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-10-16 16:08:12 +02:00
|
|
|
vips_object_sink( VipsObject *vips_object )
|
2008-10-15 22:09:22 +02:00
|
|
|
{
|
2008-10-16 16:08:12 +02:00
|
|
|
g_assert( VIPS_IS_OBJECT( vips_object ) );
|
2008-10-15 22:09:22 +02:00
|
|
|
|
2008-10-16 16:08:12 +02:00
|
|
|
if( vips_object->floating ) {
|
|
|
|
vips_object->floating = FALSE;
|
|
|
|
g_object_unref( G_OBJECT( vips_object ) );
|
2008-10-15 22:09:22 +02:00
|
|
|
}
|
|
|
|
}
|