Commit 4c750a94 authored by Pierre Wieser's avatar Pierre Wieser

Rewrite copy stack to get ride of iteration on class hierarchy

parent 08f65b7a
2011-02-21 Pierre Wieser <pwieser@trychlos.org>
Rewrite copy stack to get ride of iteration on class hierarchy
* src/api/na-object-api.h
(na_object_copy, na_object_get_hierarchy): Removed macros.
* src/api/na-icontext.h:
* src/core/na-icontext.c (na_icontext_copy): New function.
* src/core/na-object.c (object_copy_iter, iter_on_class_hierarchy):
* src/core/na-object-item.c (object_copy):
* src/core/na-object-action.c (object_copy):
* src/core/na-object-profile.c (object_copy):
* src/core/na-object-menu.c (object_copy): Updated accordingly.
Rewrite validity status check stack
* src/api/na-icontext.h:
......
......@@ -101,8 +101,8 @@ gboolean na_icontext_is_valid ( const NAIContext *context );
void na_icontext_check_mimetypes ( const NAIContext *context );
void na_icontext_copy ( NAIContext *context, const NAIContext *source );
void na_icontext_read_done ( NAIContext *context );
void na_icontext_set_scheme ( NAIContext *context, const gchar *scheme, gboolean selected );
void na_icontext_set_only_desktop( NAIContext *context, const gchar *desktop, gboolean selected );
void na_icontext_set_not_desktop ( NAIContext *context, const gchar *desktop, gboolean selected );
......
......@@ -66,11 +66,9 @@ G_BEGIN_DECLS
/* NAObject
*/
#define na_object_copy( tgt, src, rec ) na_object_object_copy( NA_OBJECT( tgt ), NA_OBJECT( src ), ( rec ))
#define na_object_dump( obj ) na_object_object_dump( NA_OBJECT( obj ))
#define na_object_dump_norec( obj ) na_object_object_dump_norec( NA_OBJECT( obj ))
#define na_object_dump_tree( tree ) na_object_object_dump_tree( tree )
#define na_object_get_hierarchy( obj ) na_object_object_get_hierarchy( NA_OBJECT( obj ))
#define na_object_ref( obj ) na_object_object_ref( NA_OBJECT( obj ))
#define na_object_unref( obj ) na_object_object_unref( NA_OBJECT( obj ))
......
......@@ -170,13 +170,11 @@ void na_object_object_reset_origin ( NAObject *object, const NAObject *or
NAObject *na_object_object_ref ( NAObject *object );
void na_object_object_unref( NAObject *object );
void na_object_object_copy ( NAObject *target, const NAObject *source, gboolean recursive );
void na_object_object_dump ( const NAObject *object );
void na_object_object_dump_norec( const NAObject *object );
void na_object_object_dump_tree ( GList *tree );
GList *na_object_object_get_hierarchy( const NAObject *object );
GList *na_object_get_hierarchy( const NAObject *object );
void na_object_free_hierarchy( GList *hierarchy );
void na_object_object_debug_invalid( const NAObject *object, const gchar *reason );
......
......@@ -316,6 +316,21 @@ na_icontext_check_mimetypes( const NAIContext *context )
na_core_utils_slist_free( mimetypes );
}
/**
* na_icontext_copy:
* @context: the target #NAIContext context.
* @source: the source #NAIContext context.
*
* Copy specific data from @source to @context.
*
* Since: 3.1.0
*/
void
na_icontext_copy( NAIContext *context, const NAIContext *source )
{
/* nothing to do for now */
}
/**
* na_icontext_read_done:
* @context: the #NAIContext to be prepared.
......
......@@ -73,7 +73,6 @@ static void instance_dispose( GObject *object );
static void instance_finalize( GObject *object );
static void object_dump( const NAObject *object );
static void object_copy( NAObject *target, const NAObject *source, gboolean recursive );
static gboolean object_are_equal( const NAObject *a, const NAObject *b );
static gboolean object_is_valid( const NAObject *object );
......@@ -168,7 +167,6 @@ class_init( NAObjectActionClass *klass )
naobject_class = NA_OBJECT_CLASS( klass );
naobject_class->dump = object_dump;
naobject_class->copy = object_copy;
naobject_class->are_equal = object_are_equal;
naobject_class->is_valid = object_is_valid;
......@@ -282,19 +280,6 @@ object_dump( const NAObject *object )
}
}
static void
object_copy( NAObject *target, const NAObject *source, gboolean recursive )
{
g_return_if_fail( NA_IS_OBJECT_ACTION( target ));
g_return_if_fail( NA_IS_OBJECT_ACTION( source ));
if( !NA_OBJECT_ACTION( target )->private->dispose_has_run &&
!NA_OBJECT_ACTION( source )->private->dispose_has_run ){
na_factory_object_copy( NA_IFACTORY_OBJECT( target ), NA_IFACTORY_OBJECT( source ));
}
}
/*
* @a is the original object
* @b is the current one
......
......@@ -259,6 +259,11 @@ object_copy( NAObject *target, const NAObject *source, gboolean recursive )
dest->private->writable = src->private->writable;
dest->private->reason = src->private->reason;
/* chain up to the parent class */
if( NA_OBJECT_CLASS( st_parent_class )->copy ){
NA_OBJECT_CLASS( st_parent_class )->copy( target, source, recursive );
}
}
}
......
......@@ -69,7 +69,6 @@ static void instance_set_property( GObject *object, guint property_id, c
static void instance_dispose( GObject *object );
static void instance_finalize( GObject *object );
static void object_copy( NAObject *target, const NAObject *source, gboolean recursive );
static void object_dump( const NAObject *object );
static void ifactory_object_iface_init( NAIFactoryObjectInterface *iface );
......@@ -155,7 +154,6 @@ class_init( NAObjectMenuClass *klass )
naobject_class = NA_OBJECT_CLASS( klass );
naobject_class->dump = object_dump;
naobject_class->copy = object_copy;
klass->private = g_new0( NAObjectMenuClassPrivate, 1 );
......@@ -245,19 +243,6 @@ instance_finalize( GObject *object )
}
}
static void
object_copy( NAObject *target, const NAObject *source, gboolean recursive )
{
g_return_if_fail( NA_IS_OBJECT_MENU( target ));
g_return_if_fail( NA_IS_OBJECT_MENU( source ));
if( !NA_OBJECT_MENU( target )->private->dispose_has_run &&
!NA_OBJECT_MENU( source )->private->dispose_has_run ){
na_factory_object_copy( NA_IFACTORY_OBJECT( target ), NA_IFACTORY_OBJECT( source ));
}
}
static void
object_dump( const NAObject *object )
{
......
......@@ -73,7 +73,6 @@ static void instance_set_property( GObject *object, guint property_id, c
static void instance_dispose( GObject *object );
static void instance_finalize( GObject *object );
static void object_copy( NAObject *target, const NAObject *source, gboolean recursive );
static void object_dump( const NAObject *object );
static gboolean object_is_valid( const NAObject *object );
......@@ -169,7 +168,6 @@ class_init( NAObjectProfileClass *klass )
naobject_class = NA_OBJECT_CLASS( klass );
naobject_class->dump = object_dump;
naobject_class->copy = object_copy;
naobject_class->is_valid = object_is_valid;
naobjectid_class = NA_OBJECT_ID_CLASS( klass );
......@@ -265,19 +263,6 @@ instance_finalize( GObject *object )
}
}
static void
object_copy( NAObject *target, const NAObject *source, gboolean recursive )
{
g_return_if_fail( NA_IS_OBJECT_PROFILE( target ));
g_return_if_fail( NA_IS_OBJECT_PROFILE( source ));
if( !NA_OBJECT_PROFILE( target )->private->dispose_has_run &&
!NA_OBJECT_PROFILE( source )->private->dispose_has_run ){
na_factory_object_copy( NA_IFACTORY_OBJECT( target ), NA_IFACTORY_OBJECT( source ));
}
}
static void
object_dump( const NAObject *object )
{
......@@ -317,11 +302,11 @@ object_is_valid( const NAObject *object )
g_debug( "%s: profile=%p (%s)", thisfn, ( void * ) profile, G_OBJECT_TYPE_NAME( profile ));
is_valid = is_valid_path_parameters( profile );
}
/* chain up to the parent class */
if( NA_OBJECT_CLASS( st_parent_class )->is_valid ){
is_valid &= NA_OBJECT_CLASS( st_parent_class )->is_valid( object );
/* chain up to the parent class */
if( NA_OBJECT_CLASS( st_parent_class )->is_valid ){
is_valid &= NA_OBJECT_CLASS( st_parent_class )->is_valid( object );
}
}
return( is_valid );
......
......@@ -48,24 +48,6 @@ struct _NAObjectPrivate {
gboolean dispose_has_run;
};
/* while iterating on the class hierarchy for are_equal() and is_valid()
*/
typedef struct {
NAObject *object;
gboolean result;
}
HierarchyIter;
/* while iterating on the class hierarchy for object_copy()
*/
typedef struct {
NAObject *target;
gboolean recursive;
}
CopyIter;
typedef gboolean ( *HierarchyIterFunc )( GObjectClass *class, const NAObject *object, void *user_data );
static GObjectClass *st_parent_class = NULL;
static GType register_type( void );
......@@ -83,11 +65,10 @@ static gboolean iduplicable_is_valid( const NAIDuplicable *object );
static void check_status_down_rec( const NAObject *object );
static void check_status_up_rec( const NAObject *object, gboolean was_modified, gboolean was_valid );
static void v_copy( NAObject *target, const NAObject *source, gboolean recursive );
static gboolean v_are_equal( const NAObject *a, const NAObject *b );
static gboolean v_is_valid( const NAObject *a );
static gboolean object_copy_iter( GObjectClass *class, const NAObject *source, CopyIter *data );
static void dump_tree( GList *tree, gint level );
static void iter_on_class_hierarchy( const NAObject *object, HierarchyIterFunc pfn, void *user_data );
static GList *build_class_hierarchy( const NAObject *object );
GType
......@@ -255,7 +236,31 @@ iduplicable_iface_init( NAIDuplicableInterface *iface )
static void
iduplicable_copy( NAIDuplicable *target, const NAIDuplicable *source )
{
na_object_copy( NA_OBJECT( target ), NA_OBJECT( source ), TRUE );
static const gchar *thisfn = "na_object_iduplicable_copy";
NAObject *dest, *src;
g_return_if_fail( NA_IS_OBJECT( target ));
g_return_if_fail( NA_IS_OBJECT( source ));
dest = NA_OBJECT( target );
src = NA_OBJECT( source );
if( !dest->private->dispose_has_run &&
!src->private->dispose_has_run ){
g_debug( "%s: target=%p (%s), source=%p (%s)",
thisfn, ( void * ) dest, G_OBJECT_TYPE_NAME( dest ), ( void * ) src, G_OBJECT_TYPE_NAME( src ));
if( NA_IS_IFACTORY_OBJECT( target )){
na_factory_object_copy( NA_IFACTORY_OBJECT( target ), NA_IFACTORY_OBJECT( source ));
}
if( NA_IS_ICONTEXT( target )){
na_icontext_copy( NA_ICONTEXT( target ), NA_ICONTEXT( source ));
}
v_copy( dest, src, TRUE );
}
}
static gboolean
......@@ -417,6 +422,14 @@ check_status_up_rec( const NAObject *object, gboolean was_modified, gboolean was
}
}
static void
v_copy( NAObject *target, const NAObject *source, gboolean recursive )
{
if( NA_OBJECT_GET_CLASS( target )->copy ){
NA_OBJECT_GET_CLASS( target )->copy( target, source, recursive );
}
}
static gboolean
v_are_equal( const NAObject *a, const NAObject *b )
{
......@@ -437,50 +450,6 @@ v_is_valid( const NAObject *a )
return( TRUE );
}
/**
* na_object_object_copy:
* @target: the target #NAObject -derived object.
* @source: the source #NAObject -derived object.
* @recursive: whether the copy should be recursive.
*
* Copies @source to @target.
*
* Since: 2.30
*/
void
na_object_object_copy( NAObject *target, const NAObject *source, gboolean recursive )
{
CopyIter *data;
g_return_if_fail( NA_IS_OBJECT( target ));
g_return_if_fail( NA_IS_OBJECT( source ));
if( !NA_OBJECT( source )->private->dispose_has_run &&
!NA_OBJECT( target )->private->dispose_has_run ){
data = g_new0( CopyIter, 1 );
data->target = target;
data->recursive = recursive;
iter_on_class_hierarchy( NA_OBJECT( source ),
( HierarchyIterFunc ) object_copy_iter, ( void * ) data );
g_free( data );
}
}
static gboolean
object_copy_iter( GObjectClass *class, const NAObject *source, CopyIter *data )
{
gboolean stop = FALSE;
if( NA_OBJECT_CLASS( class )->copy ){
NA_OBJECT_CLASS( class )->copy( data->target, source, data->recursive );
}
return( stop );
}
/**
* na_object_object_dump:
* @object: the #NAObject -derived object to be dumped.
......@@ -678,29 +647,6 @@ na_object_object_unref( NAObject *object )
}
}
/*
* iter on the whole class hierarchy
* starting with NAObject, and to the most derived up to NAObjectAction..
*/
static void
iter_on_class_hierarchy( const NAObject *object, HierarchyIterFunc pfn, void *user_data )
{
gboolean stop;
GObjectClass *class;
GList *hierarchy, *ih;
stop = FALSE;
hierarchy = build_class_hierarchy( object );
for( ih = hierarchy ; ih && !stop ; ih = ih->next ){
class = ( GObjectClass * ) ih->data;
/*g_debug( "iter_on_class_hierarchy: class=%s", G_OBJECT_CLASS_NAME( class ));*/
stop = ( *pfn )( class, object, user_data );
}
g_list_free( hierarchy );
}
/*
* build the class hierarchy
* returns a list of GObjectClass, which starts with NAObject,
......@@ -727,7 +673,7 @@ build_class_hierarchy( const NAObject *object )
}
/**
* na_object_object_get_hierarchy:
* na_object_get_hierarchy:
* @object: the #NAObject -derived object.
*
* Returns: the class hierarchy,
......@@ -736,7 +682,7 @@ build_class_hierarchy( const NAObject *object )
* Since: 2.30
*/
GList *
na_object_object_get_hierarchy( const NAObject *object )
na_object_get_hierarchy( const NAObject *object )
{
GList *hierarchy;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment