public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v3 2/9] mgmt: Add DBG macro
Date: Wed, 23 Mar 2022 13:13:34 -0700	[thread overview]
Message-ID: <20220323201341.3596128-3-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20220323201341.3596128-1-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds mgmt_log wrapper for util_debug and DBG so file and function
names are printed with the logs.
---
 src/shared/mgmt.c | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/src/shared/mgmt.c b/src/shared/mgmt.c
index 95229c248..c7e6a6c1d 100644
--- a/src/shared/mgmt.c
+++ b/src/shared/mgmt.c
@@ -27,6 +27,9 @@
 #include "src/shared/mgmt.h"
 #include "src/shared/timeout.h"
 
+#define DBG(_mgmt, _format, arg...) \
+	mgmt_log(_mgmt, "%s:%s() " _format, __FILE__, __func__, ## arg)
+
 struct mgmt {
 	int ref_count;
 	int fd;
@@ -177,6 +180,18 @@ static bool request_timeout(void *data)
 	return false;
 }
 
+static void mgmt_log(struct mgmt *mgmt, const char *format, ...)
+{
+	va_list ap;
+
+	if (!mgmt || !format || !mgmt->debug_callback)
+		return;
+
+	va_start(ap, format);
+	util_debug_va(mgmt->debug_callback, mgmt->debug_data, format, ap);
+	va_end(ap);
+}
+
 static bool send_request(struct mgmt *mgmt, struct mgmt_request *request)
 {
 	struct iovec iov;
@@ -187,8 +202,8 @@ static bool send_request(struct mgmt *mgmt, struct mgmt_request *request)
 
 	ret = io_send(mgmt->io, &iov, 1);
 	if (ret < 0) {
-		util_debug(mgmt->debug_callback, mgmt->debug_data,
-				"write failed: %s", strerror(-ret));
+		DBG(mgmt, "write failed: %s", strerror(-ret));
+
 		if (request->callback)
 			request->callback(MGMT_STATUS_FAILED, 0, NULL,
 							request->user_data);
@@ -202,9 +217,7 @@ static bool send_request(struct mgmt *mgmt, struct mgmt_request *request)
 							request,
 							NULL);
 
-	util_debug(mgmt->debug_callback, mgmt->debug_data,
-				"[0x%04x] command 0x%04x",
-				request->index, request->opcode);
+	DBG(mgmt, "[0x%04x] command 0x%04x", request->index, request->opcode);
 
 	util_hexdump('<', request->buf, ret, mgmt->debug_callback,
 							mgmt->debug_data);
@@ -283,9 +296,7 @@ static void request_complete(struct mgmt *mgmt, uint8_t status,
 	request = queue_remove_if(mgmt->pending_list,
 					match_request_opcode_index, &match);
 	if (!request) {
-		util_debug(mgmt->debug_callback, mgmt->debug_data,
-				"Unable to find request for opcode 0x%04x",
-				opcode);
+		DBG(mgmt, "Unable to find request for opcode 0x%04x", opcode);
 
 		/* Attempt to remove with no opcode */
 		request = queue_remove_if(mgmt->pending_list,
@@ -383,8 +394,7 @@ static bool can_read_data(struct io *io, void *user_data)
 		cc = mgmt->buf + MGMT_HDR_SIZE;
 		opcode = btohs(cc->opcode);
 
-		util_debug(mgmt->debug_callback, mgmt->debug_data,
-				"[0x%04x] command 0x%04x complete: 0x%02x",
+		DBG(mgmt, "[0x%04x] command 0x%04x complete: 0x%02x",
 						index, opcode, cc->status);
 
 		request_complete(mgmt, cc->status, opcode, index, length - 3,
@@ -394,15 +404,13 @@ static bool can_read_data(struct io *io, void *user_data)
 		cs = mgmt->buf + MGMT_HDR_SIZE;
 		opcode = btohs(cs->opcode);
 
-		util_debug(mgmt->debug_callback, mgmt->debug_data,
-				"[0x%04x] command 0x%02x status: 0x%02x",
+		DBG(mgmt, "[0x%04x] command 0x%02x status: 0x%02x",
 						index, opcode, cs->status);
 
 		request_complete(mgmt, cs->status, opcode, index, 0, NULL);
 		break;
 	default:
-		util_debug(mgmt->debug_callback, mgmt->debug_data,
-				"[0x%04x] event 0x%04x", index, event);
+		DBG(mgmt, "[0x%04x] event 0x%04x", index, event);
 
 		process_notify(mgmt, event, index, length,
 						mgmt->buf + MGMT_HDR_SIZE);
-- 
2.35.1


  parent reply	other threads:[~2022-03-23 20:13 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-23 20:13 [PATCH BlueZ v3 1/9] log: Don't log __FILE__ and __func__ with DBG_IDX Luiz Augusto von Dentz
2022-03-23 20:13 ` [PATCH BlueZ v2 1/9] log: Introduce DBG_IS_ENABLED Luiz Augusto von Dentz
2022-03-24  1:53   ` [BlueZ,v2,1/9] " bluez.test.bot
2022-03-24 19:50   ` [PATCH BlueZ v2 1/9] " patchwork-bot+bluetooth
2022-03-23 20:13 ` Luiz Augusto von Dentz [this message]
2022-03-23 20:13 ` [PATCH BlueZ v3 3/9] mgmt: Introduce mgmt_set_verbose Luiz Augusto von Dentz
2022-03-23 20:13 ` [PATCH BlueZ v3 4/9] adapter: Don't use DBG in mgmt_debug Luiz Augusto von Dentz
2022-03-23 20:13 ` [PATCH BlueZ v3 5/9] att: Log file and function names Luiz Augusto von Dentz
2022-03-23 20:13 ` [PATCH BlueZ v3 6/9] gatt-client: Add DBG macro Luiz Augusto von Dentz
2022-03-23 20:13 ` [PATCH BlueZ v3 7/9] gatt-server: " Luiz Augusto von Dentz
2022-03-23 20:13 ` [PATCH BlueZ v3 8/9] att: Rename att_debug and att_verbose to DBG and VERBOSE Luiz Augusto von Dentz
2022-03-23 20:13 ` [PATCH BlueZ v3 9/9] device: Don't use DBG in gatt_debug Luiz Augusto von Dentz
2022-03-23 21:48 ` [BlueZ,v3,1/9] log: Don't log __FILE__ and __func__ with DBG_IDX bluez.test.bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220323201341.3596128-3-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox