gatt-client: Add read-only handles to dbus
authorSimon Mikuda <simon.mikuda@streamunlimited.com>
Fri, 28 Jul 2023 04:49:44 +0000 (06:49 +0200)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 5 Jan 2024 13:34:03 +0000 (19:04 +0530)
This can be usefull when mapping names for services and characteristics
to their handle numbers.

doc/gatt-api.txt
src/gatt-client.c

index 4e37ed6..93fa2e3 100755 (executable)
@@ -61,6 +61,7 @@ Properties    string UUID [read-only]
                        services of this service.
 
                uint16 Handle [read-write, optional] (Server Only)
+                             [read-only] (Client Only)
 
                        Service handle. When available in the server it
                        would attempt to use to allocate into the database
@@ -301,6 +302,7 @@ Properties  string UUID [read-only]
                                "authorize"
 
                uint16 Handle [read-write, optional] (Server Only)
+                             [read-only] (Client Only)
 
                        Characteristic handle. When available in the server it
                        would attempt to use to allocate into the database
@@ -401,6 +403,7 @@ Properties  string UUID [read-only]
                                "authorize"
 
                uint16 Handle [read-write, optional] (Server Only)
+                             [read-only] (Client Only)
 
                        Characteristic handle. When available in the server it
                        would attempt to use to allocate into the database
index 5d3f0dd..2eaf519 100644 (file)
@@ -144,6 +144,17 @@ static bool uuid_cmp(const bt_uuid_t *uuid, uint16_t u16)
        return bt_uuid_cmp(uuid, &uuid16) == 0;
 }
 
+static gboolean descriptor_get_handle(const GDBusPropertyTable *property,
+                                       DBusMessageIter *iter, void *data)
+{
+       struct service *desc = data;
+       uint16_t handle = desc->start_handle;
+
+       dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16, &handle);
+
+       return TRUE;
+}
+
 static gboolean descriptor_get_uuid(const GDBusPropertyTable *property,
                                        DBusMessageIter *iter, void *data)
 {
@@ -691,6 +702,7 @@ static DBusMessage *descriptor_write_value(DBusConnection *conn,
 }
 
 static const GDBusPropertyTable descriptor_properties[] = {
+       { "Handle", "q", descriptor_get_handle },
        { "UUID", "s", descriptor_get_uuid },
        { "Characteristic", "o", descriptor_get_characteristic, },
        { "Value", "ay", descriptor_get_value, NULL, descriptor_value_exists },
@@ -769,6 +781,17 @@ static void unregister_descriptor(void *data)
                                                        GATT_DESCRIPTOR_IFACE);
 }
 
+static gboolean characteristic_get_handle(const GDBusPropertyTable *property,
+                                       DBusMessageIter *iter, void *data)
+{
+       struct characteristic *chrc = data;
+       uint16_t handle = chrc->handle;
+
+       dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16, &handle);
+
+       return TRUE;
+}
+
 static gboolean characteristic_get_uuid(const GDBusPropertyTable *property,
                                        DBusMessageIter *iter, void *data)
 {
@@ -1872,6 +1895,7 @@ static gboolean characteristic_get_descriptors(
 #endif
 
 static const GDBusPropertyTable characteristic_properties[] = {
+       { "Handle", "q", characteristic_get_handle },
        { "UUID", "s", characteristic_get_uuid, NULL, NULL },
        { "Service", "o", characteristic_get_service, NULL, NULL },
        { "Value", "ay", characteristic_get_value, NULL,
@@ -2079,6 +2103,17 @@ static void unregister_characteristic(void *data)
                                                GATT_CHARACTERISTIC_IFACE);
 }
 
+static gboolean service_get_handle(const GDBusPropertyTable *property,
+                                       DBusMessageIter *iter, void *data)
+{
+       struct service *service = data;
+       uint16_t handle = service->start_handle;
+
+       dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16, &handle);
+
+       return TRUE;
+}
+
 static gboolean service_get_uuid(const GDBusPropertyTable *property,
                                        DBusMessageIter *iter, void *data)
 {
@@ -2169,6 +2204,7 @@ static gboolean service_get_characteristics(const GDBusPropertyTable *property,
 #endif
 
 static const GDBusPropertyTable service_properties[] = {
+       { "Handle", "q", service_get_handle },
        { "UUID", "s", service_get_uuid },
        { "Device", "o", service_get_device },
        { "Primary", "b", service_get_primary },