Skip to content

Commit

Permalink
Cleanups -
Browse files Browse the repository at this point in the history
* Less string copies
* Some general cleanups
* Add extra param to runloop_message_queue_push so we can pass size_t
of the message
* Consistent conventions for local variable usage for certain things
  • Loading branch information
LibretroAdmin committed Dec 27, 2024
1 parent ed58e4a commit 18c85b5
Show file tree
Hide file tree
Showing 49 changed files with 1,397 additions and 1,253 deletions.
7 changes: 4 additions & 3 deletions audio/drivers_microphone/sdl_microphone.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ static void *sdl_microphone_open_mic(void *driver_context,
#if __APPLE__
if (!string_is_equal(audio_driver_get_ident(), "sdl2"))
{
runloop_msg_queue_push(
msg_hash_to_str(MSG_SDL2_MIC_NEEDS_SDL2_AUDIO), 1, 100, true, NULL,
const char *msg = msg_hash_to_str(MSG_SDL2_MIC_NEEDS_SDL2_AUDIO),msg_hash_to_str(MSG_SDL2_MIC_NEEDS_SDL2_AUDIO);
runloop_msg_queue_push(msg, strlen(msg),
1, 100, true, NULL,
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_WARNING);
return NULL;
}
Expand All @@ -155,7 +156,7 @@ static void *sdl_microphone_open_mic(void *driver_context,

/* Only print SDL audio devices if verbose logging is enabled */
if (verbosity_is_enabled())
{
{
int i;
int num_available_microphones = SDL_GetNumAudioDevices(true);
RARCH_DBG("[SDL mic]: %d audio capture devices found:\n", num_available_microphones);
Expand Down
13 changes: 9 additions & 4 deletions bluetooth/drivers/bluetoothctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ static void bluetoothctl_free(void *data)
static void bluetoothctl_scan(void *data)
{
char line[512];
const char *msg;
union string_list_elem_attr attr;
FILE *dev_file = NULL;
bluetoothctl_t *btctl = (bluetoothctl_t*) data;
Expand All @@ -53,7 +54,9 @@ static void bluetoothctl_scan(void *data)

pclose(popen("bluetoothctl --timeout 10 scan on", "r"));

runloop_msg_queue_push(msg_hash_to_str(MSG_BLUETOOTH_SCAN_COMPLETE),
msg = msg_hash_to_str(MSG_BLUETOOTH_SCAN_COMPLETE);

runloop_msg_queue_push(msg, strlen(msg),
1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT,
MESSAGE_QUEUE_CATEGORY_INFO);

Expand Down Expand Up @@ -199,6 +202,7 @@ static bool bluetoothctl_connect_device(void *data, unsigned idx)
static bool bluetoothctl_remove_device(void *data, unsigned idx)
{
unsigned i;
const char *msg = NULL;
bluetoothctl_t *btctl = (bluetoothctl_t*) data;
char device[18] = {0};
const char *line = btctl->lines->elems[idx].data;
Expand All @@ -208,8 +212,7 @@ static bool bluetoothctl_remove_device(void *data, unsigned idx)
* $ bluetoothctl devices
* 'Device (mac address) (device name)'
*/
list = string_split(line, " ");
if (!list)
if (!(list = string_split(line, " ")))
return false;

if (list->size == 0)
Expand All @@ -227,7 +230,9 @@ static bool bluetoothctl_remove_device(void *data, unsigned idx)

pclose(popen(btctl->command, "r"));

runloop_msg_queue_push(msg_hash_to_str(MSG_BLUETOOTH_PAIRING_REMOVED),
msg = msg_hash_to_str(MSG_BLUETOOTH_PAIRING_REMOVED);

runloop_msg_queue_push(msg, strlen(msg),
1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT,
MESSAGE_QUEUE_CATEGORY_INFO);

Expand Down
32 changes: 18 additions & 14 deletions bluetooth/drivers/bluez.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,18 +276,18 @@ static int get_default_adapter(bluez_t *bluez, DBusMessage *reply)
do
{
/* empty array? */
if (DBUS_TYPE_INVALID ==
if (DBUS_TYPE_INVALID ==
dbus_message_iter_get_arg_type(&array_2_iter))
continue;

/* a{oa{...}} */
if (DBUS_TYPE_DICT_ENTRY !=
if (DBUS_TYPE_DICT_ENTRY !=
dbus_message_iter_get_arg_type(&array_2_iter))
return 1;
dbus_message_iter_recurse(&array_2_iter, &dict_2_iter);

/* a{oa{s...}} */
if (DBUS_TYPE_STRING !=
if (DBUS_TYPE_STRING !=
dbus_message_iter_get_arg_type(&dict_2_iter))
return 1;
dbus_message_iter_get_basic(&dict_2_iter, &interface_name);
Expand Down Expand Up @@ -327,14 +327,14 @@ static int read_scanned_devices (bluez_t *bluez, DBusMessage *reply)
do
{
/* a{...} */
if (DBUS_TYPE_DICT_ENTRY !=
if (DBUS_TYPE_DICT_ENTRY !=
dbus_message_iter_get_arg_type(&array_1_iter))
return 1;

dbus_message_iter_recurse(&array_1_iter, &dict_1_iter);

/* a{o...} */
if (DBUS_TYPE_OBJECT_PATH !=
if (DBUS_TYPE_OBJECT_PATH !=
dbus_message_iter_get_arg_type(&dict_1_iter))
return 1;

Expand All @@ -344,26 +344,26 @@ static int read_scanned_devices (bluez_t *bluez, DBusMessage *reply)
return 1;

/* a{oa} */
if (DBUS_TYPE_ARRAY !=
if (DBUS_TYPE_ARRAY !=
dbus_message_iter_get_arg_type(&dict_1_iter))
return 1;

dbus_message_iter_recurse(&dict_1_iter, &array_2_iter);
do
{
/* empty array? */
if (DBUS_TYPE_INVALID ==
if (DBUS_TYPE_INVALID ==
dbus_message_iter_get_arg_type(&array_2_iter))
continue;

/* a{oa{...}} */
if (DBUS_TYPE_DICT_ENTRY !=
if (DBUS_TYPE_DICT_ENTRY !=
dbus_message_iter_get_arg_type(&array_2_iter))
return 1;
dbus_message_iter_recurse(&array_2_iter, &dict_2_iter);

/* a{oa{s...}} */
if (DBUS_TYPE_STRING !=
if (DBUS_TYPE_STRING !=
dbus_message_iter_get_arg_type(&dict_2_iter))
return 1;
dbus_message_iter_get_basic(&dict_2_iter, &interface_name);
Expand All @@ -390,13 +390,13 @@ static int read_scanned_devices (bluez_t *bluez, DBusMessage *reply)
continue;

/* a{oa{sa{...}}} */
if (DBUS_TYPE_DICT_ENTRY !=
if (DBUS_TYPE_DICT_ENTRY !=
dbus_message_iter_get_arg_type(&array_3_iter))
return 1;
dbus_message_iter_recurse(&array_3_iter, &dict_3_iter);

/* a{oa{sa{s...}}} */
if (DBUS_TYPE_STRING !=
if (DBUS_TYPE_STRING !=
dbus_message_iter_get_arg_type(&dict_3_iter))
return 1;

Expand All @@ -406,7 +406,7 @@ static int read_scanned_devices (bluez_t *bluez, DBusMessage *reply)
if (!dbus_message_iter_next(&dict_3_iter))
return 1;
/* a{oa{sa{sv}}} */
if (DBUS_TYPE_VARIANT !=
if (DBUS_TYPE_VARIANT !=
dbus_message_iter_get_arg_type(&dict_3_iter))
return 1;

Expand Down Expand Up @@ -606,7 +606,9 @@ static bool bluez_connect_device(void *data, unsigned i)

static bool bluez_remove_device(void *data, unsigned i)
{
bluez_t *bluez = (bluez_t*)data;
const char *msg = NULL;
bluez_t *bluez = (bluez_t*)data;

bluez_dbus_connect(bluez);

/* Disconnect the device */
Expand All @@ -616,7 +618,9 @@ static bool bluez_remove_device(void *data, unsigned i)
if (device_method(bluez, bluez->devices->data[i].path, "RemoveDevice"))
return false;

runloop_msg_queue_push(msg_hash_to_str(MSG_BLUETOOTH_PAIRING_REMOVED),
msg = msg_hash_to_str(MSG_BLUETOOTH_PAIRING_REMOVED);

runloop_msg_queue_push(msg, strlen(msg),
1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT,
MESSAGE_QUEUE_CATEGORY_INFO);

Expand Down
Loading

0 comments on commit 18c85b5

Please sign in to comment.