[nautilus-actions] Review NAIFactoryProvider interface



commit 9e1faed1aee2f6ecac315338d0299ff3e1034d01
Author: Pierre Wieser <pwieser trychlos org>
Date:   Tue Jan 3 23:13:15 2012 +0100

    Review NAIFactoryProvider interface

 ChangeLog                       |    3 ++
 src/core/na-factory-provider.c  |   19 ++---------
 src/core/na-ifactory-provider.c |   61 ++++++++++++++++----------------------
 3 files changed, 33 insertions(+), 50 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 1078313..b185402 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2012-01-03 Pierre Wieser <pwieser trychlos org>
 
+	* src/core/na-factory-provider.c:
+	* src/core/na-ifactory-provider.c: Review NAIFactoryProvider interface.
+
 	* src/core/na-factory-object.c:
 	* src/core/na-ifactory-object.c: Review NAIFactoryObject interface.
 
diff --git a/src/core/na-factory-provider.c b/src/core/na-factory-provider.c
index b050d28..4ffe102 100644
--- a/src/core/na-factory-provider.c
+++ b/src/core/na-factory-provider.c
@@ -36,9 +36,6 @@
 
 #include "na-factory-provider.h"
 
-extern gboolean ifactory_provider_initialized;		/* defined in na-ifactory-provider.c */
-extern gboolean ifactory_provider_finalized;
-
 /*
  * na_factory_provider_read_data:
  * @reader: the instance which implements this #NAIFactoryProvider interface.
@@ -64,12 +61,8 @@ na_factory_provider_read_data( const NAIFactoryProvider *reader, void *reader_da
 
 	boxed = NULL;
 
-	if( ifactory_provider_initialized && !ifactory_provider_finalized ){
-
-		if( NA_IFACTORY_PROVIDER_GET_INTERFACE( reader )->read_data ){
-
-			boxed = NA_IFACTORY_PROVIDER_GET_INTERFACE( reader )->read_data( reader, reader_data, object, def, messages );
-		}
+	if( NA_IFACTORY_PROVIDER_GET_INTERFACE( reader )->read_data ){
+		boxed = NA_IFACTORY_PROVIDER_GET_INTERFACE( reader )->read_data( reader, reader_data, object, def, messages );
 	}
 
 	return( boxed );
@@ -98,12 +91,8 @@ na_factory_provider_write_data( const NAIFactoryProvider *writer, void *writer_d
 
 	code = NA_IIO_PROVIDER_CODE_NOT_WILLING_TO_RUN;
 
-	if( ifactory_provider_initialized && !ifactory_provider_finalized ){
-
-		if( NA_IFACTORY_PROVIDER_GET_INTERFACE( writer )->write_data ){
-
-			code = NA_IFACTORY_PROVIDER_GET_INTERFACE( writer )->write_data( writer, writer_data, object, boxed, messages );
-		}
+	if( NA_IFACTORY_PROVIDER_GET_INTERFACE( writer )->write_data ){
+		code = NA_IFACTORY_PROVIDER_GET_INTERFACE( writer )->write_data( writer, writer_data, object, boxed, messages );
 	}
 
 	return( code );
diff --git a/src/core/na-ifactory-provider.c b/src/core/na-ifactory-provider.c
index f97a6c4..6166238 100644
--- a/src/core/na-ifactory-provider.c
+++ b/src/core/na-ifactory-provider.c
@@ -44,12 +44,11 @@ struct _NAIFactoryProviderInterfacePrivate {
 	void *empty;						/* so that gcc -pedantic is happy */
 };
 
-gboolean ifactory_provider_initialized = FALSE;
-gboolean ifactory_provider_finalized   = FALSE;
+static guint st_initializations = 0;	/* interface initialization count */
 
 static GType register_type( void );
-static void  interface_base_init( NAIFactoryProviderInterface *klass );
-static void  interface_base_finalize( NAIFactoryProviderInterface *klass );
+static void  interface_init( NAIFactoryProviderInterface *klass );
+static void  interface_finalize( NAIFactoryProviderInterface *klass );
 
 static guint ifactory_provider_get_version( const NAIFactoryProvider *instance );
 
@@ -85,8 +84,8 @@ register_type( void )
 
 	static const GTypeInfo info = {
 		sizeof( NAIFactoryProviderInterface ),
-		( GBaseInitFunc ) interface_base_init,
-		( GBaseFinalizeFunc ) interface_base_finalize,
+		( GBaseInitFunc ) interface_init,
+		( GBaseFinalizeFunc ) interface_finalize,
 		NULL,
 		NULL,
 		NULL,
@@ -105,11 +104,11 @@ register_type( void )
 }
 
 static void
-interface_base_init( NAIFactoryProviderInterface *klass )
+interface_init( NAIFactoryProviderInterface *klass )
 {
-	static const gchar *thisfn = "na_ifactory_provider_interface_base_init";
+	static const gchar *thisfn = "na_ifactory_provider_interface_init";
 
-	if( !ifactory_provider_initialized ){
+	if( !st_initializations ){
 
 		g_debug( "%s: klass=%p (%s)", thisfn, ( void * ) klass, G_OBJECT_CLASS_NAME( klass ));
 
@@ -122,21 +121,21 @@ interface_base_init( NAIFactoryProviderInterface *klass )
 		klass->write_start = NULL;
 		klass->write_data = NULL;
 		klass->write_done = NULL;
-
-		ifactory_provider_initialized = TRUE;
 	}
+
+	st_initializations += 1;
 }
 
 static void
-interface_base_finalize( NAIFactoryProviderInterface *klass )
+interface_finalize( NAIFactoryProviderInterface *klass )
 {
-	static const gchar *thisfn = "na_ifactory_provider_interface_base_finalize";
+	static const gchar *thisfn = "na_ifactory_provider_interface_finalize";
 
-	if( ifactory_provider_initialized && !ifactory_provider_finalized ){
+	st_initializations -= 1;
 
-		g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
+	if( !st_initializations ){
 
-		ifactory_provider_finalized = TRUE;
+		g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
 
 		g_free( klass->private );
 	}
@@ -192,12 +191,9 @@ na_ifactory_provider_read_item( const NAIFactoryProvider *reader, void *reader_d
 	g_return_if_fail( NA_IS_IFACTORY_PROVIDER( reader ));
 	g_return_if_fail( NA_IS_IFACTORY_OBJECT( object ));
 
-	if( ifactory_provider_initialized && !ifactory_provider_finalized ){
-
-		v_factory_provider_read_start( reader, reader_data, object, messages );
-		na_factory_object_read_item( object, reader, reader_data, messages );
-		v_factory_provider_read_done( reader, reader_data, object, messages );
-	}
+	v_factory_provider_read_start( reader, reader_data, object, messages );
+	na_factory_object_read_item( object, reader, reader_data, messages );
+	v_factory_provider_read_done( reader, reader_data, object, messages );
 }
 
 /**
@@ -224,22 +220,17 @@ na_ifactory_provider_write_item( const NAIFactoryProvider *writer, void *writer_
 	g_return_val_if_fail( NA_IS_IFACTORY_PROVIDER( writer ), NA_IIO_PROVIDER_CODE_PROGRAM_ERROR );
 	g_return_val_if_fail( NA_IS_IFACTORY_OBJECT( object ), NA_IIO_PROVIDER_CODE_PROGRAM_ERROR );
 
-	code = NA_IIO_PROVIDER_CODE_NOT_WILLING_TO_RUN;
-
-	if( ifactory_provider_initialized && !ifactory_provider_finalized ){
+	g_debug( "%s: writer=%p, writer_data=%p, object=%p (%s)",
+			thisfn, ( void * ) writer, ( void * ) writer_data, ( void * ) object, G_OBJECT_TYPE_NAME( object ));
 
-		g_debug( "%s: writer=%p, writer_data=%p, object=%p (%s)",
-				thisfn, ( void * ) writer, ( void * ) writer_data, ( void * ) object, G_OBJECT_TYPE_NAME( object ));
+	code = v_factory_provider_write_start( writer, writer_data, object, messages );
 
-		code = v_factory_provider_write_start( writer, writer_data, object, messages );
-
-		if( code == NA_IIO_PROVIDER_CODE_OK ){
-			code = na_factory_object_write_item( object, writer, writer_data, messages );
-		}
+	if( code == NA_IIO_PROVIDER_CODE_OK ){
+		code = na_factory_object_write_item( object, writer, writer_data, messages );
+	}
 
-		if( code == NA_IIO_PROVIDER_CODE_OK ){
-			code = v_factory_provider_write_done( writer, writer_data, object, messages );
-		}
+	if( code == NA_IIO_PROVIDER_CODE_OK ){
+		code = v_factory_provider_write_done( writer, writer_data, object, messages );
 	}
 
 	return( code );



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]