mirror of
https://github.com/CTCaer/RetroArch.git
synced 2025-03-01 16:15:35 +00:00
(bluetooth) Cleanups
This commit is contained in:
parent
0267736465
commit
b4be553ccc
@ -39,10 +39,10 @@ static void bluetoothctl_free(void *data)
|
|||||||
|
|
||||||
static void bluetoothctl_scan(void *data)
|
static void bluetoothctl_scan(void *data)
|
||||||
{
|
{
|
||||||
bluetoothctl_t *btctl = (bluetoothctl_t*) data;
|
|
||||||
char line[512];
|
char line[512];
|
||||||
union string_list_elem_attr attr;
|
union string_list_elem_attr attr;
|
||||||
FILE *dev_file = NULL;
|
FILE *dev_file = NULL;
|
||||||
|
bluetoothctl_t *btctl = (bluetoothctl_t*) data;
|
||||||
|
|
||||||
attr.i = 0;
|
attr.i = 0;
|
||||||
if (btctl->lines)
|
if (btctl->lines)
|
||||||
@ -73,9 +73,9 @@ static void bluetoothctl_scan(void *data)
|
|||||||
|
|
||||||
static void bluetoothctl_get_devices(void *data, struct string_list* devices)
|
static void bluetoothctl_get_devices(void *data, struct string_list* devices)
|
||||||
{
|
{
|
||||||
bluetoothctl_t *btctl = (bluetoothctl_t*) data;
|
|
||||||
unsigned i;
|
unsigned i;
|
||||||
union string_list_elem_attr attr;
|
union string_list_elem_attr attr;
|
||||||
|
bluetoothctl_t *btctl = (bluetoothctl_t*) data;
|
||||||
|
|
||||||
attr.i = 0;
|
attr.i = 0;
|
||||||
|
|
||||||
@ -99,16 +99,16 @@ 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(void *data, unsigned i)
|
||||||
{
|
{
|
||||||
bluetoothctl_t *btctl = (bluetoothctl_t*) data;
|
bluetoothctl_t *btctl = (bluetoothctl_t*) data;
|
||||||
char ln[512] = {0};
|
char ln[512] = {0};
|
||||||
char device[18] = {0};
|
char device[18] = {0};
|
||||||
const char *line = btctl->lines->elems[i].data;
|
const char *line = btctl->lines->elems[i].data;
|
||||||
FILE *command_file = NULL;
|
FILE *command_file = NULL;
|
||||||
|
|
||||||
if (btctl->bluetoothctl_counter[i] == 60)
|
if (btctl->bluetoothctl_counter[i] == 60)
|
||||||
{
|
{
|
||||||
static struct string_list* list = NULL;
|
static struct string_list* list = NULL;
|
||||||
btctl->bluetoothctl_counter[i] = 0;
|
btctl->bluetoothctl_counter[i] = 0;
|
||||||
list = string_split(line, " ");
|
list = string_split(line, " ");
|
||||||
if (!list)
|
if (!list)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -146,8 +146,8 @@ static bool bluetoothctl_device_is_connected(void *data, unsigned i)
|
|||||||
|
|
||||||
static bool bluetoothctl_connect_device(void *data, unsigned idx)
|
static bool bluetoothctl_connect_device(void *data, unsigned idx)
|
||||||
{
|
{
|
||||||
bluetoothctl_t *btctl = (bluetoothctl_t*) data;
|
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
bluetoothctl_t *btctl = (bluetoothctl_t*) data;
|
||||||
char device[18] = {0};
|
char device[18] = {0};
|
||||||
const char *line = btctl->lines->elems[idx].data;
|
const char *line = btctl->lines->elems[idx].data;
|
||||||
static struct string_list* list = NULL;
|
static struct string_list* list = NULL;
|
||||||
@ -156,7 +156,7 @@ static bool bluetoothctl_connect_device(void *data, unsigned idx)
|
|||||||
* $ bluetoothctl devices
|
* $ bluetoothctl devices
|
||||||
* 'Device (mac address) (device name)'
|
* 'Device (mac address) (device name)'
|
||||||
*/
|
*/
|
||||||
list = string_split(line, " ");
|
list = string_split(line, " ");
|
||||||
if (!list)
|
if (!list)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -191,14 +191,15 @@ static bool bluetoothctl_connect_device(void *data, unsigned idx)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bluetoothctl_device_get_sublabel (void *data, char *s, unsigned i, size_t len)
|
static void bluetoothctl_device_get_sublabel(
|
||||||
|
void *data, char *s, unsigned i, size_t len)
|
||||||
{
|
{
|
||||||
bluetoothctl_t *btctl = (bluetoothctl_t*) data;
|
bluetoothctl_t *btctl = (bluetoothctl_t*) data;
|
||||||
/* bluetoothctl devices outputs lines of the format:
|
/* bluetoothctl devices outputs lines of the format:
|
||||||
* $ bluetoothctl devices
|
* $ bluetoothctl devices
|
||||||
* 'Device (mac address) (device name)'
|
* 'Device (mac address) (device name)'
|
||||||
*/
|
*/
|
||||||
const char *line = btctl->lines->elems[i].data;
|
const char *line = btctl->lines->elems[i].data;
|
||||||
strlcpy(s, line+7, 18);
|
strlcpy(s, line+7, 18);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,8 +77,9 @@ set_bool_property (
|
|||||||
const char *arg_property,
|
const char *arg_property,
|
||||||
int value)
|
int value)
|
||||||
{
|
{
|
||||||
DBusMessage *message, *reply;
|
|
||||||
DBusError err;
|
DBusError err;
|
||||||
|
DBusMessage *message, *reply;
|
||||||
|
DBusMessageIter req_iter, req_subiter;
|
||||||
|
|
||||||
dbus_error_init(&err);
|
dbus_error_init(&err);
|
||||||
|
|
||||||
@ -91,7 +92,6 @@ set_bool_property (
|
|||||||
if (!message)
|
if (!message)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
DBusMessageIter req_iter, req_subiter;
|
|
||||||
dbus_message_iter_init_append(message, &req_iter);
|
dbus_message_iter_init_append(message, &req_iter);
|
||||||
if (!dbus_message_iter_append_basic(
|
if (!dbus_message_iter_append_basic(
|
||||||
&req_iter, DBUS_TYPE_STRING, &arg_adapter))
|
&req_iter, DBUS_TYPE_STRING, &arg_adapter))
|
||||||
@ -464,14 +464,14 @@ static int read_scanned_devices (bluez_t *bluez, DBusMessage *reply)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bluez_dbus_connect (bluez_t *bluez)
|
static void bluez_dbus_connect(bluez_t *bluez)
|
||||||
{
|
{
|
||||||
DBusError err;
|
DBusError err;
|
||||||
dbus_error_init(&err);
|
dbus_error_init(&err);
|
||||||
bluez->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 (bluez_t *bluez)
|
static void bluez_dbus_disconnect(bluez_t *bluez)
|
||||||
{
|
{
|
||||||
if (!bluez->dbus_connection)
|
if (!bluez->dbus_connection)
|
||||||
return;
|
return;
|
||||||
@ -481,11 +481,11 @@ static void bluez_dbus_disconnect (bluez_t *bluez)
|
|||||||
bluez->dbus_connection = NULL;
|
bluez->dbus_connection = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bluez_scan (void *data)
|
static void bluez_scan(void *data)
|
||||||
{
|
{
|
||||||
bluez_t *bluez = (bluez_t*)data;
|
|
||||||
DBusError err;
|
DBusError err;
|
||||||
DBusMessage *reply;
|
DBusMessage *reply;
|
||||||
|
bluez_t *bluez = (bluez_t*)data;
|
||||||
|
|
||||||
bluez_dbus_connect(bluez);
|
bluez_dbus_connect(bluez);
|
||||||
|
|
||||||
@ -500,7 +500,8 @@ static void bluez_scan (void *data)
|
|||||||
dbus_message_unref(reply);
|
dbus_message_unref(reply);
|
||||||
|
|
||||||
/* Power device on */
|
/* Power device on */
|
||||||
if (set_bool_property(bluez, bluez->adapter, "org.bluez.Adapter1", "Powered", 1))
|
if (set_bool_property(bluez, bluez->adapter,
|
||||||
|
"org.bluez.Adapter1", "Powered", 1))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Start discovery */
|
/* Start discovery */
|
||||||
@ -528,11 +529,13 @@ static void bluez_scan (void *data)
|
|||||||
bluez_dbus_disconnect(bluez);
|
bluez_dbus_disconnect(bluez);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bluez_get_devices (void *data, 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;
|
unsigned i;
|
||||||
union string_list_elem_attr attr;
|
union string_list_elem_attr attr;
|
||||||
|
bluez_t *bluez = (bluez_t*)data;
|
||||||
|
|
||||||
attr.i = 0;
|
attr.i = 0;
|
||||||
|
|
||||||
if (!bluez->devices)
|
if (!bluez->devices)
|
||||||
@ -546,21 +549,21 @@ static void bluez_get_devices (void *data, struct string_list* devices_string_li
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool bluez_device_is_connected (void *data, unsigned i)
|
static bool bluez_device_is_connected(void *data, unsigned i)
|
||||||
{
|
{
|
||||||
bluez_t *bluez = (bluez_t*)data;
|
|
||||||
int value;
|
int value;
|
||||||
|
bluez_t *bluez = (bluez_t*)data;
|
||||||
|
|
||||||
if (bluez->bluez_cache_counter[i] == 60)
|
if (bluez->bluez_cache_counter[i] == 60)
|
||||||
{
|
{
|
||||||
bluez->bluez_cache_counter[i] = 0;
|
bluez->bluez_cache_counter[i] = 0;
|
||||||
bluez_dbus_connect(bluez);
|
bluez_dbus_connect(bluez);
|
||||||
|
|
||||||
|
/* Device disappeared */
|
||||||
if (get_bool_property(bluez, bluez->devices->data[i].path,
|
if (get_bool_property(bluez, bluez->devices->data[i].path,
|
||||||
"org.bluez.Device1", "Connected", &value))
|
"org.bluez.Device1", "Connected", &value))
|
||||||
{
|
|
||||||
/* Device disappeared */
|
|
||||||
value = false;
|
value = false;
|
||||||
}
|
|
||||||
bluez_dbus_disconnect(bluez);
|
bluez_dbus_disconnect(bluez);
|
||||||
|
|
||||||
bluez->bluez_cache[i] = value;
|
bluez->bluez_cache[i] = value;
|
||||||
@ -571,7 +574,8 @@ static bool bluez_device_is_connected (void *data, unsigned i)
|
|||||||
return bluez->bluez_cache[i];
|
return bluez->bluez_cache[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bluez_device_get_sublabel(void *data, char *s, unsigned i, size_t len)
|
static void bluez_device_get_sublabel(
|
||||||
|
void *data, char *s, unsigned i, size_t len)
|
||||||
{
|
{
|
||||||
bluez_t *bluez = (bluez_t*)data;
|
bluez_t *bluez = (bluez_t*)data;
|
||||||
strlcpy(s, bluez->devices->data[i].address, len);
|
strlcpy(s, bluez->devices->data[i].address, len);
|
||||||
@ -586,8 +590,10 @@ static bool bluez_connect_device(void *data, unsigned i)
|
|||||||
if (set_bool_property(bluez, bluez->devices->data[i].path,
|
if (set_bool_property(bluez, bluez->devices->data[i].path,
|
||||||
"org.bluez.Device1", "Trusted", 1))
|
"org.bluez.Device1", "Trusted", 1))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* Pair the device */
|
/* Pair the device */
|
||||||
device_method(bluez, bluez->devices->data[i].path, "Pair");
|
device_method(bluez, bluez->devices->data[i].path, "Pair");
|
||||||
|
|
||||||
/* Can be "Already Exists" */
|
/* Can be "Already Exists" */
|
||||||
/* Connect the device */
|
/* Connect the device */
|
||||||
if (device_method(bluez, bluez->devices->data[i].path, "Connect"))
|
if (device_method(bluez, bluez->devices->data[i].path, "Connect"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user