From patchwork Mon Mar 3 15:48:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 22910 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id ED6D0BD808 for ; Mon, 3 Mar 2025 15:48:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 03594687EB; Mon, 3 Mar 2025 16:48:51 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ZmyOS/dB"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 595C168777 for ; Mon, 3 Mar 2025 16:48:48 +0100 (CET) Received: from pb-laptop.local (185.221.143.4.nat.pool.zt.hu [185.221.143.4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D017E8DB for ; Mon, 3 Mar 2025 16:47:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1741016836; bh=R4zYeWhgQ8GXqDxHddFIi9PKdM0ZVS9Hx/9PUBXa/WM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ZmyOS/dBSezu7OPNNB8cQPJV62ejHXwZkNVqOlH8Ocv1qnEymxqrJv8ZMcki59KoU z7kVBzKRXDwaDXAg7b4vDxRtJYK8AEtsIkw/6n4gKA32rQN3NBUwCu9iN7aPT5pSX+ O9GDf7BaJUjItkRrUYDS+uGhdlQ2s/Gvr++D7uvE= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [PATCH v1 1/3] libcamera: base: log: Take `LogCategory` by reference Date: Mon, 3 Mar 2025 16:48:42 +0100 Message-ID: <20250303154844.745574-2-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250303154844.745574-1-barnabas.pocze@ideasonboard.com> References: <20250303154844.745574-1-barnabas.pocze@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" When no log category is specified, `nullptr` is passed, and then the `_log()` function implementations replace that with `LogCategory::defaultCategory()`. But since the call site always knows the log category, this condition can be removed and the `_LOG1()` macro can use `LogCategory::defaultCategory()`. So remove the condition from the `_log()` implementations and use references to refer to log categories. Reviewed-by: Laurent Pinchart --- include/libcamera/base/log.h | 8 ++++---- src/libcamera/base/log.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/libcamera/base/log.h b/include/libcamera/base/log.h index 8af74b59d..958cb488d 100644 --- a/include/libcamera/base/log.h +++ b/include/libcamera/base/log.h @@ -96,12 +96,12 @@ public: protected: virtual std::string logPrefix() const = 0; - LogMessage _log(const LogCategory *category, LogSeverity severity, + LogMessage _log(const LogCategory &category, LogSeverity severity, const char *fileName = __builtin_FILE(), unsigned int line = __builtin_LINE()) const; }; -LogMessage _log(const LogCategory *category, LogSeverity severity, +LogMessage _log(const LogCategory &category, LogSeverity severity, const char *fileName = __builtin_FILE(), unsigned int line = __builtin_LINE()); @@ -109,9 +109,9 @@ LogMessage _log(const LogCategory *category, LogSeverity severity, #define _LOG_CATEGORY(name) logCategory##name #define _LOG1(severity) \ - _log(nullptr, Log##severity).stream() + _log(LogCategory::defaultCategory(), Log##severity).stream() #define _LOG2(category, severity) \ - _log(&_LOG_CATEGORY(category)(), Log##severity).stream() + _log(_LOG_CATEGORY(category)(), Log##severity).stream() /* * Expand the LOG() macro to _LOG1() or _LOG2() based on the number of diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp index 6a040b592..ba57ad8f1 100644 --- a/src/libcamera/base/log.cpp +++ b/src/libcamera/base/log.cpp @@ -952,11 +952,11 @@ Loggable::~Loggable() * * \return A log message */ -LogMessage Loggable::_log(const LogCategory *category, LogSeverity severity, +LogMessage Loggable::_log(const LogCategory &category, LogSeverity severity, const char *fileName, unsigned int line) const { return LogMessage(fileName, line, - category ? *category : LogCategory::defaultCategory(), + category, severity, logPrefix()); } @@ -972,11 +972,11 @@ LogMessage Loggable::_log(const LogCategory *category, LogSeverity severity, * * \return A log message */ -LogMessage _log(const LogCategory *category, LogSeverity severity, +LogMessage _log(const LogCategory &category, LogSeverity severity, const char *fileName, unsigned int line) { return LogMessage(fileName, line, - category ? *category : LogCategory::defaultCategory(), + category, severity); }