public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: 294305068@qq.com
To: linux-bluetooth@vger.kernel.org
Cc: caitao <caitao@kylinos.cn>
Subject: [PATCH BlueZ] src/device: Add ConnectedUUIDs property
Date: Fri, 10 Apr 2026 16:59:01 +0800	[thread overview]
Message-ID: <tencent_8CF6DCCE00806DF68DB0363D6A1E68340707@qq.com> (raw)

From: caitao <caitao@kylinos.cn>

Add a new D-Bus property "ConnectedUUIDs" (array of strings, read-only)
to the org.bluez.Device interface. This property tracks the UUIDs of
profiles that are currently connected on the device.

The property is updated dynamically when a service state changes to
CONNECTED or DISCONNECTED.
---
 doc/org.bluez.Device.rst |  5 +++
 src/device.c             | 72 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+)

diff --git a/doc/org.bluez.Device.rst b/doc/org.bluez.Device.rst
index 3e6a30aaf..c592afbd5 100644
--- a/doc/org.bluez.Device.rst
+++ b/doc/org.bluez.Device.rst
@@ -284,6 +284,11 @@ array{string} UUIDs [readonly, optional]
 
 List of 128-bit UUIDs that represents the available remote services.
 
+array{string} ConnectedUUIDs [readonly]
+````````````````````````````````````````
+
+List of 128-bit UUIDs of profiles currently connected.
+
 boolean Paired [readonly]
 `````````````````````````
 
diff --git a/src/device.c b/src/device.c
index bb5bcd4f0..3bb244b98 100644
--- a/src/device.c
+++ b/src/device.c
@@ -244,6 +244,7 @@ struct btd_device {
 	char		*modalias;
 	struct btd_adapter	*adapter;
 	GSList		*uuids;
+	GSList		*connected_uuids;	/* Currently connected UUIDs */
 	GSList		*primaries;		/* List of primary services */
 	GSList		*services;		/* List of btd_service */
 	GSList		*pending;		/* Pending services */
@@ -910,6 +911,7 @@ static void device_free(gpointer user_data)
 	device->client_dbus = NULL;
 
 	g_slist_free_full(device->uuids, g_free);
+	g_slist_free_full(device->connected_uuids, g_free);
 	g_slist_free_full(device->primaries, g_free);
 	g_slist_free_full(device->svc_callbacks, svc_dev_remove);
 
@@ -1464,6 +1466,70 @@ static gboolean dev_property_get_uuids(const GDBusPropertyTable *property,
 	return TRUE;
 }
 
+static GSList *device_get_connected_uuids(struct btd_device *device)
+{
+	return device->connected_uuids;
+}
+
+static gboolean property_get_connected_uuids(const GDBusPropertyTable *property,
+						DBusMessageIter *iter,
+						void *data)
+{
+	struct btd_device *device = data;
+	GSList *l, *uuids = device_get_connected_uuids(device);
+	DBusMessageIter array_iter;
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+					 DBUS_TYPE_STRING_AS_STRING,
+					 &array_iter);
+
+	for (l = uuids; l; l = g_slist_next(l)) {
+		const char *uuid = l->data;
+		dbus_message_iter_append_basic(&array_iter,
+					       DBUS_TYPE_STRING,
+					       &uuid);
+	}
+
+	dbus_message_iter_close_container(iter, &array_iter);
+	return TRUE;
+}
+
+static void device_add_connected_uuid(struct btd_device *device, const char *uuid)
+{
+	if (!device || !uuid)
+		return;
+
+	if (g_slist_find_custom(device->connected_uuids, uuid,
+				(GCompareFunc)strcmp))
+		return;
+
+	device->connected_uuids = g_slist_append(device->connected_uuids,
+						 g_strdup(uuid));
+
+	g_dbus_emit_property_changed(dbus_conn, device->path,
+				     DEVICE_INTERFACE, "ConnectedUUIDs");
+}
+
+static void device_remove_connected_uuid(struct btd_device *device, const char *uuid)
+{
+	GSList *match;
+
+	if (!device || !uuid)
+		return;
+
+	match = g_slist_find_custom(device->connected_uuids, uuid,
+				    (GCompareFunc)strcmp);
+	if (!match)
+		return;
+
+	g_free(match->data);
+	device->connected_uuids = g_slist_delete_link(device->connected_uuids,
+						      match);
+
+	g_dbus_emit_property_changed(dbus_conn, device->path,
+				     DEVICE_INTERFACE, "ConnectedUUIDs");
+}
+
 static gboolean dev_property_get_modalias(const GDBusPropertyTable *property,
 					DBusMessageIter *iter, void *data)
 {
@@ -3715,6 +3781,7 @@ static const GDBusPropertyTable device_properties[] = {
 	{ "RSSI", "n", dev_property_get_rssi, NULL, dev_property_exists_rssi },
 	{ "Connected", "b", dev_property_get_connected },
 	{ "UUIDs", "as", dev_property_get_uuids },
+	{ "ConnectedUUIDs", "as", property_get_connected_uuids },
 	{ "Modalias", "s", dev_property_get_modalias, NULL,
 						dev_property_exists_modalias },
 	{ "Adapter", "o", dev_property_get_adapter },
@@ -8231,6 +8298,11 @@ static void service_state_changed(struct btd_service *service,
 		device_profile_connected(device, profile, err);
 	else if (old_state == BTD_SERVICE_STATE_DISCONNECTING)
 		device_profile_disconnected(device, profile, err);
+
+	if (new_state == BTD_SERVICE_STATE_CONNECTED)
+		device_add_connected_uuid(device, profile->remote_uuid);
+	else if (new_state == BTD_SERVICE_STATE_DISCONNECTED)
+		device_remove_connected_uuid(device, profile->remote_uuid);
 }
 
 struct btd_service *btd_device_get_service(struct btd_device *dev,
-- 
2.43.0


             reply	other threads:[~2026-04-10  8:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-10  8:59 294305068 [this message]
2026-04-10 10:51 ` [BlueZ] src/device: Add ConnectedUUIDs property bluez.test.bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_8CF6DCCE00806DF68DB0363D6A1E68340707@qq.com \
    --to=294305068@qq.com \
    --cc=caitao@kylinos.cn \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox