RetroArch/tasks/task_wifi.c
2017-05-15 02:44:24 +02:00

74 lines
2 KiB
C

/* RetroArch - A frontend for libretro.
* Copyright (C) 2016-2017 - Jean-André Santoni
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <errno.h>
#include <compat/strl.h>
#include <retro_assert.h>
#include <retro_miscellaneous.h>
#include <string/stdstring.h>
#include "tasks_internal.h"
#include "../verbosity.h"
#include "../wifi/wifi_driver.h"
typedef struct wifi_handle wifi_handle_t;
struct wifi_handle
{
void *empty;
};
static void task_wifi_scan_handler(retro_task_t *task)
{
driver_wifi_scan();
task_set_progress(task, 100);
task_set_title(task, strdup(msg_hash_to_str(MSG_WIFI_SCAN_COMPLETE)));
task_set_finished(task, true);
return;
}
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));
if (!task || !state)
goto error;
/* 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 = cb;
task->title = strdup(msg_hash_to_str(
MSG_SCANNING_WIRELESS_NETWORKS));
task_queue_push(task);
return true;
error:
if (state)
free(state);
if (task)
free(task);
return false;
}