diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2012-12-14 23:33:01 +0100 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2012-12-14 23:33:01 +0100 |
commit | 8590e5b610ae12584e13b3495ce3af895233aaff (patch) | |
tree | b273869921ca142ee5c7f98d3912c94d045ff17b | |
parent | 420d1e997ead5ed3d2404a6f689ee9d24108e53b (diff) |
client: Add helper function for checking default controller
-rw-r--r-- | client/main.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/client/main.c b/client/main.c index 221c636fd..8e66ea8a1 100644 --- a/client/main.c +++ b/client/main.c @@ -213,15 +213,20 @@ static GDBusProxy *find_proxy_by_address(const char *address) return NULL; } -static gboolean parse_argument_on_off(const char *arg, dbus_bool_t *value) +static gboolean check_default_ctrl(void) { - if (!arg || !strlen(arg)) { - printf("Missing on/off argument\n"); + if (!default_ctrl) { + printf("No default controller available\n"); return FALSE; } - if (!default_ctrl) { - printf("No default controller available\n"); + return TRUE; +} + +static gboolean parse_argument_on_off(const char *arg, dbus_bool_t *value) +{ + if (!arg || !strlen(arg)) { + printf("Missing on/off argument\n"); return FALSE; } @@ -256,10 +261,8 @@ static void cmd_info(const char *arg) const char *address; if (!arg || !strlen(arg)) { - if (!default_ctrl) { - printf("No default controller available\n"); + if (check_default_ctrl() == FALSE) return; - } proxy = default_ctrl; } else { @@ -336,6 +339,9 @@ static void cmd_power(const char *arg) if (parse_argument_on_off(arg, &powered) == FALSE) return; + if (check_default_ctrl() == FALSE) + return; + str = g_strdup_printf("power %s", powered == TRUE ? "on" : "off"); if (g_dbus_proxy_set_property_basic(default_ctrl, "Powered", @@ -354,6 +360,9 @@ static void cmd_pairable(const char *arg) if (parse_argument_on_off(arg, &pairable) == FALSE) return; + if (check_default_ctrl() == FALSE) + return; + str = g_strdup_printf("pairable %s", pairable == TRUE ? "on" : "off"); if (g_dbus_proxy_set_property_basic(default_ctrl, "Pairable", @@ -372,6 +381,9 @@ static void cmd_discoverable(const char *arg) if (parse_argument_on_off(arg, &discoverable) == FALSE) return; + if (check_default_ctrl() == FALSE) + return; + str = g_strdup_printf("discoverable %s", discoverable == TRUE ? "on" : "off"); |