Hi, On 06/13/2014 04:48 AM, Peter Hutterer wrote: > 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 log handler and the log priority is now a part of the libinput interface. > We can drop the various setters and getters, the caller owns the struct anyway > so we don't need functions to give it those values. > > 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. > > There is no need for a default log function anymore. Any serious caller should > hook into it anyway, those that don't care can just use NULL. > > There is no default log priority anymore, a caller must set the desired > priority in the interface. > > Signed-off-by: Peter Hutterer <[email protected]> > --- > There's a side-effect to this that I'm not sure is intended. We don't copy > the interface into libinput, we merely keep a reference. The caller is > already able to change open_restricted/close_restricted at runtime, though > we can't do this ourselves (it's const). > > Given that, I figured we can leave the log handler and priority up to the > caller as well then, switching at runtime. That's the main reason for > dropping the set/get priority calls. If that side effect wasn't intended, > then we'll have rework a few things. Jonas? > > src/evdev-mt-touchpad-buttons.c | 15 +++-- > src/evdev-mt-touchpad-tap.c | 13 ++++- > src/evdev.c | 23 +++++--- > src/libinput-private.h | 20 ++++--- > src/libinput.c | 73 ++++++----------------- > src/libinput.h | 99 +++++++++---------------------- > src/path.c | 20 +++++-- > src/timer.c | 4 +- > src/udev-seat.c | 17 +++--- > test/litest.c | 9 +-- > test/log.c | 126 > ++++++++++++++-------------------------- > test/misc.c | 2 + > test/path.c | 2 + > test/udev.c | 7 ++- > tools/event-debug.c | 28 ++++----- > 15 files changed, 194 insertions(+), 264 deletions(-) > > diff --git a/src/evdev-mt-touchpad-buttons.c b/src/evdev-mt-touchpad-buttons.c > index ce48ed0..b86f344 100644 > --- a/src/evdev-mt-touchpad-buttons.c > +++ b/src/evdev-mt-touchpad-buttons.c > @@ -452,6 +452,7 @@ tp_button_handle_event(struct tp_dispatch *tp, > enum button_event event, > uint64_t time) > { > + struct libinput *libinput = tp->device->base.seat->libinput; > enum button_state current = t->button.state; > > switch(t->button.state) { > @@ -485,7 +486,8 @@ tp_button_handle_event(struct tp_dispatch *tp, > } > > 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_event_to_str(event), > button_state_to_str(t->button.state)); > @@ -538,11 +540,13 @@ tp_process_button(struct tp_dispatch *tp, > const struct input_event *e, > uint64_t time) > { > + struct libinput *libinput = tp->device->base.seat->libinput; > uint32_t mask = 1 << (e->code - BTN_LEFT); > > /* Ignore other buttons on clickpads */ > 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)); > return 0; > } > @@ -562,6 +566,7 @@ int > tp_init_buttons(struct tp_dispatch *tp, > struct evdev_device *device) > { > + struct libinput *libinput = tp->device->base.seat->libinput; > struct tp_touch *t; > int width, height; > double diagonal; > @@ -574,10 +579,12 @@ tp_init_buttons(struct tp_dispatch *tp, > if (libevdev_has_event_code(device->evdev, EV_KEY, BTN_MIDDLE) || > libevdev_has_event_code(device->evdev, EV_KEY, BTN_RIGHT)) { > if (tp->buttons.is_clickpad) > - log_bug_kernel("clickpad advertising right button\n"); > + log_bug_kernel(libinput, > + "clickpad advertising right button\n"); > } else { > if (!tp->buttons.is_clickpad) > - log_bug_kernel("non clickpad without right button?\n"); > + log_bug_kernel(libinput, > + "non clickpad without right button?\n"); > } > > width = abs(device->abs.max_x - device->abs.min_x); > diff --git a/src/evdev-mt-touchpad-tap.c b/src/evdev-mt-touchpad-tap.c > index 34bb0d0..2541218 100644 > --- a/src/evdev-mt-touchpad-tap.c > +++ b/src/evdev-mt-touchpad-tap.c > @@ -130,6 +130,7 @@ tp_tap_clear_timer(struct tp_dispatch *tp) > static void > 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) { > case TAP_EVENT_TOUCH: > @@ -138,7 +139,8 @@ tp_tap_idle_handle_event(struct tp_dispatch *tp, enum > tap_event event, uint64_t > break; > case TAP_EVENT_RELEASE: > 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; > case TAP_EVENT_TIMEOUT: > break; > @@ -197,11 +199,13 @@ tp_tap_hold_handle_event(struct tp_dispatch *tp, enum > tap_event event, uint64_t > static void > 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) { > case TAP_EVENT_MOTION: > 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; > case TAP_EVENT_TOUCH: > 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 > 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; > + > if (!tp->tap.enabled) > 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) > 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_event_to_str(event), > tap_state_to_str(tp->tap.state)); > diff --git a/src/evdev.c b/src/evdev.c > index 51ad5e3..e099060 100644 > --- a/src/evdev.c > +++ b/src/evdev.c > @@ -110,6 +110,7 @@ evdev_device_transform_y(struct evdev_device *device, > static void > evdev_flush_pending_event(struct evdev_device *device, uint64_t time) > { > + struct libinput *libinput = device->base.seat->libinput; > struct motion_params motion; > int32_t cx, cy; > double x, y; > @@ -142,7 +143,8 @@ evdev_flush_pending_event(struct evdev_device *device, > uint64_t time) > break; > > 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); > break; > } > @@ -191,7 +193,8 @@ evdev_flush_pending_event(struct evdev_device *device, > uint64_t time) > break; > > 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); > break; > } > @@ -586,6 +589,7 @@ configure_pointer_acceleration(struct evdev_device > *device) > static int > evdev_configure_device(struct evdev_device *device) > { > + struct libinput *libinput = device->base.seat->libinput; > struct libevdev *evdev = device->evdev; > const struct input_absinfo *absinfo; > int has_abs, has_rel, has_mt; > @@ -670,7 +674,8 @@ evdev_configure_device(struct evdev_device *device) > !libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_PEN) && > (has_abs || has_mt)) { > 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); > } > for (i = KEY_ESC; i < KEY_MAX; i++) { > @@ -699,7 +704,8 @@ evdev_configure_device(struct evdev_device *device) > > 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, > has_abs ? " absolute-motion" : "", > has_rel ? " relative-motion": "", > @@ -707,12 +713,14 @@ evdev_configure_device(struct evdev_device *device) > } > if (has_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); > } > if (has_touch && !has_button) { > 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); > } > > @@ -735,7 +743,8 @@ evdev_device_create(struct libinput_seat *seat, > * read. mtdev_get() also expects this. */ > fd = open_restricted(libinput, devnode, O_RDWR | O_NONBLOCK); > 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)); > return NULL; > } > diff --git a/src/libinput-private.h b/src/libinput-private.h > index f0bda1f..43a4b88 100644 > --- a/src/libinput-private.h > +++ b/src/libinput-private.h > @@ -88,17 +88,21 @@ struct libinput_device { > typedef void (*libinput_source_dispatch_t)(void *data); > > > -#define log_debug(...) log_msg(LIBINPUT_LOG_PRIORITY_DEBUG, __VA_ARGS__) > -#define log_info(...) log_msg(LIBINPUT_LOG_PRIORITY_INFO, __VA_ARGS__) > -#define log_error(...) log_msg(LIBINPUT_LOG_PRIORITY_ERROR, __VA_ARGS__) > -#define log_bug_kernel(...) log_msg(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_client(...) log_msg(LIBINPUT_LOG_PRIORITY_ERROR, "client > bug: " __VA_ARGS__); > +#define log_debug(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_DEBUG, > __VA_ARGS__) > +#define log_info(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_INFO, > __VA_ARGS__) > +#define log_error(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, > __VA_ARGS__) > +#define log_bug_kernel(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, > "kernel bug: " __VA_ARGS__) > +#define log_bug_libinput(li_, ...) log_msg((li_), > LIBINPUT_LOG_PRIORITY_ERROR, "libinput bug: " __VA_ARGS__); > +#define log_bug_client(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, > "client bug: " __VA_ARGS__); > > void > -log_msg(enum libinput_log_priority priority, const char *format, ...); > +log_msg(const struct libinput *libinput, > + enum libinput_log_priority priority, > + const char *format, ...); > + > void > -log_msg_va(enum libinput_log_priority priority, > +log_msg_va(const struct libinput *libinput, > + enum libinput_log_priority priority, > const char *format, > va_list args); > > diff --git a/src/libinput.c b/src/libinput.c > index 5b10a10..5521375 100644 > --- a/src/libinput.c > +++ b/src/libinput.c > @@ -80,75 +80,29 @@ struct libinput_event_touch { > double y; > }; > > -static void > -libinput_default_log_func(enum libinput_log_priority priority, > - void *data, > - const char *format, va_list args) > -{ > - const char *prefix; > - > - switch(priority) { > - case LIBINPUT_LOG_PRIORITY_DEBUG: prefix = "debug"; break; > - case LIBINPUT_LOG_PRIORITY_INFO: prefix = "info"; break; > - case LIBINPUT_LOG_PRIORITY_ERROR: prefix = "error"; break; > - default: prefix="<invalid priority>"; break; > - } > - > - fprintf(stderr, "libinput %s: ", prefix); > - 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 > -log_msg_va(enum libinput_log_priority priority, > +log_msg_va(const struct libinput *libinput, > + enum libinput_log_priority priority, > const char *format, > va_list args) > { > - if (log_data.handler && log_data.priority <= priority) > - log_data.handler(priority, log_data.user_data, format, args); > + if (libinput->interface->log_handler && > + libinput->interface->log_priority <= priority) > + libinput->interface->log_handler(libinput, priority, format, > args); > } > > void > -log_msg(enum libinput_log_priority priority, const char *format, ...) > +log_msg(const struct libinput *libinput, > + enum libinput_log_priority priority, > + const char *format, ...) > { > va_list args; > > va_start(args, format); > - log_msg_va(priority, format, args); > + log_msg_va(libinput, priority, format, args); > va_end(args); > } > > -LIBINPUT_EXPORT void > -libinput_log_set_priority(enum libinput_log_priority priority) > -{ > - log_data.priority = priority; > -} > - > -LIBINPUT_EXPORT enum libinput_log_priority > -libinput_log_get_priority(void) > -{ > - return log_data.priority; > -} > - > -LIBINPUT_EXPORT void > -libinput_log_set_handler(libinput_log_handler log_handler, > - void *user_data) > -{ > - log_data.handler = log_handler; > - log_data.user_data = user_data; > -} > - > static void > libinput_post_event(struct libinput *libinput, > struct libinput_event *event); > @@ -476,6 +430,15 @@ libinput_init(struct libinput *libinput, > const struct libinput_interface_backend *interface_backend, > void *user_data) > { > + switch (interface->log_priority) { > + case LIBINPUT_LOG_PRIORITY_DEBUG: > + case LIBINPUT_LOG_PRIORITY_INFO: > + case LIBINPUT_LOG_PRIORITY_ERROR: > + break; > + default: > + return -1; > + } > + > libinput->epoll_fd = epoll_create1(EPOLL_CLOEXEC);; > if (libinput->epoll_fd < 0) > return -1; > diff --git a/src/libinput.h b/src/libinput.h > index 4501c66..c48d708 100644 > --- a/src/libinput.h > +++ b/src/libinput.h > @@ -759,6 +759,23 @@ libinput_event_touch_get_base_event(struct > libinput_event_touch *event); > * @defgroup base Initialization and manipulation of libinput contexts > */ > > +/** > + * @ingroup base > + * > + * Log handler type for custom logging. > + * > + * @param libinput The libinput context > + * @param priority The priority of the current message > + * @param format Message format in printf-style > + * @param args Message arguments > + * > + * @see libinput_set_log_priority > + */ > +typedef void (*libinput_log_handler)(const struct libinput *libinput, > + enum libinput_log_priority priority, > + const char *format, va_list args) > + LIBINPUT_ATTRIBUTE_PRINTF(3, 0); > + > struct libinput_interface { > /** > * Open the device at the given path with the flags provided and > @@ -780,6 +797,18 @@ struct libinput_interface { > * libinput_udev_create_for_seat() > */ > void (*close_restricted)(int fd, void *user_data); > + > + /** > + * The log handler to be called for internal log messages. Using > + * NULL is permitted but not recommended. > + */ > + libinput_log_handler log_handler; > + > + /** > + * The log priority for this context. This priority may be changed > + * at runtime and takes effect for the next log message. > + */ > + enum libinput_log_priority log_priority; > }; > > /** > @@ -1025,76 +1054,6 @@ void > libinput_destroy(struct libinput *libinput); > > /** > - * @ingroup base > - * > - * Set the global log priority. Messages with priorities equal to or > - * higher than the argument will be printed to the current log handler. > - * > - * The default log priority is LIBINPUT_LOG_PRIORITY_ERROR. > - * > - * @param priority The minimum priority of log messages to print. > - * > - * @see libinput_log_set_handler > - * @see libinput_log_get_priority > - */ > -void > -libinput_log_set_priority(enum libinput_log_priority priority); > - > -/** > - * @ingroup base > - * > - * Get the global log priority. Messages with priorities equal to or > - * higher than the argument will be printed to the current log handler. > - * > - * The default log priority is LIBINPUT_LOG_PRIORITY_ERROR. > - * > - * @return The minimum priority of log messages to print. > - * > - * @see libinput_log_set_handler > - * @see libinput_log_set_priority > - */ > -enum libinput_log_priority > -libinput_log_get_priority(void); > - > -/** > - * @ingroup base > - * > - * Log handler type for custom logging. > - * > - * @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 args Message arguments > - * > - * @see libinput_set_log_priority > - * @see libinput_log_set_handler > - */ > -typedef void (*libinput_log_handler)(enum libinput_log_priority priority, > - void *user_data, > - const char *format, va_list args) > - LIBINPUT_ATTRIBUTE_PRINTF(3, 0); > - > -/** > - * @ingroup base > - * > - * Set the global log handler. Messages with priorities equal to or higher > - * than the current log priority will be passed to the given > - * log handler. > - * > - * The default log handler prints to stderr. > - * > - * @param log_handler The log handler for library messages. > - * @param user_data Caller-specific data pointer, passed into the log > - * handler. > - * > - * @see libinput_log_set_handler > - */ > -void > -libinput_log_set_handler(libinput_log_handler log_handler, > - void *user_data); > - > -/** > * @defgroup seat Initialization and manipulation of seats > * > * A seat has two identifiers, the physical name and the logical name. The
Your removing a bunch of exported symbols here, so you should also bump the soname to indicate ABI breakage. Other then that this looks good to me and is: Reviewed-by: Hans de Goede <[email protected]> Regards, Hans > diff --git a/src/path.c b/src/path.c > index 27e5ad6..e9c0ee8 100644 > --- a/src/path.c > +++ b/src/path.c > @@ -160,7 +160,9 @@ path_device_enable(struct path_input *input, const char > *devnode) > > if (path_get_udev_properties(devnode, &sysname, > &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; > } > > @@ -171,7 +173,9 @@ path_device_enable(struct path_input *input, const char > *devnode) > } else { > seat = path_seat_create(input, seat_name, seat_logical_name); > 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; > } > } > @@ -181,10 +185,14 @@ path_device_enable(struct path_input *input, const char > *devnode) > > if (device == EVDEV_UNHANDLED_DEVICE) { > device = NULL; > - log_info("not using input device '%s'.\n", devnode); > + log_info(&input->base, > + "not using input device '%s'.\n", > + devnode); > goto out; > } 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; > } > > @@ -264,7 +272,7 @@ libinput_path_add_device(struct libinput *libinput, > struct libinput_device *device; > > if (libinput->interface_backend != &interface_backend) { > - log_bug_client("Mismatching backends.\n"); > + log_bug_client(libinput, "Mismatching backends.\n"); > return NULL; > } > > @@ -301,7 +309,7 @@ libinput_path_remove_device(struct libinput_device > *device) > struct path_device *dev; > > if (libinput->interface_backend != &interface_backend) { > - log_bug_client("Mismatching backends.\n"); > + log_bug_client(libinput, "Mismatching backends.\n"); > return; > } > > diff --git a/src/timer.c b/src/timer.c > index 65fdd17..f546185 100644 > --- a/src/timer.c > +++ b/src/timer.c > @@ -59,7 +59,7 @@ libinput_timer_arm_timer_fd(struct libinput *libinput) > > r = timerfd_settime(libinput->timer.fd, TFD_TIMER_ABSTIME, &its, NULL); > if (r) > - log_error("timerfd_settime error: %s\n", strerror(errno)); > + log_error(libinput, "timerfd_settime error: %s\n", > strerror(errno)); > } > > void > @@ -96,7 +96,7 @@ libinput_timer_handler(void *data) > > r = clock_gettime(CLOCK_MONOTONIC, &ts); > if (r) { > - log_error("clock_gettime error: %s\n", strerror(errno)); > + log_error(libinput, "clock_gettime error: %s\n", > strerror(errno)); > return; > } > > diff --git a/src/udev-seat.c b/src/udev-seat.c > index 1e1307b..1758b4e 100644 > --- a/src/udev-seat.c > +++ b/src/udev-seat.c > @@ -80,10 +80,10 @@ device_added(struct udev_device *udev_device, struct > udev_input *input) > libinput_seat_unref(&seat->base); > > 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; > } 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; > } > > @@ -100,7 +100,8 @@ device_added(struct udev_device *udev_device, struct > udev_input *input) > &device->abs.calibration[4], > &device->abs.calibration[5]) == 6) { > 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[1], > 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, > &seat->base.devices_list, base.link) { > 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); > evdev_device_remove(device); > break; > @@ -243,7 +245,8 @@ udev_input_enable(struct libinput *libinput) > > input->udev_monitor = udev_monitor_new_from_netlink(udev, "udev"); > 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; > } > > @@ -251,7 +254,7 @@ udev_input_enable(struct libinput *libinput) > "input", NULL); > > 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); > input->udev_monitor = NULL; > return -1; > @@ -367,7 +370,7 @@ libinput_udev_set_seat(struct libinput *libinput, > return -1; > > if (libinput->interface_backend != &interface_backend) { > - log_bug_client("Mismatching backends.\n"); > + log_bug_client(libinput, "Mismatching backends.\n"); > return -1; > } > > diff --git a/test/litest.c b/test/litest.c > index d3f8f0d..560e8e5 100644 > --- a/test/litest.c > +++ b/test/litest.c > @@ -250,8 +250,8 @@ litest_list_tests(struct list *tests) > } > > static void > -litest_log_handler(enum libinput_log_priority pri, > - void *user_data, > +litest_log_handler(const struct libinput *libinput, > + enum libinput_log_priority pri, > const char *format, > va_list args) > { > @@ -282,6 +282,8 @@ close_restricted(int fd, void *userdata) > struct libinput_interface interface = { > .open_restricted = open_restricted, > .close_restricted = close_restricted, > + .log_handler = litest_log_handler, > + .log_priority = LIBINPUT_LOG_PRIORITY_ERROR, > }; > > static const struct option opts[] = { > @@ -321,8 +323,7 @@ litest_run(int argc, char **argv) { > litest_list_tests(&all_tests); > return 0; > case 'v': > - > libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_DEBUG); > - libinput_log_set_handler(litest_log_handler, > NULL); > + interface.log_priority = > LIBINPUT_LOG_PRIORITY_DEBUG; > break; > default: > fprintf(stderr, "usage: %s [--list]\n", > argv[0]); > diff --git a/test/log.c b/test/log.c > index a281820..a430c03 100644 > --- a/test/log.c > +++ b/test/log.c > @@ -30,9 +30,10 @@ > #include <unistd.h> > > #include "litest.h" > +#include "libinput-util.h" > > static int log_handler_called; > -static void *log_handler_userdata; > +static struct libinput *log_context; > > static int open_restricted(const char *path, int flags, void *data) > { > @@ -45,146 +46,109 @@ static void close_restricted(int fd, void *data) > close(fd); > } > > -const struct libinput_interface simple_interface = { > - .open_restricted = open_restricted, > - .close_restricted = close_restricted, > -}; > - > static void > -simple_log_handler(enum libinput_log_priority priority, > - void *userdata, > +simple_log_handler(const struct libinput *libinput, > + enum libinput_log_priority priority, > const char *format, > va_list args) > { > log_handler_called++; > - ck_assert(userdata == log_handler_userdata); > ck_assert(format != NULL); > + ck_assert(libinput != NULL); > + if (log_context) > + ck_assert(libinput == log_context); > } > > -START_TEST(log_default_priority) > +struct libinput_interface simple_interface = { > + .open_restricted = open_restricted, > + .close_restricted = close_restricted, > + .log_handler = simple_log_handler, > + .log_priority = LIBINPUT_LOG_PRIORITY_DEBUG, > +}; > + > +static void > +simple_interface_reset(void) > { > - enum libinput_log_priority pri; > + simple_interface.open_restricted = open_restricted; > + simple_interface.close_restricted = close_restricted; > + simple_interface.log_handler = simple_log_handler; > + simple_interface.log_priority = LIBINPUT_LOG_PRIORITY_DEBUG; > > - pri = libinput_log_get_priority(); > - > - ck_assert_int_eq(pri, LIBINPUT_LOG_PRIORITY_ERROR); > + log_context = NULL; > + log_handler_called = 0; > } > -END_TEST > > START_TEST(log_handler_invoked) > { > 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"); > - > - ck_assert_int_gt(log_handler_called, 0); > - log_handler_called = 0; > - > - 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"); > - > - ck_assert_int_gt(log_handler_called, 0); > - log_handler_called = 0; > - > - libinput_destroy(li); > + ck_assert_notnull(li); > + log_context = li; > > - libinput_log_set_priority(pri); > -} > -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); > + simple_interface_reset(); > } > END_TEST > > START_TEST(log_handler_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(NULL, NULL); > - log_handler_userdata = NULL; > > + simple_interface.log_handler = NULL; > + simple_interface.log_priority = LIBINPUT_LOG_PRIORITY_DEBUG; > li = libinput_path_create_context(&simple_interface, NULL); > libinput_path_add_device(li, "/tmp"); > > ck_assert_int_eq(log_handler_called, 0); > - log_handler_called = 0; > - libinput_log_set_handler(simple_log_handler, NULL); > > libinput_destroy(li); > - libinput_log_set_priority(pri); > + simple_interface_reset(); > } > END_TEST > > START_TEST(log_priority) > { > 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; > + simple_interface.log_priority = LIBINPUT_LOG_PRIORITY_ERROR; > > li = libinput_path_create_context(&simple_interface, NULL); > libinput_path_add_device(li, "/tmp"); > > ck_assert_int_eq(log_handler_called, 0); > > - libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_INFO); > + simple_interface.log_priority = LIBINPUT_LOG_PRIORITY_INFO; > 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); > + simple_interface_reset(); > +} > +END_TEST > + > +START_TEST(log_invalid_priority) > +{ > + struct libinput *li; > + > + simple_interface.log_priority = 0xFF; > + > + li = libinput_path_create_context(&simple_interface, NULL); > + ck_assert(li == NULL); > + > + simple_interface_reset(); > } > END_TEST > > int main (int argc, char **argv) { > - 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_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_invalid_priority); > > return litest_run(argc, argv); > } > diff --git a/test/misc.c b/test/misc.c > index 133bdb6..f4a3c43 100644 > --- a/test/misc.c > +++ b/test/misc.c > @@ -43,6 +43,8 @@ static void close_restricted(int fd, void *data) > const struct libinput_interface simple_interface = { > .open_restricted = open_restricted, > .close_restricted = close_restricted, > + .log_handler = NULL, > + .log_priority = LIBINPUT_LOG_PRIORITY_ERROR, > }; > > static struct libevdev_uinput * > diff --git a/test/path.c b/test/path.c > index 24f60e0..20553c3 100644 > --- a/test/path.c > +++ b/test/path.c > @@ -51,6 +51,8 @@ static void close_restricted(int fd, void *data) > const struct libinput_interface simple_interface = { > .open_restricted = open_restricted, > .close_restricted = close_restricted, > + .log_handler = NULL, > + .log_priority = LIBINPUT_LOG_PRIORITY_ERROR, > }; > > > diff --git a/test/udev.c b/test/udev.c > index 996bc02..5684718 100644 > --- a/test/udev.c > +++ b/test/udev.c > @@ -45,13 +45,14 @@ static void close_restricted(int fd, void *data) > const struct libinput_interface simple_interface = { > .open_restricted = open_restricted, > .close_restricted = close_restricted, > + .log_handler = NULL, > + .log_priority = LIBINPUT_LOG_PRIORITY_ERROR, > }; > > > START_TEST(udev_create_NULL) > { > struct libinput *li; > - const struct libinput_interface interface; > struct udev *udev; > > udev = udev_new(); > @@ -59,13 +60,13 @@ START_TEST(udev_create_NULL) > li = libinput_udev_create_context(NULL, NULL, NULL); > ck_assert(li == NULL); > > - li = libinput_udev_create_context(&interface, NULL, NULL); > + li = libinput_udev_create_context(&simple_interface, NULL, NULL); > ck_assert(li == NULL); > > li = libinput_udev_create_context(NULL, NULL, udev); > ck_assert(li == NULL); > > - li = libinput_udev_create_context(&interface, NULL, udev); > + li = libinput_udev_create_context(&simple_interface, NULL, udev); > ck_assert(li != NULL); > ck_assert_int_eq(libinput_udev_set_seat(li, NULL), -1); > libinput_destroy(li); > diff --git a/tools/event-debug.c b/tools/event-debug.c > index af3f648..e3df8dd 100644 > --- a/tools/event-debug.c > +++ b/tools/event-debug.c > @@ -126,9 +126,20 @@ close_restricted(int fd, void *user_data) > close(fd); > } > > -static const struct libinput_interface interface = { > +static void > +log_handler(const struct libinput *li, > + enum libinput_log_priority priority, > + const char *format, > + va_list args) > +{ > + vprintf(format, args); > +} > + > +static struct libinput_interface interface = { > .open_restricted = open_restricted, > .close_restricted = close_restricted, > + .log_handler = log_handler, > + .log_priority = LIBINPUT_LOG_PRIORITY_ERROR, > }; > > static int > @@ -438,15 +449,6 @@ mainloop(struct libinput *li) > 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 > main(int argc, char **argv) > { > @@ -456,10 +458,8 @@ main(int argc, char **argv) > if (parse_args(argc, argv)) > return 1; > > - if (verbose) { > - libinput_log_set_handler(log_handler, NULL); > - libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_DEBUG); > - } > + if (verbose) > + interface.log_priority = LIBINPUT_LOG_PRIORITY_DEBUG; > > if (mode == MODE_UDEV) { > if (open_udev(&li)) > _______________________________________________ wayland-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/wayland-devel
