Return-Path: From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v2 11/11] client: Make scan:clear clear individual fields Date: Thu, 14 Dec 2017 10:03:00 -0200 Message-Id: <20171214120300.20018-11-luiz.dentz@gmail.com> In-Reply-To: <20171214120300.20018-1-luiz.dentz@gmail.com> References: <20171214120300.20018-1-luiz.dentz@gmail.com> Sender: linux-bluetooth-owner@vger.kernel.org List-ID: From: Luiz Augusto von Dentz This reintroduces the option to clear individual fields which was removed when redesining the commands which now read the fields when no arguments are provided. --- client/main.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/client/main.c b/client/main.c index 3fd2c96cc..802b841e2 100644 --- a/client/main.c +++ b/client/main.c @@ -1409,18 +1409,68 @@ static void clear_discovery_filter_setup(DBusMessageIter *iter, void *user_data) dbus_message_iter_close_container(iter, &dict); } -static void cmd_scan_filter_clear(int argc, char *argv[]) +static void filter_clear_uuids(void) { - /* set default values for all options */ - filter.rssi = DISTANCE_VAL_INVALID; - filter.pathloss = DISTANCE_VAL_INVALID; g_strfreev(filter.uuids); filter.uuids = NULL; filter.uuids_len = 0; +} + +static void filter_clear_rssi(void) +{ + filter.rssi = DISTANCE_VAL_INVALID; +} + +static void filter_clear_pathloss(void) +{ + filter.pathloss = DISTANCE_VAL_INVALID; +} + +static void filter_clear_transport(void) +{ g_free(filter.transport); filter.transport = NULL; +} + +static void filter_clear_duplicate(void) +{ filter.duplicate = false; +} + +static const struct filter_clear { + const char *name; + void (*clear) (void); +} filter_clear[] = { + { "uuids", filter_clear_uuids }, + { "rssi", filter_clear_rssi }, + { "pathloss", filter_clear_pathloss }, + { "transport", filter_clear_transport }, + { "duplicate-data", filter_clear_duplicate }, + {} +}; + +static void cmd_scan_filter_clear(int argc, char *argv[]) +{ + const struct filter_clear *fc; + bool all = false; + + if (argc < 2 || !strlen(argv[1])) + all = true; + for (fc = filter_clear; fc && fc->name; fc++) { + if (all || !strcmp(fc->name, argv[1])) { + fc->clear(); + if (!all) + goto done; + } + } + + if (!all) { + bt_shell_printf("Invalid argument %s\n", argv[1]); + return; + } + +done: if (check_default_ctrl() == FALSE) return; @@ -2273,7 +2323,8 @@ static const struct bt_shell_menu scan_menu = { { "duplicate-data", "[on/off]", cmd_scan_filter_duplicate_data, "Set/Get duplicate data filter", mode_generator }, - { "clear", NULL, cmd_scan_filter_clear, + { "clear", "[uuids/rssi/pathloss/transport/duplicate-data]", + cmd_scan_filter_clear, "Clears discovery filter." }, { } }, }; -- 2.13.6