[nautilus-actions] Refactoring: src/api/na-api.h renamed to src/api/na-extension.h



commit 8832275200fb1e17ad3922090642b9bedde31a92
Author: Pierre Wieser <pwieser trychlos org>
Date:   Mon Feb 15 14:31:46 2010 +0100

    Refactoring: src/api/na-api.h renamed to src/api/na-extension.h

 ChangeLog                    |    7 +++
 src/api/README               |    9 ++--
 src/api/na-api.h             |  114 ---------------------------------------
 src/api/na-extension.h       |  120 ++++++++++++++++++++++++++++++++++++++++++
 src/io-desktop/nadp-module.c |   46 +++++++++-------
 src/io-gconf/nagp-module.c   |   46 +++++++++-------
 src/runtime/na-module.c      |   23 ++++----
 7 files changed, 195 insertions(+), 170 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e7328d7..f44b68b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2009-02-15 Pierre Wieser <pwieser trychlos org>
 
+	Rename src/api/na-api.h to src/api/na-extension.h
+
+	* src/api/README:
+	* src/io-desktop/nadp-module.c:
+	* src/io-gconf/nagp-module.c:
+	* src/runtime/na-module.c: Updated accordingly.
+
 	Define XML provider as a dynamic module.
 	
 	* io-xml/Makefile.am:
diff --git a/src/api/README b/src/api/README
index 2833de7..0783131 100644
--- a/src/api/README
+++ b/src/api/README
@@ -1,7 +1,8 @@
 This is the Nautilus-Actions extension interface.
 
-These files are used by dynamic extensions (e.g. I/O providers).
+Each extension library should at least implement the interface defined
+in na-extension.h.
 
-Headers are to be installed as part of a development environment of
-such a dynamic extension. They are to be included by the extension
-as '#include <nautilus-actions/api/header.h>'.
+Headers are installed as part of a development environment of such an
+extension. They are to be included by the extension as
+'#include <nautilus-actions/header.h>'.
diff --git a/src/api/na-extension.h b/src/api/na-extension.h
new file mode 100644
index 0000000..89ed552
--- /dev/null
+++ b/src/api/na-extension.h
@@ -0,0 +1,120 @@
+/*
+ * Nautilus Actions
+ * A Nautilus extension which offers configurable context menu actions.
+ *
+ * Copyright (C) 2005 The GNOME Foundation
+ * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
+ * Copyright (C) 2009, 2010 Pierre Wieser and others (see AUTHORS)
+ *
+ * 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 Library; see the file COPYING.  If not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place,
+ * Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Authors:
+ *   Frederic Ruaudel <grumz grumz net>
+ *   Rodrigo Moya <rodrigo gnome-db org>
+ *   Pierre Wieser <pwieser trychlos org>
+ *   ... and many others (see AUTHORS)
+ */
+
+#ifndef __NAUTILUS_ACTIONS_API_NA_EXTENSION_H__
+#define __NAUTILUS_ACTIONS_API_NA_EXTENSION_H__
+
+/**
+ * SECTION: na_extension
+ * @short_description: Nautilus-Actions extension interface definition.
+ * @include: nautilus-actions/na-extension.h
+ *
+ * Nautilus-Actions accepts extensions as dynamically loadable libraries
+ * (aka plugins).
+ *
+ * At startup time, candidate libraries are searched for in PKGLIBDIR/
+ * directory. A valid candidate must at least export the #na_extension_startup()
+ * and #na_extension_list_types() functions.
+ *
+ * Nautilus-Actions v 2.30 - API version:  1
+ */
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+/**
+ * na_extension_startup:
+ * @module: the #GTypeModule of the library being loaded.
+ *
+ * This function is called by the Nautilus-Actions plugin manager when
+ * the library is first loaded in memory. The library may so take
+ * advantage of this call by initializing itself, registering its
+ * internal #GType types, etc.
+ *
+ * Returns: %TRUE if the initialization is successfull, %FALSE else.
+ * In this later case, the library is unloaded and no more considered.
+ *
+ * A Nautilus-Actions extension must implement this function in order
+ * to be considered as a valid candidate to dynamic load.
+ */
+gboolean na_extension_startup    ( GTypeModule *module );
+
+/**
+ * na_extension_get_version:
+ *
+ * Returns: the version of this API supported by the module.
+ *
+ * If this function is not exported by the library, or returns zero,
+ * the plugin manager considers that the library only implements the
+ * version 1 of this API.
+ */
+guint    na_extension_get_version( void );
+
+/**
+ * na_extension_list_types:
+ * @types: the address where to store the zero-terminated array of
+ *  instantiable #GType types this library implements.
+ *
+ * Returned #GType types must already have been registered in the
+ * #GType system (e.g. at #na_extension_startup() time), and may implement
+ * one or more of the interfaces defined in Nautilus-Actions API.
+ *
+ * The Nautilus-Actions plugin manager will instantiate one #GTypeInstance-
+ * derived object for each returned #GType type, and associate these objects
+ * to this library.
+ *
+ * Returns: the number of #GType types returned in the @types array, not
+ * counting the terminating zero item.
+ *
+ * A Nautilus-Actions extension must implement this function in order
+ * to be considered as a valid candidate to dynamic load.
+ *
+ * If this function is not exported by the library, or returns zero,
+ * the plugin manager considers that the library doesn't implement
+ * any Nautilus-Action interface. In this case, the library is
+ * unloaded and no more considered.
+ */
+guint    na_extension_list_types ( const GType **types );
+
+/**
+ * na_extension_shutdown:
+ *
+ * This function is called by Nautilus-Actions when it is about to
+ * shutdown itself.
+ *
+ * The dynamicaly loaded library may take advantage of this call to
+ * release any resource it may have previously allocated.
+ */
+void     na_extension_shutdown   ( void );
+
+G_END_DECLS
+
+#endif /* __NAUTILUS_ACTIONS_API_NA_EXTENSION_H__ */
diff --git a/src/io-desktop/nadp-module.c b/src/io-desktop/nadp-module.c
index 4a716d5..fe0675b 100644
--- a/src/io-desktop/nadp-module.c
+++ b/src/io-desktop/nadp-module.c
@@ -32,23 +32,28 @@
 #include <config.h>
 #endif
 
-#include <syslog.h>
-
-#include <nautilus-actions/api/na-api.h>
+#include <api/na-extension.h>
 
 #include "nadp-desktop-provider.h"
 
+/* the count of GType types provided by this extension
+ * each new GType type must
+ * - be registered in na_extension_startup()
+ * - be addressed in na_extension_list_types().
+ */
+#define NADP_TYPES_COUNT	1
+
 /*
- * na_api_module_init:
+ * na_extension_startup:
  *
  * mandatory starting with API v. 1.
  */
 /* TODO: remove this when we will be ready to release the desktop provider */
 #ifdef NA_MAINTAINER_MODE
 gboolean
