* [PATCH] Report local services(UUIDs) through DBus
@ 2010-03-24 20:26 Francisco Alecrim
2010-03-24 21:53 ` Johan Hedberg
0 siblings, 1 reply; 2+ messages in thread
From: Francisco Alecrim @ 2010-03-24 20:26 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Francisco Alecrim
Include UUIDs field to method GetProperties(org.bluez.Adapter).
Applications can get local services(UUIDs) available through DBus.
---
doc/adapter-api.txt | 5 +++++
src/adapter.c | 20 +++++++++++++++++++-
src/sdpd-database.c | 21 +++++++++++++++++++++
src/sdpd.h | 1 +
test/list-devices | 3 +++
5 files changed, 49 insertions(+), 1 deletions(-)
diff --git a/doc/adapter-api.txt b/doc/adapter-api.txt
index 48cab40..6098c76 100644
--- a/doc/adapter-api.txt
+++ b/doc/adapter-api.txt
@@ -270,3 +270,8 @@ Properties string Address [readonly]
array{object} Devices [readonly]
List of device object paths.
+
+ array{string} UUIDs [readonly]
+
+ List of 128-bit UUIDs that represents the available
+ local services.
diff --git a/src/adapter.c b/src/adapter.c
index 5fd0736..2027484 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -37,6 +37,7 @@
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
#include <bluetooth/sdp.h>
+#include <bluetooth/sdp_lib.h>
#include <glib.h>
#include <dbus/dbus.h>
@@ -1196,7 +1197,8 @@ static DBusMessage *get_properties(DBusConnection *conn,
DBusMessageIter dict;
char str[MAX_NAME_LENGTH + 1], srcaddr[18];
gboolean value;
- char **devices;
+ char **devices, **uuids;
+ sdp_list_t *list, *lfree;
int i;
GSList *l;
@@ -1270,6 +1272,22 @@ static DBusMessage *get_properties(DBusConnection *conn,
&devices, i);
g_free(devices);
+ /* UUIDs */
+ list = sdp_get_record_list_by_device(&adapter->bdaddr);
+ lfree = list; /* keep head to prevent leak */
+ uuids = g_new0(char *, sdp_list_len(list) + 1);
+
+ for (i = 0; list; list = list->next, i++) {
+ sdp_record_t *rec = list->data;
+ uuids[i] = bt_uuid2string(&rec->svclass);
+ }
+ dict_append_array(&dict, "UUIDs", DBUS_TYPE_STRING, &uuids, i);
+
+ sdp_list_free(lfree, NULL);
+ for (i = 0; uuids[i]; i++)
+ g_free(uuids[i]);
+ g_free(uuids);
+
dbus_message_iter_close_container(&iter, &dict);
return reply;
diff --git a/src/sdpd-database.c b/src/sdpd-database.c
index 07a0bc3..b07aa97 100644
--- a/src/sdpd-database.c
+++ b/src/sdpd-database.c
@@ -273,6 +273,27 @@ sdp_list_t *sdp_get_access_list(void)
return access_db;
}
+sdp_list_t *sdp_get_record_list_by_device(const bdaddr_t *device)
+{
+ sdp_list_t *list, *acc;
+
+ acc = access_db;
+ list = NULL;
+ for (; acc; acc = acc->next) {
+ sdp_access_t *a = acc->data;
+ sdp_record_t *rec = sdp_record_find(a->handle);
+ if (!rec)
+ continue;
+
+ if (bacmp(&a->device, device) == 0 ||
+ bacmp(&a->device, BDADDR_ANY) == 0)
+
+ list = sdp_list_append(list, rec);
+ }
+
+ return list;
+}
+
int sdp_check_access(uint32_t handle, bdaddr_t *device)
{
sdp_list_t *p = access_locate(handle);
diff --git a/src/sdpd.h b/src/sdpd.h
index 1352a83..15e163b 100644
--- a/src/sdpd.h
+++ b/src/sdpd.h
@@ -79,6 +79,7 @@ void sdp_record_add(const bdaddr_t *device, sdp_record_t *rec);
int sdp_record_remove(uint32_t handle);
sdp_list_t *sdp_get_record_list(void);
sdp_list_t *sdp_get_access_list(void);
+sdp_list_t *sdp_get_record_list_by_device(const bdaddr_t *device);
int sdp_check_access(uint32_t handle, bdaddr_t *device);
uint32_t sdp_next_handle(void);
diff --git a/test/list-devices b/test/list-devices
index 511d0cf..9120714 100755
--- a/test/list-devices
+++ b/test/list-devices
@@ -40,6 +40,9 @@ for i in adapter_list:
if (key == "Devices"):
list = extract_objects(value)
print " %s = %s" % (key, list)
+ elif (key == "UUIDs"):
+ list = extract_uuids(value)
+ print " %s = %s" % (key, list)
else:
print " %s = %s" % (key, value)
--
1.6.3.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Report local services(UUIDs) through DBus
2010-03-24 20:26 [PATCH] Report local services(UUIDs) through DBus Francisco Alecrim
@ 2010-03-24 21:53 ` Johan Hedberg
0 siblings, 0 replies; 2+ messages in thread
From: Johan Hedberg @ 2010-03-24 21:53 UTC (permalink / raw)
To: Francisco Alecrim; +Cc: linux-bluetooth
Hi,
On Wed, Mar 24, 2010, Francisco Alecrim wrote:
> Include UUIDs field to method GetProperties(org.bluez.Adapter).
> Applications can get local services(UUIDs) available through DBus.
> ---
> doc/adapter-api.txt | 5 +++++
> src/adapter.c | 20 +++++++++++++++++++-
> src/sdpd-database.c | 21 +++++++++++++++++++++
> src/sdpd.h | 1 +
> test/list-devices | 3 +++
> 5 files changed, 49 insertions(+), 1 deletions(-)
Thanks for the patch! It looks quite nice and clean :)
However, since it doesn't implement the PropertyChanged signals for the
new property I'll wait until Marcel gets the next release out the door
before pushing this one upstream (so we don't get a new BlueZ release
with a partially implemented API)
Johan
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-03-24 21:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-24 20:26 [PATCH] Report local services(UUIDs) through DBus Francisco Alecrim
2010-03-24 21:53 ` Johan Hedberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).