[Xfce4-commits] <xfce4-session:master> Use dbus_g_proxy_new_for_name_owner for the well known services name, as this will check if the name has an owner, if not it tries to activate the service if it is provided, like that we avoid many dbus_name_has_owner calls.

Jérôme Guelfucci noreply at xfce.org
Sat Feb 27 00:36:04 CET 2010


Updating branch refs/heads/master
         to 3fb54b289df5a943272e3056122a17e940181ec0 (commit)
       from 2d777073bf3825a23b29c1587cd69c693d51d9c3 (commit)

commit 3fb54b289df5a943272e3056122a17e940181ec0
Author: Ali Abdallah <aliov at xfce.org>
Date:   Mon Feb 1 13:18:12 2010 +0100

    Use dbus_g_proxy_new_for_name_owner for the well known services name, as this will
    check if the name has an owner, if not it tries to activate the service if it is
    provided, like that we avoid many dbus_name_has_owner calls.

 xfce4-session/xfsm-manager.c         |   18 +---
 xfce4-session/xfsm-shutdown-helper.c |  161 ++++++++++++++++------------------
 2 files changed, 79 insertions(+), 100 deletions(-)

diff --git a/xfce4-session/xfsm-manager.c b/xfce4-session/xfsm-manager.c
index 7839a16..0fa7732 100644
--- a/xfce4-session/xfsm-manager.c
+++ b/xfce4-session/xfsm-manager.c
@@ -348,19 +348,11 @@ static void xfsm_manager_consolekit_init (XfsmManager *manager)
   GError *error = NULL;
   gboolean ret;
   
-  /* Make sure that consolekit is running*/
-  if ( !xfsm_dbus_name_has_owner (dbus_g_connection_get_connection (manager->system_bus),
-				  "org.freedesktop.ConsoleKit") )
-    {
-      
-      g_message (G_STRLOC "ConsoleKit is not running or not installed");
-      return;
-    }
-  
-  manager->consolekit_proxy = dbus_g_proxy_new_for_name (manager->system_bus,
-							 "org.freedesktop.ConsoleKit",
-							 "/org/freedesktop/ConsoleKit/Manager",
-							 "org.freedesktop.ConsoleKit.Manager");
+  manager->consolekit_proxy = dbus_g_proxy_new_for_name_owner (manager->system_bus,
+							       "org.freedesktop.ConsoleKit",
+							       "/org/freedesktop/ConsoleKit/Manager",
+							       "org.freedesktop.ConsoleKit.Manager",
+							       NULL);
 
   
   if ( G_UNLIKELY (!manager->consolekit_proxy) )
diff --git a/xfce4-session/xfsm-shutdown-helper.c b/xfce4-session/xfsm-shutdown-helper.c
index 536efbe..257ab92 100644
--- a/xfce4-session/xfsm-shutdown-helper.c
+++ b/xfce4-session/xfsm-shutdown-helper.c
@@ -335,17 +335,12 @@ xfsm_shutdown_helper_init_polkit_data (XfsmShutdownHelper *helper)
   GValue hash_elem = { 0 };
   gboolean subject_created = FALSE;
   
-  if ( !xfsm_dbus_name_has_owner (dbus_g_connection_get_connection (helper->system_bus), 
-				  "org.freedesktop.PolicyKit1") )
-    {
-      return FALSE;
-    }
-
   helper->polkit_proxy = 
-    dbus_g_proxy_new_for_name (helper->system_bus,
-			       "org.freedesktop.PolicyKit1",
-			       "/org/freedesktop/PolicyKit1/Authority",
-			       "org.freedesktop.PolicyKit1.Authority");
+    dbus_g_proxy_new_for_name_owner (helper->system_bus,
+				     "org.freedesktop.PolicyKit1",
+				     "/org/freedesktop/PolicyKit1/Authority",
+				     "org.freedesktop.PolicyKit1.Authority",
+				     NULL);
 
   if ( !helper->polkit_proxy )
     return FALSE;
@@ -368,10 +363,11 @@ xfsm_shutdown_helper_init_polkit_data (XfsmShutdownHelper *helper)
       gboolean ret;
       gchar *consolekit_session;
       
