GATT-Client: Modify Read and Write procedure as per Bluez 5.43 76/121676/3 accepted/tizen_common accepted/tizen_ivi accepted/tizen_mobile accepted/tizen_tv accepted/tizen_wearable accepted/tizen/common/20170330.151723 accepted/tizen/ivi/20170330.223802 accepted/tizen/mobile/20170330.223703 accepted/tizen/tv/20170330.223733 accepted/tizen/unified/20170330.223828 accepted/tizen/wearable/20170330.223746 submit/tizen/20170330.042352
authorh.sandeep <h.sandeep@samsung.com>
Fri, 17 Mar 2017 09:31:55 +0000 (15:01 +0530)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Thu, 30 Mar 2017 00:15:53 +0000 (09:15 +0900)
Change-Id: I6b3967fae826dcf9cad32657611c0c7b8f3c482c
Signed-off-by: h.sandeep <h.sandeep@samsung.com>
bt-api/bt-gatt-client.c

index 71e85c546fc6c7d8dd029a0694a81525974b717c..9e0f92ad21cdc8fa160c48061d9695cc760ccb87 100644 (file)
@@ -939,6 +939,8 @@ BT_EXPORT_API int bluetooth_gatt_read_characteristic_value(const char *character
 {
        GDBusConnection *conn;
        char *handle;
+       GVariantBuilder *builder = NULL;
+       guint16 offset = 0;
 
        BT_CHECK_PARAMETER(characteristic, return);
        BT_CHECK_ENABLED(return);
@@ -948,18 +950,29 @@ BT_EXPORT_API int bluetooth_gatt_read_characteristic_value(const char *character
 
        handle = g_strdup(characteristic);
 
+       builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+
+       /*offset*/
+       g_variant_builder_add(builder, "{sv}", "offset",
+               g_variant_new("q", offset));
+
+       /* Device Object path*/
+//  g_variant_builder_add(builder, "{sv}", "device",
+//  g_variant_new_object("o", NULL));
+
        g_dbus_connection_call(conn,
                        BT_BLUEZ_NAME,
                        characteristic,
                        GATT_CHAR_INTERFACE,
                        "ReadValue",
-                       NULL,
+                       g_variant_new("(a{sv})", builder),
                        G_VARIANT_TYPE("(ay)"),
                        G_DBUS_CALL_FLAGS_NONE,
                        -1,
                        NULL,
                        (GAsyncReadyCallback)__bluetooth_internal_read_cb,
                        (gpointer)handle);
+       g_variant_builder_unref(builder);
 
        return BLUETOOTH_ERROR_NONE;
 }
@@ -967,11 +980,13 @@ BT_EXPORT_API int bluetooth_gatt_read_characteristic_value(const char *character
 BT_EXPORT_API int bluetooth_gatt_set_characteristics_value(
                const char *char_handle, const guint8 *value, int length)
 {
-       GVariant *val;
-       GVariantBuilder *builder;
+       GVariant *val, *options;
+       GVariantBuilder *builder1;
+       GVariantBuilder *builder2;
        GError *error = NULL;
        GDBusConnection *conn;
        int i = 0;
+       guint16 offset = 0;
 
        BT_DBG("+");
        BT_CHECK_PARAMETER(char_handle, return);
@@ -982,19 +997,29 @@ BT_EXPORT_API int bluetooth_gatt_set_characteristics_value(
        conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
-
+       builder1 = g_variant_builder_new(G_VARIANT_TYPE("ay"));
        for (i = 0; i < length; i++)
-               g_variant_builder_add(builder, "y", value[i]);
+               g_variant_builder_add(builder1, "y", value[i]);
+
+       val = g_variant_new("ay", builder1);
+
+       builder2 = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+       /*offset*/
+       g_variant_builder_add(builder2, "{sv}", "offset",
+                               g_variant_new_uint16(offset));
 
-       val = g_variant_new("(ay)", builder);
+       /* Device Object path*/
+//  g_variant_builder_add(builder2, "{sv}", "device",
+//  g_variant_new_object("o", NULL));
+
+       options = g_variant_new("a{sv}", builder2);
 
        g_dbus_connection_call_sync(conn,
                        BT_BLUEZ_NAME,
                        char_handle,
                        GATT_CHAR_INTERFACE,
                        "WriteValue",
-                       val,
+                       g_variant_new("(@ay@a{sv})", val, options),
                        NULL,
                        G_DBUS_CALL_FLAGS_NONE,
                        -1, NULL, &error);
@@ -1002,11 +1027,11 @@ BT_EXPORT_API int bluetooth_gatt_set_characteristics_value(
        if (error) {
                BT_ERR("Set value Failed: %s", error->message);
                g_clear_error(&error);
-               g_variant_builder_unref(builder);
+               g_variant_builder_unref(builder1);
                return BLUETOOTH_ERROR_INTERNAL;
        }
-
-       g_variant_builder_unref(builder);
+       g_variant_builder_unref(builder1);
+       g_variant_builder_unref(builder2);
 
        BT_DBG("-");
        return BLUETOOTH_ERROR_NONE;
@@ -1057,9 +1082,11 @@ static void __bluetooth_internal_write_cb(GObject *source_object,
 BT_EXPORT_API int bluetooth_gatt_set_characteristics_value_by_type(
                const char *char_handle, const guint8 *value, int length, guint8 write_type)
 {
-       GVariant *val;
-       GVariantBuilder *builder;
+       GVariant *val, *options;
+       GVariantBuilder *builder1;
+       GVariantBuilder *builder2;
        GDBusConnection *conn;
+       guint16 offset = 0;
        int i = 0;
        int ret = BLUETOOTH_ERROR_NONE;
 
@@ -1071,34 +1098,50 @@ BT_EXPORT_API int bluetooth_gatt_set_characteristics_value_by_type(
        conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
+       builder1 = g_variant_builder_new(G_VARIANT_TYPE("ay"));
 
        for (i = 0; i < length; i++)
-               g_variant_builder_add(builder, "y", value[i]);
+               g_variant_builder_add(builder1, "y", value[i]);
+
+       val = g_variant_new("ay", builder1);
+
+       builder2 = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+       /*offset*/
+       g_variant_builder_add(builder2, "{sv}", "offset",
+                       g_variant_new_uint16(offset));
+
+       /* Device Object path*/
+//  g_variant_builder_add(builder2, "{sv}", "device",
+//  g_variant_new_object("o", NULL));
+
+       options = g_variant_new("a{sv}", builder2);
 
-       val = g_variant_new("ay", builder);
        g_dbus_connection_call(conn,
                        BT_BLUEZ_NAME,
                        char_handle,
                        GATT_CHAR_INTERFACE,
                        "WriteValuebyType",
-                       g_variant_new("(y@ay)", write_type, val),
+                       g_variant_new("(y@ay@a{sv})",
+                       write_type, val, options),
                        G_VARIANT_TYPE("(y)"),
                        G_DBUS_CALL_FLAGS_NONE,
                        -1, NULL,
                        (GAsyncReadyCallback)__bluetooth_internal_write_cb,
                        NULL);
 
-       g_variant_builder_unref(builder);
+       g_variant_builder_unref(builder1);
+       g_variant_builder_unref(builder2);
        return ret;
 }
 
 BT_EXPORT_API int bluetooth_gatt_set_characteristics_value_request(
                        const char *char_handle, const guint8 *value, int length)
 {
-       GVariant *val;
+       GVariant *val, *options;
        GDBusConnection *conn;
-       GVariantBuilder *builder;
+       GVariantBuilder *builder1;
+       GVariantBuilder *builder2;
+       guint offset = 0;
        int i;
 
        BT_DBG("+");
@@ -1110,28 +1153,41 @@ BT_EXPORT_API int bluetooth_gatt_set_characteristics_value_request(
        conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
+       builder1 = g_variant_builder_new(G_VARIANT_TYPE("ay"));
 
        for (i = 0; i < length; i++) {
-               g_variant_builder_add(builder, "y", value[i]);
+               g_variant_builder_add(builder1, "y", value[i]);
                BT_DBG("value [] = %d", value[i]);
        }
 
-       val = g_variant_new("(ay)", builder);
+       val = g_variant_new("ay", builder1);
+
+       builder2 = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+       /*offset*/
+       g_variant_builder_add(builder2, "{sv}", "offset",
+                               g_variant_new_uint16(offset));
+
+       /* Device Object path*/
+//  g_variant_builder_add(builder2, "{sv}", "device",
+//  g_variant_new_object("o", NULL));
+
+       options = g_variant_new("a{sv}", builder2);
 
        g_dbus_connection_call(conn,
                                BT_BLUEZ_NAME,
                                char_handle,
                                GATT_CHAR_INTERFACE,
                                "WriteValue",
-                               val,
+                               g_variant_new("(@ay@a{sv})",
+                               val, options),
                                NULL,
                                G_DBUS_CALL_FLAGS_NONE,
                                -1, NULL,
                                (GAsyncReadyCallback)__bluetooth_internal_write_cb,
                                NULL);
 
-       g_variant_builder_unref(builder);
+       g_variant_builder_unref(builder1);
+       g_variant_builder_unref(builder2);
 
        BT_DBG("-");
        return BLUETOOTH_ERROR_NONE;
@@ -1403,6 +1459,8 @@ static void __bluetooth_internal_read_desc_cb(GObject *source_object,
 BT_EXPORT_API int bluetooth_gatt_read_descriptor_value(const char *char_descriptor)
 {
        GDBusConnection *conn;
+       GVariantBuilder *builder;
+       guint offset = 0;
        char *handle;
 
        BT_DBG("+");
@@ -1414,18 +1472,28 @@ BT_EXPORT_API int bluetooth_gatt_read_descriptor_value(const char *char_descript
 
        handle = g_strdup(char_descriptor);
 
+       builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+
+       /*offset*/
+       g_variant_builder_add(builder, "{sv}", "offset",
+                               g_variant_new("q", offset));
+       /* Device Object path*/
+//  g_variant_builder_add(builder, "{sv}", "device",
+//  g_variant_new("o", serv_info->serv_path));
+
        g_dbus_connection_call(conn,
                        BT_BLUEZ_NAME,
                        char_descriptor,
                        GATT_DESC_INTERFACE,
                        "ReadValue",
-                       NULL,
+                       g_variant_new("(a{sv})", builder),
                        G_VARIANT_TYPE("(ay)"),
                        G_DBUS_CALL_FLAGS_NONE,
                        -1,
                        NULL,
                        (GAsyncReadyCallback)__bluetooth_internal_read_desc_cb,
                        (gpointer)handle);
+       g_variant_builder_unref(builder);
 
        BT_DBG("-");
        return BLUETOOTH_ERROR_NONE;
@@ -1475,9 +1543,11 @@ static void __bluetooth_internal_write_desc_cb(GObject *source_object,
 BT_EXPORT_API int bluetooth_gatt_write_descriptor_value(
                        const char *desc_handle, const guint8 *value, int length)
 {
-       GVariant *val;
+       GVariant *val, *options;
        GDBusConnection *conn;
-       GVariantBuilder *builder;
+       GVariantBuilder *builder1;
+       GVariantBuilder *builder2;
+       guint offset = 0;
        int i;
 
        BT_DBG("+");
@@ -1489,26 +1559,39 @@ BT_EXPORT_API int bluetooth_gatt_write_descriptor_value(
        conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
+       builder1 = g_variant_builder_new(G_VARIANT_TYPE("ay"));
 
        for (i = 0; i < length; i++)
-               g_variant_builder_add(builder, "y", value[i]);
+               g_variant_builder_add(builder1, "y", value[i]);
 
-       val = g_variant_new("(ay)", builder);
+       val = g_variant_new("ay", builder1);
+
+       builder2 = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+       /*offset*/
+       g_variant_builder_add(builder2, "{sv}", "offset",
+                               g_variant_new_uint16(offset));
+
+       /* Device Object path*/
+//  g_variant_builder_add(builder2, "{sv}", "device",
+//  g_variant_new_object("o", NULL));
+
+       options = g_variant_new("a{sv}", builder2);
 
        g_dbus_connection_call(conn,
                                BT_BLUEZ_NAME,
                                desc_handle,
                                GATT_DESC_INTERFACE,
                                "WriteValue",
-                               val,
+                               g_variant_new("(@ay@a{sv})",
+                               val, options),
                                G_VARIANT_TYPE("(y)"),
                                G_DBUS_CALL_FLAGS_NONE,
                                -1, NULL,
                                (GAsyncReadyCallback)__bluetooth_internal_write_desc_cb,
                                NULL);
 
-       g_variant_builder_unref(builder);
+       g_variant_builder_unref(builder1);
+       g_variant_builder_unref(builder2);
 
        BT_DBG("-");
        return BLUETOOTH_ERROR_NONE;