[maemo-commits] [maemo-commits] r10866 - in projects/haf/trunk/libosso: . debian src

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Fri Mar 30 16:59:06 EEST 2007
Author: kihamala
Date: 2007-03-30 16:59:04 +0300 (Fri, 30 Mar 2007)
New Revision: 10866

Modified:
   projects/haf/trunk/libosso/ChangeLog
   projects/haf/trunk/libosso/debian/changelog
   projects/haf/trunk/libosso/src/osso-cp-plugin.c
   projects/haf/trunk/libosso/src/osso-cp-plugin.h
   projects/haf/trunk/libosso/src/osso-init.c
   projects/haf/trunk/libosso/src/osso-internal.h
Log:
Resident Ev.. Plugin patch from Johan


Modified: projects/haf/trunk/libosso/ChangeLog
===================================================================
--- projects/haf/trunk/libosso/ChangeLog	2007-03-30 13:34:21 UTC (rev 10865)
+++ projects/haf/trunk/libosso/ChangeLog	2007-03-30 13:59:04 UTC (rev 10866)
@@ -1,3 +1,13 @@
+2007-03-28  Johan Bilien <johan.bilien at nokia.com>
+
+	* src/osso-internal.h: replaced GArray *cp_plugins with
+	a GHashTable
+	* src/osso-cp-plugin.c:
+	(try_plugin): use this hash table to store
+	the dlopen handle, and reuse the handle if the same plugin
+	is run again (making it resident).
+	(close_lib): removed since unused
+
 2007-03-27  Marius Vollmer  <marius.vollmer at nokia.com>
 
 	* src/osso-state.h (validate_state): Removed static prototype,

Modified: projects/haf/trunk/libosso/debian/changelog
===================================================================
--- projects/haf/trunk/libosso/debian/changelog	2007-03-30 13:34:21 UTC (rev 10865)
+++ projects/haf/trunk/libosso/debian/changelog	2007-03-30 13:59:04 UTC (rev 10866)
@@ -1,3 +1,10 @@
+libosso (2.5-1) unstable; urgency=low
+
+  * UNRELEASED
+  * Resident Plugin I patch from Johan Bilien (MB#1184).
+
+ -- Kimmo Hämäläinen <kimmo.hamalainen at nokia.com>  Fri, 30 Mar 2007 16:57:34 +0300
+
 libosso (2.4-1) unstable; urgency=low
 
   * Bring back osso_application_set_exit_cb(), osso_state_open_write(),

Modified: projects/haf/trunk/libosso/src/osso-cp-plugin.c
===================================================================
--- projects/haf/trunk/libosso/src/osso-cp-plugin.c	2007-03-30 13:34:21 UTC (rev 10865)
+++ projects/haf/trunk/libosso/src/osso-cp-plugin.c	2007-03-30 13:59:04 UTC (rev 10866)
@@ -84,10 +84,10 @@
 
 
 static void *
-try_plugin (const char *dir, const char *file)
+try_plugin (osso_context_t *osso, const char *dir, const char *file)
 {
   char libname[PATH_MAX];
-  void *handle;
+  void *handle = NULL;
 
   if (snprintf (libname, PATH_MAX, "%s/%s", dir, file) >= PATH_MAX)
     {
@@ -95,11 +95,19 @@
       return NULL;
     }
 
+  if (osso->cp_plugins)
+    handle = g_hash_table_lookup (osso->cp_plugins, libname);
+
+  if (handle)
+    return handle;
+
   handle = dlopen (libname, RTLD_LAZY | RTLD_GLOBAL);
   if (handle == NULL)
     {
       ULOG_ERR_F("Unable to load library '%s': %s", libname, dlerror());
     }
+
+  g_hash_table_insert (osso->cp_plugins, g_strdup (libname), handle);
   return handle;
 }
 
@@ -107,10 +115,9 @@
 				     const gchar *filename,
 				     gpointer data, gboolean user_activated)
 {
-    gint r;
+    void *handle = NULL;
     osso_return_t ret;
     osso_cp_plugin_exec_f *exec = NULL;
-    _osso_cp_plugin_t p;
    
     if (osso == NULL || filename == NULL) {
 	ULOG_ERR_F("invalid arguments");
@@ -134,8 +141,9 @@
         
 
     /* First try builtin path */
-    p.lib = try_plugin (OSSO_CTRLPANELPLUGINDIR, filename);
-    if (p.lib == NULL)
+    handle = try_plugin (osso, OSSO_CTRLPANELPLUGINDIR, filename);
+
+    if (handle == NULL)
       {
 	/* Then try the directories in LIBOSSO_CP_PLUGIN_DIRS
 	 */
@@ -145,8 +153,8 @@
 	    char *dirs_copy = strdup (dirs), *ptr = dirs_copy, *tok;
 	    while ((tok = strsep (&ptr, ":")))
 	      {
-		p.lib = try_plugin (tok, filename);
-		if (p.lib)
+		handle = try_plugin (osso, tok, filename);
+		if (handle)
 		  break;
 	      }
 	    if (dirs_copy)
@@ -156,18 +164,15 @@
 	  }
       }
 
-    if (p.lib == NULL) {
+    if (handle == NULL) {
         ULOG_ERR_F("library '%s' could not be opened", filename);
         return OSSO_ERROR;
     }
 
-    p.name = g_path_get_basename(filename);
-
     dprint("..");
     fflush(stderr);
-    g_array_append_val(osso->cp_plugins, p);
     
-    exec = dlsym(p.lib, "execute");
+    exec = dlsym(handle, "execute");
     dprint("..");
     /* function wasn't found or it was NULL */
     if (exec == NULL) {
@@ -181,11 +186,6 @@
     ret = exec(osso, data, user_activated);  
     _exec_err1:
 
-    r = _close_lib(osso->cp_plugins, p.name); /* p.name is freed here */
-    if (r != 0) {
-	ULOG_ERR_F("Error closing library");
-	ret = OSSO_ERROR;
-    }
     return ret;
 }
 
@@ -193,16 +193,12 @@
 					const gchar *filename,
 					gpointer data)
 {
-    gchar *pluginname;
-    _osso_cp_plugin_t *p = NULL;
-    GArray *a;
-    gint i;
+    void *handle = NULL;
     
     if (osso == NULL || filename == NULL) {
 	ULOG_ERR_F("invalid arguments");
 	return OSSO_INVALID;
     }
-    a = osso->cp_plugins;
 
     if (is_applet_running_in_cp (osso, filename))
     {
@@ -210,20 +206,15 @@
          * by controlpanel, which will take care of saving its state */
         return OSSO_OK;
     }
-    
-    pluginname = g_path_get_basename(filename);
-    for (i = 0; i < a->len; i++) {
-	p = &g_array_index(a, _osso_cp_plugin_t, i);
-	if (strcmp(p->name, pluginname) == 0)
-	    break;
-    }
-    g_free(pluginname); pluginname = NULL;
 
-    if (i < a->len) {
+    if (osso->cp_plugins)
+      handle = g_hash_table_lookup(osso->cp_plugins, filename);
+
+    if (handle) {
 	osso_return_t ret;
 	osso_cp_plugin_save_state_f *ss = NULL;
 
- 	ss = dlsym(p->lib, "save_state"); 
+ 	ss = dlsym(handle, "save_state"); 
 	
 	/* function wasn't found or it was NULL */
 	if (ss == NULL) {
@@ -243,27 +234,3 @@
 	return OSSO_ERROR;
     }
 }
-
-
-static int _close_lib(GArray *a, const gchar *n)
-{
-    gint i=0, r=0;
-    _osso_cp_plugin_t *p = NULL;
-
-    while (i < a->len) {
-        p = &g_array_index(a, _osso_cp_plugin_t, i);
-        if (strcmp(p->name, n) == 0)
-            break;
-        else
-            i++;
-    }
-
-    if (i < a->len) {
-        r = dlclose(p->lib);
-        g_free(p->name);
-        g_array_remove_index_fast(a, i);
-    }
-
-    return r;
-}
-                        

Modified: projects/haf/trunk/libosso/src/osso-cp-plugin.h
===================================================================
--- projects/haf/trunk/libosso/src/osso-cp-plugin.h	2007-03-30 13:34:21 UTC (rev 10865)
+++ projects/haf/trunk/libosso/src/osso-cp-plugin.h	2007-03-30 13:59:04 UTC (rev 10866)
@@ -65,12 +65,4 @@
 						    gpointer data);
 
 
-
-static int _close_lib(GArray *a, const gchar *n);
-
-struct _osso_cp {
-    gchar *name;
-    gpointer data;
-};
-
 #endif

Modified: projects/haf/trunk/libosso/src/osso-init.c
===================================================================
--- projects/haf/trunk/libosso/src/osso-init.c	2007-03-30 13:34:21 UTC (rev 10865)
+++ projects/haf/trunk/libosso/src/osso-init.c	2007-03-30 13:59:04 UTC (rev 10866)
@@ -349,7 +349,7 @@
         free(osso);
         return NULL;
     }
-    osso->cp_plugins = g_array_new(FALSE, FALSE, sizeof(_osso_cp_plugin_t));
+    osso->cp_plugins = g_hash_table_new(g_str_hash, g_str_equal);
     osso->rpc_timeout = -1;
     osso->next_handler_id = 1;
     return osso;
@@ -386,7 +386,7 @@
         free(osso);
         return NULL;
     }
