diff --git a/bluetooth/bluetooth_driver.h b/bluetooth/bluetooth_driver.h index 840315e463..404dec082b 100644 --- a/bluetooth/bluetooth_driver.h +++ b/bluetooth/bluetooth_driver.h @@ -28,13 +28,7 @@ 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 }; @@ -44,14 +38,11 @@ typedef struct bluetooth_driver void (*free)(void *data); - 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); + 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); const char *ident; } bluetooth_driver_t; @@ -70,10 +61,6 @@ 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); diff --git a/bluetooth/drivers/bluetoothctl.c b/bluetooth/drivers/bluetoothctl.c index 414d902eed..186cb29f7f 100644 --- a/bluetooth/drivers/bluetoothctl.c +++ b/bluetooth/drivers/bluetoothctl.c @@ -18,48 +18,40 @@ #include "../bluetooth_driver.h" #include "../../retroarch.h" -/* 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}; +typedef struct +{ + bool bluetoothctl_cache[256]; + unsigned bluetoothctl_counter[256]; + struct string_list* lines; + char command[256]; +} bluetoothctl_t; static void *bluetoothctl_init(void) { - return (void*)-1; + return calloc(1, sizeof(bluetoothctl_t)); } static void bluetoothctl_free(void *data) { - (void)data; + if (data) + free(data); } -static bool bluetoothctl_start(void *data) -{ - (void)data; - return true; -} - -static void bluetoothctl_stop(void *data) -{ - (void)data; -} - -static void bluetoothctl_scan(void) +static void bluetoothctl_scan(void *data) { + bluetoothctl_t *btctl = (bluetoothctl_t*) data; char line[512]; union string_list_elem_attr attr; FILE *dev_file = NULL; attr.i = 0; - if (lines) - free(lines); - lines = string_list_new(); + if (btctl->lines) + free(btctl->lines); + btctl->lines = string_list_new(); pclose(popen("bluetoothctl -- power on", "r")); - pclose(popen("bluetoothctl --timeout 15 scan on", "r")); + pclose(popen("bluetoothctl --timeout 10 scan on", "r")); runloop_msg_queue_push(msg_hash_to_str(MSG_BLUETOOTH_SCAN_COMPLETE), 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, @@ -73,26 +65,27 @@ static void bluetoothctl_scan(void) if (len > 0 && line[len-1] == '\n') line[--len] = '\0'; - string_list_append(lines, line, attr); + string_list_append(btctl->lines, line, attr); } pclose(dev_file); } -static void bluetoothctl_get_devices(struct string_list* devices) +static void bluetoothctl_get_devices(void *data, struct string_list* devices) { + bluetoothctl_t *btctl = (bluetoothctl_t*) data; unsigned i; union string_list_elem_attr attr; attr.i = 0; - if (!lines) + if (!btctl->lines) return; - for (i = 0; i < lines->size; i++) + for (i = 0; i < btctl->lines->size; i++) { char device[64]; - const char *line = lines->elems[i].data; + const char *line = btctl->lines->elems[i].data; /* bluetoothctl devices outputs lines of the format: * $ bluetoothctl devices @@ -103,17 +96,18 @@ static void bluetoothctl_get_devices(struct string_list* devices) } } -static bool bluetoothctl_device_is_connected(unsigned i) +static bool bluetoothctl_device_is_connected(void *data, unsigned i) { + bluetoothctl_t *btctl = (bluetoothctl_t*) data; char ln[512] = {0}; char device[18] = {0}; - const char *line = lines->elems[i].data; + const char *line = btctl->lines->elems[i].data; FILE *command_file = NULL; - if (bluetoothctl_counter[i] == 60) + if (btctl->bluetoothctl_counter[i] == 60) { static struct string_list* list = NULL; - bluetoothctl_counter[i] = 0; + btctl->bluetoothctl_counter[i] = 0; list = string_split(line, " "); if (!list) return false; @@ -127,34 +121,35 @@ static bool bluetoothctl_device_is_connected(unsigned i) strlcpy(device, list->elems[1].data, sizeof(device)); string_list_free(list); - snprintf(command, sizeof(command), "\ + snprintf(btctl->command, sizeof(btctl->command), "\ bluetoothctl -- info %s | grep 'Connected: yes'", device); - command_file = popen(command, "r"); + command_file = popen(btctl->command, "r"); while (fgets(ln, 512, command_file)) { - bluetoothctl_cache[i] = true; + btctl->bluetoothctl_cache[i] = true; return true; } pclose(command_file); - bluetoothctl_cache[i] = false; + btctl->bluetoothctl_cache[i] = false; } else { - bluetoothctl_counter[i]++; - return bluetoothctl_cache[i]; + btctl->bluetoothctl_counter[i]++; + return btctl->bluetoothctl_cache[i]; } return false; } -static bool bluetoothctl_connect_device(unsigned idx) +static bool bluetoothctl_connect_device(void *data, unsigned idx) { + bluetoothctl_t *btctl = (bluetoothctl_t*) data; unsigned i; char device[18] = {0}; - const char *line = lines->elems[idx].data; + const char *line = btctl->lines->elems[idx].data; static struct string_list* list = NULL; /* bluetoothctl devices outputs lines of the format: @@ -174,43 +169,42 @@ static bool bluetoothctl_connect_device(unsigned idx) strlcpy(device, list->elems[1].data, sizeof(device)); string_list_free(list); - snprintf(command, sizeof(command), "\ + snprintf(btctl->command, sizeof(btctl->command), "\ bluetoothctl -- trust %s", device); - pclose(popen(command, "r")); + pclose(popen(btctl->command, "r")); - snprintf(command, sizeof(command), "\ + snprintf(btctl->command, sizeof(btctl->command), "\ bluetoothctl -- pair %s", device); - pclose(popen(command, "r")); + pclose(popen(btctl->command, "r")); - snprintf(command, sizeof(command), "\ + snprintf(btctl->command, sizeof(btctl->command), "\ bluetoothctl -- connect %s", device); - pclose(popen(command, "r")); + pclose(popen(btctl->command, "r")); - bluetoothctl_counter[idx] = 0; + btctl->bluetoothctl_counter[idx] = 0; return true; } -void bluetoothctl_device_get_sublabel (char *s, unsigned i, size_t len) +void bluetoothctl_device_get_sublabel (void *data, 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 = lines->elems[i].data; + const char *line = btctl->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, diff --git a/bluetooth/drivers/bluez.c b/bluetooth/drivers/bluez.c index 273c8e4df2..5e56f6e129 100644 --- a/bluetooth/drivers/bluez.c +++ b/bluetooth/drivers/bluez.c @@ -49,37 +49,29 @@ typedef struct #undef VECTOR_LIST_TYPE #undef VECTOR_LIST_NAME -/* 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}; +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; static void *bluez_init (void) { - return (void*)-1; + return calloc(1, sizeof(bluez_t)); } static void bluez_free (void *data) { - (void)data; -} - -static bool bluez_start (void *data) -{ - (void)data; - return true; -} - -static void bluez_stop (void *data) -{ - (void)data; + if (data) + free(data); } static int set_bool_property ( + bluez_t *bluez, const char *path, const char *arg_adapter, const char *arg_property, @@ -118,7 +110,7 @@ set_bool_property ( &req_iter, &req_subiter)) goto fault; - reply = dbus_connection_send_with_reply_and_block(dbus_connection, + reply = dbus_connection_send_with_reply_and_block(bluez->dbus_connection, message, 1000, &err); if (!reply) goto fault; @@ -133,6 +125,7 @@ fault: } static int get_bool_property( + bluez_t *bluez, const char *path, const char *arg_adapter, const char *arg_property, @@ -155,7 +148,7 @@ static int get_bool_property( DBUS_TYPE_INVALID)) return 1; - reply = dbus_connection_send_with_reply_and_block(dbus_connection, + reply = dbus_connection_send_with_reply_and_block(bluez->dbus_connection, message, 1000, &err); dbus_message_unref(message); @@ -176,24 +169,24 @@ static int get_bool_property( return 0; } -static int adapter_discovery (const char *method) +static int adapter_discovery (bluez_t *bluez, const char *method) { DBusMessage *message = dbus_message_new_method_call( - "org.bluez", adapter, + "org.bluez", bluez->adapter, "org.bluez.Adapter1", method); if (!message) return 1; - if (!dbus_connection_send(dbus_connection, message, NULL)) + if (!dbus_connection_send(bluez->dbus_connection, message, NULL)) return 1; - dbus_connection_flush(dbus_connection); + dbus_connection_flush(bluez->dbus_connection); dbus_message_unref(message); return 0; } -static int get_managed_objects (DBusMessage **reply) +static int get_managed_objects (bluez_t *bluez, DBusMessage **reply) { DBusMessage *message; DBusError err; @@ -205,7 +198,7 @@ static int get_managed_objects (DBusMessage **reply) if (!message) return 1; - *reply = dbus_connection_send_with_reply_and_block(dbus_connection, + *reply = dbus_connection_send_with_reply_and_block(bluez->dbus_connection, message, -1, &err); /* if (!reply) is done by the caller in this one */ @@ -213,7 +206,7 @@ static int get_managed_objects (DBusMessage **reply) return 0; } -static int device_method (const char *path, const char *method) +static int device_method (bluez_t *bluez, const char *path, const char *method) { DBusMessage *message, *reply; DBusError err; @@ -225,46 +218,18 @@ static int device_method (const char *path, const char *method) if (!message) return 1; - reply = dbus_connection_send_with_reply_and_block(dbus_connection, + reply = dbus_connection_send_with_reply_and_block(bluez->dbus_connection, message, 10000, &err); if (!reply) return 1; - dbus_connection_flush(dbus_connection); + dbus_connection_flush(bluez->dbus_connection); dbus_message_unref(message); return 0; } -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) +static int get_default_adapter(bluez_t *bluez, DBusMessage *reply) { /* "...an application would discover the available adapters by * performing a ObjectManager.GetManagedObjects call and look for any @@ -329,7 +294,7 @@ static int get_default_adapter(DBusMessage *reply) if (string_is_equal(interface_name, "org.bluez.Adapter1")) { - strlcpy(adapter, obj_path, 256); + strlcpy(bluez->adapter, obj_path, 256); return 0; } } while (dbus_message_iter_next(&array_2_iter)); @@ -339,7 +304,7 @@ static int get_default_adapter(DBusMessage *reply) return 1; } -static int read_scanned_devices (DBusMessage *reply) +static int read_scanned_devices (bluez_t *bluez, DBusMessage *reply) { device_info_t device; DBusMessageIter root_iter; @@ -490,7 +455,7 @@ static int read_scanned_devices (DBusMessage *reply) } } while (dbus_message_iter_next(&array_3_iter)); - if (!device_info_vector_list_append(devices, device)) + if (!device_info_vector_list_append(bluez->devices, device)) return 1; } while (dbus_message_iter_next(&array_2_iter)); @@ -499,138 +464,143 @@ static int read_scanned_devices (DBusMessage *reply) return 0; } -static void bluez_dbus_connect (void) +static void bluez_dbus_connect (bluez_t *bluez) { DBusError err; dbus_error_init(&err); - dbus_connection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err); + bluez->dbus_connection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err); } -static void bluez_dbus_disconnect (void) +static void bluez_dbus_disconnect (bluez_t *bluez) { - if (!dbus_connection) + if (!bluez->dbus_connection) return; - dbus_connection_close(dbus_connection); - dbus_connection_unref(dbus_connection); - dbus_connection = NULL; + dbus_connection_close(bluez->dbus_connection); + dbus_connection_unref(bluez->dbus_connection); + bluez->dbus_connection = NULL; } -static void bluez_scan (void) +static void bluez_scan (void *data) { + bluez_t *bluez = (bluez_t*)data; DBusError err; DBusMessage *reply; - bluez_dbus_connect(); + bluez_dbus_connect(bluez); - if (get_managed_objects(&reply)) + if (get_managed_objects(bluez, &reply)) return; if (!reply) return; /* Get default adapter */ - if (get_default_adapter(reply)) + if (get_default_adapter(bluez, reply)) return; dbus_message_unref(reply); /* Power device on */ - if (set_bool_property(adapter, "org.bluez.Adapter1", "Powered", 1)) + if (set_bool_property(bluez, bluez->adapter, "org.bluez.Adapter1", "Powered", 1)) return; /* Start discovery */ - if (adapter_discovery("StartDiscovery")) + if (adapter_discovery(bluez, "StartDiscovery")) return; retro_sleep(10000); /* Stop discovery */ - if (adapter_discovery("StopDiscovery")) + if (adapter_discovery(bluez, "StopDiscovery")) return; /* Get scanned devices */ - if (get_managed_objects(&reply)) + if (get_managed_objects(bluez, &reply)) return; if (!reply) return; - if (devices) - device_info_vector_list_free(devices); - devices = device_info_vector_list_new(); + if (bluez->devices) + device_info_vector_list_free(bluez->devices); + bluez->devices = device_info_vector_list_new(); - read_scanned_devices(reply); + read_scanned_devices(bluez, reply); dbus_message_unref(reply); - bluez_dbus_disconnect(); + bluez_dbus_disconnect(bluez); } -static void bluez_get_devices (struct string_list* devices_string_list) +static void bluez_get_devices (void *data, struct string_list* devices_string_list) { + bluez_t *bluez = (bluez_t*)data; unsigned i; union string_list_elem_attr attr; attr.i = 0; - if (!devices) + if (!bluez->devices) return; - for (i = 0; i < devices->count; i++) + for (i = 0; i < bluez->devices->count; i++) { char device[64]; - strlcpy(device, devices->data[i].name, sizeof(device)); + strlcpy(device, bluez->devices->data[i].name, sizeof(device)); string_list_append(devices_string_list, device, attr); } } -static bool bluez_device_is_connected (unsigned i) +static bool bluez_device_is_connected (void *data, unsigned i) { + bluez_t *bluez = (bluez_t*)data; int value; - if (bluez_cache_counter[i] == 60) + if (bluez->bluez_cache_counter[i] == 60) { - 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_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[i] = value; + bluez->bluez_cache[i] = value; return value; } - bluez_cache_counter[i]++; - return bluez_cache[i]; + bluez->bluez_cache_counter[i]++; + return bluez->bluez_cache[i]; } -static void bluez_device_get_sublabel(char *s, unsigned i, size_t len) +static void bluez_device_get_sublabel(void *data, char *s, unsigned i, size_t len) { - strlcpy(s, devices->data[i].address, len); + bluez_t *bluez = (bluez_t*)data; + strlcpy(s, bluez->devices->data[i].address, len); } -static bool bluez_connect_device(unsigned i) +static bool bluez_connect_device(void *data, unsigned i) { - bluez_dbus_connect(); + bluez_t *bluez = (bluez_t*)data; + bluez_dbus_connect(bluez); - /* Remove the device */ - device_remove(devices->data[i].path); /* Trust the device */ - if (set_bool_property(devices->data[i].path, + if (set_bool_property(bluez, bluez->devices->data[i].path, "org.bluez.Device1", "Trusted", 1)) return false; /* Pair the device */ - if (device_method(devices->data[i].path, "Pair")) - return false; + device_method(bluez, bluez->devices->data[i].path, "Pair"); + /* Can be "Already Exists" */ /* Connect the device */ - if (device_method(devices->data[i].path, "Connect")) + if (device_method(bluez, bluez->devices->data[i].path, "Connect")) return false; - bluez_dbus_disconnect(); - bluez_cache_counter[i] = 0; + bluez_dbus_disconnect(bluez); + bluez->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, diff --git a/menu/drivers/ozone/ozone_texture.c b/menu/drivers/ozone/ozone_texture.c index 3b91ada157..a1d233e873 100644 --- a/menu/drivers/ozone/ozone_texture.c +++ b/menu/drivers/ozone/ozone_texture.c @@ -263,11 +263,12 @@ 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: diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index f10e78478d..88b8404475 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -2691,12 +2691,13 @@ 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: diff --git a/retroarch.c b/retroarch.c index 633de18c0f..572bed09c9 100644 --- a/retroarch.c +++ b/retroarch.c @@ -877,8 +877,6 @@ 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 */ @@ -20471,31 +20469,46 @@ const char* config_get_bluetooth_driver_options(void) void driver_bluetooth_scan(void) { struct rarch_state *p_rarch = &rarch_st; - p_rarch->bluetooth_driver->scan(); + if ( (p_rarch->bluetooth_driver_active) && + (p_rarch->bluetooth_driver->scan) ) + p_rarch->bluetooth_driver->scan(p_rarch->bluetooth_data); } void driver_bluetooth_get_devices(struct string_list* devices) { struct rarch_state *p_rarch = &rarch_st; - p_rarch->bluetooth_driver->get_devices(devices); + if ( (p_rarch->bluetooth_driver_active) && + (p_rarch->bluetooth_driver->get_devices) ) + p_rarch->bluetooth_driver->get_devices(p_rarch->bluetooth_data, devices); } bool driver_bluetooth_device_is_connected(unsigned i) { struct rarch_state *p_rarch = &rarch_st; - return p_rarch->bluetooth_driver->device_is_connected(i); + 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; + } } void driver_bluetooth_device_get_sublabel(char *s, unsigned i, size_t len) { struct rarch_state *p_rarch = &rarch_st; - p_rarch->bluetooth_driver->device_get_sublabel(s, i, len); + 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); } bool driver_bluetooth_connect_device(unsigned i) { struct rarch_state *p_rarch = &rarch_st; - return p_rarch->bluetooth_driver->connect_device(i); + if (p_rarch->bluetooth_driver_active) + return p_rarch->bluetooth_driver->connect_device(p_rarch->bluetooth_data, i); + else + return false; } bool bluetooth_driver_ctl(enum rarch_bluetooth_ctl_state state, void *data) @@ -20506,12 +20519,9 @@ 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; - break; - case RARCH_BLUETOOTH_CTL_SET_ACTIVE: - p_rarch->bluetooth_driver_active = true; + p_rarch->bluetooth_driver_active = false; break; case RARCH_BLUETOOTH_CTL_FIND_DRIVER: { @@ -20548,11 +20558,6 @@ 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) { @@ -20561,29 +20566,7 @@ bool bluetooth_driver_ctl(enum rarch_bluetooth_ctl_state state, void *data) } p_rarch->bluetooth_data = NULL; - 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;*/ - } + p_rarch->bluetooth_driver_active = false; break; case RARCH_BLUETOOTH_CTL_INIT: /* Resource leaks will follow if bluetooth is initialized twice. */ @@ -20597,11 +20580,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"); - bluetooth_driver_ctl(RARCH_BLUETOOTH_CTL_UNSET_ACTIVE, NULL); + p_rarch->bluetooth_driver_active = false; + } else { + p_rarch->bluetooth_driver_active = true; } - /*if (bluetooth_cb.initialized) - bluetooth_cb.initialized();*/ break; default: break; @@ -33813,6 +33796,9 @@ 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. */