Change the logging system to be per-context

Rather than a single global logging function, make the logging dependent on
the individual context. This way we won't stomp on each other's feet in the
(admittedly unusual) case of having multiple libinput contexts.

The userdata argument to the log handler was dropped. The caller has a ref to
the libinput context now, any userdata can be attached to that context
instead.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
Peter Hutterer 2014-06-18 19:51:19 +10:00
parent 6250397ac8
commit 97a6bf10f9
12 changed files with 161 additions and 155 deletions

View file

@ -452,6 +452,7 @@ tp_button_handle_event(struct tp_dispatch *tp,
enum button_event event, enum button_event event,
uint64_t time) uint64_t time)
{ {
struct libinput *libinput = tp->device->base.seat->libinput;
enum button_state current = t->button.state; enum button_state current = t->button.state;
switch(t->button.state) { switch(t->button.state) {
@ -485,7 +486,8 @@ tp_button_handle_event(struct tp_dispatch *tp,
} }
if (current != t->button.state) if (current != t->button.state)
log_debug("button state: from %s, event %s to %s\n", log_debug(libinput,
"button state: from %s, event %s to %s\n",
button_state_to_str(current), button_state_to_str(current),
button_event_to_str(event), button_event_to_str(event),
button_state_to_str(t->button.state)); button_state_to_str(t->button.state));
@ -538,11 +540,13 @@ tp_process_button(struct tp_dispatch *tp,
const struct input_event *e, const struct input_event *e,
uint64_t time) uint64_t time)
{ {
struct libinput *libinput = tp->device->base.seat->libinput;
uint32_t mask = 1 << (e->code - BTN_LEFT); uint32_t mask = 1 << (e->code - BTN_LEFT);
/* Ignore other buttons on clickpads */ /* Ignore other buttons on clickpads */
if (tp->buttons.is_clickpad && e->code != BTN_LEFT) { if (tp->buttons.is_clickpad && e->code != BTN_LEFT) {
log_bug_kernel("received %s button event on a clickpad\n", log_bug_kernel(libinput,
"received %s button event on a clickpad\n",
libevdev_event_code_get_name(EV_KEY, e->code)); libevdev_event_code_get_name(EV_KEY, e->code));
return 0; return 0;
} }
@ -562,6 +566,7 @@ int
tp_init_buttons(struct tp_dispatch *tp, tp_init_buttons(struct tp_dispatch *tp,
struct evdev_device *device) struct evdev_device *device)
{ {
struct libinput *libinput = tp->device->base.seat->libinput;
struct tp_touch *t; struct tp_touch *t;
int width, height; int width, height;
double diagonal; double diagonal;
@ -575,10 +580,12 @@ tp_init_buttons(struct tp_dispatch *tp,
if (libevdev_has_event_code(device->evdev, EV_KEY, BTN_MIDDLE) || if (libevdev_has_event_code(device->evdev, EV_KEY, BTN_MIDDLE) ||
libevdev_has_event_code(device->evdev, EV_KEY, BTN_RIGHT)) { libevdev_has_event_code(device->evdev, EV_KEY, BTN_RIGHT)) {
if (tp->buttons.is_clickpad) if (tp->buttons.is_clickpad)
log_bug_kernel("clickpad advertising right button\n"); log_bug_kernel(libinput,
"clickpad advertising right button\n");
} else { } else {
if (!tp->buttons.is_clickpad) if (!tp->buttons.is_clickpad)
log_bug_kernel("non clickpad without right button?\n"); log_bug_kernel(libinput,
"non clickpad without right button?\n");
} }
absinfo_x = device->abs.absinfo_x; absinfo_x = device->abs.absinfo_x;

View file

@ -130,6 +130,7 @@ tp_tap_clear_timer(struct tp_dispatch *tp)
static void static void
tp_tap_idle_handle_event(struct tp_dispatch *tp, enum tap_event event, uint64_t time) tp_tap_idle_handle_event(struct tp_dispatch *tp, enum tap_event event, uint64_t time)
{ {
struct libinput *libinput = tp->device->base.seat->libinput;
switch (event) { switch (event) {
case TAP_EVENT_TOUCH: case TAP_EVENT_TOUCH:
@ -138,7 +139,8 @@ tp_tap_idle_handle_event(struct tp_dispatch *tp, enum tap_event event, uint64_t
break; break;
case TAP_EVENT_RELEASE: case TAP_EVENT_RELEASE:
case TAP_EVENT_MOTION: case TAP_EVENT_MOTION:
log_bug_libinput("invalid event, no fingers are down\n"); log_bug_libinput(libinput,
"invalid event, no fingers are down\n");
break; break;
case TAP_EVENT_TIMEOUT: case TAP_EVENT_TIMEOUT:
break; break;
@ -197,11 +199,13 @@ tp_tap_hold_handle_event(struct tp_dispatch *tp, enum tap_event event, uint64_t
static void static void
tp_tap_tapped_handle_event(struct tp_dispatch *tp, enum tap_event event, uint64_t time) tp_tap_tapped_handle_event(struct tp_dispatch *tp, enum tap_event event, uint64_t time)
{ {
struct libinput *libinput = tp->device->base.seat->libinput;
switch (event) { switch (event) {
case TAP_EVENT_MOTION: case TAP_EVENT_MOTION:
case TAP_EVENT_RELEASE: case TAP_EVENT_RELEASE:
log_bug_libinput("invalid event when fingers are up\n"); log_bug_libinput(libinput,
"invalid event when fingers are up\n");
break; break;
case TAP_EVENT_TOUCH: case TAP_EVENT_TOUCH:
tp->tap.state = TAP_STATE_DRAGGING_OR_DOUBLETAP; tp->tap.state = TAP_STATE_DRAGGING_OR_DOUBLETAP;
@ -426,7 +430,9 @@ tp_tap_dead_handle_event(struct tp_dispatch *tp, enum tap_event event, uint64_t
static void static void
tp_tap_handle_event(struct tp_dispatch *tp, enum tap_event event, uint64_t time) tp_tap_handle_event(struct tp_dispatch *tp, enum tap_event event, uint64_t time)
{ {
struct libinput *libinput = tp->device->base.seat->libinput;
enum tp_tap_state current; enum tp_tap_state current;
if (!tp->tap.enabled) if (!tp->tap.enabled)
return; return;
@ -477,7 +483,8 @@ tp_tap_handle_event(struct tp_dispatch *tp, enum tap_event event, uint64_t time)
if (tp->tap.state == TAP_STATE_IDLE || tp->tap.state == TAP_STATE_DEAD) if (tp->tap.state == TAP_STATE_IDLE || tp->tap.state == TAP_STATE_DEAD)
tp_tap_clear_timer(tp); tp_tap_clear_timer(tp);
log_debug("tap state: %s → %s → %s\n", log_debug(libinput,
"tap state: %s → %s → %s\n",
tap_state_to_str(current), tap_state_to_str(current),
tap_event_to_str(event), tap_event_to_str(event),
tap_state_to_str(tp->tap.state)); tap_state_to_str(tp->tap.state));

View file

@ -115,6 +115,7 @@ evdev_device_transform_y(struct evdev_device *device,
static void static void
evdev_flush_pending_event(struct evdev_device *device, uint64_t time) evdev_flush_pending_event(struct evdev_device *device, uint64_t time)
{ {
struct libinput *libinput = device->base.seat->libinput;
struct motion_params motion; struct motion_params motion;
int32_t cx, cy; int32_t cx, cy;
double x, y; double x, y;
@ -147,7 +148,8 @@ evdev_flush_pending_event(struct evdev_device *device, uint64_t time)
break; break;
if (device->mt.slots[slot].seat_slot != -1) { if (device->mt.slots[slot].seat_slot != -1) {
log_bug_kernel("%s: Driver sent multiple touch down for the " log_bug_kernel(libinput,
"%s: Driver sent multiple touch down for the "
"same slot", device->devnode); "same slot", device->devnode);
break; break;
} }
@ -196,7 +198,8 @@ evdev_flush_pending_event(struct evdev_device *device, uint64_t time)
break; break;
if (device->abs.seat_slot != -1) { if (device->abs.seat_slot != -1) {
log_bug_kernel("%s: Driver sent multiple touch down for the " log_bug_kernel(libinput,
"%s: Driver sent multiple touch down for the "
"same slot", device->devnode); "same slot", device->devnode);
break; break;
} }
@ -591,6 +594,7 @@ configure_pointer_acceleration(struct evdev_device *device)
static int static int
evdev_configure_device(struct evdev_device *device) evdev_configure_device(struct evdev_device *device)
{ {
struct libinput *libinput = device->base.seat->libinput;
struct libevdev *evdev = device->evdev; struct libevdev *evdev = device->evdev;
const struct input_absinfo *absinfo; const struct input_absinfo *absinfo;
struct input_absinfo fixed; struct input_absinfo fixed;
@ -696,7 +700,8 @@ evdev_configure_device(struct evdev_device *device)
!libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_PEN) && !libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_PEN) &&
(has_abs || has_mt)) { (has_abs || has_mt)) {
device->dispatch = evdev_mt_touchpad_create(device); device->dispatch = evdev_mt_touchpad_create(device);
log_info("input device '%s', %s is a touchpad\n", log_info(libinput,
"input device '%s', %s is a touchpad\n",
device->devname, device->devnode); device->devname, device->devnode);
} }
for (i = KEY_ESC; i < KEY_MAX; i++) { for (i = KEY_ESC; i < KEY_MAX; i++) {
@ -725,7 +730,8 @@ evdev_configure_device(struct evdev_device *device)
device->seat_caps |= EVDEV_DEVICE_POINTER; device->seat_caps |= EVDEV_DEVICE_POINTER;
log_info("input device '%s', %s is a pointer caps =%s%s%s\n", log_info(libinput,
"input device '%s', %s is a pointer caps =%s%s%s\n",
device->devname, device->devnode, device->devname, device->devnode,
has_abs ? " absolute-motion" : "", has_abs ? " absolute-motion" : "",
has_rel ? " relative-motion": "", has_rel ? " relative-motion": "",
@ -733,12 +739,14 @@ evdev_configure_device(struct evdev_device *device)
} }
if (has_keyboard) { if (has_keyboard) {
device->seat_caps |= EVDEV_DEVICE_KEYBOARD; device->seat_caps |= EVDEV_DEVICE_KEYBOARD;
log_info("input device '%s', %s is a keyboard\n", log_info(libinput,
"input device '%s', %s is a keyboard\n",
device->devname, device->devnode); device->devname, device->devnode);
} }
if (has_touch && !has_button) { if (has_touch && !has_button) {
device->seat_caps |= EVDEV_DEVICE_TOUCH; device->seat_caps |= EVDEV_DEVICE_TOUCH;
log_info("input device '%s', %s is a touch device\n", log_info(libinput,
"input device '%s', %s is a touch device\n",
device->devname, device->devnode); device->devname, device->devnode);
} }
@ -761,7 +769,8 @@ evdev_device_create(struct libinput_seat *seat,
* read. mtdev_get() also expects this. */ * read. mtdev_get() also expects this. */
fd = open_restricted(libinput, devnode, O_RDWR | O_NONBLOCK); fd = open_restricted(libinput, devnode, O_RDWR | O_NONBLOCK);
if (fd < 0) { if (fd < 0) {
log_info("opening input device '%s' failed (%s).\n", log_info(libinput,
"opening input device '%s' failed (%s).\n",
devnode, strerror(-fd)); devnode, strerror(-fd));
return NULL; return NULL;
} }

View file

@ -56,6 +56,9 @@ struct libinput {
const struct libinput_interface *interface; const struct libinput_interface *interface;
const struct libinput_interface_backend *interface_backend; const struct libinput_interface_backend *interface_backend;
libinput_log_handler log_handler;
enum libinput_log_priority log_priority;
void *user_data; void *user_data;
}; };
@ -88,17 +91,21 @@ struct libinput_device {
typedef void (*libinput_source_dispatch_t)(void *data); typedef void (*libinput_source_dispatch_t)(void *data);
#define log_debug(...) log_msg(LIBINPUT_LOG_PRIORITY_DEBUG, __VA_ARGS__) #define log_debug(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_DEBUG, __VA_ARGS__)
#define log_info(...) log_msg(LIBINPUT_LOG_PRIORITY_INFO, __VA_ARGS__) #define log_info(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_INFO, __VA_ARGS__)
#define log_error(...) log_msg(LIBINPUT_LOG_PRIORITY_ERROR, __VA_ARGS__) #define log_error(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, __VA_ARGS__)
#define log_bug_kernel(...) log_msg(LIBINPUT_LOG_PRIORITY_ERROR, "kernel bug: " __VA_ARGS__) #define log_bug_kernel(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, "kernel bug: " __VA_ARGS__)
#define log_bug_libinput(...) log_msg(LIBINPUT_LOG_PRIORITY_ERROR, "libinput bug: " __VA_ARGS__); #define log_bug_libinput(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, "libinput bug: " __VA_ARGS__);
#define log_bug_client(...) log_msg(LIBINPUT_LOG_PRIORITY_ERROR, "client bug: " __VA_ARGS__); #define log_bug_client(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, "client bug: " __VA_ARGS__);
void void
log_msg(enum libinput_log_priority priority, const char *format, ...); log_msg(struct libinput *libinput,
enum libinput_log_priority priority,
const char *format, ...);
void void
log_msg_va(enum libinput_log_priority priority, log_msg_va(struct libinput *libinput,
enum libinput_log_priority priority,
const char *format, const char *format,
va_list args); va_list args);

View file

@ -81,8 +81,8 @@ struct libinput_event_touch {
}; };
static void static void
libinput_default_log_func(enum libinput_log_priority priority, libinput_default_log_func(struct libinput *libinput,
void *data, enum libinput_log_priority priority,
const char *format, va_list args) const char *format, va_list args)
{ {
const char *prefix; const char *prefix;
@ -98,55 +98,47 @@ libinput_default_log_func(enum libinput_log_priority priority,
vfprintf(stderr, format, args); vfprintf(stderr, format, args);
} }
struct log_data {
enum libinput_log_priority priority;
libinput_log_handler handler;
void *user_data;
};
static struct log_data log_data = {
.priority = LIBINPUT_LOG_PRIORITY_ERROR,
.handler = libinput_default_log_func,
.user_data = NULL,
};
void void
log_msg_va(enum libinput_log_priority priority, log_msg_va(struct libinput *libinput,
enum libinput_log_priority priority,
const char *format, const char *format,
va_list args) va_list args)
{ {
if (log_data.handler && log_data.priority <= priority) if (libinput->log_handler &&
log_data.handler(priority, log_data.user_data, format, args); libinput->log_priority <= priority)
libinput->log_handler(libinput, priority, format, args);
} }
void void
log_msg(enum libinput_log_priority priority, const char *format, ...) log_msg(struct libinput *libinput,
enum libinput_log_priority priority,
const char *format, ...)
{ {
va_list args; va_list args;
va_start(args, format); va_start(args, format);
log_msg_va(priority, format, args); log_msg_va(libinput, priority, format, args);
va_end(args); va_end(args);
} }
LIBINPUT_EXPORT void LIBINPUT_EXPORT void
libinput_log_set_priority(enum libinput_log_priority priority) libinput_log_set_priority(struct libinput *libinput,
enum libinput_log_priority priority)
{ {
log_data.priority = priority; libinput->log_priority = priority;
} }
LIBINPUT_EXPORT enum libinput_log_priority LIBINPUT_EXPORT enum libinput_log_priority
libinput_log_get_priority(void) libinput_log_get_priority(const struct libinput *libinput)
{ {
return log_data.priority; return libinput->log_priority;
} }
LIBINPUT_EXPORT void LIBINPUT_EXPORT void
libinput_log_set_handler(libinput_log_handler log_handler, libinput_log_set_handler(struct libinput *libinput,
void *user_data) libinput_log_handler log_handler)
{ {
log_data.handler = log_handler; libinput->log_handler = log_handler;
log_data.user_data = user_data;
} }
static void static void
@ -499,6 +491,8 @@ libinput_init(struct libinput *libinput,
return -1; return -1;
} }
libinput->log_handler = libinput_default_log_func;
libinput->log_priority = LIBINPUT_LOG_PRIORITY_ERROR;
libinput->interface = interface; libinput->interface = interface;
libinput->interface_backend = interface_backend; libinput->interface_backend = interface_backend;
libinput->user_data = user_data; libinput->user_data = user_data;

View file

@ -1032,13 +1032,15 @@ libinput_destroy(struct libinput *libinput);
* *
* The default log priority is LIBINPUT_LOG_PRIORITY_ERROR. * The default log priority is LIBINPUT_LOG_PRIORITY_ERROR.
* *
* @param libinput A previously initialized libinput context
* @param priority The minimum priority of log messages to print. * @param priority The minimum priority of log messages to print.
* *
* @see libinput_log_set_handler * @see libinput_log_set_handler
* @see libinput_log_get_priority * @see libinput_log_get_priority
*/ */
void void
libinput_log_set_priority(enum libinput_log_priority priority); libinput_log_set_priority(struct libinput *libinput,
enum libinput_log_priority priority);
/** /**
* @ingroup base * @ingroup base
@ -1048,30 +1050,30 @@ libinput_log_set_priority(enum libinput_log_priority priority);
* *
* The default log priority is LIBINPUT_LOG_PRIORITY_ERROR. * The default log priority is LIBINPUT_LOG_PRIORITY_ERROR.
* *
* @param libinput A previously initialized libinput context
* @return The minimum priority of log messages to print. * @return The minimum priority of log messages to print.
* *
* @see libinput_log_set_handler * @see libinput_log_set_handler
* @see libinput_log_set_priority * @see libinput_log_set_priority
*/ */
enum libinput_log_priority enum libinput_log_priority
libinput_log_get_priority(void); libinput_log_get_priority(const struct libinput *libinput);
/** /**
* @ingroup base * @ingroup base
* *
* Log handler type for custom logging. * Log handler type for custom logging.
* *
* @param libinput The libinput context
* @param priority The priority of the current message * @param priority The priority of the current message
* @param user_data Caller-specific data pointer as previously passed into
* libinput_log_set_handler()
* @param format Message format in printf-style * @param format Message format in printf-style
* @param args Message arguments * @param args Message arguments
* *
* @see libinput_set_log_priority * @see libinput_set_log_priority
* @see libinput_log_set_handler * @see libinput_log_set_handler
*/ */
typedef void (*libinput_log_handler)(enum libinput_log_priority priority, typedef void (*libinput_log_handler)(struct libinput *libinput,
void *user_data, enum libinput_log_priority priority,
const char *format, va_list args) const char *format, va_list args)
LIBINPUT_ATTRIBUTE_PRINTF(3, 0); LIBINPUT_ATTRIBUTE_PRINTF(3, 0);
@ -1084,6 +1086,7 @@ typedef void (*libinput_log_handler)(enum libinput_log_priority priority,
* *
* The default log handler prints to stderr. * The default log handler prints to stderr.
* *
* @param libinput A previously initialized libinput context
* @param log_handler The log handler for library messages. * @param log_handler The log handler for library messages.
* @param user_data Caller-specific data pointer, passed into the log * @param user_data Caller-specific data pointer, passed into the log
* handler. * handler.
@ -1091,8 +1094,8 @@ typedef void (*libinput_log_handler)(enum libinput_log_priority priority,
* @see libinput_log_set_handler * @see libinput_log_set_handler
*/ */
void void
libinput_log_set_handler(libinput_log_handler log_handler, libinput_log_set_handler(struct libinput *libinput,
void *user_data); libinput_log_handler log_handler);
/** /**
* @defgroup seat Initialization and manipulation of seats * @defgroup seat Initialization and manipulation of seats

View file

@ -160,7 +160,9 @@ path_device_enable(struct path_input *input, const char *devnode)
if (path_get_udev_properties(devnode, &sysname, if (path_get_udev_properties(devnode, &sysname,
&seat_name, &seat_logical_name) == -1) { &seat_name, &seat_logical_name) == -1) {
log_info("failed to obtain sysname for device '%s'.\n", devnode); log_info(&input->base,
"failed to obtain sysname for device '%s'.\n",
devnode);
return NULL; return NULL;
} }
@ -171,7 +173,9 @@ path_device_enable(struct path_input *input, const char *devnode)
} else { } else {
seat = path_seat_create(input, seat_name, seat_logical_name); seat = path_seat_create(input, seat_name, seat_logical_name);
if (!seat) { if (!seat) {
log_info("failed to create seat for device '%s'.\n", devnode); log_info(&input->base,
"failed to create seat for device '%s'.\n",
devnode);
goto out; goto out;
} }
} }
@ -181,10 +185,14 @@ path_device_enable(struct path_input *input, const char *devnode)
if (device == EVDEV_UNHANDLED_DEVICE) { if (device == EVDEV_UNHANDLED_DEVICE) {
device = NULL; device = NULL;
log_info("not using input device '%s'.\n", devnode); log_info(&input->base,
"not using input device '%s'.\n",
devnode);
goto out; goto out;
} else if (device == NULL) { } else if (device == NULL) {
log_info("failed to create input device '%s'.\n", devnode); log_info(&input->base,
"failed to create input device '%s'.\n",
devnode);
goto out; goto out;
} }
@ -264,7 +272,7 @@ libinput_path_add_device(struct libinput *libinput,
struct libinput_device *device; struct libinput_device *device;
if (libinput->interface_backend != &interface_backend) { if (libinput->interface_backend != &interface_backend) {
log_bug_client("Mismatching backends.\n"); log_bug_client(libinput, "Mismatching backends.\n");
return NULL; return NULL;
} }
@ -301,7 +309,7 @@ libinput_path_remove_device(struct libinput_device *device)
struct path_device *dev; struct path_device *dev;
if (libinput->interface_backend != &interface_backend) { if (libinput->interface_backend != &interface_backend) {
log_bug_client("Mismatching backends.\n"); log_bug_client(libinput, "Mismatching backends.\n");
return; return;
} }

View file

@ -59,7 +59,7 @@ libinput_timer_arm_timer_fd(struct libinput *libinput)
r = timerfd_settime(libinput->timer.fd, TFD_TIMER_ABSTIME, &its, NULL); r = timerfd_settime(libinput->timer.fd, TFD_TIMER_ABSTIME, &its, NULL);
if (r) if (r)
log_error("timerfd_settime error: %s\n", strerror(errno)); log_error(libinput, "timerfd_settime error: %s\n", strerror(errno));
} }
void void
@ -96,7 +96,7 @@ libinput_timer_handler(void *data)
r = clock_gettime(CLOCK_MONOTONIC, &ts); r = clock_gettime(CLOCK_MONOTONIC, &ts);
if (r) { if (r) {
log_error("clock_gettime error: %s\n", strerror(errno)); log_error(libinput, "clock_gettime error: %s\n", strerror(errno));
return; return;
} }

View file

@ -80,10 +80,10 @@ device_added(struct udev_device *udev_device, struct udev_input *input)
libinput_seat_unref(&seat->base); libinput_seat_unref(&seat->base);
if (device == EVDEV_UNHANDLED_DEVICE) { if (device == EVDEV_UNHANDLED_DEVICE) {
log_info("not using input device '%s'.\n", devnode); log_info(&input->base, "not using input device '%s'.\n", devnode);
return 0; return 0;
} else if (device == NULL) { } else if (device == NULL) {
log_info("failed to create input device '%s'.\n", devnode); log_info(&input->base, "failed to create input device '%s'.\n", devnode);
return 0; return 0;
} }
@ -100,7 +100,8 @@ device_added(struct udev_device *udev_device, struct udev_input *input)
&device->abs.calibration[4], &device->abs.calibration[4],
&device->abs.calibration[5]) == 6) { &device->abs.calibration[5]) == 6) {
device->abs.apply_calibration = 1; device->abs.apply_calibration = 1;
log_info("Applying calibration: %f %f %f %f %f %f\n", log_info(&input->base,
"Applying calibration: %f %f %f %f %f %f\n",
device->abs.calibration[0], device->abs.calibration[0],
device->abs.calibration[1], device->abs.calibration[1],
device->abs.calibration[2], device->abs.calibration[2],
@ -128,7 +129,8 @@ device_removed(struct udev_device *udev_device, struct udev_input *input)
list_for_each_safe(device, next, list_for_each_safe(device, next,
&seat->base.devices_list, base.link) { &seat->base.devices_list, base.link) {
if (!strcmp(device->devnode, devnode)) { if (!strcmp(device->devnode, devnode)) {
log_info("input device %s, %s removed\n", log_info(&input->base,
"input device %s, %s removed\n",
device->devname, device->devnode); device->devname, device->devnode);
evdev_device_remove(device); evdev_device_remove(device);
break; break;
@ -243,7 +245,8 @@ udev_input_enable(struct libinput *libinput)
input->udev_monitor = udev_monitor_new_from_netlink(udev, "udev"); input->udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
if (!input->udev_monitor) { if (!input->udev_monitor) {
log_info("udev: failed to create the udev monitor\n"); log_info(libinput,
"udev: failed to create the udev monitor\n");
return -1; return -1;
} }
@ -251,7 +254,7 @@ udev_input_enable(struct libinput *libinput)
"input", NULL); "input", NULL);
if (udev_monitor_enable_receiving(input->udev_monitor)) { if (udev_monitor_enable_receiving(input->udev_monitor)) {
log_info("udev: failed to bind the udev monitor\n"); log_info(libinput, "udev: failed to bind the udev monitor\n");
udev_monitor_unref(input->udev_monitor); udev_monitor_unref(input->udev_monitor);
input->udev_monitor = NULL; input->udev_monitor = NULL;
return -1; return -1;
@ -369,7 +372,7 @@ libinput_udev_assign_seat(struct libinput *libinput,
return -1; return -1;
if (libinput->interface_backend != &interface_backend) { if (libinput->interface_backend != &interface_backend) {
log_bug_client("Mismatching backends.\n"); log_bug_client(libinput, "Mismatching backends.\n");
return -1; return -1;
} }

View file

@ -44,6 +44,7 @@
#include "libinput-util.h" #include "libinput-util.h"
static int in_debugger = -1; static int in_debugger = -1;
static int verbose = 0;
struct test { struct test {
struct list node; struct list node;
@ -250,8 +251,8 @@ litest_list_tests(struct list *tests)
} }
static void static void
litest_log_handler(enum libinput_log_priority pri, litest_log_handler(struct libinput *libinput,
void *user_data, enum libinput_log_priority pri,
const char *format, const char *format,
va_list args) va_list args)
{ {
@ -321,8 +322,7 @@ litest_run(int argc, char **argv) {
litest_list_tests(&all_tests); litest_list_tests(&all_tests);
return 0; return 0;
case 'v': case 'v':
libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_DEBUG); verbose = 1;
libinput_log_set_handler(litest_log_handler, NULL);
break; break;
default: default:
fprintf(stderr, "usage: %s [--list]\n", argv[0]); fprintf(stderr, "usage: %s [--list]\n", argv[0]);
@ -482,6 +482,11 @@ litest_create_context(void)
struct libinput *libinput = struct libinput *libinput =
libinput_path_create_context(&interface, NULL); libinput_path_create_context(&interface, NULL);
ck_assert_notnull(libinput); ck_assert_notnull(libinput);
libinput_log_set_handler(libinput, litest_log_handler);
if (verbose)
libinput_log_set_priority(libinput, LIBINPUT_LOG_PRIORITY_DEBUG);
return libinput; return libinput;
} }

View file

@ -32,7 +32,7 @@
#include "litest.h" #include "litest.h"
static int log_handler_called; static int log_handler_called;
static void *log_handler_userdata; static struct libinput *log_handler_context;
static int open_restricted(const char *path, int flags, void *data) static int open_restricted(const char *path, int flags, void *data)
{ {
@ -51,56 +51,41 @@ const struct libinput_interface simple_interface = {
}; };
static void static void
simple_log_handler(enum libinput_log_priority priority, simple_log_handler(struct libinput *libinput,
void *userdata, enum libinput_log_priority priority,
const char *format, const char *format,
va_list args) va_list args)
{ {
log_handler_called++; log_handler_called++;
ck_assert(userdata == log_handler_userdata); if (log_handler_context)
ck_assert(libinput == log_handler_context);
ck_assert(format != NULL); ck_assert(format != NULL);
} }
START_TEST(log_default_priority) START_TEST(log_default_priority)
{ {
enum libinput_log_priority pri; enum libinput_log_priority pri;
struct libinput *li;
pri = libinput_log_get_priority(); li = libinput_path_create_context(&simple_interface, NULL);
pri = libinput_log_get_priority(li);
ck_assert_int_eq(pri, LIBINPUT_LOG_PRIORITY_ERROR); ck_assert_int_eq(pri, LIBINPUT_LOG_PRIORITY_ERROR);
libinput_destroy(li);
} }
END_TEST END_TEST
START_TEST(log_handler_invoked) START_TEST(log_handler_invoked)
{ {
struct libinput *li; struct libinput *li;
enum libinput_log_priority pri = libinput_log_get_priority();
libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_DEBUG);
libinput_log_set_handler(simple_log_handler, NULL);
log_handler_userdata = NULL;
li = libinput_path_create_context(&simple_interface, NULL); li = libinput_path_create_context(&simple_interface, NULL);
libinput_path_add_device(li, "/tmp");
ck_assert_int_gt(log_handler_called, 0); libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG);
log_handler_called = 0; libinput_log_set_handler(li, simple_log_handler);
log_handler_context = li;
libinput_destroy(li);
libinput_log_set_priority(pri);
}
END_TEST
START_TEST(log_userdata_NULL)
{
struct libinput *li;
enum libinput_log_priority pri = libinput_log_get_priority();
libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_DEBUG);
libinput_log_set_handler(simple_log_handler, NULL);
log_handler_userdata = NULL;
li = libinput_path_create_context(&simple_interface, NULL);
libinput_path_add_device(li, "/tmp"); libinput_path_add_device(li, "/tmp");
ck_assert_int_gt(log_handler_called, 0); ck_assert_int_gt(log_handler_called, 0);
@ -108,73 +93,48 @@ START_TEST(log_userdata_NULL)
libinput_destroy(li); libinput_destroy(li);
libinput_log_set_priority(pri); log_handler_context = NULL;
}
END_TEST
START_TEST(log_userdata)
{
struct libinput *li;
enum libinput_log_priority pri = libinput_log_get_priority();
libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_DEBUG);
libinput_log_set_handler(simple_log_handler, &li);
log_handler_userdata = &li;
li = libinput_path_create_context(&simple_interface, NULL);
libinput_path_add_device(li, "/tmp");
ck_assert_int_gt(log_handler_called, 0);
log_handler_called = 0;
libinput_destroy(li);
libinput_log_set_priority(pri);
} }
END_TEST END_TEST
START_TEST(log_handler_NULL) START_TEST(log_handler_NULL)
{ {
struct libinput *li; struct libinput *li;
enum libinput_log_priority pri = libinput_log_get_priority();
libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_DEBUG);
libinput_log_set_handler(NULL, NULL);
log_handler_userdata = NULL;
li = libinput_path_create_context(&simple_interface, NULL); li = libinput_path_create_context(&simple_interface, NULL);
libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG);
libinput_log_set_handler(li, NULL);
libinput_path_add_device(li, "/tmp"); libinput_path_add_device(li, "/tmp");
ck_assert_int_eq(log_handler_called, 0); ck_assert_int_eq(log_handler_called, 0);
log_handler_called = 0; log_handler_called = 0;
libinput_log_set_handler(simple_log_handler, NULL);
libinput_destroy(li); libinput_destroy(li);
libinput_log_set_priority(pri);
} }
END_TEST END_TEST
START_TEST(log_priority) START_TEST(log_priority)
{ {
struct libinput *li; struct libinput *li;
enum libinput_log_priority pri = libinput_log_get_priority();
libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_ERROR);
libinput_log_set_handler(simple_log_handler, NULL);
log_handler_userdata = NULL;
li = libinput_path_create_context(&simple_interface, NULL); li = libinput_path_create_context(&simple_interface, NULL);
libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_ERROR);
libinput_log_set_handler(li, simple_log_handler);
log_handler_context = li;
libinput_path_add_device(li, "/tmp"); libinput_path_add_device(li, "/tmp");
ck_assert_int_eq(log_handler_called, 0); ck_assert_int_eq(log_handler_called, 0);
libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_INFO); libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_INFO);
libinput_path_add_device(li, "/tmp"); libinput_path_add_device(li, "/tmp");
ck_assert_int_gt(log_handler_called, 0); ck_assert_int_gt(log_handler_called, 0);
log_handler_called = 0; log_handler_called = 0;
libinput_destroy(li); libinput_destroy(li);
libinput_log_set_priority(pri); log_handler_context = NULL;
} }
END_TEST END_TEST
@ -182,8 +142,6 @@ int main (int argc, char **argv) {
litest_add_no_device("log:defaults", log_default_priority); litest_add_no_device("log:defaults", log_default_priority);
litest_add_no_device("log:logging", log_handler_invoked); litest_add_no_device("log:logging", log_handler_invoked);
litest_add_no_device("log:logging", log_handler_NULL); litest_add_no_device("log:logging", log_handler_NULL);
litest_add_no_device("log:logging", log_userdata);
litest_add_no_device("log:logging", log_userdata_NULL);
litest_add_no_device("log:logging", log_priority); litest_add_no_device("log:logging", log_priority);
return litest_run(argc, argv); return litest_run(argc, argv);

View file

@ -131,6 +131,15 @@ static const struct libinput_interface interface = {
.close_restricted = close_restricted, .close_restricted = close_restricted,
}; };
static void
log_handler(struct libinput *li,
enum libinput_log_priority priority,
const char *format,
va_list args)
{
vprintf(format, args);
}
static int static int
open_udev(struct libinput **li) open_udev(struct libinput **li)
{ {
@ -146,6 +155,11 @@ open_udev(struct libinput **li)
return 1; return 1;
} }
if (verbose) {
libinput_log_set_handler(*li, log_handler);
libinput_log_set_priority(*li, LIBINPUT_LOG_PRIORITY_DEBUG);
}
if (libinput_udev_assign_seat(*li, seat)) { if (libinput_udev_assign_seat(*li, seat)) {
fprintf(stderr, "Failed to set seat\n"); fprintf(stderr, "Failed to set seat\n");
libinput_destroy(*li); libinput_destroy(*li);
@ -166,6 +180,11 @@ open_device(struct libinput **li, const char *path)
return 1; return 1;
} }
if (verbose) {
libinput_log_set_handler(*li, log_handler);
libinput_log_set_priority(*li, LIBINPUT_LOG_PRIORITY_DEBUG);
}
device = libinput_path_add_device(*li, path); device = libinput_path_add_device(*li, path);
if (!device) { if (!device) {
fprintf(stderr, "Failed to initialized device %s\n", path); fprintf(stderr, "Failed to initialized device %s\n", path);
@ -447,15 +466,6 @@ mainloop(struct libinput *li)
close(fds[1].fd); close(fds[1].fd);
} }
static void
log_handler(enum libinput_log_priority priority,
void *user_data,
const char *format,
va_list args)
{
vprintf(format, args);
}
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
@ -465,11 +475,6 @@ main(int argc, char **argv)
if (parse_args(argc, argv)) if (parse_args(argc, argv))
return 1; return 1;
if (verbose) {
libinput_log_set_handler(log_handler, NULL);
libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_DEBUG);
}
if (mode == MODE_UDEV) { if (mode == MODE_UDEV) {
if (open_udev(&li)) if (open_udev(&li))
return 1; return 1;