Revert "Bluetooth fixes"

This commit is contained in:
Autechre 2020-06-28 19:40:37 +02:00 committed by GitHub
parent 594e93fc64
commit b57e6e76c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 225 additions and 164 deletions

View File

@ -28,7 +28,13 @@ enum rarch_bluetooth_ctl_state
RARCH_BLUETOOTH_CTL_NONE = 0,
RARCH_BLUETOOTH_CTL_DESTROY,
RARCH_BLUETOOTH_CTL_DEINIT,
RARCH_BLUETOOTH_CTL_SET_ACTIVE,
RARCH_BLUETOOTH_CTL_UNSET_ACTIVE,
RARCH_BLUETOOTH_CTL_IS_ACTIVE,
RARCH_BLUETOOTH_CTL_FIND_DRIVER,
RARCH_BLUETOOTH_CTL_SET_CB,
RARCH_BLUETOOTH_CTL_STOP,
RARCH_BLUETOOTH_CTL_START,
RARCH_BLUETOOTH_CTL_INIT
};
@ -38,11 +44,14 @@ typedef struct bluetooth_driver
void (*free)(void *data);
void (*scan)(void *data);
void (*get_devices)(void *data, struct string_list *list);
bool (*device_is_connected)(void *data, unsigned i);
void (*device_get_sublabel)(void *data, char *s, unsigned i, size_t len);
bool (*connect_device)(void *data, unsigned i);
bool (*start)(void *data);
void (*stop)(void *data);
void (*scan)(void);
void (*get_devices)(struct string_list *list);
bool (*device_is_connected)(unsigned i);
void (*device_get_sublabel)(char *s, unsigned i, size_t len);
bool (*connect_device)(unsigned i);
const char *ident;
} bluetooth_driver_t;
@ -61,6 +70,10 @@ extern bluetooth_driver_t bluetooth_bluez;
**/
const char* config_get_bluetooth_driver_options(void);
void driver_bluetooth_stop(void);
bool driver_bluetooth_start(void);
void driver_bluetooth_scan(void);
void driver_bluetooth_get_devices(struct string_list *list);

View File

