[glib/wip/kdbus-junk: 32/37] gdbus-tool: simplify some logic



commit 5c10dd2963cc7592da56e18b948cf4329a27b94a
Author: Ryan Lortie <desrt desrt ca>
Date:   Tue Dec 2 14:42:55 2014 -0500

    gdbus-tool: simplify some logic
    
    This would have gotten pretty ugly with 5 possibilities...

 gio/gdbus-tool.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)
---
diff --git a/gio/gdbus-tool.c b/gio/gdbus-tool.c
index f24dd71..db23b43 100644
--- a/gio/gdbus-tool.c
+++ b/gio/gdbus-tool.c
@@ -343,12 +343,16 @@ print_names (GDBusConnection *c,
 
 static gboolean  opt_connection_system  = FALSE;
 static gboolean  opt_connection_session = FALSE;
+static gboolean  opt_connection_user    = FALSE;
+static gboolean  opt_connection_machine = FALSE;
 static gchar    *opt_connection_address = NULL;
 
 static const GOptionEntry connection_entries[] =
 {
   { "system", 'y', 0, G_OPTION_ARG_NONE, &opt_connection_system, N_("Connect to the system bus"), NULL},
   { "session", 'e', 0, G_OPTION_ARG_NONE, &opt_connection_session, N_("Connect to the session bus"), NULL},
+  { "user", 'u', 0, G_OPTION_ARG_NONE, &opt_connection_user, N_("Connect to the system bus"), NULL},
+  { "machine", 'm', 0, G_OPTION_ARG_NONE, &opt_connection_machine, N_("Connect to the session bus"), NULL},
   { "address", 'a', 0, G_OPTION_ARG_STRING, &opt_connection_address, N_("Connect to given D-Bus address"), 
NULL},
   { NULL }
 };
@@ -373,11 +377,16 @@ static GDBusConnection *
 connection_get_dbus_connection (GError **error)
 {
   GDBusConnection *c;
+  guint count;
 
   c = NULL;
 
+  count = !!opt_connection_system +
+          !!opt_connection_session +
+          !!opt_connection_address;
+
   /* First, ensure we have exactly one connect */
-  if (!opt_connection_system && !opt_connection_session && opt_connection_address == NULL)
+  if (count == 0)
     {
       g_set_error (error,
                    G_IO_ERROR,
@@ -385,9 +394,7 @@ connection_get_dbus_connection (GError **error)
                    _("No connection endpoint specified"));
       goto out;
     }
-  else if ((opt_connection_system && (opt_connection_session || opt_connection_address != NULL)) ||
-           (opt_connection_session && (opt_connection_system || opt_connection_address != NULL)) ||
-           (opt_connection_address != NULL && (opt_connection_system || opt_connection_session)))
+  else if (count > 1)
     {
       g_set_error (error,
                    G_IO_ERROR,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]