From c26542e3a59588a27cf231a9af6202ad43beb006 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Thu, 5 Jan 2023 13:52:15 -0800 Subject: [PATCH] shared/gatt-client: Use parent debug_callback if not set on clone If clone don't have a dedicated callback set use its parent so users of bt_gatt_client_clone don't have to keep setting the same callback for all clone instances. --- src/shared/gatt-client.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c index 4b5787b..8c9b262 100644 --- a/src/shared/gatt-client.c +++ b/src/shared/gatt-client.c @@ -41,7 +41,8 @@ #define GATT_SVC_UUID 0x1801 #define SVC_CHNGD_UUID 0x2a05 #define DBG(_client, _format, arg...) \ - gatt_log(_client, "%s:%s() " _format, __FILE__, __func__, ## arg) + gatt_log(_client, "[%p] %s:%s() " _format, _client, __FILE__, \ + __func__, ## arg) struct ready_cb { bt_gatt_client_callback_t callback; @@ -386,15 +387,28 @@ static void discovery_op_free(struct discovery_op *op) static bool read_db_hash(struct discovery_op *op); +static void gatt_log_va(struct bt_gatt_client *client, const char *format, + va_list va) +{ + if (!client || !format) + return; + + if (client->debug_callback) + util_debug_va(client->debug_callback, client->debug_data, + format, va); + else + gatt_log_va(client->parent, format, va); +} + static void gatt_log(struct bt_gatt_client *client, const char *format, ...) { va_list ap; - if (!client || !format || !client->debug_callback) + if (!client || !format) return; va_start(ap, format); - util_debug_va(client->debug_callback, client->debug_data, format, ap); + gatt_log_va(client, format, ap); va_end(ap); } -- 2.7.4