aboutsummaryrefslogtreecommitdiffstats
path: root/attrib/client.c
diff options
context:
space:
mode:
authorVinicius Costa Gomes <vinicius.gomes@openbossa.org>2010-08-04 11:21:56 -0300
committerJohan Hedberg <johan.hedberg@nokia.com>2010-08-09 18:06:49 -0400
commitc606feeb48f9949083f8f9eb75356759f4018071 (patch)
tree72b033c78d1137f918cf8a4bf9750612790eae17 /attrib/client.c
parenta9a4e52bee4f35d67ee416009b561149519bbf56 (diff)
downloadbluez-c606feeb48f9949083f8f9eb75356759f4018071.tar.gz
bluez-c606feeb48f9949083f8f9eb75356759f4018071.tar.xz
bluez-c606feeb48f9949083f8f9eb75356759f4018071.zip
Add the GetCharacteristics() DBus method
This method allows the retrieval of every known information about the characteristics beloging to a Service.
Diffstat (limited to 'attrib/client.c')
-rw-r--r--attrib/client.c85
1 files changed, 65 insertions, 20 deletions
diff --git a/attrib/client.c b/attrib/client.c
index dd9dec65..422d30f7 100644
--- a/attrib/client.c
+++ b/attrib/client.c
@@ -115,10 +115,73 @@ static int gatt_path_cmp(const struct gatt_service *gatt, const char *path)
return strcmp(gatt->path, path);
}
+static void append_char_dict(DBusMessageIter *iter, struct characteristic *chr)
+{
+ DBusMessageIter dict;
+ const char *name = "";
+ char *uuid;
+
+ dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+ DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+ DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
+ DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+
+ uuid = bt_uuid2string(&chr->type);
+ dict_append_entry(&dict, "UUID", DBUS_TYPE_STRING, &uuid);
+ g_free(uuid);
+
+ /* FIXME: Translate UUID to name. */
+ dict_append_entry(&dict, "Name", DBUS_TYPE_STRING, &name);
+ dict_append_entry(&dict, "Description", DBUS_TYPE_STRING, &name);
+
+ /* FIXME: Missing Format, Value and Representation */
+
+ dbus_message_iter_close_container(iter, &dict);
+}
+
static DBusMessage *get_characteristics(DBusConnection *conn,
DBusMessage *msg, void *data)
{
- return dbus_message_new_method_return(msg);
+ struct primary *prim = data;
+ DBusMessage *reply;
+ DBusMessageIter iter, array;
+ GSList *l;
+
+ reply = dbus_message_new_method_return(msg);
+ if (reply == NULL)
+ return NULL;
+
+ dbus_message_iter_init_append(reply, &iter);
+
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+ DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+ DBUS_TYPE_OBJECT_PATH_AS_STRING
+ DBUS_TYPE_ARRAY_AS_STRING
+ DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+ DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
+ DBUS_DICT_ENTRY_END_CHAR_AS_STRING
+ DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &array);
+
+ for (l = prim->chars; l; l = l->next) {
+ struct characteristic *chr = l->data;
+ DBusMessageIter sub;
+
+ DBG("path %s", chr->path);
+
+ dbus_message_iter_open_container(&array, DBUS_TYPE_DICT_ENTRY,
+ NULL, &sub);
+
+ dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH,
+ &chr->path);
+
+ append_char_dict(&sub, chr);
+
+ dbus_message_iter_close_container(&array, &sub);
+ }
+
+ dbus_message_iter_close_container(&iter, &array);
+
+ return reply;
}
static DBusMessage *register_watcher(DBusConnection *conn,
@@ -148,9 +211,6 @@ static DBusMessage *get_properties(DBusConnection *conn,
struct characteristic *chr = data;
DBusMessage *reply;
DBusMessageIter iter;
- DBusMessageIter dict;
- const char *name = "";
- char *uuid;
reply = dbus_message_new_method_return(msg);
if (!reply)
@@ -158,22 +218,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
dbus_message_iter_init_append(reply, &iter);
- dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
- DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
- DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
- DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
-
- uuid = bt_uuid2string(&chr->type);
- dict_append_entry(&dict, "UUID", DBUS_TYPE_STRING, &uuid);
- g_free(uuid);
-
- /* FIXME: Translate UUID to name. */
- dict_append_entry(&dict, "Name", DBUS_TYPE_STRING, &name);
- dict_append_entry(&dict, "Description", DBUS_TYPE_STRING, &name);
-
- /* FIXME: Missing Format, Value and Representation */
-
- dbus_message_iter_close_container(&iter, &dict);
+ append_char_dict(&iter, chr);
return reply;
}