[gnome-bluetooth/wip/hadess/lib-changes] lib: Add bluetooth_device_to_string() function
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-bluetooth/wip/hadess/lib-changes] lib: Add bluetooth_device_to_string() function
- Date: Thu, 25 Nov 2021 17:20:33 +0000 (UTC)
commit 11f790c0737e2de528b9c629c4e7a2b26b777e51
Author: Bastien Nocera <hadess hadess net>
Date: Thu Nov 25 10:53:48 2021 +0100
lib: Add bluetooth_device_to_string() function
Will help with creating test applications.
lib/bluetooth-device.c | 37 ++++++++++++++++++++++++++-----------
lib/bluetooth-device.h | 1 +
lib/gnome-bluetooth.map | 1 +
3 files changed, 28 insertions(+), 11 deletions(-)
---
diff --git a/lib/bluetooth-device.c b/lib/bluetooth-device.c
index cb18de19..a80be225 100644
--- a/lib/bluetooth-device.c
+++ b/lib/bluetooth-device.c
@@ -219,21 +219,36 @@ bluetooth_device_get_object_path (BluetoothDevice *device)
#define BOOL_STR(x) (x ? "True" : "False")
-void
-bluetooth_device_dump (BluetoothDevice *device)
+char *
+bluetooth_device_to_string (BluetoothDevice *device)
{
- g_return_if_fail (BLUETOOTH_IS_DEVICE (device));
+ GString *str;
+
+ g_return_val_if_fail (BLUETOOTH_IS_DEVICE (device), NULL);
+
+ str = g_string_new (NULL);
- g_print ("Device: %s (%s)\n", device->alias, device->address);
- g_print ("\tD-Bus Path: %s\n", device->proxy ? g_dbus_proxy_get_object_path (device->proxy) :
"(none)");
- g_print ("\tType: %s Icon: %s\n", bluetooth_type_to_string (device->type), device->icon);
- g_print ("\tPaired: %s Trusted: %s Connected: %s\n", BOOL_STR(device->paired),
BOOL_STR(device->trusted), BOOL_STR(device->connected));
+ g_string_append_printf (str, "Device: %s (%s)\n", device->alias, device->address);
+ g_string_append_printf (str, "\tD-Bus Path: %s\n", device->proxy ? g_dbus_proxy_get_object_path
(device->proxy) : "(none)");
+ g_string_append_printf (str, "\tType: %s Icon: %s\n", bluetooth_type_to_string (device->type),
device->icon);
+ g_string_append_printf (str, "\tPaired: %s Trusted: %s Connected: %s\n", BOOL_STR(device->paired),
BOOL_STR(device->trusted), BOOL_STR(device->connected));
if (device->uuids != NULL) {
guint i;
- g_print ("\tUUIDs: ");
+ g_string_append_printf (str, "\tUUIDs: ");
for (i = 0; device->uuids[i] != NULL; i++)
- g_print ("%s ", device->uuids[i]);
- g_print ("\n");
+ g_string_append_printf (str, "%s ", device->uuids[i]);
}
- g_print ("\n");
+
+ return g_string_free (str, FALSE);
+}
+
+void
+bluetooth_device_dump (BluetoothDevice *device)
+{
+ g_autofree char *str = NULL;
+
+ g_return_if_fail (BLUETOOTH_IS_DEVICE (device));
+
+ str = bluetooth_device_to_string (device);
+ g_print ("%s\n", str);
}
diff --git a/lib/bluetooth-device.h b/lib/bluetooth-device.h
index 48a86ecc..bef2f39e 100644
--- a/lib/bluetooth-device.h
+++ b/lib/bluetooth-device.h
@@ -15,3 +15,4 @@ G_DECLARE_FINAL_TYPE (BluetoothDevice, bluetooth_device, BLUETOOTH, DEVICE, GObj
const char *bluetooth_device_get_object_path (BluetoothDevice *device);
void bluetooth_device_dump (BluetoothDevice *device);
+char *bluetooth_device_to_string (BluetoothDevice *device);
diff --git a/lib/gnome-bluetooth.map b/lib/gnome-bluetooth.map
index 881e623c..d5cfc7fe 100644
--- a/lib/gnome-bluetooth.map
+++ b/lib/gnome-bluetooth.map
@@ -24,6 +24,7 @@ global:
bluetooth_device_get_type;
bluetooth_device_dump;
bluetooth_device_get_object_path;
+ bluetooth_device_to_string;
bluetooth_agent_get_type;
bluetooth_agent_error_get_type;
bluetooth_agent_new;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]