-na_api_module_init( GTypeModule *module )
+na_extension_startup( GTypeModule *module )
 {
-	static const gchar *thisfn = "nadp_module_na_api_module_initialize";
+	static const gchar *thisfn = "nadp_module_na_extension_startup";
 
 	g_debug( "%s: module=%p", thisfn, ( void * ) module );
 
@@ -59,14 +64,14 @@ na_api_module_init( GTypeModule *module )
 #endif
 
 /*
- * na_api_module_get_version:
+ * na_extension_get_version:
  *
  * optional, defaults to 1.
  */
 guint
-na_api_module_get_version( void )
+na_extension_get_version( void )
 {
-	static const gchar *thisfn = "nadp_module_na_api_module_get_version";
+	static const gchar *thisfn = "nadp_module_na_extension_get_version";
 	guint version;
 
 	version = 1;
@@ -77,34 +82,35 @@ na_api_module_get_version( void )
 }
 
 /*
- * na_api_module_list_types:
+ * na_extension_list_types:
  *
  * mandatory starting with v. 1.
  */
 guint
-na_api_module_list_types( const GType **types )
+na_extension_list_types( const GType **types )
 {
-	static const gchar *thisfn = "nadp_module_na_api_module_list_types";
-	#define count 1
-	static GType type_list[count];
+	static const gchar *thisfn = "nadp_module_na_extension_list_types";
+	static GType types_list [1+NADP_TYPES_COUNT];
 
 	g_debug( "%s: types=%p", thisfn, ( void * ) types );
 
-	type_list[0] = NADP_DESKTOP_PROVIDER_TYPE;
-	*types = type_list;
+	types_list[0] = NADP_DESKTOP_PROVIDER_TYPE;
+
+	types_list[NADP_TYPES_COUNT] = 0;
+	*types = types_list;
 
-	return( count );
+	return( NADP_TYPES_COUNT );
 }
 
 /*
- * na_api_module_shutdown:
+ * na_extension_shutdown:
  *
  * mandatory starting with v. 1.
  */
 void
-na_api_module_shutdown( void )
+na_extension_shutdown( void )
 {
-	static const gchar *thisfn = "nadp_module_na_api_module_shutdown";
+	static const gchar *thisfn = "nadp_module_na_extension_shutdown";
 
 	g_debug( "%s", thisfn );
 }
diff --git a/src/io-gconf/nagp-module.c b/src/io-gconf/nagp-module.c
index 1c47db0..efe7327 100644
--- a/src/io-gconf/nagp-module.c
+++ b/src/io-gconf/nagp-module.c
@@ -32,21 +32,26 @@
 #include <config.h>
 #endif
 
-#include <syslog.h>
-
-#include <nautilus-actions/api/na-api.h>
+#include <api/na-extension.h>
 
 #include "nagp-gconf-provider.h"
 
+/* the count of GType types provided by this extension
+ * each new GType type must
+ * - be registered in na_extension_startup()
+ * - be addressed in na_extension_list_types().
+ */
+#define NAGP_TYPES_COUNT	1
+
 /*
- * na_api_module_init:
+ * na_extension_startup:
  *
  * mandatory starting with API v. 1.
  */
 gboolean
-na_api_module_init( GTypeModule *module )
+na_extension_startup( GTypeModule *module )
 {
-	static const gchar *thisfn = "nagp_module_na_api_module_initialize";
+	static const gchar *thisfn = "nagp_module_na_extension_startup";
 
 	g_debug( "%s: module=%p", thisfn, ( void * ) module );
 
@@ -56,14 +61,14 @@ na_api_module_init( GTypeModule *module )
 }
 
 /*
- * na_api_module_get_version:
+ * na_extension_get_version:
  *
  * optional, defaults to 1.
  */
 guint
-na_api_module_get_version( void )
+na_extension_get_version( void )
 {
-	static const gchar *thisfn = "nagp_module_na_api_module_get_version";
+	static const gchar *thisfn = "nagp_module_na_extension_get_version";
 	guint version;
 
 	version = 1;
@@ -74,34 +79,35 @@ na_api_module_get_version( void )
 }
 
 /*
- * na_api_module_list_types:
+ * na_extension_list_types:
  *
  * mandatory starting with v. 1.
  */
 guint
-na_api_module_list_types( const GType **types )
+na_extension_list_types( const GType **types )
 {
-	static const gchar *thisfn = "nagp_module_na_api_module_list_types";
-	#define count 1
-	static GType type_list[count];
+	static const gchar *thisfn = "nagp_module_na_extension_list_types";
+	static GType types_list [1+NAGP_TYPES_COUNT];
 
 	g_debug( "%s: types=%p", thisfn, ( void * ) types );
 
-	type_list[0] = NAGP_GCONF_PROVIDER_TYPE;
-	*types = type_list;
+	types_list[0] = NAGP_GCONF_PROVIDER_TYPE;
+
+	types_list[NAGP_TYPES_COUNT] = 0;
+	*types = types_list;
 
-	return( count );
+	return( NAGP_TYPES_COUNT );
 }
 
 /*
- * na_api_module_shutdown:
+ * na_extension_shutdown:
  *
  * mandatory starting with v. 1.
  */
 void
-na_api_module_shutdown( void )
+na_extension_shutdown( void )
 {
-	static const gchar *thisfn = "nagp_module_na_api_module_shutdown";
+	static const gchar *thisfn = "nagp_module_na_extension_shutdown";
 
 	g_debug( "%s", thisfn );
 }
diff --git a/src/runtime/na-module.c b/src/runtime/na-module.c
index 3a9c286..41ef6b5 100644
--- a/src/runtime/na-module.c
+++ b/src/runtime/na-module.c
@@ -34,7 +34,8 @@
 
 #include <gmodule.h>
 
-#include "na-utils.h"
+#include <api/na-core-utils.h>
+
 #include "na-module.h"
 
 /* private class data
@@ -54,7 +55,7 @@ struct NAModulePrivate {
 
 	/* api
 	 */
-	gboolean ( *initialize ) ( GTypeModule *module );
+	gboolean ( *startup )    ( GTypeModule *module );
 	guint    ( *get_version )( void );
 	gint     ( *list_types ) ( const GType **types );
 	void     ( *shutdown )   ( void );
@@ -253,7 +254,7 @@ na_module_load_modules( void )
 				fname = g_build_filename( dirname, entry, NULL );
 				module = module_new( fname );
 				if( module ){
-					module->private->name = na_utils_remove_suffix( entry, suffix );
+					module->private->name = na_core_utils_str_remove_suffix( entry, suffix );
 					modules = g_list_prepend( modules, module );
 					g_debug( "%s: module %s successfully loaded", thisfn, entry );
 				}
@@ -331,11 +332,9 @@ is_a_na_plugin( NAModule *module )
 	gboolean ok;
 
 	ok =
-		plugin_check( module, "na_api_module_init"       , ( gpointer * ) &module->private->initialize) &&
-		plugin_check( module, "na_api_module_get_version", ( gpointer * ) &module->private->get_version ) &&
-		plugin_check( module, "na_api_module_list_types" , ( gpointer * ) &module->private->list_types ) &&
-		plugin_check( module, "na_api_module_shutdown"   , ( gpointer * ) &module->private->shutdown ) &&
-		module->private->initialize( G_TYPE_MODULE( module ));
+		plugin_check( module, "na_extension_startup"    , ( gpointer * ) &module->private->startup) &&
+		plugin_check( module, "na_extension_list_types" , ( gpointer * ) &module->private->list_types ) &&
+		module->private->startup( G_TYPE_MODULE( module ));
 
 	if( ok ){
 		g_debug( "%s: %s: ok", thisfn, module->private->path );
@@ -360,9 +359,9 @@ plugin_check( NAModule *module, const gchar *symbol, gpointer *pfn )
 }
 
 /*
- * the 'na_api_module_init' function of the plugin has been already
- * called ; the GTypes the plugin provides have so already been declared
- * in the GType system
+ * the 'na_extension_startup' function of the plugin has been already
+ * called ; the GType types the plugin provides have so already been
+ * registered in the GType system
  *
  * we ask here the plugin to give us a list of these GTypes
  * for each GType, we allocate a new object of the given class
@@ -435,7 +434,7 @@ module_unload( GTypeModule *gmodule )
 		g_module_close( module->private->library );
 	}
 
-	module->private->initialize = NULL;
+	module->private->startup = NULL;
 	module->private->get_version = NULL;
 	module->private->list_types = NULL;
 	module->private->shutdown = NULL;



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