-      proxy  = dbus_g_proxy_new_for_name (helper->system_bus,
-					  "org.freedesktop.ConsoleKit",
-					  "/org/freedesktop/ConsoleKit/Manager",
-					  "org.freedesktop.ConsoleKit.Manager");
+      proxy  = dbus_g_proxy_new_for_name_owner (helper->system_bus,
+						"org.freedesktop.ConsoleKit",
+						"/org/freedesktop/ConsoleKit/Manager",
+						"org.freedesktop.ConsoleKit.Manager",
+						NULL);
       if ( proxy )
 	{
 	  ret = dbus_g_proxy_call (proxy, "GetSessionForCookie", &error,
@@ -640,32 +636,35 @@ xfsm_shutdown_helper_check_upower (XfsmShutdownHelper *helper)
   iface = "org.freedesktop.Power";
 
   helper->devkit_is_upower = TRUE;
+  
+  proxy_prop = dbus_g_proxy_new_for_name_owner (helper->system_bus,
+						name,
+						path,
+						DBUS_INTERFACE_PROPERTIES,
+						NULL);
 
-  if ( !xfsm_dbus_name_has_owner (dbus_g_connection_get_connection (helper->system_bus), 
-				  name) )
-    {
-      name = "org.freedesktop.DeviceKit.Power";
-      path = "/org/freedesktop/DeviceKit/Power";
-      iface = "org.freedesktop.DeviceKit.Power";
+  if ( !proxy_prop )
+  {
+    g_message ("UPower not found, trying DevKitPower");
+    
+    name = "org.freedesktop.DeviceKit.Power";
+    path = "/org/freedesktop/DeviceKit/Power";
+    iface = "org.freedesktop.DeviceKit.Power";
       
-      helper->devkit_is_upower = FALSE;
-
-      if ( !xfsm_dbus_name_has_owner (dbus_g_connection_get_connection (helper->system_bus), 
-				      name) )
-	return FALSE;
-    }
+    helper->devkit_is_upower = FALSE;
+    proxy_prop = dbus_g_proxy_new_for_name_owner (helper->system_bus,
+						  name,
+						  path,
+						  DBUS_INTERFACE_PROPERTIES,
+						  NULL);
   
-  proxy_prop = dbus_g_proxy_new_for_name (helper->system_bus,
-					  name,
-					  path,
-					  DBUS_INTERFACE_PROPERTIES);
+    if ( !proxy_prop )
+      {
+	g_message ("Devkit Power is not running or not installed");
+	return FALSE;
+      }
+  }
   
-  if ( !proxy_prop )
-    {
-      g_warning ("Failed to create proxy for %s", name);
-      return FALSE;
-    }
-
   /* The Hash table is a pair of (strings, GValues) */
   g_type_hash_map = dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE);
 
@@ -728,17 +727,11 @@ xfsm_shutdown_helper_check_console_kit (XfsmShutdownHelper *helper)
   DBusGProxy *proxy;
   GError *error = NULL;
 
-  /* Check if D-Bus has "org.freedesktop.ConsoleKit" */
-  if ( !xfsm_dbus_name_has_owner (dbus_g_connection_get_connection (helper->system_bus), 
-				  "org.freedesktop.ConsoleKit") )
-    {
-      return FALSE;
-    }
-
-  proxy = dbus_g_proxy_new_for_name (helper->system_bus,
-				     "org.freedesktop.ConsoleKit",
-				     "/org/freedesktop/ConsoleKit/Manager",
-				     "org.freedesktop.ConsoleKit.Manager");
+  proxy = dbus_g_proxy_new_for_name_owner (helper->system_bus,
+					   "org.freedesktop.ConsoleKit",
+					   "/org/freedesktop/ConsoleKit/Manager",
+					   "org.freedesktop.ConsoleKit.Manager",
+					   NULL);
 
   if (!proxy)
     {
@@ -790,17 +783,12 @@ xfsm_shutdown_helper_check_hal (XfsmShutdownHelper *helper)
   DBusGProxy *proxy_device;
   GError *error = NULL;
 
-  if ( !xfsm_dbus_name_has_owner (dbus_g_connection_get_connection (helper->system_bus), 
-				  "org.freedesktop.Hal") )
-    {
-      return FALSE;
-    }
-
   proxy_power = 
-    dbus_g_proxy_new_for_name (helper->system_bus,
-			       "org.freedesktop.Hal",
-			       "/org/freedesktop/Hal/devices/computer",
-			       "org.freedesktop.Hal.Device.SystemPowerManagement");
+      dbus_g_proxy_new_for_name_owner (helper->system_bus,
+				       "org.freedesktop.Hal",
+				       "/org/freedesktop/Hal/devices/computer",
+				       "org.freedesktop.Hal.Device.SystemPowerManagement",
+				       NULL);
   
   if (!proxy_power)
     {
@@ -850,6 +838,10 @@ xfsm_shutdown_helper_check_hal (XfsmShutdownHelper *helper)
 					    "/org/freedesktop/Hal/devices/computer",
 					    "org.freedesktop.Hal.Device");
 
+
+  if ( !proxy_device )
+      return FALSE;
+
   dbus_g_proxy_call (proxy_device, "GetPropertyBoolean", &error,
 		     G_TYPE_STRING, "power_management.can_hibernate",
 		     G_TYPE_INVALID,
@@ -1431,18 +1423,17 @@ xfsm_shutdown_helper_upower_sleep (XfsmShutdownHelper *helper,
   
   g_message (G_STRLOC ": Using %s to %s", name, action);
 
-  proxy = dbus_g_proxy_new_for_name (helper->system_bus,
-				     name,
-				     path,
-				     iface);
+  proxy = dbus_g_proxy_new_for_name_owner (helper->system_bus,
+					   name,
+					   path,
+					   iface,
+					   &error_local);
 				     
   if ( !proxy )
     {
-      g_warning ("Failed to create proxy for %s", name);
-      *error = g_error_new (1, 0, "%s %s %s", 
-			    _("Failed to connect to the helper program."),
-			    name,
-			    _("does not exist"));
+      g_warning ("Failed to create proxy for %s : %s", name, error_local->message);
+      g_set_error (error, 1, 0, "%s", error_local->message);
+      g_error_free (error_local);
       return FALSE;
     }
   
@@ -1492,32 +1483,30 @@ xfsm_shutdown_helper_console_kit_shutdown (XfsmShutdownHelper *helper,
 
   g_message (G_STRLOC ": Using ConsoleKit to %s", action);
   
-  proxy = dbus_g_proxy_new_for_name (helper->system_bus,
-				     "org.freedesktop.ConsoleKit",
-				     "/org/freedesktop/ConsoleKit/Manager",
-				     "org.freedesktop.ConsoleKit.Manager");
+  proxy = dbus_g_proxy_new_for_name_owner (helper->system_bus,
+					   "org.freedesktop.ConsoleKit",
+					   "/org/freedesktop/ConsoleKit/Manager",
+					   "org.freedesktop.ConsoleKit.Manager",
+					   &error_local);
   
   if (!proxy)
     {
-      g_warning ("Failed to create proxy for 'org.freedesktop.ConsoleKit'");
-      *error = g_error_new (1, 0, "%s %s %s", 
-			    _("Failed to connect to the helper program."),
-			    "org.freedesktop.ConsoleKit",
-			    _("does not exist"));
+      g_warning ("Failed to create proxy for 'org.freedesktop.ConsoleKit' : %s", error_local->message);
+      g_set_error (error, 1, 0, "%s", error_local->message);
+      g_error_free (error_local);
       return FALSE;
     }
   
   ret = dbus_g_proxy_call (proxy, action, &error_local,
 			   G_TYPE_INVALID,
 			   G_TYPE_INVALID);
-
+  
   g_object_unref (proxy);
   
   if ( !ret )
     {
       *error = g_error_new (1, 0, "%s", error_local->message);
       g_error_free (error_local);
-       
       return FALSE;
     }
   
@@ -1545,18 +1534,16 @@ xfsm_shutdown_helper_hal_send (XfsmShutdownHelper *helper,
   
   g_message (G_STRLOC ": Using ConsoleKit to %s", action);
 
-  proxy = dbus_g_proxy_new_for_name (helper->system_bus,
-				     "org.freedesktop.Hal",
-				     "/org/freedesktop/Hal/devices/computer",
-				     "org.freedesktop.Hal.Device.SystemPowerManagement");
-
+  proxy = dbus_g_proxy_new_for_name_owner (helper->system_bus,
+					   "org.freedesktop.Hal",
+					   "/org/freedesktop/Hal/devices/computer",
+					   "org.freedesktop.Hal.Device.SystemPowerManagement",
+					   &error_local);
   if ( !proxy )
     {
-      g_warning ("Failed to create proxy for 'org.freedesktop.Hal'");
-      *error = g_error_new (1, 0, "%s %s %s", 
-			    _("Failed to connect to the helper program."),
-			    "org.freedesktop.Hal",
-			    _("does not exist"));
+      g_warning ("Failed to create proxy for 'org.freedesktop.Hal' : %s", error_local->message);
+      g_set_error (error, 1, 0, "%s", error_local->message);
+      g_error_free (error_local);
       return FALSE;
     }
 



More information about the Xfce4-commits mailing list