From 8bdcb2f1232a364884eefc66e4413d373e3729cd Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 15 May 2017 02:44:24 +0200 Subject: [PATCH] Push callback to task_push_wifi_scan --- menu/menu_displaylist.c | 43 ++++++++++++++++++++++++++++++- tasks/task_wifi.c | 56 +++-------------------------------------- tasks/tasks_internal.h | 2 +- 3 files changed, 46 insertions(+), 55 deletions(-) diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 1774b16116..f94143c0c4 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -3979,6 +3979,47 @@ static void menu_displaylist_parse_playlist_history( (void*)menu->db_playlist_file); } +#ifdef HAVE_NETWORKING +static void wifi_scan_callback(void *task_data, + void *user_data, const char *error) +{ + unsigned i; + file_list_t *file_list = NULL; + struct string_list *ssid_list = NULL; + + const char *path = NULL; + const char *label = NULL; + unsigned menu_type = 0; + enum msg_hash_enums enum_idx = MSG_UNKNOWN; + + menu_entries_get_last_stack(&path, &label, &menu_type, &enum_idx, NULL); + + /* Don't push the results if we left the wifi menu */ + if (!string_is_equal(label, + msg_hash_to_str(MENU_ENUM_LABEL_DEFERRED_WIFI_SETTINGS_LIST))) + return; + + file_list = menu_entries_get_selection_buf_ptr(0); + menu_entries_ctl(MENU_ENTRIES_CTL_CLEAR, file_list); + + ssid_list = string_list_new(); + + driver_wifi_get_ssids(ssid_list); + + for (i = 0; i < ssid_list->size; i++) + { + const char *ssid = ssid_list->elems[i].data; + menu_entries_append_enum(file_list, + ssid, + msg_hash_to_str(MENU_ENUM_LABEL_CONNECT_WIFI), + MENU_ENUM_LABEL_CONNECT_WIFI, + MENU_WIFI, 0, 0); + } + + string_list_free(ssid_list); +} +#endif + bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data) { size_t i; @@ -4829,7 +4870,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data) if (ssid_list->size == 0) { - task_push_wifi_scan(); + task_push_wifi_scan(wifi_scan_callback); menu_entries_append_enum(info->list, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NO_NETWORKS_FOUND), diff --git a/tasks/task_wifi.c b/tasks/task_wifi.c index aca612f509..369eb8c47e 100644 --- a/tasks/task_wifi.c +++ b/tasks/task_wifi.c @@ -15,70 +15,22 @@ #include #include -#include -#include #include #include #include -#include -#include #include #include "tasks_internal.h" #include "../verbosity.h" #include "../wifi/wifi_driver.h" -#include "../menu/menu_entries.h" -#include "../menu/menu_driver.h" typedef struct wifi_handle wifi_handle_t; struct wifi_handle { - struct string_list *ssid_list; + void *empty; }; -static void wifi_scan_callback(void *task_data, - void *user_data, const char *error) -{ - unsigned i; - file_list_t *file_list = NULL; - struct string_list *ssid_list = NULL; - -#ifdef HAVE_MENU - const char *path = NULL; - const char *label = NULL; - unsigned menu_type = 0; - enum msg_hash_enums enum_idx = MSG_UNKNOWN; - - menu_entries_get_last_stack(&path, &label, &menu_type, &enum_idx, NULL); - - /* Don't push the results if we left the wifi menu */ - if (!string_is_equal(label, - msg_hash_to_str(MENU_ENUM_LABEL_DEFERRED_WIFI_SETTINGS_LIST))) - return; - - file_list = menu_entries_get_selection_buf_ptr(0); - menu_entries_ctl(MENU_ENTRIES_CTL_CLEAR, file_list); -#endif - - ssid_list = string_list_new(); - - driver_wifi_get_ssids(ssid_list); - -#ifdef HAVE_MENU - for (i = 0; i < ssid_list->size; i++) - { - const char *ssid = ssid_list->elems[i].data; - menu_entries_append_enum(file_list, - ssid, - msg_hash_to_str(MENU_ENUM_LABEL_CONNECT_WIFI), - MENU_ENUM_LABEL_CONNECT_WIFI, - MENU_WIFI, 0, 0); - } -#endif - - string_list_free(ssid_list); -} static void task_wifi_scan_handler(retro_task_t *task) { @@ -91,7 +43,7 @@ static void task_wifi_scan_handler(retro_task_t *task) return; } -bool task_push_wifi_scan(void) +bool task_push_wifi_scan(retro_task_callback_t cb) { retro_task_t *task = (retro_task_t *)calloc(1, sizeof(*task)); wifi_handle_t *state = (wifi_handle_t*)calloc(1, sizeof(*state)); @@ -99,14 +51,12 @@ bool task_push_wifi_scan(void) if (!task || !state) goto error; - state->ssid_list = string_list_new(); - /* blocking means no other task can run while this one is running, * which is the default */ task->type = TASK_TYPE_BLOCKING; task->state = state; task->handler = task_wifi_scan_handler; - task->callback = wifi_scan_callback; + task->callback = cb; task->title = strdup(msg_hash_to_str( MSG_SCANNING_WIRELESS_NETWORKS)); diff --git a/tasks/tasks_internal.h b/tasks/tasks_internal.h index 9cb45e166d..3374633916 100644 --- a/tasks/tasks_internal.h +++ b/tasks/tasks_internal.h @@ -101,7 +101,7 @@ void *task_push_http_post_transfer(const char *url, const char *post_data, bool task_retriever_info_t *http_task_get_transfer_list(void); -bool task_push_wifi_scan(void); +bool task_push_wifi_scan(retro_task_callback_t cb); bool task_push_netplay_lan_scan(retro_task_callback_t cb);