2016-12-02 23:56:29 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2017-01-22 12:40:32 +00:00
|
|
|
* Copyright (C) 2016-2017 - Jean-André Santoni
|
2019-06-16 18:32:27 +00:00
|
|
|
* Copyright (C) 2016-2019 - Andrés Suárez
|
2016-12-02 23:56:29 +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/>.
|
|
|
|
*/
|
|
|
|
|
2022-06-19 01:41:04 +00:00
|
|
|
#include <features/features_cpu.h>
|
2016-12-02 23:56:29 +00:00
|
|
|
|
|
|
|
#include "tasks_internal.h"
|
2017-02-04 08:20:41 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../config.h"
|
|
|
|
#endif
|
|
|
|
|
2022-06-19 01:41:04 +00:00
|
|
|
#ifdef HAVE_NETPLAYDISCOVERY
|
|
|
|
|
2021-11-05 18:12:55 +00:00
|
|
|
#include "../network/netplay/netplay.h"
|
2017-02-04 08:20:41 +00:00
|
|
|
|
2022-06-19 01:41:04 +00:00
|
|
|
struct netplay_lan_scan_data
|
|
|
|
{
|
|
|
|
retro_time_t timeout;
|
|
|
|
void (*cb)(const void*);
|
|
|
|
bool query;
|
|
|
|
bool busy;
|
|
|
|
};
|
|
|
|
|
2016-12-02 23:56:29 +00:00
|
|
|
static void task_netplay_lan_scan_handler(retro_task_t *task)
|
|
|
|
{
|
2022-06-19 01:41:04 +00:00
|
|
|
struct netplay_lan_scan_data *data =
|
|
|
|
(struct netplay_lan_scan_data*)task->task_data;
|
|
|
|
|
|
|
|
if (data->query)
|
2016-12-02 23:56:29 +00:00
|
|
|
{
|
2016-12-04 18:08:24 +00:00
|
|
|
netplay_discovery_driver_ctl(
|
2022-06-19 01:41:04 +00:00
|
|
|
RARCH_NETPLAY_DISCOVERY_CTL_LAN_CLEAR_RESPONSES, NULL);
|
|
|
|
|
|
|
|
if (!init_netplay_discovery())
|
|
|
|
goto finished;
|
|
|
|
|
|
|
|
if (!netplay_discovery_driver_ctl(
|
|
|
|
RARCH_NETPLAY_DISCOVERY_CTL_LAN_SEND_QUERY, NULL))
|
|
|
|
goto finished;
|
|
|
|
|
|
|
|
data->timeout += cpu_features_get_time_usec();
|
|
|
|
data->query = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!netplay_discovery_driver_ctl(
|
|
|
|
RARCH_NETPLAY_DISCOVERY_CTL_LAN_GET_RESPONSES, NULL))
|
|
|
|
{
|
|
|
|
if (cpu_features_get_time_usec() >= data->timeout)
|
|
|
|
goto finished;
|
|
|
|
}
|
2016-12-02 23:56:29 +00:00
|
|
|
}
|
|
|
|
|
2022-06-19 01:41:04 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
finished:
|
|
|
|
deinit_netplay_discovery();
|
|
|
|
|
2016-12-29 05:50:18 +00:00
|
|
|
task_set_progress(task, 100);
|
|
|
|
task_set_finished(task, true);
|
2016-12-02 23:56:29 +00:00
|
|
|
}
|
|
|
|
|
2022-06-19 01:41:04 +00:00
|
|
|
static void task_netplay_lan_scan_callback(retro_task_t *task,
|
|
|
|
void *task_data, void *user_data, const char *error)
|
|
|
|
{
|
|
|
|
struct netplay_lan_scan_data *data =
|
|
|
|
(struct netplay_lan_scan_data*)task_data;
|
|
|
|
net_driver_state_t *net_st = networking_state_get_ptr();
|
|
|
|
|
|
|
|
data->cb(&net_st->discovered_hosts);
|
|
|
|
|
|
|
|
data->busy = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool task_push_netplay_lan_scan(void (*cb)(const void*), unsigned timeout)
|
2016-12-02 23:56:29 +00:00
|
|
|
{
|
2022-06-19 01:41:04 +00:00
|
|
|
static struct netplay_lan_scan_data data = {0};
|
|
|
|
retro_task_t *task;
|
|
|
|
|
|
|
|
/* Do not run more than one LAN scan task at a time. */
|
|
|
|
if (data.busy)
|
|
|
|
return false;
|
2016-12-02 23:56:29 +00:00
|
|
|
|
2022-06-19 01:41:04 +00:00
|
|
|
task = task_init();
|
2016-12-02 23:56:29 +00:00
|
|
|
if (!task)
|
2016-12-05 06:06:32 +00:00
|
|
|
return false;
|
2016-12-02 23:56:29 +00:00
|
|
|
|
2022-06-19 01:41:04 +00:00
|
|
|
data.busy = true;
|
|
|
|
data.query = true;
|
|
|
|
data.timeout = (retro_time_t)timeout * 1000;
|
|
|
|
data.cb = cb;
|
|
|
|
|
|
|
|
task->handler = task_netplay_lan_scan_handler;
|
|
|
|
task->callback = task_netplay_lan_scan_callback;
|
|
|
|
task->task_data = &data;
|
2016-12-02 23:56:29 +00:00
|
|
|
|
2017-05-14 18:43:39 +00:00
|
|
|
task_queue_push(task);
|
2016-12-02 23:56:29 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2022-06-19 01:41:04 +00:00
|
|
|
#else
|
|
|
|
bool task_push_netplay_lan_scan(void (*cb)(const void*), unsigned timeout)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2021-08-12 14:44:07 +00:00
|
|
|
#endif
|