[maemo-commits] [maemo-commits] r8822 - in projects/haf/branches/maemo-af-desktop/hildon-desktop: . libhildondesktop src

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Tue Dec 19 17:11:20 EET 2006
Author: lucasr
Date: 2006-12-19 17:11:19 +0200 (Tue, 19 Dec 2006)
New Revision: 8822

Modified:
   projects/haf/branches/maemo-af-desktop/hildon-desktop/ChangeLog
   projects/haf/branches/maemo-af-desktop/hildon-desktop/libhildondesktop/hildon-desktop-plugin.c
   projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-plugin-loader-default.c
   projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-plugin-loader-default.h
   projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-plugin-loader-factory.c
   projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-plugin-loader-legacy.c
Log:
2006-12-19  Lucas Rocha  <lucas.rocha at nokia.com>

	* src/hd-plugin-loader-factory.c: fix internal registry to really
	re-use  plugin loader instances.
	* src/hd-plugin-loader-default.[ch]: add internal registry to store
	and re-use instances of HildonDesktopPlugin.
	* src/hd-plugin-loader-legacy.c: use g_path_is_absolute instead of
	string checking.
	* libhildondesktop/hildon-desktop-plugin.c: clean GType list when
	unloading the module.


Modified: projects/haf/branches/maemo-af-desktop/hildon-desktop/ChangeLog
===================================================================
--- projects/haf/branches/maemo-af-desktop/hildon-desktop/ChangeLog	2006-12-19 13:37:01 UTC (rev 8821)
+++ projects/haf/branches/maemo-af-desktop/hildon-desktop/ChangeLog	2006-12-19 15:11:19 UTC (rev 8822)
@@ -1,3 +1,14 @@
+2006-12-19  Lucas Rocha  <lucas.rocha at nokia.com>
+
+	* src/hd-plugin-loader-factory.c: fix internal registry to really
+	re-use  plugin loader instances.
+	* src/hd-plugin-loader-default.[ch]: add internal registry to store
+	and re-use instances of HildonDesktopPlugin.
+	* src/hd-plugin-loader-legacy.c: use g_path_is_absolute instead of
+	string checking.
+	* libhildondesktop/hildon-desktop-plugin.c: clean GType list when
+	unloading the module.
+
 2006-12-19  Moises Martinez  <moises.martinez at nokia.com>
 
 	* test/test5.c: test added

Modified: projects/haf/branches/maemo-af-desktop/hildon-desktop/libhildondesktop/hildon-desktop-plugin.c
===================================================================
--- projects/haf/branches/maemo-af-desktop/hildon-desktop/libhildondesktop/hildon-desktop-plugin.c	2006-12-19 13:37:01 UTC (rev 8821)
+++ projects/haf/branches/maemo-af-desktop/hildon-desktop/libhildondesktop/hildon-desktop-plugin.c	2006-12-19 15:11:19 UTC (rev 8822)
@@ -94,6 +94,8 @@
 {
   plugin->priv = HILDON_DESKTOP_PLUGIN_GET_PRIVATE (plugin);
 
+  plugin->gtypes = NULL;
+
   plugin->priv->path      = NULL;
   plugin->priv->library   = NULL;
 
@@ -106,6 +108,7 @@
 {
   HildonDesktopPlugin *plugin = HILDON_DESKTOP_PLUGIN (object);
 
+  g_list_free (plugin->gtypes);
   g_free (plugin->priv->path);
 
   G_OBJECT_CLASS (hildon_desktop_plugin_parent_class)->finalize (object);
@@ -206,6 +209,9 @@
   plugin->priv->library  = NULL;
   plugin->priv->load     = NULL;
   plugin->priv->unload   = NULL;
+
+  g_list_free (plugin->gtypes);
+  plugin->gtypes = NULL;
 }
 
 HildonDesktopPlugin *

Modified: projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-plugin-loader-default.c
===================================================================
--- projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-plugin-loader-default.c	2006-12-19 13:37:01 UTC (rev 8821)
+++ projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-plugin-loader-default.c	2006-12-19 15:11:19 UTC (rev 8822)
@@ -33,17 +33,27 @@
 
 G_DEFINE_TYPE (HDPluginLoaderDefault, hd_plugin_loader_default, HD_TYPE_PLUGIN_LOADER);
 
+struct _HDPluginLoaderDefaultPrivate 
+{
+  GHashTable *registry;
+};
+
 static GList * 
 hd_plugin_loader_default_open_module (HDPluginLoaderDefault *loader,
-                                     GError **error)
+                                      GError **error)
 {
+  HDPluginLoaderDefaultPrivate *priv;
   HildonDesktopPlugin *plugin; 
   GKeyFile *keyfile;
   GList *objects = NULL;
   GError *keyfile_error = NULL;
   gchar *module_file = NULL;
   gchar *module_path = NULL;
-  
+
+  g_return_val_if_fail (HD_IS_PLUGIN_LOADER_DEFAULT (loader), NULL);
+
+  priv = loader->priv;
+ 
   keyfile = hd_plugin_loader_get_key_file (HD_PLUGIN_LOADER (loader));
   
   module_file = g_key_file_get_string (keyfile,
@@ -58,7 +68,7 @@
     return NULL;
   }
 
-  if (module_file && module_file[0] == G_DIR_SEPARATOR)
+  if (g_path_is_absolute (module_file))
   {
     module_path = module_file;
   }
@@ -71,8 +81,15 @@
     g_free (module_file);
   }
 
