RetroArch/tasks/task_wifi.c

131 lines
3.7 KiB
C
Raw Normal View History

2016-11-29 23:18:27 +00:00
/* RetroArch - A frontend for libretro.
2017-01-22 12:40:32 +00:00
* Copyright (C) 2016-2017 - Jean-André Santoni
2016-11-29 23:18:27 +00:00
*
* 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 "../msg_hash.h"
#include "../network/wifi_driver.h"
2016-11-29 23:18:27 +00:00
#include "../verbosity.h"
#define FUNC_PUSH_TASK(funcname, handlerfunc, message) \
bool funcname(retro_task_callback_t cb) \
{ \
retro_task_t *task = task_init(); \
if (!task) \
return false; \
task->type = TASK_TYPE_BLOCKING; \
task->state = NULL; \
task->handler = handlerfunc; \
task->callback = cb; \
task->title = strdup(msg_hash_to_str( \
message)); \
task_queue_push(task); \
return true; \
}
2016-11-29 23:18:27 +00:00
static void task_wifi_scan_handler(retro_task_t *task)
{
2020-12-10 18:24:34 +00:00
if (!task)
return;
2016-11-29 23:18:27 +00:00
driver_wifi_scan();
task_set_progress(task, 100);
task_free_title(task);
task_set_title(task, strdup(msg_hash_to_str(MSG_WIFI_SCAN_COMPLETE)));
task_set_finished(task, true);
2016-11-29 23:18:27 +00:00
}
static void task_wifi_enable_handler(retro_task_t *task)
2016-11-29 23:18:27 +00:00
{
2020-12-10 18:24:34 +00:00
if (!task)
return;
driver_wifi_enable(true);
task_set_progress(task, 100);
task_set_finished(task, true);
}
static void task_wifi_disable_handler(retro_task_t *task)
{
2020-12-10 18:24:34 +00:00
if (!task)
return;
driver_wifi_enable(false);
2016-11-29 23:18:27 +00:00
task_set_progress(task, 100);
task_set_finished(task, true);
}
static void task_wifi_disconnect_handler(retro_task_t *task)
{
wifi_network_info_t netinfo;
2020-12-10 18:24:34 +00:00
if (!task)
return;
if (driver_wifi_connection_info(&netinfo))
driver_wifi_disconnect_ssid(&netinfo);
task_set_progress(task, 100);
task_set_finished(task, true);
}
static void task_wifi_connect_handler(retro_task_t *task)
{
2020-12-10 18:24:34 +00:00
if (!task)
return;
2021-02-08 08:35:57 +00:00
driver_wifi_connect_ssid((const wifi_network_info_t*)task->user_data);
2020-12-10 18:24:34 +00:00
free(task->user_data);
task_set_progress(task, 100);
task_set_finished(task, true);
}
bool task_push_wifi_connect(retro_task_callback_t cb, void *netptr) {
char msg[128];
retro_task_t *task = task_init();
wifi_network_info_t *netinfo = (wifi_network_info_t*)netptr;
2017-05-15 00:50:14 +00:00
if (!task)
return false;
snprintf(msg, sizeof(msg), msg_hash_to_str(MSG_WIFI_CONNECTING_TO), netinfo->ssid);
2016-11-29 23:18:27 +00:00
task->type = TASK_TYPE_BLOCKING;
2017-05-15 00:50:14 +00:00
task->state = NULL;
task->handler = task_wifi_connect_handler;
2017-05-15 00:44:24 +00:00
task->callback = cb;
task->title = strdup(msg);
task->user_data = malloc(sizeof(*netinfo));
memcpy(task->user_data, netinfo, sizeof(*netinfo));
2017-05-14 18:43:39 +00:00
task_queue_push(task);
2016-11-29 23:18:27 +00:00
return true;
2016-11-30 16:37:32 +00:00
}
FUNC_PUSH_TASK(task_push_wifi_scan, task_wifi_scan_handler, MSG_SCANNING_WIRELESS_NETWORKS)
FUNC_PUSH_TASK(task_push_wifi_enable, task_wifi_enable_handler, MSG_ENABLING_WIRELESS)
FUNC_PUSH_TASK(task_push_wifi_disable, task_wifi_disable_handler, MSG_DISABLING_WIRELESS)
FUNC_PUSH_TASK(task_push_wifi_disconnect, task_wifi_disconnect_handler, MSG_DISCONNECTING_WIRELESS)