@ -18,40 +18,48 @@
#include "../bluetooth_driver.h"
#include "../../retroarch.h"
typedef struct
{
bool bluetoothctl_cache[256];
unsigned bluetoothctl_counter[256];
struct string_list* lines;
char command[256];
} bluetoothctl_t;
/* TODO/FIXME - static globals - should go into userdata
* struct for driver */
static bool bluetoothctl_cache[256] = {0};
static unsigned bluetoothctl_counter[256] = {0};
static struct string_list* lines = NULL;
static char command[256] = {0};
static void *bluetoothctl_init(void)
{
return calloc(1, sizeof(bluetoothctl_t));
return (void*)-1;
}
static void bluetoothctl_free(void *data)
{
if (data)
free(data);
(void)data;
}
static void bluetoothctl_scan(void *data)
static bool bluetoothctl_start(void *data)
{
(void)data;
return true;
}
static void bluetoothctl_stop(void *data)
{
(void)data;
}
static void bluetoothctl_scan(void)
{
bluetoothctl_t *btctl = (bluetoothctl_t*) data;
char line[512];
union string_list_elem_attr attr;
FILE *dev_file = NULL;
attr.i = 0;
if (btctl->lines)
free(btctl->lines);
btctl->lines = string_list_new();
if (lines)
free(lines);
lines = string_list_new();
pclose(popen("bluetoothctl -- power on", "r"));
pclose(popen("bluetoothctl --timeout 10 scan on", "r"));
pclose(popen("bluetoothctl --timeout 15 scan on", "r"));
runloop_msg_queue_push(msg_hash_to_str(MSG_BLUETOOTH_SCAN_COMPLETE),
1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT,
@ -65,27 +73,26 @@ static void bluetoothctl_scan(void *data)
if (len > 0 && line[len-1] == '\n')
line[--len] = '\0';
string_list_append(btctl->lines, line, attr);
string_list_append(lines, line, attr);
}
pclose(dev_file);
}
static void bluetoothctl_get_devices(void *data, struct string_list* devices)
static void bluetoothctl_get_devices(struct string_list* devices)
{
bluetoothctl_t *btctl = (bluetoothctl_t*) data;
unsigned i;
union string_list_elem_attr attr;
attr.i = 0;
if (!btctl->lines)
if (!lines)
return;
for (i = 0; i < btctl->lines->size; i++)
for (i = 0; i < lines->size; i++)
{
char device[64];
const char *line = btctl->lines->elems[i].data;
const char *line = lines->elems[i].data;
/* bluetoothctl devices outputs lines of the format:
* $ bluetoothctl devices
@ -96,18 +103,17 @@ static void bluetoothctl_get_devices(void *data, struct string_list* devices)
}
}
static bool bluetoothctl_device_is_connected(void *data, unsigned i)
static bool bluetoothctl_device_is_connected(unsigned i)
{
bluetoothctl_t *btctl = (bluetoothctl_t*) data;
char ln[512] = {0};
char device[18] = {0};
const char *line = btctl->lines->elems[i].data;
const char *line = lines->elems[i].data;
FILE *command_file = NULL;
if (btctl->bluetoothctl_counter[i] == 60)
if (bluetoothctl_counter[i] == 60)
{
static struct string_list* list = NULL;
btctl->bluetoothctl_counter[i] = 0;
bluetoothctl_counter[i] = 0;
list = string_split(line, " ");
if (!list)
return false;
@ -121,35 +127,34 @@ static bool bluetoothctl_device_is_connected(void *data, unsigned i)
strlcpy(device, list->elems[1].data, sizeof(device));
string_list_free(list);
snprintf(btctl->command, sizeof(btctl->command), "\
snprintf(command, sizeof(command), "\
bluetoothctl -- info %s | grep 'Connected: yes'",
device);
command_file = popen(btctl->command, "r");
command_file = popen(command, "r");
while (fgets(ln, 512, command_file))
{
btctl->bluetoothctl_cache[i] = true;
bluetoothctl_cache[i] = true;
return true;
}
pclose(command_file);
btctl->bluetoothctl_cache[i] = false;
bluetoothctl_cache[i] = false;
}
else
{
btctl->bluetoothctl_counter[i]++;
return btctl->bluetoothctl_cache[i];
bluetoothctl_counter[i]++;
return bluetoothctl_cache[i];
}
return false;
}
static bool bluetoothctl_connect_device(void *data, unsigned idx)
static bool bluetoothctl_connect_device(unsigned idx)
{
bluetoothctl_t *btctl = (bluetoothctl_t*) data;
unsigned i;
char device[18] = {0};
const char *line = btctl->lines->elems[idx].data;
const char *line = lines->elems[idx].data;
static struct string_list* list = NULL;
/* bluetoothctl devices outputs lines of the format:
@ -169,42 +174,43 @@ static bool bluetoothctl_connect_device(void *data, unsigned idx)
strlcpy(device, list->elems[1].data, sizeof(device));
string_list_free(list);
snprintf(btctl->command, sizeof(btctl->command), "\
snprintf(command, sizeof(command), "\
bluetoothctl -- trust %s",
device);
pclose(popen(btctl->command, "r"));
pclose(popen(command, "r"));
snprintf(btctl->command, sizeof(btctl->command), "\
snprintf(command, sizeof(command), "\
bluetoothctl -- pair %s",
device);
pclose(popen(btctl->command, "r"));
pclose(popen(command, "r"));
snprintf(btctl->command, sizeof(btctl->command), "\
snprintf(command, sizeof(command), "\
bluetoothctl -- connect %s",
device);
pclose(popen(btctl->command, "r"));
pclose(popen(command, "r"));
btctl->bluetoothctl_counter[idx] = 0;
bluetoothctl_counter[idx] = 0;
return true;
}
void bluetoothctl_device_get_sublabel (void *data, char *s, unsigned i, size_t len)
void bluetoothctl_device_get_sublabel (char *s, unsigned i, size_t len)
{
bluetoothctl_t *btctl = (bluetoothctl_t*) data;
/* bluetoothctl devices outputs lines of the format:
* $ bluetoothctl devices
* 'Device (mac address) (device name)'
*/
const char *line = btctl->lines->elems[i].data;
const char *line = lines->elems[i].data;
strlcpy(s, line+7, 18);
}
bluetooth_driver_t bluetooth_bluetoothctl = {
bluetoothctl_init,
bluetoothctl_free,
bluetoothctl_start,
bluetoothctl_stop,
bluetoothctl_scan,
bluetoothctl_get_devices,
bluetoothctl_device_is_connected,

View File

@ -49,29 +49,37 @@ typedef struct
#undef VECTOR_LIST_TYPE
#undef VECTOR_LIST_NAME
typedef struct
{
struct device_info_vector_list *devices;
char adapter[256];
DBusConnection* dbus_connection;
bool bluez_cache[256];
int bluez_cache_counter[256];
} bluez_t;
/* TODO/FIXME - static globals - should go into userdata
* struct for driver */
static struct device_info_vector_list *devices = NULL;
static char adapter[256] = {0};
static DBusConnection* dbus_connection = NULL;
static bool bluez_cache[256] = {0};
static int bluez_cache_counter[256] = {0};
static void *bluez_init (void)
{
return calloc(1, sizeof(bluez_t));
return (void*)-1;
}
static void bluez_free (void *data)
{
if (data)
free(data);
(void)data;
}
static bool bluez_start (void *data)
{
(void)data;
return true;
}
static void bluez_stop (void *data)
{
(void)data;
}
static int
set_bool_property (
bluez_t *bluez,
const char *path,
const char *arg_adapter,
const char *arg_property,
@ -110,7 +118,7 @@ set_bool_property (
&req_iter, &req_subiter))
goto fault;
reply = dbus_connection_send_with_reply_and_block(bluez->dbus_connection,
reply = dbus_connection_send_with_reply_and_block(dbus_connection,
message, 1000, &err);
if (!reply)
goto fault;
@ -125,7 +133,6 @@ fault:
}
static int get_bool_property(
bluez_t *bluez,
const char *path,
const char *arg_adapter,
const char *arg_property,
@ -148,7 +155,7 @@ static int get_bool_property(
DBUS_TYPE_INVALID))
return 1;
reply = dbus_connection_send_with_reply_and_block(bluez->dbus_connection,
reply = dbus_connection_send_with_reply_and_block(dbus_connection,
message, 1000, &err);
dbus_message_unref(message);
@ -169,24 +176,24 @@ static int get_bool_property(
return 0;
}
static int adapter_discovery (bluez_t *bluez, const char *method)
static int adapter_discovery (const char *method)
{
DBusMessage *message = dbus_message_new_method_call(
"org.bluez", bluez->adapter,
"org.bluez", adapter,
"org.bluez.Adapter1", method);
if (!message)
return 1;
if (!dbus_connection_send(bluez->dbus_connection, message, NULL))
if (!dbus_connection_send(dbus_connection, message, NULL))
return 1;
dbus_connection_flush(bluez->dbus_connection);
dbus_connection_flush(dbus_connection);
dbus_message_unref(message);
return 0;
}
static int get_managed_objects (bluez_t *bluez, DBusMessage **reply)
static int get_managed_objects (DBusMessage **reply)
{
DBusMessage *message;
DBusError err;
@ -198,7 +205,7 @@ static int get_managed_objects (bluez_t *bluez, DBusMessage **reply)
if (!message)
return 1;
*reply = dbus_connection_send_with_reply_and_block(bluez->dbus_connection,
*reply = dbus_connection_send_with_reply_and_block(dbus_connection,
message, -1, &err);
/* if (!reply) is done by the caller in this one */
@ -206,7 +213,7 @@ static int get_managed_objects (bluez_t *bluez, DBusMessage **reply)
return 0;
}
static int device_method (bluez_t *bluez, const char *path, const char *method)
static int device_method (const char *path, const char *method)
{
DBusMessage *message, *reply;
DBusError err;
@ -218,18 +225,46 @@ static int device_method (bluez_t *bluez, const char *path, const char *method)
if (!message)
return 1;
reply = dbus_connection_send_with_reply_and_block(bluez->dbus_connection,
reply = dbus_connection_send_with_reply_and_block(dbus_connection,
message, 10000, &err);
if (!reply)
return 1;
dbus_connection_flush(bluez->dbus_connection);
dbus_connection_flush(dbus_connection);
dbus_message_unref(message);
return 0;
}
static int get_default_adapter(bluez_t *bluez, DBusMessage *reply)
static int device_remove (const char *path)
{
DBusMessage *message, *reply;
DBusError err;
dbus_error_init(&err);
message = dbus_message_new_method_call( "org.bluez", adapter,
"org.bluez.Adapter11", "RemoveDevice");
if (!message)
return 1;
if (!dbus_message_append_args(message,
DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID))
return 1;
reply = dbus_connection_send_with_reply_and_block(dbus_connection,
message, 10000, &err);
if (!reply)
return 1;
dbus_connection_flush(dbus_connection);
dbus_message_unref(message);
return 0;
}
static int get_default_adapter(DBusMessage *reply)
{
/* "...an application would discover the available adapters by
* performing a ObjectManager.GetManagedObjects call and look for any
@ -294,7 +329,7 @@ static int get_default_adapter(bluez_t *bluez, DBusMessage *reply)
if (string_is_equal(interface_name, "org.bluez.Adapter1"))
{
strlcpy(bluez->adapter, obj_path, 256);
strlcpy(adapter, obj_path, 256);
return 0;
}
} while (dbus_message_iter_next(&array_2_iter));
@ -304,7 +339,7 @@ static int get_default_adapter(bluez_t *bluez, DBusMessage *reply)
return 1;
}
static int read_scanned_devices (bluez_t *bluez, DBusMessage *reply)
static int read_scanned_devices (DBusMessage *reply)
{
device_info_t device;
DBusMessageIter root_iter;
@ -455,7 +490,7 @@ static int read_scanned_devices (bluez_t *bluez, DBusMessage *reply)
}
} while (dbus_message_iter_next(&array_3_iter));
if (!device_info_vector_list_append(bluez->devices, device))
if (!device_info_vector_list_append(devices, device))
return 1;
} while (dbus_message_iter_next(&array_2_iter));
@ -464,143 +499,138 @@ static int read_scanned_devices (bluez_t *bluez, DBusMessage *reply)
return 0;
}
static void bluez_dbus_connect (bluez_t *bluez)
static void bluez_dbus_connect (void)
{
DBusError err;
dbus_error_init(&err);
bluez->dbus_connection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
dbus_connection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
}
static void bluez_dbus_disconnect (bluez_t *bluez)
static void bluez_dbus_disconnect (void)
{
if (!bluez->dbus_connection)
if (!dbus_connection)
return;
dbus_connection_close(bluez->dbus_connection);
dbus_connection_unref(bluez->dbus_connection);
bluez->dbus_connection = NULL;
dbus_connection_close(dbus_connection);
dbus_connection_unref(dbus_connection);
dbus_connection = NULL;
}
static void bluez_scan (void *data)
static void bluez_scan (void)
{
bluez_t *bluez = (bluez_t*)data;
DBusError err;
DBusMessage *reply;
bluez_dbus_connect(bluez);
bluez_dbus_connect();
if (get_managed_objects(bluez, &reply))
if (get_managed_objects(&reply))
return;
if (!reply)
return;
/* Get default adapter */
if (get_default_adapter(bluez, reply))
if (get_default_adapter(reply))
return;
dbus_message_unref(reply);
/* Power device on */
if (set_bool_property(bluez, bluez->adapter, "org.bluez.Adapter1", "Powered", 1))
if (set_bool_property(adapter, "org.bluez.Adapter1", "Powered", 1))
return;
/* Start discovery */
if (adapter_discovery(bluez, "StartDiscovery"))
if (adapter_discovery("StartDiscovery"))
return;
retro_sleep(10000);
/* Stop discovery */
if (adapter_discovery(bluez, "StopDiscovery"))
if (adapter_discovery("StopDiscovery"))
return;
/* Get scanned devices */
if (get_managed_objects(bluez, &reply))
if (get_managed_objects(&reply))
return;
if (!reply)
return;
if (bluez->devices)
device_info_vector_list_free(bluez->devices);
bluez->devices = device_info_vector_list_new();
if (devices)
device_info_vector_list_free(devices);
devices = device_info_vector_list_new();
read_scanned_devices(bluez, reply);
read_scanned_devices(reply);
dbus_message_unref(reply);
bluez_dbus_disconnect(bluez);
bluez_dbus_disconnect();
}
static void bluez_get_devices (void *data, struct string_list* devices_string_list)
static void bluez_get_devices (struct string_list* devices_string_list)
{
bluez_t *bluez = (bluez_t*)data;
unsigned i;
union string_list_elem_attr attr;
attr.i = 0;
if (!bluez->devices)
if (!devices)
return;
for (i = 0; i < bluez->devices->count; i++)
for (i = 0; i < devices->count; i++)
{
char device[64];
strlcpy(device, bluez->devices->data[i].name, sizeof(device));
strlcpy(device, devices->data[i].name, sizeof(device));
string_list_append(devices_string_list, device, attr);
}
}
static bool bluez_device_is_connected (void *data, unsigned i)
static bool bluez_device_is_connected (unsigned i)
{
bluez_t *bluez = (bluez_t*)data;
int value;
if (bluez->bluez_cache_counter[i] == 60)
if (bluez_cache_counter[i] == 60)
{
bluez->bluez_cache_counter[i] = 0;
bluez_dbus_connect(bluez);
if (get_bool_property(bluez, bluez->devices->data[i].path,
"org.bluez.Device1", "Connected", &value))
{
/* Device disappeared */
value = false;
}
bluez_dbus_disconnect(bluez);
bluez_cache_counter[i] = 0;
bluez_dbus_connect();
get_bool_property(devices->data[i].path, "org.bluez.Device1",
"Connected", &value);
bluez_dbus_disconnect();
bluez->bluez_cache[i] = value;
bluez_cache[i] = value;
return value;
}
bluez->bluez_cache_counter[i]++;
return bluez->bluez_cache[i];
bluez_cache_counter[i]++;
return bluez_cache[i];
}
static void bluez_device_get_sublabel(void *data, char *s, unsigned i, size_t len)
static void bluez_device_get_sublabel(char *s, unsigned i, size_t len)
{
bluez_t *bluez = (bluez_t*)data;
strlcpy(s, bluez->devices->data[i].address, len);
strlcpy(s, devices->data[i].address, len);
}
static bool bluez_connect_device(void *data, unsigned i)
static bool bluez_connect_device(unsigned i)
{
bluez_t *bluez = (bluez_t*)data;
bluez_dbus_connect(bluez);
bluez_dbus_connect();
/* Remove the device */
device_remove(devices->data[i].path);
/* Trust the device */
if (set_bool_property(bluez, bluez->devices->data[i].path,
if (set_bool_property(devices->data[i].path,
"org.bluez.Device1", "Trusted", 1))
return false;
/* Pair the device */
device_method(bluez, bluez->devices->data[i].path, "Pair");
/* Can be "Already Exists" */
if (device_method(devices->data[i].path, "Pair"))
return false;
/* Connect the device */
if (device_method(bluez, bluez->devices->data[i].path, "Connect"))
if (device_method(devices->data[i].path, "Connect"))
return false;
bluez_dbus_disconnect(bluez);
bluez->bluez_cache_counter[i] = 0;
bluez_dbus_disconnect();
bluez_cache_counter[i] = 0;
return true;
}
bluetooth_driver_t bluetooth_bluez = {
bluez_init,
bluez_free,
bluez_start,
bluez_stop,
bluez_scan,
bluez_get_devices,
bluez_device_is_connected,

View File

@ -263,12 +263,11 @@ uintptr_t ozone_entries_icon_get_texture(ozone_handle_t *ozone,
return ozone->icons_textures[OZONE_ENTRIES_ICONS_TEXTURE_ACHIEVEMENTS];
case MENU_ENUM_LABEL_NETWORK_INFORMATION:
case MENU_ENUM_LABEL_NETWORK_SETTINGS:
case MENU_ENUM_LABEL_BLUETOOTH_SETTINGS:
case MENU_ENUM_LABEL_WIFI_SETTINGS:
case MENU_ENUM_LABEL_NETWORK_INFO_ENTRY:
case MENU_ENUM_LABEL_NETWORK_HOSTING_SETTINGS:
return ozone->icons_textures[OZONE_ENTRIES_ICONS_TEXTURE_NETWORK];
case MENU_ENUM_LABEL_BLUETOOTH_SETTINGS:
return ozone->icons_textures[OZONE_ENTRIES_ICONS_TEXTURE_BLUETOOTH];
case MENU_ENUM_LABEL_PLAYLIST_SETTINGS:
return ozone->icons_textures[OZONE_ENTRIES_ICONS_TEXTURE_PLAYLIST];
case MENU_ENUM_LABEL_USER_SETTINGS:

View File

@ -2691,13 +2691,12 @@ static uintptr_t xmb_icon_get_id(xmb_handle_t *xmb,
return xmb->textures.list[XMB_TEXTURE_RELOAD];
case MENU_ENUM_LABEL_NETWORK_INFORMATION:
case MENU_ENUM_LABEL_NETWORK_SETTINGS:
case MENU_ENUM_LABEL_BLUETOOTH_SETTINGS:
case MENU_ENUM_LABEL_WIFI_SETTINGS:
case MENU_ENUM_LABEL_NETWORK_INFO_ENTRY:
case MENU_ENUM_LABEL_NETWORK_HOSTING_SETTINGS:
return xmb->textures.list[XMB_TEXTURE_NETWORK];
#endif
case MENU_ENUM_LABEL_BLUETOOTH_SETTINGS:
return xmb->textures.list[XMB_TEXTURE_BLUETOOTH];
case MENU_ENUM_LABEL_SHUTDOWN:
return xmb->textures.list[XMB_TEXTURE_SHUTDOWN];
case MENU_ENUM_LABEL_CHEAT_APPLY_CHANGES:

View File

@ -877,6 +877,8 @@ static hid_driver_t *hid_drivers[] = {
static bluetooth_driver_t bluetooth_null = {
NULL, /* init */
NULL, /* free */
NULL, /* start */
NULL, /* stop */
NULL, /* scan */
NULL, /* get_devices */
NULL, /* device_is_connected */
@ -20469,46 +20471,31 @@ const char* config_get_bluetooth_driver_options(void)
void driver_bluetooth_scan(void)
{
struct rarch_state *p_rarch = &rarch_st;
if ( (p_rarch->bluetooth_driver_active) &&
(p_rarch->bluetooth_driver->scan) )
p_rarch->bluetooth_driver->scan(p_rarch->bluetooth_data);
p_rarch->bluetooth_driver->scan();
}
void driver_bluetooth_get_devices(struct string_list* devices)
{
struct rarch_state *p_rarch = &rarch_st;
if ( (p_rarch->bluetooth_driver_active) &&
(p_rarch->bluetooth_driver->get_devices) )
p_rarch->bluetooth_driver->get_devices(p_rarch->bluetooth_data, devices);
p_rarch->bluetooth_driver->get_devices(devices);
}
bool driver_bluetooth_device_is_connected(unsigned i)
{
struct rarch_state *p_rarch = &rarch_st;
if ( (p_rarch->bluetooth_driver_active) &&
(p_rarch->bluetooth_driver->device_is_connected) )
{
return p_rarch->bluetooth_driver->device_is_connected(p_rarch->bluetooth_data, i);
} else {
return false;
}
return p_rarch->bluetooth_driver->device_is_connected(i);
}
void driver_bluetooth_device_get_sublabel(char *s, unsigned i, size_t len)
{
struct rarch_state *p_rarch = &rarch_st;
if ( (p_rarch->bluetooth_driver_active) &&
(p_rarch->bluetooth_driver->device_get_sublabel) )
p_rarch->bluetooth_driver->device_get_sublabel(p_rarch->bluetooth_data, s, i, len);
p_rarch->bluetooth_driver->device_get_sublabel(s, i, len);
}
bool driver_bluetooth_connect_device(unsigned i)
{
struct rarch_state *p_rarch = &rarch_st;
if (p_rarch->bluetooth_driver_active)
return p_rarch->bluetooth_driver->connect_device(p_rarch->bluetooth_data, i);
else
return false;
return p_rarch->bluetooth_driver->connect_device(i);
}
bool bluetooth_driver_ctl(enum rarch_bluetooth_ctl_state state, void *data)
@ -20519,9 +20506,12 @@ bool bluetooth_driver_ctl(enum rarch_bluetooth_ctl_state state, void *data)
switch (state)
{
case RARCH_BLUETOOTH_CTL_DESTROY:
p_rarch->bluetooth_driver_active = false;
p_rarch->bluetooth_driver = NULL;
p_rarch->bluetooth_data = NULL;
p_rarch->bluetooth_driver_active = false;
break;
case RARCH_BLUETOOTH_CTL_SET_ACTIVE:
p_rarch->bluetooth_driver_active = true;
break;
case RARCH_BLUETOOTH_CTL_FIND_DRIVER:
{
@ -20558,6 +20548,11 @@ bool bluetooth_driver_ctl(enum rarch_bluetooth_ctl_state state, void *data)
}
}
break;
case RARCH_BLUETOOTH_CTL_UNSET_ACTIVE:
p_rarch->bluetooth_driver_active = false;
break;
case RARCH_BLUETOOTH_CTL_IS_ACTIVE:
return p_rarch->bluetooth_driver_active;
case RARCH_BLUETOOTH_CTL_DEINIT:
if (p_rarch->bluetooth_data && p_rarch->bluetooth_driver)
{
@ -20566,7 +20561,29 @@ bool bluetooth_driver_ctl(enum rarch_bluetooth_ctl_state state, void *data)
}
p_rarch->bluetooth_data = NULL;
p_rarch->bluetooth_driver_active = false;
break;
case RARCH_BLUETOOTH_CTL_STOP:
if ( p_rarch->bluetooth_driver
&& p_rarch->bluetooth_driver->stop
&& p_rarch->bluetooth_data)
p_rarch->bluetooth_driver->stop(p_rarch->bluetooth_data);
break;
case RARCH_BLUETOOTH_CTL_START:
if ( p_rarch->bluetooth_driver
&& p_rarch->bluetooth_data
&& p_rarch->bluetooth_driver->start)
{
bool bluetooth_allow = settings->bools.bluetooth_allow;
if (bluetooth_allow)
return p_rarch->bluetooth_driver->start(p_rarch->bluetooth_data);
}
return false;
case RARCH_BLUETOOTH_CTL_SET_CB:
{
/*struct retro_bluetooth_callback *cb =
(struct retro_bluetooth_callback*)data;
bluetooth_cb = *cb;*/
}
break;
case RARCH_BLUETOOTH_CTL_INIT:
/* Resource leaks will follow if bluetooth is initialized twice. */
@ -20580,11 +20597,11 @@ bool bluetooth_driver_ctl(enum rarch_bluetooth_ctl_state state, void *data)
if (!p_rarch->bluetooth_data)
{
RARCH_ERR("Failed to initialize bluetooth driver. Will continue without bluetooth.\n");
p_rarch->bluetooth_driver_active = false;
} else {
p_rarch->bluetooth_driver_active = true;
bluetooth_driver_ctl(RARCH_BLUETOOTH_CTL_UNSET_ACTIVE, NULL);
}
/*if (bluetooth_cb.initialized)
bluetooth_cb.initialized();*/
break;
default:
break;
@ -33796,9 +33813,6 @@ static void drivers_init(struct rarch_state *p_rarch, int flags)
}
}
if (flags & DRIVER_BLUETOOTH_MASK)
bluetooth_driver_ctl(RARCH_BLUETOOTH_CTL_INIT, NULL);
if (flags & DRIVER_LOCATION_MASK)
{
/* Only initialize location driver if we're ever going to use it. */