bluetooth: make uuid profile detection more generic

This commit is contained in:
Luiz Augusto von Dentz 2011-07-01 10:12:23 +03:00 committed by Denis Kenzior
parent 55f1c95ed1
commit c9714bd4b5
2 changed files with 19 additions and 16 deletions

View File

@ -226,9 +226,9 @@ done:
g_slist_free(prop_handlers); g_slist_free(prop_handlers);
} }
static void has_uuid(DBusMessageIter *array, gpointer user_data) static void parse_uuids(DBusMessageIter *array, gpointer user_data)
{ {
gboolean *profiles = user_data; GSList **uuids = user_data;
DBusMessageIter value; DBusMessageIter value;
if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY) if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
@ -241,8 +241,7 @@ static void has_uuid(DBusMessageIter *array, gpointer user_data)
dbus_message_iter_get_basic(&value, &uuid); dbus_message_iter_get_basic(&value, &uuid);
if (!strcasecmp(uuid, HFP_AG_UUID)) *uuids = g_slist_prepend(*uuids, (char *) uuid);
*profiles |= HFP_AG;
dbus_message_iter_next(&value); dbus_message_iter_next(&value);
} }
@ -262,14 +261,13 @@ static void parse_string(DBusMessageIter *iter, gpointer user_data)
static void device_properties_cb(DBusPendingCall *call, gpointer user_data) static void device_properties_cb(DBusPendingCall *call, gpointer user_data)
{ {
DBusMessage *reply; DBusMessage *reply;
int have_uuid = 0;
const char *path = user_data; const char *path = user_data;
const char *adapter = NULL; const char *adapter = NULL;
const char *adapter_addr = NULL; const char *adapter_addr = NULL;
const char *device_addr = NULL; const char *device_addr = NULL;
const char *alias = NULL; const char *alias = NULL;
struct bluetooth_profile *profile;
struct DBusError derr; struct DBusError derr;
GSList *uuids = NULL;
reply = dbus_pending_call_steal_reply(call); reply = dbus_pending_call_steal_reply(call);
@ -284,7 +282,7 @@ static void device_properties_cb(DBusPendingCall *call, gpointer user_data)
DBG(""); DBG("");
bluetooth_parse_properties(reply, "UUIDs", has_uuid, &have_uuid, bluetooth_parse_properties(reply, "UUIDs", parse_uuids, &uuids,
"Adapter", parse_string, &adapter, "Adapter", parse_string, &adapter,
"Address", parse_string, &device_addr, "Address", parse_string, &device_addr,
"Alias", parse_string, &alias, NULL); "Alias", parse_string, &alias, NULL);
@ -293,15 +291,22 @@ static void device_properties_cb(DBusPendingCall *call, gpointer user_data)
adapter_addr = g_hash_table_lookup(adapter_address_hash, adapter_addr = g_hash_table_lookup(adapter_address_hash,
adapter); adapter);
if ((have_uuid & HFP_AG) && device_addr && adapter_addr) { if (!device_addr && !adapter_addr)
profile = g_hash_table_lookup(uuid_hash, HFP_AG_UUID); goto done;
for (; uuids; uuids = uuids->next) {
struct bluetooth_profile *profile;
const char *uuid = uuids->data;
profile = g_hash_table_lookup(uuid_hash, uuid);
if (profile == NULL || profile->create == NULL) if (profile == NULL || profile->create == NULL)
goto done; continue;
profile->create(path, device_addr, adapter_addr, alias); profile->create(path, device_addr, adapter_addr, alias);
} }
done: done:
g_slist_free(uuids);
dbus_message_unref(reply); dbus_message_unref(reply);
} }
@ -342,7 +347,7 @@ static gboolean property_changed(DBusConnection *connection, DBusMessage *msg,
dbus_message_iter_get_basic(&iter, &property); dbus_message_iter_get_basic(&iter, &property);
if (g_str_equal(property, "UUIDs") == TRUE) { if (g_str_equal(property, "UUIDs") == TRUE) {
int profiles = 0; GSList *uuids = NULL;
const char *path = dbus_message_get_path(msg); const char *path = dbus_message_get_path(msg);
DBusMessageIter variant; DBusMessageIter variant;
@ -354,13 +359,13 @@ static gboolean property_changed(DBusConnection *connection, DBusMessage *msg,
dbus_message_iter_recurse(&iter, &variant); dbus_message_iter_recurse(&iter, &variant);
has_uuid(&variant, &profiles); parse_uuids(&variant, &uuids);
/* We need the full set of properties to be able to create /* We need the full set of properties to be able to create
* the modem properly, including Adapter and Alias, so * the modem properly, including Adapter and Alias, so
* refetch everything again * refetch everything again
*/ */
if (profiles) if (uuids)
bluetooth_send_with_reply(path, BLUEZ_DEVICE_INTERFACE, bluetooth_send_with_reply(path, BLUEZ_DEVICE_INTERFACE,
"GetProperties", device_properties_cb, "GetProperties", device_properties_cb,
g_strdup(path), g_free, -1, g_strdup(path), g_free, -1,

View File

@ -28,9 +28,7 @@
#define DBUS_TIMEOUT 15 #define DBUS_TIMEOUT 15
#define HFP_AG_UUID "0000111f-0000-1000-8000-00805f9b34fb" #define HFP_AG_UUID "0000111f-0000-1000-8000-00805f9b34fb"
#define HFP_HS_UUID "0000111e-0000-1000-8000-00805f9b34fb"
/* Profiles bitfield */
#define HFP_AG 0x01
struct bluetooth_profile { struct bluetooth_profile {
const char *name; const char *name;