[Gnucash-changes] Take ownership of plugins passed to the manager.

David Hampton hampton at cvs.gnucash.org
Sat Jun 11 17:32:47 EDT 2005


Log Message:
-----------
Take ownership of plugins passed to the manager.  Free all plugins at
gui shutdown. Documentation.

Tags:
----
gnucash-gnome2-dev

Modified Files:
--------------
    gnucash:
        ChangeLog
    gnucash/src/gnome-utils:
        gnc-plugin-manager.c
        gnc-plugin-manager.h

Revision Data
-------------
Index: ChangeLog
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/ChangeLog,v
retrieving revision 1.1487.2.224
retrieving revision 1.1487.2.225
diff -LChangeLog -LChangeLog -u -r1.1487.2.224 -r1.1487.2.225
--- ChangeLog
+++ ChangeLog
@@ -1,3 +1,9 @@
+2005-06-11  David Hampton  <hampton at employees.org>
+
+	* src/gnome-utils/gnc-plugin-manager.[ch]: Take ownership of
+	plugins passed to the manager.  Free all plugins at gui shutdown.
+	Documentation.
+
 2005-06-11  Derek Atkins  <derek at ihtfp.com>
 
 	* src/core-utils/Makefile.am
Index: gnc-plugin-manager.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnome-utils/Attic/gnc-plugin-manager.c,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -Lsrc/gnome-utils/gnc-plugin-manager.c -Lsrc/gnome-utils/gnc-plugin-manager.c -u -r1.1.2.1 -r1.1.2.2
--- src/gnome-utils/gnc-plugin-manager.c
+++ src/gnome-utils/gnc-plugin-manager.c
@@ -28,12 +28,15 @@
 
 #include "messages.h"
 #include "gnc-trace.h"
+#include "gnc-hooks.h"
 
 static short module = MOD_GUI;
 
 static void gnc_plugin_manager_class_init (GncPluginManagerClass *klass);
 static void gnc_plugin_manager_init (GncPluginManager *plugin);
+static void gnc_plugin_manager_dispose (GObject *object);
 static void gnc_plugin_manager_finalize (GObject *object);
+static void gnc_plugin_manager_shutdown (gpointer dummy, gpointer dummy2);
 
 struct GncPluginManagerPrivate
 {
@@ -84,6 +87,8 @@
 	if (singleton == NULL) {
 		singleton = g_object_new (GNC_TYPE_PLUGIN_MANAGER,
   					  NULL);
+		gnc_hook_add_dangler (HOOK_UI_SHUTDOWN,
+				      gnc_plugin_manager_shutdown, NULL);
 	}
 
 	return singleton;
@@ -104,8 +109,6 @@
 	if (index >= 0)
 		return;
 
-	g_object_ref (plugin);
-
 	manager->priv->plugins = g_list_append (manager->priv->plugins, plugin);
 	g_hash_table_insert (manager->priv->plugins_table,
 			     g_strdup( GNC_PLUGIN_GET_CLASS(plugin)->plugin_name ),
@@ -167,6 +170,7 @@
 
 	parent_class = g_type_class_peek_parent (klass);
 
+	object_class->dispose = gnc_plugin_manager_dispose;
 	object_class->finalize = gnc_plugin_manager_finalize;
 
 	signals[PLUGIN_ADDED] = g_signal_new ("plugin-added",
@@ -198,16 +202,41 @@
 }
 
 static void
-gnc_plugin_manager_finalize (GObject *object)
+gnc_plugin_manager_dispose (GObject *object)
 {
 	GncPluginManager *manager = GNC_PLUGIN_MANAGER (object);
 
 	g_return_if_fail (GNC_IS_PLUGIN_MANAGER (manager));
 	g_return_if_fail (manager->priv != NULL);
 
-	g_list_free (manager->priv->plugins);
 	g_hash_table_destroy (manager->priv->plugins_table);
+	manager->priv->plugins_table = NULL;
+
+	g_list_foreach (manager->priv->plugins, (GFunc)g_object_unref, NULL);
+	g_list_free (manager->priv->plugins);
+	manager->priv->plugins = NULL;
+
+	G_OBJECT_CLASS (parent_class)->dispose (object);
+}
+
+static void
+gnc_plugin_manager_finalize (GObject *object)
+{
+	GncPluginManager *manager = GNC_PLUGIN_MANAGER (object);
+
+	g_return_if_fail (GNC_IS_PLUGIN_MANAGER (manager));
+	g_return_if_fail (manager->priv != NULL);
+
 	g_free (manager->priv);
 
 	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
+
+static void
+gnc_plugin_manager_shutdown (gpointer dummy, gpointer dummy2)
+{
+	if (singleton != NULL) {
+	  g_object_unref(singleton);
+	  singleton = NULL;
+	}
+}
Index: gnc-plugin-manager.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnome-utils/Attic/gnc-plugin-manager.h,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -Lsrc/gnome-utils/gnc-plugin-manager.h -Lsrc/gnome-utils/gnc-plugin-manager.h -u -r1.1.2.1 -r1.1.2.2
--- src/gnome-utils/gnc-plugin-manager.h
+++ src/gnome-utils/gnc-plugin-manager.h
@@ -22,6 +22,33 @@
  * Boston, MA  02111-1307,  USA       gnu at gnu.org
  */
 
+/** @addtogroup GUI
+    @{ */
+/** @addtogroup Plugin Architecture
+    @{ */
+/** @addtogroup Plugin Manger
+    @{ */
+/** @file gnc-plugin-manager.h 
+    @brief  Plugin management functions for the GnuCash UI
+    @author Copyright (C) 2003 Jan Arne Petersen <jpetersen at uni-bonn.de>
+
+    The plugin manager maintains a list of all plugins that have been
+    instantiated by various parts of Gnucash.  The manager will
+    provide this list upon request, it will also look up individual
+    plugins on request.  The main client of this manager is the main
+    gnucash window code.  All plugins registered here will
+    automatically be installed in each top level gnucash window that
+    is created.
+
+    This code installs a hook to be called when the gnucash user
+    interface shuts down, and at that time it will unref any plugins
+    that are still in its plugin list.
+
+    Note: This code maintains a list of plugins (which provide user
+    interface items), not a list of plugin-pages (which provide window
+    content).
+*/
+
 #ifndef __GNC_PLUGIN_MANAGER_H
 #define __GNC_PLUGIN_MANAGER_H
 
@@ -29,6 +56,9 @@
 
 G_BEGIN_DECLS
 
+/** @name Basic Object Implementation */
+/** @{ */
+
 /* type macros */
 #define GNC_TYPE_PLUGIN_MANAGER            (gnc_plugin_manager_get_type ())
 #define GNC_PLUGIN_MANAGER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_PLUGIN_MANAGER, GncPluginManager))
@@ -41,33 +71,98 @@
 typedef struct GncPluginManagerPrivate GncPluginManagerPrivate;
 
 typedef struct {
-	GObject parent;
+	GObject object;
 
 	GncPluginManagerPrivate *priv;
 } GncPluginManager;
 
 typedef struct {
-	GObjectClass parent;
+	GObjectClass object;
 
 	/* Signals */
 	void (* plugin_added) (GncPluginManager *plugin_manager, GncPlugin *plugin);
 	void (* plugin_removed) (GncPluginManager *plugin_manager, GncPlugin *plugin);
 } GncPluginManagerClass;
 
-/* function prototypes */
-GType             gnc_plugin_manager_get_type      (void);
+/** Retrieve the GType value for the gnucash plugin manager.
+ *
+ *  @return The GType that corresponds to an object of this type.
+ */
+GType gnc_plugin_manager_get_type (void);
+
+/** @} */
+
+
+
+/** @name Management Functions */
+/** @{ */
+
+/** Retrieve a pointer to the plugin manager.  This object is a
+ *  singleton, that can only be retrieved via this function.  Once you
+ *  have a pointer to the manager, you can call it to add/remove
+ *  plugins, etc.
+ *
+ *  @return A pointer to the plugin manager object.
+ */
+GncPluginManager *gnc_plugin_manager_get (void);
+
+
+/** Add a plugin to the list maintained by the plugin manager.
+ *
+ *  @param manager A pointer to the plugin manager.  Retrieve this by
+ *  calling gnc_plugin_manager_get().
+ *
+ *  @param plugin A pointer to the plugin to add.
+ *
+ *  @note This function assumes ownership of this plugin.  Do not unref
+ *  the plugin after passing it off to the plugin manager.
+ */
+void gnc_plugin_manager_add_plugin (GncPluginManager *manager,
+				    GncPlugin *plugin);
+
+
+/** Remove a plugin from the list maintained by the plugin manager.
+ *
+ *  @param manager A pointer to the plugin manager.  Retrieve this by
+ *  calling gnc_plugin_manager_get().
+ *
+ *  @param plugin A pointer to the plugin to add.
+ */
+void gnc_plugin_manager_remove_plugin (GncPluginManager *manager,
+				       GncPlugin *plugin);
+
+
+/** Get a list of all plugins being held by the plugin manager.  This
+ *  function is used by the main gnucash window code to get the list
+ *  of plugins that need to be added to a new top level window.
+ *
+ *  @param manager A pointer to the plugin manager.  Retrieve this by
+ *  calling gnc_plugin_manager_get().
+ *
+ *  @return A list of plugins.  This list is owned by the caller, and
+ *  the must be frees when the caller is finished with it.
+ */
+GList *gnc_plugin_manager_get_plugins (GncPluginManager *manager);
+
+
+/** Find a plugin by name from the list of plugins being held by the
+ * plugin manager.
+ *
+ *  @param manager A pointer to the plugin manager.  Retrieve this by
+ *  calling gnc_plugin_manager_get().
+ *
+ *  @return A pointer to the requested plugin, or NULL if the plugin
+ *  couldn't be found.
+ */
+GncPlugin *gnc_plugin_manager_get_plugin (GncPluginManager *manager,
+					  const gchar *name);
+/** @} */
 
-GncPluginManager *gnc_plugin_manager_get           (void);
-
-void              gnc_plugin_manager_add_plugin    (GncPluginManager *manager,
-						    GncPlugin *plugin);
-void		  gnc_plugin_manager_remove_plugin (GncPluginManager *manager,
-						    GncPlugin *plugin);
-
-GList            *gnc_plugin_manager_get_plugins   (GncPluginManager *manager);
-GncPlugin        *gnc_plugin_manager_get_plugin    (GncPluginManager *manager,
-						    const gchar *name);
 
 G_END_DECLS
 
 #endif /* __GNC_PLUGIN_MANAGER_H */
+
+/** @} */
+/** @} */
+/** @} */


More information about the gnucash-changes mailing list