From de5b4e7dcbe080ced18c25a128f965f58ce48bc1 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 6 Sep 2018 13:23:13 +0200 Subject: [PATCH 1/3] lib: Split off logging helpers --- libfprint/drivers_api.h | 21 +------------------ libfprint/fp_internal.h | 20 +----------------- libfprint/fpi-log.h | 45 +++++++++++++++++++++++++++++++++++++++++ libfprint/meson.build | 1 + 4 files changed, 48 insertions(+), 39 deletions(-) create mode 100644 libfprint/fpi-log.h diff --git a/libfprint/drivers_api.h b/libfprint/drivers_api.h index cba678a..bd0bdd7 100644 --- a/libfprint/drivers_api.h +++ b/libfprint/drivers_api.h @@ -22,12 +22,6 @@ #define __DRIVERS_API_H__ #include - -#ifdef FP_COMPONENT -#undef G_LOG_DOMAIN -#define G_LOG_DOMAIN "libfprint-"FP_COMPONENT -#endif - #include #include #include @@ -36,25 +30,12 @@ #include #include "fprint.h" +#include "fpi-log.h" #include "fpi-ssm.h" #include "fpi-poll.h" #include "assembling.h" #include "drivers/driver_ids.h" -#define fp_dbg g_debug -#define fp_info g_debug -#define fp_warn g_warning -#define fp_err g_warning - -#define BUG_ON(condition) G_STMT_START \ - if (condition) { \ - char *s; \ - s = g_strconcat ("BUG: (", #condition, ")", NULL); \ - g_warning ("%s: %s() %s:%d", s, G_STRFUNC, __FILE__, __LINE__); \ - g_free (s); \ - } G_STMT_END -#define BUG() BUG_ON(1) - struct fp_dev; libusb_device_handle *fpi_dev_get_usb_dev(struct fp_dev *dev); void *fpi_dev_get_user_data (struct fp_dev *dev); diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h index 9aa03f2..3336cac 100644 --- a/libfprint/fp_internal.h +++ b/libfprint/fp_internal.h @@ -22,37 +22,19 @@ #include -#ifdef FP_COMPONENT -#undef G_LOG_DOMAIN -#define G_LOG_DOMAIN "libfprint-"FP_COMPONENT -#endif - #include #include #include #include #include "fprint.h" +#include "fpi-log.h" #include "drivers/driver_ids.h" #define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) -#define fp_dbg g_debug -#define fp_info g_debug -#define fp_warn g_warning -#define fp_err g_warning - -#define BUG_ON(condition) G_STMT_START \ - if (condition) { \ - char *s; \ - s = g_strconcat ("BUG: (", #condition, ")", NULL); \ - g_warning ("%s: %s() %s:%d", s, G_STRFUNC, __FILE__, __LINE__); \ - g_free (s); \ - } G_STMT_END -#define BUG() BUG_ON(1) - enum fp_dev_state { DEV_STATE_INITIAL = 0, DEV_STATE_ERROR, diff --git a/libfprint/fpi-log.h b/libfprint/fpi-log.h new file mode 100644 index 0000000..38d720c --- /dev/null +++ b/libfprint/fpi-log.h @@ -0,0 +1,45 @@ +/* + * Logging + * Copyright (C) 2007-2008 Daniel Drake + * Copyright (C) 2018 Bastien Nocera + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __FPI_LOG_H__ +#define __FPI_LOG_H__ + +#ifdef FP_COMPONENT +#undef G_LOG_DOMAIN +#define G_LOG_DOMAIN "libfprint-"FP_COMPONENT +#endif + +#include + +#define fp_dbg g_debug +#define fp_info g_debug +#define fp_warn g_warning +#define fp_err g_warning + +#define BUG_ON(condition) G_STMT_START \ + if (condition) { \ + char *s; \ + s = g_strconcat ("BUG: (", #condition, ")", NULL); \ + g_warning ("%s: %s() %s:%d", s, G_STRFUNC, __FILE__, __LINE__); \ + g_free (s); \ + } G_STMT_END +#define BUG() BUG_ON(1) + +#endif diff --git a/libfprint/meson.build b/libfprint/meson.build index c6d1ac9..ceacc35 100644 --- a/libfprint/meson.build +++ b/libfprint/meson.build @@ -4,6 +4,7 @@ libfprint_sources = [ 'async.c', 'core.c', 'data.c', + 'fpi-log.h', 'fpi-ssm.c', 'fpi-ssm.h', 'fpi-poll.h', From fc66919e1fb69acbc435ec103fa0d9ba34e3cc3f Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 6 Sep 2018 14:42:33 +0200 Subject: [PATCH 2/3] lib: Make BUG_ON() use fp_err() So that when we change fp_err() to an assertion, BUG_ON() is changed as well. --- libfprint/fpi-log.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libfprint/fpi-log.h b/libfprint/fpi-log.h index 38d720c..a21f4e1 100644 --- a/libfprint/fpi-log.h +++ b/libfprint/fpi-log.h @@ -37,7 +37,7 @@ if (condition) { \ char *s; \ s = g_strconcat ("BUG: (", #condition, ")", NULL); \ - g_warning ("%s: %s() %s:%d", s, G_STRFUNC, __FILE__, __LINE__); \ + fp_err ("%s: %s() %s:%d", s, G_STRFUNC, __FILE__, __LINE__); \ g_free (s); \ } G_STMT_END #define BUG() BUG_ON(1) From 3cb3b1d63ae09a6cea2667e03c0cc0ad19555100 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 6 Sep 2018 14:43:10 +0200 Subject: [PATCH 3/3] lib: Add Logging API documentation --- doc/libfprint-docs.xml | 1 + doc/libfprint-sections.txt | 11 ++++++++ libfprint/fpi-log.h | 51 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/doc/libfprint-docs.xml b/doc/libfprint-docs.xml index c4e3445..5ca1722 100644 --- a/doc/libfprint-docs.xml +++ b/doc/libfprint-docs.xml @@ -38,6 +38,7 @@ Writing Drivers + diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index 91310b9..3cc33b4 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -141,6 +141,17 @@ fp_img_get_minutiae poll +
+fpi-log.h +fpi-log +fp_dbg +fp_info +fp_warn +fp_err +BUG_ON +BUG +
+
fpi-ssm.h fpi-ssm diff --git a/libfprint/fpi-log.h b/libfprint/fpi-log.h index a21f4e1..d9f354e 100644 --- a/libfprint/fpi-log.h +++ b/libfprint/fpi-log.h @@ -21,6 +21,19 @@ #ifndef __FPI_LOG_H__ #define __FPI_LOG_H__ +/** + * SECTION:fpi-log + * @title: Logging + * + * Logging in libfprint is handled through GLib's logging system, and behave the same + * way as in the GLib [Message Output and Debugging Functions](https://developer.gnome.org/glib/stable/glib-Message-Logging.html) + * documentation. + * + * You should include `fpi-log.h` as early as possible in your sources, just after + * setting the `FP_COMPONENT` define to a string unique to your sources. This will + * set the suffix of the `G_LOG_DOMAIN` used for printing. + */ + #ifdef FP_COMPONENT #undef G_LOG_DOMAIN #define G_LOG_DOMAIN "libfprint-"FP_COMPONENT @@ -28,11 +41,43 @@ #include +/** + * fp_dbg: + * + * Same as g_debug(). + * + */ #define fp_dbg g_debug + +/** + * fp_info: + * + * Same as g_debug(). + */ #define fp_info g_debug + +/** + * fp_warn: + * + * Same as g_warning(). + */ #define fp_warn g_warning + +/** + * fp_err: + * + * Same as g_warning(). In the future, this might be changed to a + * g_assert() instead, so bear this in mind when adding those calls + * to your driver. + */ #define fp_err g_warning +/** + * BUG_ON: + * @condition: the condition to check + * + * Uses fp_err() to print an error if the @condition is true. + */ #define BUG_ON(condition) G_STMT_START \ if (condition) { \ char *s; \ @@ -40,6 +85,12 @@ fp_err ("%s: %s() %s:%d", s, G_STRFUNC, __FILE__, __LINE__); \ g_free (s); \ } G_STMT_END + +/** + * BUG: + * + * Same as BUG_ON() but is always true. + */ #define BUG() BUG_ON(1) #endif