Commit 32fcfde8 authored by Bastien Nocera's avatar Bastien Nocera

lib: Use GLib and libusb directly for debug output

Use GLib internally to output debug information, and tell about
libusb's LIBUSB_DEBUG envvar for libusb debug.

fp_set_debug() is now a no-op.

https://bugs.freedesktop.org/show_bug.cgi?id=106552
parent 363a1b33
...@@ -19,13 +19,14 @@ ...@@ -19,13 +19,14 @@
#define FP_COMPONENT "aeslib" #define FP_COMPONENT "aeslib"
#include "fp_internal.h"
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <libusb.h> #include <libusb.h>
#include <glib.h> #include <glib.h>
#include "fp_internal.h"
#include "assembling.h" #include "assembling.h"
#include "aeslib.h" #include "aeslib.h"
......
...@@ -21,13 +21,14 @@ ...@@ -21,13 +21,14 @@
#define FP_COMPONENT "assembling" #define FP_COMPONENT "assembling"
#include "fp_internal.h"
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <libusb.h> #include <libusb.h>
#include <glib.h> #include <glib.h>
#include "fp_internal.h"
#include "assembling.h" #include "assembling.h"
static unsigned int calc_error(struct fpi_frame_asmbl_ctx *ctx, static unsigned int calc_error(struct fpi_frame_asmbl_ctx *ctx,
......
...@@ -19,12 +19,12 @@ ...@@ -19,12 +19,12 @@
#define FP_COMPONENT "async" #define FP_COMPONENT "async"
#include "fp_internal.h"
#include <config.h> #include <config.h>
#include <errno.h> #include <errno.h>
#include <glib.h> #include <glib.h>
#include "fp_internal.h"
/* Drivers call this when device initialisation has completed */ /* Drivers call this when device initialisation has completed */
void fpi_drvcb_open_complete(struct fp_dev *dev, int status) void fpi_drvcb_open_complete(struct fp_dev *dev, int status)
{ {
......
...@@ -27,9 +27,6 @@ ...@@ -27,9 +27,6 @@
#include "fp_internal.h" #include "fp_internal.h"
static int log_level = 0;
static int log_level_fixed = 0;
libusb_context *fpi_usb_ctx = NULL; libusb_context *fpi_usb_ctx = NULL;
GSList *opened_devices = NULL; GSList *opened_devices = NULL;
...@@ -116,52 +113,6 @@ GSList *opened_devices = NULL; ...@@ -116,52 +113,6 @@ GSList *opened_devices = NULL;
static GSList *registered_drivers = NULL; static GSList *registered_drivers = NULL;
void fpi_log(enum fpi_log_level level, const char *component,
const char *function, const char *format, ...)
{
va_list args;
FILE *stream = stdout;
const char *prefix;
if (!log_level)
return;
if (level == FPRINT_LOG_LEVEL_WARNING && log_level < 2)
return;
if (level == FPRINT_LOG_LEVEL_INFO && log_level < 3)
return;
switch (level) {
case FPRINT_LOG_LEVEL_INFO:
prefix = "info";
break;
case FPRINT_LOG_LEVEL_WARNING:
stream = stderr;
prefix = "warning";
break;
case FPRINT_LOG_LEVEL_ERROR:
stream = stderr;
prefix = "error";
break;
case FPRINT_LOG_LEVEL_DEBUG:
stream = stderr;
prefix = "debug";
break;
default:
stream = stderr;
prefix = "unknown";
break;
}
fprintf(stream, "%s:%s [%s] ", component ? component : "fp", prefix,
function);
va_start (args, format);
vfprintf(stream, format, args);
va_end (args);
fprintf(stream, "\n");
}
static void register_driver(struct fp_driver *drv) static void register_driver(struct fp_driver *drv)
{ {
if (drv->id == 0) { if (drv->id == 0) {
...@@ -787,38 +738,11 @@ API_EXPORTED int fp_dev_get_img_height(struct fp_dev *dev) ...@@ -787,38 +738,11 @@ API_EXPORTED int fp_dev_get_img_height(struct fp_dev *dev)
* fp_set_debug: * fp_set_debug:
* @level: the verbosity level * @level: the verbosity level
* *
* Set message verbosity. * This call does nothing, see fp_init() for details.
* - Level 0: no messages ever printed by the library (default)
* - Level 1: error messages are printed to stderr
* - Level 2: warning and error messages are printed to stderr
* - Level 3: informational messages are printed to stdout, warning and error
* messages are printed to stderr
*
* The default level is 0, which means no messages are ever printed. If you
* choose to increase the message verbosity level, ensure that your
* application does not close the stdout/stderr file descriptors.
*
* You are advised to set level 3. libfprint is conservative with its message
* logging and most of the time, will only log messages that explain error
* conditions and other oddities. This will help you debug your software.
*
* If the LIBFPRINT_DEBUG environment variable was set when libfprint was
* initialized, this function does nothing: the message verbosity is fixed
* to the value in the environment variable.
*
* If libfprint was compiled without any message logging, this function does
* nothing: you'll never get any messages.
*
* If libfprint was compiled with verbose debug message logging, this function
* does nothing: you'll always get messages from all levels.
*/ */
API_EXPORTED void fp_set_debug(int level) API_EXPORTED void fp_set_debug(int level)
{ {
if (log_level_fixed) /* Nothing */
return;
log_level = level;
libusb_set_debug(fpi_usb_ctx, level);
} }
/** /**
...@@ -827,11 +751,27 @@ API_EXPORTED void fp_set_debug(int level) ...@@ -827,11 +751,27 @@ API_EXPORTED void fp_set_debug(int level)
* Initialise libfprint. This function must be called before you attempt to * Initialise libfprint. This function must be called before you attempt to
* use the library in any way. * use the library in any way.
* *
* To enable debug output of libfprint specifically, use GLib's `G_MESSAGES_DEBUG`
* environment variable as explained in [Running and debugging GLib Applications](https://developer.gnome.org/glib/stable/glib-running.html#G_MESSAGES_DEBUG).
*
* The log domains used in libfprint are either `libfprint` or `libfprint-FP_COMPONENT`
* where `FP_COMPONENT` is defined in the source code for each driver, or component
* of the library. Starting with `all` and trimming down is advised.
*
* To enable debugging of libusb, for USB-based fingerprint reader drivers, use
* libusb's `LIBUSB_DEBUG` environment variable as explained in the
* [libusb-1.0 API Reference](http://libusb.sourceforge.net/api-1.0/#msglog).
*
* Example:
*
* ```
* LIBUSB_DEBUG=4 G_MESSAGES_DEBUG=all my-libfprint-application
* ```
*
* Returns: 0 on success, non-zero on error. * Returns: 0 on success, non-zero on error.
*/ */
API_EXPORTED int fp_init(void) API_EXPORTED int fp_init(void)
{ {
char *dbg = getenv("LIBFPRINT_DEBUG");
int r; int r;
G_DEBUG_HERE(); G_DEBUG_HERE();
...@@ -839,14 +779,6 @@ API_EXPORTED int fp_init(void) ...@@ -839,14 +779,6 @@ API_EXPORTED int fp_init(void)
if (r < 0) if (r < 0)
return r; return r;
if (dbg) {
log_level = atoi(dbg);
if (log_level) {
log_level_fixed = 1;
libusb_set_debug(fpi_usb_ctx, log_level);
}
}
register_drivers(); register_drivers();
fpi_poll_init(); fpi_poll_init();
return 0; return 0;
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#define FP_COMPONENT "aes1610" #define FP_COMPONENT "aes1610"
#include "fp_internal.h"
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
...@@ -32,7 +34,6 @@ ...@@ -32,7 +34,6 @@
#include <assembling.h> #include <assembling.h>
#include <aeslib.h> #include <aeslib.h>
#include <fp_internal.h>
#include "driver_ids.h" #include "driver_ids.h"
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#define FP_COMPONENT "aes1660" #define FP_COMPONENT "aes1660"
#include "fp_internal.h"
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
...@@ -26,7 +28,6 @@ ...@@ -26,7 +28,6 @@
#include <libusb.h> #include <libusb.h>
#include <fp_internal.h>
#include <assembling.h> #include <assembling.h>
#include <aeslib.h> #include <aeslib.h>
......
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#define FP_COMPONENT "aes2501" #define FP_COMPONENT "aes2501"
#include "fp_internal.h"
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
...@@ -30,7 +32,6 @@ ...@@ -30,7 +32,6 @@
#include <assembling.h> #include <assembling.h>
#include <aeslib.h> #include <aeslib.h>
#include <fp_internal.h>
#include "aes2501.h" #include "aes2501.h"
#include "driver_ids.h" #include "driver_ids.h"
......
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#define FP_COMPONENT "aes2550" #define FP_COMPONENT "aes2550"
#include "fp_internal.h"
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
...@@ -30,7 +32,6 @@ ...@@ -30,7 +32,6 @@
#include <assembling.h> #include <assembling.h>
#include <aeslib.h> #include <aeslib.h>
#include <fp_internal.h>
#include "aes2550.h" #include "aes2550.h"
#include "driver_ids.h" #include "driver_ids.h"
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#define FP_COMPONENT "aes2660" #define FP_COMPONENT "aes2660"
#include "fp_internal.h"
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
...@@ -26,8 +28,6 @@ ...@@ -26,8 +28,6 @@
#include <libusb.h> #include <libusb.h>
#include <fp_internal.h>
#include <assembling.h> #include <assembling.h>
#include <aeslib.h> #include <aeslib.h>
......
...@@ -29,13 +29,14 @@ ...@@ -29,13 +29,14 @@
#define FP_COMPONENT "aes3500" #define FP_COMPONENT "aes3500"
#include "fp_internal.h"
#include <errno.h> #include <errno.h>
#include <glib.h> #include <glib.h>
#include <libusb.h> #include <libusb.h>
#include <aeslib.h> #include <aeslib.h>
#include <fp_internal.h>
#include "aes3k.h" #include "aes3k.h"
#include "driver_ids.h" #include "driver_ids.h"
......
...@@ -36,13 +36,14 @@ ...@@ -36,13 +36,14 @@
#define FP_COMPONENT "aes3k" #define FP_COMPONENT "aes3k"
#include "fp_internal.h"
#include <errno.h> #include <errno.h>
#include <glib.h> #include <glib.h>
#include <libusb.h> #include <libusb.h>
#include <aeslib.h> #include <aeslib.h>
#include <fp_internal.h>
#include "aes3k.h" #include "aes3k.h"
......
...@@ -26,13 +26,14 @@ ...@@ -26,13 +26,14 @@
#define FP_COMPONENT "aes4000" #define FP_COMPONENT "aes4000"
#include "fp_internal.h"
#include <errno.h> #include <errno.h>
#include <glib.h> #include <glib.h>
#include <libusb.h> #include <libusb.h>
#include <aeslib.h> #include <aeslib.h>
#include <fp_internal.h>
#include "aes3k.h" #include "aes3k.h"
#include "driver_ids.h" #include "driver_ids.h"
......
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#define FP_COMPONENT "aesX660" #define FP_COMPONENT "aesX660"
#include "fp_internal.h"
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
...@@ -32,7 +34,6 @@ ...@@ -32,7 +34,6 @@
#include <assembling.h> #include <assembling.h>
#include <aeslib.h> #include <aeslib.h>
#include <fp_internal.h>
#include "aesx660.h" #include "aesx660.h"
......
...@@ -20,10 +20,11 @@ ...@@ -20,10 +20,11 @@
#define FP_COMPONENT "elan" #define FP_COMPONENT "elan"
#include "fp_internal.h"
#include <errno.h> #include <errno.h>
#include <libusb.h> #include <libusb.h>
#include <assembling.h> #include <assembling.h>
#include <fp_internal.h>
#include <fprint.h> #include <fprint.h>
#include "elan.h" #include "elan.h"
......
...@@ -33,6 +33,10 @@ ...@@ -33,6 +33,10 @@
* *
*/ */
#define FP_COMPONENT "etes603"
#include "fp_internal.h"
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
#include <stdarg.h> #include <stdarg.h>
...@@ -41,8 +45,6 @@ ...@@ -41,8 +45,6 @@
#include <libusb.h> #include <libusb.h>
#include <glib.h> #include <glib.h>
#define FP_COMPONENT "etes603"
#include <fp_internal.h>
#include "driver_ids.h" #include "driver_ids.h"
/* libusb defines */ /* libusb defines */
......
...@@ -17,15 +17,16 @@ ...@@ -17,15 +17,16 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#define FP_COMPONENT "fdu2000"
#include "fp_internal.h"
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <libusb.h> #include <libusb.h>
#define FP_COMPONENT "fdu2000"
#include <fp_internal.h>
#include "driver_ids.h" #include "driver_ids.h"
#ifndef HAVE_MEMMEM #ifndef HAVE_MEMMEM
......
...@@ -25,14 +25,14 @@ ...@@ -25,14 +25,14 @@
#define FP_COMPONENT "upeksonly" #define FP_COMPONENT "upeksonly"
#include "fp_internal.h"
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <glib.h> #include <glib.h>
#include <libusb.h> #include <libusb.h>
#include <fp_internal.h>
#include <assembling.h> #include <assembling.h>
#include "upeksonly.h" #include "upeksonly.h"
......
...@@ -20,10 +20,11 @@ ...@@ -20,10 +20,11 @@
#define FP_COMPONENT "upektc" #define FP_COMPONENT "upektc"
#include "fp_internal.h"
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <libusb.h> #include <libusb.h>
#include <fp_internal.h>
#include "upektc.h" #include "upektc.h"
#include "driver_ids.h" #include "driver_ids.h"
......
...@@ -19,13 +19,14 @@ ...@@ -19,13 +19,14 @@
#define FP_COMPONENT "upektc_img" #define FP_COMPONENT "upektc_img"
#include "fp_internal.h"
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <libusb.h> #include <libusb.h>
#include <aeslib.h> #include <aeslib.h>
#include <fp_internal.h>
#include "upektc_img.h" #include "upektc_img.h"
#include "driver_ids.h" #include "driver_ids.h"
......
...@@ -27,14 +27,14 @@ ...@@ -27,14 +27,14 @@
#define FP_COMPONENT "upekts" #define FP_COMPONENT "upekts"
#include "fp_internal.h"
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <glib.h> #include <glib.h>
#include <libusb.h> #include <libusb.h>
#include <fp_internal.h>
#include "driver_ids.h" #include "driver_ids.h"
#define EP_IN (1 | LIBUSB_ENDPOINT_IN) #define EP_IN (1 | LIBUSB_ENDPOINT_IN)
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#define FP_COMPONENT "uru4000" #define FP_COMPONENT "uru4000"
#include "fp_internal.h"
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
...@@ -28,8 +30,6 @@ ...@@ -28,8 +30,6 @@
#include <pk11pub.h> #include <pk11pub.h>
#include <libusb.h> #include <libusb.h>
#include <fp_internal.h>
#include "driver_ids.h" #include "driver_ids.h"
#define EP_INTR (1 | LIBUSB_ENDPOINT_IN) #define EP_INTR (1 | LIBUSB_ENDPOINT_IN)
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#define FP_COMPONENT "vcom5s" #define FP_COMPONENT "vcom5s"
#include "fp_internal.h"
/* TODO: /* TODO:
* calibration? * calibration?
* image size: windows gets 300x300 through vpas enrollment util? * image size: windows gets 300x300 through vpas enrollment util?
...@@ -32,8 +34,6 @@ ...@@ -32,8 +34,6 @@
#include <glib.h> #include <glib.h>
#include <libusb.h> #include <libusb.h>
#include <fp_internal.h>
#include "driver_ids.h" #include "driver_ids.h"
#define CTRL_IN 0xc0 #define CTRL_IN 0xc0
......
...@@ -19,9 +19,10 @@ ...@@ -19,9 +19,10 @@
#define FP_COMPONENT "vfs0050" #define FP_COMPONENT "vfs0050"
#include "fp_internal.h"
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <fp_internal.h>
#include <assembling.h> #include <assembling.h>
#include "driver_ids.h" #include "driver_ids.h"
......
...@@ -17,14 +17,14 @@ ...@@ -17,14 +17,14 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#define FP_COMPONENT "vfs101"
#include "fp_internal.h"
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#define FP_COMPONENT "vfs101"
#include <fp_internal.h>
#include "driver_ids.h" #include "driver_ids.h"
/* Input-Output usb endpoint */ /* Input-Output usb endpoint */
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
#define FP_COMPONENT "vfs301" #define FP_COMPONEN