-    osso->cp_plugins = g_array_new(FALSE, FALSE, sizeof(_osso_cp_plugin_t));
+    osso->cp_plugins = g_hash_table_new(g_str_hash, g_str_equal);
     osso->rpc_timeout = -1;
     osso->next_handler_id = 1;
     return osso;
@@ -412,7 +412,7 @@
         g_hash_table_destroy(osso->id_hash);
     }
     if (osso->cp_plugins != NULL) {
-        g_array_free(osso->cp_plugins, TRUE);
+        g_hash_table_destroy(osso->cp_plugins);
     }
     
 #ifdef LIBOSSO_DEBUG

Modified: projects/haf/trunk/libosso/src/osso-internal.h
===================================================================
--- projects/haf/trunk/libosso/src/osso-internal.h	2007-03-30 13:34:21 UTC (rev 10865)
+++ projects/haf/trunk/libosso/src/osso-internal.h	2007-03-30 13:59:04 UTC (rev 10866)
@@ -139,12 +139,6 @@
     GSList *handlers;
 } _osso_hash_value_t;
 
-typedef struct {
-    void *lib;
-    gchar *name;
-    gchar *svcname;
-} _osso_cp_plugin_t;
-
 /**
  * This structure is used to store library specific stuff
  */
@@ -171,7 +165,7 @@
     _osso_hw_cb_t hw_cbs;
     osso_hw_state_t hw_state;
     guint rpc_timeout;
-    GArray *cp_plugins;
+    GHashTable *cp_plugins;
     int next_handler_id;    /* next available handler id, unique in this
                                context */
     const DBusMessage *reply_dummy, *error_dummy;
@@ -201,7 +195,7 @@
     _osso_hw_cb_t hw_cbs;
     osso_hw_state_t hw_state;
     guint rpc_timeout;
-    GArray *cp_plugins;
+    GHashTable *cp_plugins;
     int next_handler_id;    /* next available handler id, unique in this
                                context */
     const DBusMessage *reply_dummy, *error_dummy;


More information about the maemo-commits mailing list