-  plugin = hildon_desktop_plugin_new (module_path);
+  plugin = (HildonDesktopPlugin *) g_hash_table_lookup (priv->registry, 
+                                                        module_path);
 
+  if (!plugin)
+  {
+    plugin = hildon_desktop_plugin_new (module_path);
+    g_hash_table_insert (priv->registry, g_strdup (module_path), plugin);
+  }
+
   if (g_type_module_use (G_TYPE_MODULE (plugin)) == FALSE)
   {
     g_warning ("Error loading module at %s", module_path);
@@ -133,15 +150,42 @@
   return objects;
 }
 
+static gboolean
+hd_plugin_loader_factory_free_module (gchar *key, GObject *object)
+{
+  g_free (key);
+
+  return TRUE;
+}
+
 static void
 hd_plugin_loader_default_finalize (GObject *loader)
 {
+  HDPluginLoaderDefaultPrivate *priv;
+
+  g_return_if_fail (loader != NULL);
+  g_return_if_fail (HD_IS_PLUGIN_LOADER_DEFAULT (loader));
+
+  priv = HD_PLUGIN_LOADER_DEFAULT (loader)->priv;
+ 
+  if (priv->registry != NULL) 
+  {
+    g_hash_table_foreach_remove (priv->registry, 
+                                 (GHRFunc) hd_plugin_loader_factory_free_module, 
+                                 NULL);
+
+    g_hash_table_destroy (priv->registry);
+  }
+
   G_OBJECT_CLASS (hd_plugin_loader_default_parent_class)->finalize (loader);
 }
 
 static void
 hd_plugin_loader_default_init (HDPluginLoaderDefault *loader)
 {
+  loader->priv = HD_PLUGIN_LOADER_DEFAULT_GET_PRIVATE (loader);
+
+  loader->priv->registry = g_hash_table_new (g_str_hash, g_str_equal);
 }
 
 static void
@@ -156,5 +200,6 @@
   object_class->finalize = hd_plugin_loader_default_finalize;
 
   loader_class->load = hd_plugin_loader_default_load;
+
+  g_type_class_add_private (object_class, sizeof (HDPluginLoaderDefaultPrivate));
 }
-

Modified: projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-plugin-loader-default.h
===================================================================
--- projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-plugin-loader-default.h	2006-12-19 13:37:01 UTC (rev 8821)
+++ projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-plugin-loader-default.h	2006-12-19 15:11:19 UTC (rev 8822)
@@ -41,14 +41,16 @@
 #define HD_IS_PLUGIN_LOADER_DEFAULT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), HD_TYPE_PLUGIN_LOADER_DEFAULT_CLASS))
 #define HD_PLUGIN_LOADER_DEFAULT_GET_CLASS(obj)	 (G_TYPE_INSTANCE_GET_CLASS ((obj), HD_TYPE_PLUGIN_LOADER_DEFAULT, HDPluginLoaderDefaultClass))
 
-struct _HDPluginLoaderDefaultClass
+struct _HDPluginLoaderDefault
 {
-  HDPluginLoaderClass parent_class;
+  HDPluginLoader parent;
+
+  HDPluginLoaderDefaultPrivate *priv;
 };
 
-struct _HDPluginLoaderDefault
+struct _HDPluginLoaderDefaultClass
 {
-  HDPluginLoader parent;
+  HDPluginLoaderClass parent_class;
 };
 
 GType  hd_plugin_loader_default_get_type  (void);

Modified: projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-plugin-loader-factory.c
===================================================================
--- projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-plugin-loader-factory.c	2006-12-19 13:37:01 UTC (rev 8821)
+++ projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-plugin-loader-factory.c	2006-12-19 15:11:19 UTC (rev 8822)
@@ -154,25 +154,23 @@
 
   if (!loader) 
   {
+    /* Create instance of plugin loader and add to registry for 
+       later use */
     if (!g_ascii_strcasecmp (type, HD_PLUGIN_LOADER_TYPE_OLD_API) ||
         !g_ascii_strcasecmp (type, HD_PLUGIN_LOADER_TYPE_OLD_API_HOME)) 
     {
-      /* Create instance of Old API plugin loader and 
-         add to registry for later use */
       loader = g_object_new (HD_TYPE_PLUGIN_LOADER_LEGACY, NULL);
-      g_hash_table_insert (priv->registry, type, loader);
     }
     else if (!g_ascii_strcasecmp (type, HD_PLUGIN_LOADER_TYPE_DEFAULT)) 
     {
-      /* Create instance of Default API plugin loader and 
-         add to registry for later use */
       loader = g_object_new (HD_TYPE_PLUGIN_LOADER_DEFAULT, NULL);
-      g_hash_table_insert (priv->registry, type, loader);
     }
     else
     {
       g_warning ("Unknown Plugin Loader type: %s", type);
     }
+
+    g_hash_table_insert (priv->registry, g_strdup (type), loader);
   }
 
   hd_plugin_loader_set_key_file (loader, keyfile);

Modified: projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-plugin-loader-legacy.c
===================================================================
--- projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-plugin-loader-legacy.c	2006-12-19 13:37:01 UTC (rev 8821)
+++ projects/haf/branches/maemo-af-desktop/hildon-desktop/src/hd-plugin-loader-legacy.c	2006-12-19 15:11:19 UTC (rev 8822)
@@ -248,7 +248,7 @@
       return;
     }
 
-  if (module_file && module_file[0] == G_DIR_SEPARATOR)
+  if (g_path_is_absolute (module_file))
     module_path = module_file;
   else
     {


More information about the maemo-commits mailing list