From: Ryan Lortie Date: Tue, 2 Dec 2014 19:42:55 +0000 (-0500) Subject: gdbus-tool: simplify some logic X-Git-Url: http://review.tizen.org/git/?p=platform%2Fupstream%2Fglib.git;a=commitdiff_plain;h=853692bdfd9f8a87aed70d21f643dc13b57c92d1 gdbus-tool: simplify some logic This would have gotten pretty ugly with 5 possibilities... --- 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,