Return-Path: From: Claudio Takahasi To: linux-bluetooth@vger.kernel.org Cc: claudio.takahasi@openbossa.org, Alvaro Silva Subject: [PATCH BlueZ v0 15/16] tools: Add setting Value property of gatt-service Date: Mon, 10 Mar 2014 15:50:44 -0300 Message-Id: <1394477445-8987-16-git-send-email-claudio.takahasi@openbossa.org> In-Reply-To: <1394477445-8987-1-git-send-email-claudio.takahasi@openbossa.org> References: <1394477445-8987-1-git-send-email-claudio.takahasi@openbossa.org> Sender: linux-bluetooth-owner@vger.kernel.org List-ID: From: Alvaro Silva 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. --- tools/gatt-service.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/tools/gatt-service.c b/tools/gatt-service.c index 25528ca..481495c 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 }, { } }; -- 1.8.3.1