From: Alvaro Silva Date: Mon, 24 Mar 2014 13:30:08 +0000 (-0300) Subject: tools: Add setting Value property of gatt-service X-Git-Tag: android-x86-4.4-r3~4541 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=4987c5bc20cf1ef1e77c015f6b607f04f40ee5ae;p=android-x86%2Fexternal-bluetooth-bluez.git tools: Add setting Value property of gatt-service This patch extends the gatt-service.c example adding a generic callback to allow set the characteristic Value. It doesn't check for characteristic properties yet. --- diff --git a/tools/gatt-service.c b/tools/gatt-service.c index a5a64b5e1..6ccaeb57d 100644 --- a/tools/gatt-service.c +++ b/tools/gatt-service.c @@ -35,6 +35,8 @@ #include #include +#include "src/error.h" + #define GATT_MGR_IFACE "org.bluez.GattManager1" #define GATT_SERVICE_IFACE "org.bluez.GattService1" #define GATT_CHR_IFACE "org.bluez.GattCharacteristic1" @@ -81,9 +83,38 @@ static gboolean chr_get_value(const GDBusPropertyTable *property, return TRUE; } +static void chr_set_value(const GDBusPropertyTable *property, + DBusMessageIter *iter, + GDBusPendingPropertySet id, void *user_data) +{ + struct characteristic *chr = user_data; + DBusMessageIter array; + uint8_t *value; + int len; + + printf("Set('Value', ...)\n"); + + if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY) { + printf("Invalid value for Set('Value'...)\n"); + g_dbus_pending_property_error(id, + ERROR_INTERFACE ".InvalidArguments", + "Invalid arguments in method call"); + return; + } + + dbus_message_iter_recurse(iter, &array); + dbus_message_iter_get_fixed_array(&array, &value, &len); + + g_free(chr->value); + chr->value = g_memdup(value, len); + chr->vlen = len; + + g_dbus_pending_property_success(id); +} + static const GDBusPropertyTable chr_properties[] = { { "UUID", "s", chr_get_uuid }, - { "Value", "ay", chr_get_value, NULL, NULL }, + { "Value", "ay", chr_get_value, chr_set_value, NULL }, { } };