[Xfce4-commits] <xfce4-panel:master> Improve checking if we own the dbus name.

Nick Schermer noreply at xfce.org
Tue Jul 27 20:24:01 CEST 2010


Updating branch refs/heads/master
         to 211d94da3dce2bd1d23329502de21c899cb8a95c (commit)
       from c53c83a8a3d0c34e00c2b7aba3cc5a6edffa28bf (commit)

commit 211d94da3dce2bd1d23329502de21c899cb8a95c
Author: Nick Schermer <nick at xfce.org>
Date:   Tue Jul 27 20:18:03 2010 +0200

    Improve checking if we own the dbus name.

 panel/main.c               |   13 +++++++------
 panel/panel-dbus-client.c  |   17 -----------------
 panel/panel-dbus-client.h  |    2 --
 panel/panel-dbus-service.c |   29 ++++++++++++++++++++++++-----
 panel/panel-dbus-service.h |    4 +++-
 5 files changed, 34 insertions(+), 31 deletions(-)

diff --git a/panel/main.c b/panel/main.c
index a2aace2..367d960 100644
--- a/panel/main.c
+++ b/panel/main.c
@@ -219,17 +219,20 @@ main (gint argc, gchar **argv)
       succeed = panel_dbus_client_plugin_event (opt_plugin_event, &error);
       goto dbus_return;
     }
-  else if (panel_dbus_client_check_instance_running ())
+
+  launch_panel:
+
+  /* start dbus service */
+  dbus_service = panel_dbus_service_get ();
+  if (!panel_dbus_service_is_owner (dbus_service))
     {
-      /* quit without error if and instance is running */
+      /* quit without error if an instance is running */
       succeed = TRUE;
 
       g_print ("%s: %s\n\n", G_LOG_DOMAIN, _("There is already a running instance"));
       goto dbus_return;
     }
 
-  launch_panel:
-
   /* start session management */
   sm_client = xfce_sm_client_get ();
   xfce_sm_client_set_restart_style (sm_client, XFCE_SM_CLIENT_RESTART_IMMEDIATELY);
@@ -246,8 +249,6 @@ main (gint argc, gchar **argv)
   for (i = 0; i < G_N_ELEMENTS (signums); i++)
     signal (signums[i], signal_handler_quit);
 
-  dbus_service = panel_dbus_service_get ();
-
   application = panel_application_get ();
 
   /* open dialog if we started from launch_panel */
diff --git a/panel/panel-dbus-client.c b/panel/panel-dbus-client.c
index caff76c..49cc512 100644
--- a/panel/panel-dbus-client.c
+++ b/panel/panel-dbus-client.c
@@ -71,23 +71,6 @@ panel_dbus_client_get_proxy (GError **error)
 
 
 gboolean
-panel_dbus_client_check_instance_running (void)
-{
-  DBusGProxy *dbus_proxy;
-
-  /* if no proxy is returned, there is no registered PanelDBusService */
-  dbus_proxy = panel_dbus_client_get_proxy (NULL);
-  if (dbus_proxy == NULL)
-    return FALSE;
-
-  g_object_unref (G_OBJECT (dbus_proxy));
-
-  return TRUE;
-}
-
-
-
-gboolean
 panel_dbus_client_display_preferences_dialog (guint    active,
                                               GError **error)
 {
diff --git a/panel/panel-dbus-client.h b/panel/panel-dbus-client.h
index 73d284d..2377119 100644
--- a/panel/panel-dbus-client.h
+++ b/panel/panel-dbus-client.h
@@ -22,8 +22,6 @@
 #include <glib.h>
 #include <gdk/gdk.h>
 
-gboolean  panel_dbus_client_check_instance_running     (void);
-
 gboolean  panel_dbus_client_display_preferences_dialog (guint         active,
                                                         GError      **error);
 
diff --git a/panel/panel-dbus-service.c b/panel/panel-dbus-service.c
index cb4a481..46e789a 100644
--- a/panel/panel-dbus-service.c
+++ b/panel/panel-dbus-service.c
@@ -85,6 +85,9 @@ struct _PanelDBusService
 
   /* queue for remote-events */
   GHashTable      *remote_events;
+
+  /* whether the service is owner of the name */
+  guint            is_owner : 1;
 };
 
 typedef struct
@@ -126,7 +129,9 @@ panel_dbus_service_init (PanelDBusService *service)
 {
   GError         *error = NULL;
   DBusConnection *connection;
+  gint            result;
 
+  service->is_owner = FALSE;
   service->remote_events = g_hash_table_new_full (g_int_hash, g_int_equal, NULL,
                                                   panel_dbus_service_plugin_event_free);
 
@@ -135,12 +140,17 @@ panel_dbus_service_init (PanelDBusService *service)
     {
       /* TODO handle error */
       connection = dbus_g_connection_get_connection (service->connection);
-      dbus_bus_request_name (connection, PANEL_DBUS_NAME, 0, NULL);
+      result = dbus_bus_request_name (connection, PANEL_DBUS_NAME, DBUS_NAME_FLAG_DO_NOT_QUEUE, NULL);
+      if (result == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
+        {
+          /* yes we own the name */
+          service->is_owner = TRUE;
 
-      /* register this object */
-      dbus_g_connection_register_g_object (service->connection,
-                                           PANEL_DBUS_PATH,
-                                           G_OBJECT (service));
+          /* register this object */
+          dbus_g_connection_register_g_object (service->connection,
+                                               PANEL_DBUS_PATH,
+                                               G_OBJECT (service));
+        }
     }
   else
     {
@@ -436,6 +446,15 @@ panel_dbus_service_get (void)
 
 
 
+gboolean
+panel_dbus_service_is_owner (PanelDBusService *service)
+{
+  panel_return_val_if_fail (PANEL_IS_DBUS_SERVICE (service), FALSE);
+  return service->is_owner;
+}
+
+
+
 void
 panel_dbus_service_exit_panel (gboolean restart)
 {
diff --git a/panel/panel-dbus-service.h b/panel/panel-dbus-service.h
index da8c14a..2b9d12e 100644
--- a/panel/panel-dbus-service.h
+++ b/panel/panel-dbus-service.h
@@ -38,7 +38,9 @@ GType               panel_dbus_service_get_type    (void) G_GNUC_CONST;
 
 PanelDBusService   *panel_dbus_service_get         (void);
 
-void                panel_dbus_service_exit_panel  (gboolean restart);
+gboolean            panel_dbus_service_is_owner    (PanelDBusService *service);
+
+void                panel_dbus_service_exit_panel  (gboolean          restart);
 
 gboolean            panel_dbus_service_get_restart (void);
 



More information about the Xfce4-commits mailing list