client: Introduce data_clear() calling ->clear() 10/204910/1
authorERAMOTO Masaya <eramoto.masaya@jp.fujitsu.com>
Fri, 16 Feb 2018 05:51:29 +0000 (14:51 +0900)
committerAmit Purwar <amit.purwar@samsung.com>
Mon, 15 Apr 2019 03:29:21 +0000 (08:59 +0530)
Change-Id: I96e980ea20bffa99096c367db92478f6aea1ab10
Signed-off-by: Amit Purwar <amit.purwar@samsung.com>
client/main.c

index 1fd27fc..9c75a09 100644 (file)
@@ -1408,10 +1408,12 @@ static void filter_clear_duplicate(void)
        filter.duplicate = false;
 }
 
-static const struct filter_clear {
+struct clear_entry {
        const char *name;
        void (*clear) (void);
-} filter_clear[] = {
+};
+
+static const struct clear_entry filter_clear[] = {
        { "uuids", filter_clear_uuids },
        { "rssi", filter_clear_rssi },
        { "pathloss", filter_clear_pathloss },
@@ -1440,29 +1442,44 @@ static char *filter_clear_generator(const char *text, int state)
        return NULL;
 }
 
-static void cmd_scan_filter_clear(int argc, char *argv[])
+static gboolean data_clear(const struct clear_entry *entry_table,
+                                                       const char *name)
 {
-       const struct filter_clear *fc;
+       const struct clear_entry *entry;
        bool all = false;
 
-       if (argc < 2 || !strlen(argv[1]))
+       if (!name || !strlen(name) || !strcmp("all", name))
                all = true;
 
-       for (fc = filter_clear; fc && fc->name; fc++) {
-               if (all || !strcmp(fc->name, argv[1])) {
-                       fc->clear();
-                       filter.set = false;
+       for (entry = entry_table; entry && entry->name; entry++) {
+               if (all || !strcmp(entry->name, name)) {
+                       entry->clear();
                        if (!all)
                                goto done;
                }
        }
 
        if (!all) {
-               bt_shell_printf("Invalid argument %s\n", argv[1]);
-               return;
+               bt_shell_printf("Invalid argument %s\n", name);
+               return FALSE;
        }
 
 done:
+       return TRUE;
+}
+
+static void cmd_scan_filter_clear(int argc, char *argv[])
+{
+       bool all = false;
+
+       if (argc < 2 || !strlen(argv[1]))
+               all = true;
+
+       if (!data_clear(filter_clear, all ? "all" : argv[1]))
+               return;
+
+       filter.set = false;
+
        if (check_default_ctrl() == FALSE)
                return;