gatt-server: Add DBG macro
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Mon, 21 Mar 2022 20:29:48 +0000 (13:29 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:53 +0000 (14:55 +0530)
This adds gatt_log wrapper for util_debug and DBG so file and function
names are printed with the logs.

Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
src/shared/gatt-server.c

index 9aed2ec..270461f 100644 (file)
@@ -45,6 +45,9 @@
 
 #define NFY_MULT_TIMEOUT 10
 
+#define DBG(_server, _format, arg...) \
+       gatt_log(_server, "%s:%s() " _format, __FILE__, __func__, ## arg)
+
 struct async_read_op {
        struct bt_att_chan *chan;
        struct bt_gatt_server *server;
@@ -247,6 +250,18 @@ static bool encode_read_by_grp_type_rsp(struct gatt_db *db, struct queue *q,
        return true;
 }
 
+static void gatt_log(struct bt_gatt_server *server, const char *format, ...)
+{
+       va_list ap;
+
+       if (!server || !format || !server->debug_callback)
+               return;
+
+       va_start(ap, format);
+       util_debug_va(server->debug_callback, server->debug_data, format, ap);
+       va_end(ap);
+}
+
 static void read_by_grp_type_cb(struct bt_att_chan *chan, uint8_t opcode,
                                        const void *pdu, uint16_t length,
                                        void *user_data)
@@ -273,9 +288,7 @@ static void read_by_grp_type_cb(struct bt_att_chan *chan, uint8_t opcode,
        end = get_le16(pdu + 2);
        get_uuid_le(pdu + 4, length - 4, &type);
 
-       util_debug(server->debug_callback, server->debug_data,
-                               "Read By Grp Type - start: 0x%04x end: 0x%04x",
-                               start, end);
+       DBG(server, "Read By Grp Type - start: 0x%04x end: 0x%04x", start, end);
 
        if (!start || !end) {
                ecode = BT_ATT_ERROR_INVALID_HANDLE;
@@ -497,9 +510,7 @@ static void read_by_type_cb(struct bt_att_chan *chan, uint8_t opcode,
        end = get_le16(pdu + 2);
        get_uuid_le(pdu + 4, length - 4, &type);
 
-       util_debug(server->debug_callback, server->debug_data,
-                               "Read By Type - start: 0x%04x end: 0x%04x",
-                               start, end);
+       DBG(server, "Read By Type - start: 0x%04x end: 0x%04x", start, end);
 
        if (!start || !end) {
                ecode = BT_ATT_ERROR_INVALID_HANDLE;
@@ -631,9 +642,7 @@ static void find_info_cb(struct bt_att_chan *chan, uint8_t opcode,
        start = get_le16(pdu);
        end = get_le16(pdu + 2);
 
-       util_debug(server->debug_callback, server->debug_data,
-                                       "Find Info - start: 0x%04x end: 0x%04x",
-                                       start, end);
+       DBG(server, "Find Info - start: 0x%04x end: 0x%04x", start, end);
 
        if (!start || !end) {
                ecode = BT_ATT_ERROR_INVALID_HANDLE;
@@ -733,9 +742,10 @@ static void find_by_type_val_cb(struct bt_att_chan *chan, uint8_t opcode,
        end = get_le16(pdu + 2);
        uuid16 = get_le16(pdu + 4);
 
-       util_debug(server->debug_callback, server->debug_data,
-                       "Find By Type Value - start: 0x%04x end: 0x%04x uuid: 0x%04x",
-                       start, end, uuid16);
+       DBG(server,
+           "Find By Type Value - start: 0x%04x end: 0x%04x uuid: 0x%04x",
+           start, end, uuid16);
+
        ehandle = start;
        if (start > end) {
                data.ecode = BT_ATT_ERROR_INVALID_HANDLE;
@@ -781,8 +791,7 @@ static void write_complete_cb(struct gatt_db_attribute *attr, int err,
                return;
        }
 
-       util_debug(server->debug_callback, server->debug_data,
-                                               "Write Complete: err %d", err);
+       DBG(server, "Write Complete: err %d", err);
 
        handle = gatt_db_attribute_get_handle(attr);
 
@@ -862,10 +871,8 @@ static void write_cb(struct bt_att_chan *chan, uint8_t opcode, const void *pdu,
        }
 #endif
 
-       util_debug(server->debug_callback, server->debug_data,
-                               "Write %s - handle: 0x%04x",
-                               (opcode == BT_ATT_OP_WRITE_REQ) ? "Req" : "Cmd",
-                               handle);
+       DBG(server, "Write %s - handle: 0x%04x",
+               (opcode == BT_ATT_OP_WRITE_REQ) ? "Req" : "Cmd", handle);
 
 #if defined TIZEN_FEATURE_BLUEZ_MODIFY
        /* Because the length includes handle 2bytes,
@@ -945,8 +952,7 @@ static void read_complete_cb(struct gatt_db_attribute *attr, int err,
        uint16_t mtu;
        uint16_t handle;
 
-       util_debug(server->debug_callback, server->debug_data,
-                               "Read Complete: err %d", err);
+       DBG(server, "Read Complete: err %d", err);
 
        mtu = bt_att_get_mtu(server->att);
        handle = gatt_db_attribute_get_handle(attr);
@@ -1038,10 +1044,8 @@ static void handle_read_req(struct bt_att_chan *chan,
        }
 #endif
 
-       util_debug(server->debug_callback, server->debug_data,
-                       "Read %sReq - handle: 0x%04x",
-                       opcode == BT_ATT_OP_READ_BLOB_REQ ? "Blob " : "",
-                       handle);
+       DBG(server, "Read %sReq - handle: 0x%04x",
+               opcode == BT_ATT_OP_READ_BLOB_REQ ? "Blob " : "", handle);
 
        ecode = check_permissions(server, attr, BT_ATT_PERM_READ_MASK);
        if (ecode)
@@ -1247,8 +1251,7 @@ static void read_multiple_cb(struct bt_att_chan *chan, uint8_t opcode,
 
        handle = data->handles[0];
 
-       util_debug(server->debug_callback, server->debug_data,
-                       "%s Req - %zu handles, 1st: 0x%04x",
+       DBG(server, "%s Req - %zu handles, 1st: 0x%04x",
                        data->opcode == BT_ATT_OP_READ_MULT_REQ ?
                        "Read Multiple" : "Read Multiple Variable Length",
                        data->num_handles, handle);
@@ -1455,8 +1458,7 @@ static void prep_write_cb(struct bt_att_chan *chan, uint8_t opcode,
        }
 #endif
 
-       util_debug(server->debug_callback, server->debug_data,
-                               "Prep Write Req - handle: 0x%04x", handle);
+       DBG(server, "Prep Write Req - handle: 0x%04x", handle);
 
 #if defined TIZEN_FEATURE_BLUEZ_MODIFY
        /* Because the length includes handle 2bytes and offset 2bytes,
@@ -1585,8 +1587,7 @@ static void exec_write_cb(struct bt_att_chan *chan, uint8_t opcode,
 
        flags = ((uint8_t *) pdu)[0];
 
-       util_debug(server->debug_callback, server->debug_data,
-                               "Exec Write Req - flags: 0x%02x", flags);
+       DBG(server, "Exec Write Req - flags: 0x%02x", flags);
 
        if (flags == 0x00)
                write = false;
@@ -1672,8 +1673,7 @@ static void exchange_mtu_cb(struct bt_att_chan *chan, uint8_t opcode,
                server->mtu_chngd_callback(final_mtu, server->mtu_chngd_data);
 #endif
 
-       util_debug(server->debug_callback, server->debug_data,
-                       "att server MTU exchange complete, with MTU: %u", final_mtu);
+       DBG(server, "MTU exchange complete, with MTU: %u", final_mtu);
 }
 
 static bool gatt_server_register_att_handlers(struct bt_gatt_server *server)