Change the logging system to be per-context
authorPeter Hutterer <peter.hutterer@who-t.net>
Wed, 18 Jun 2014 09:51:19 +0000 (19:51 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Mon, 23 Jun 2014 05:39:08 +0000 (15:39 +1000)
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>
12 files changed:
src/evdev-mt-touchpad-buttons.c
src/evdev-mt-touchpad-tap.c
src/evdev.c
src/libinput-private.h
src/libinput.c
src/libinput.h
src/path.c
src/timer.c
src/udev-seat.c
test/litest.c
test/log.c
tools/event-debug.c

index 45d5d703d46323cb628b4d1c9b63167c99b90d3f..2ac231c7bb9d212579864c4ba3f10647d4a7d550 100644 (file)
@@ -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;
@@ -575,10 +580,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");
        }
 
        absinfo_x = device->abs.absinfo_x;
index 34bb0d0bccc9d10c0d37b7024cc1a9357ef33ed6..2541218473d5532049865ed05294fdbb37dc1367 100644 (file)
@@ -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));
index 63eaa4dfaa32a0500af21a7815b5b31f009bec43..f72bd43e0ac1cd590476d3358b66d04bb5497414 100644 (file)
@@ -115,6 +115,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;
@@ -147,7 +148,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;
                }
@@ -196,7 +198,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;
                }
@@ -591,6 +594,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;
        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) &&
                    (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++) {
@@ -725,7 +730,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": "",
@@ -733,12 +739,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);
        }
 
@@ -761,7 +769,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;
        }
index 4a92fb95af8807ef5a4d248c663baee56d9a04aa..e3d9bb1e33b4431333c9279ea0a4410cfaee8b29 100644 (file)
@@ -56,6 +56,9 @@ struct libinput {
 
        const struct libinput_interface *interface;
        const struct libinput_interface_backend *interface_backend;
+
+       libinput_log_handler log_handler;
+       enum libinput_log_priority log_priority;
        void *user_data;
 };
 
@@ -88,17 +91,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(struct libinput *libinput,
+       enum libinput_log_priority priority,
+       const char *format, ...);
+
 void
-log_msg_va(enum libinput_log_priority priority,
+log_msg_va(struct libinput *libinput,
+          enum libinput_log_priority priority,
           const char *format,
           va_list args);
 
index b468aa76a9c9780531b6afa5896a4ad21a39f884..915577767dd7e41063bcf8b63c80c7b65a564d60 100644 (file)
@@ -81,8 +81,8 @@ struct libinput_event_touch {
 };
 
 static void
-libinput_default_log_func(enum libinput_log_priority priority,
-                         void *data,
+libinput_default_log_func(struct libinput *libinput,
+                         enum libinput_log_priority priority,
                          const char *format, va_list args)
 {
        const char *prefix;
@@ -98,55 +98,47 @@ libinput_default_log_func(enum libinput_log_priority priority,
        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(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->log_handler &&
+           libinput->log_priority <= priority)
+               libinput->log_handler(libinput, priority, format, args);
 }
 
 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_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)
+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_log_get_priority(void)
+libinput_log_get_priority(const struct libinput *libinput)
 {
-       return log_data.priority;
+       return libinput->log_priority;
 }
 
 LIBINPUT_EXPORT void
-libinput_log_set_handler(libinput_log_handler log_handler,
-                        void *user_data)
+libinput_log_set_handler(struct libinput *libinput,
+                        libinput_log_handler log_handler)
 {
-       log_data.handler = log_handler;
-       log_data.user_data = user_data;
+       libinput->log_handler = log_handler;
 }
 
 static void
@@ -499,6 +491,8 @@ libinput_init(struct libinput *libinput,
                return -1;
        }
 
+       libinput->log_handler = libinput_default_log_func;
+       libinput->log_priority = LIBINPUT_LOG_PRIORITY_ERROR;
        libinput->interface = interface;
        libinput->interface_backend = interface_backend;
        libinput->user_data = user_data;
index 678e49dcf5dbe16b217ab72f261a9533bd9dc011..5e75cc2c314ae747796c9aa7bf658ae51dc8a95c 100644 (file)
@@ -1032,13 +1032,15 @@ libinput_destroy(struct libinput *libinput);
  *
  * 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.
  *
  * @see libinput_log_set_handler
  * @see libinput_log_get_priority
  */
 void
-libinput_log_set_priority(enum libinput_log_priority priority);
+libinput_log_set_priority(struct libinput *libinput,
+                         enum libinput_log_priority priority);
 
 /**
  * @ingroup base
@@ -1048,30 +1050,30 @@ libinput_log_set_priority(enum libinput_log_priority priority);
  *
  * 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.
  *
  * @see libinput_log_set_handler
  * @see libinput_log_set_priority
  */
 enum libinput_log_priority
-libinput_log_get_priority(void);
+libinput_log_get_priority(const struct libinput *libinput);
 
 /**
  * @ingroup base
  *
  * Log handler type for custom logging.
  *
+ * @param libinput The libinput context
  * @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,
+typedef void (*libinput_log_handler)(struct libinput *libinput,
+                                    enum libinput_log_priority priority,
                                     const char *format, va_list args)
           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.
  *
+ * @param libinput A previously initialized libinput context
  * @param log_handler The log handler for library messages.
  * @param user_data Caller-specific data pointer, passed into the log
  * handler.
@@ -1091,8 +1094,8 @@ typedef void (*libinput_log_handler)(enum libinput_log_priority priority,
  * @see libinput_log_set_handler
  */
 void
-libinput_log_set_handler(libinput_log_handler log_handler,
-                        void *user_data);
+libinput_log_set_handler(struct libinput *libinput,
+                        libinput_log_handler log_handler);
 
 /**
  * @defgroup seat Initialization and manipulation of seats
index 27e5ad63901a6cf5cca794bcbb3ad5454fd1be5f..e9c0ee8dc4e3d6fb4c56de4bc58492447d132610 100644 (file)
@@ -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;
        }
 
index 65fdd17a57fb25f3a86627940ad030bd967be0bd..f54618584b933063d67019b4d46ca5dd72ed04f3 100644 (file)
@@ -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;
        }
 
index 89160ff892dab89beb0b8831d30acb321c4a47c0..9082697f11e12b9c5f5a0e29f8726c0aaa6c30fb 100644 (file)
@@ -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;
@@ -369,7 +372,7 @@ libinput_udev_assign_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;
        }
 
index d3f8f0ddaa0f5c80414d476bcc2fc7500d090d78..793d72f73080ac0cbc58c6bbd0be37da9a5172c9 100644 (file)
@@ -44,6 +44,7 @@
 #include "libinput-util.h"
 
 static int in_debugger = -1;
+static int verbose = 0;
 
 struct test {
        struct list node;
@@ -250,8 +251,8 @@ litest_list_tests(struct list *tests)
 }
 
 static void
-litest_log_handler(enum libinput_log_priority pri,
-                  void *user_data,
+litest_log_handler(struct libinput *libinput,
+                  enum libinput_log_priority pri,
                   const char *format,
                   va_list args)
 {
@@ -321,8 +322,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);
+                               verbose = 1;
                                break;
                        default:
                                fprintf(stderr, "usage: %s [--list]\n", argv[0]);
@@ -482,6 +482,11 @@ litest_create_context(void)
        struct libinput *libinput =
                libinput_path_create_context(&interface, NULL);
        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;
 }
 
index a28182072ce64e1d6f8656202d950215750995b5..02ed4f08e04c9bb6cd4a0b9cf8400e81ec5e0ce8 100644 (file)
@@ -32,7 +32,7 @@
 #include "litest.h"
 
 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)
 {
@@ -51,130 +51,90 @@ const struct libinput_interface simple_interface = {
 };
 
 static void
-simple_log_handler(enum libinput_log_priority priority,
-                  void *userdata,
+simple_log_handler(struct libinput *libinput,
+                  enum libinput_log_priority priority,
                   const char *format,
                   va_list args)
 {
        log_handler_called++;
-       ck_assert(userdata == log_handler_userdata);
+       if (log_handler_context)
+               ck_assert(libinput == log_handler_context);
        ck_assert(format != NULL);
 }
 
 START_TEST(log_default_priority)
 {
        enum libinput_log_priority pri;
-
-       pri = libinput_log_get_priority();
-
-       ck_assert_int_eq(pri, LIBINPUT_LOG_PRIORITY_ERROR);
-}
-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");
+       pri = libinput_log_get_priority(li);
 
-       ck_assert_int_gt(log_handler_called, 0);
-       log_handler_called = 0;
+       ck_assert_int_eq(pri, LIBINPUT_LOG_PRIORITY_ERROR);
 
        libinput_destroy(li);
-       libinput_log_set_priority(pri);
 }
 END_TEST
 
-START_TEST(log_userdata_NULL)
+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)
-{
-       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;
+       libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG);
+       libinput_log_set_handler(li, simple_log_handler);
+       log_handler_context = 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);
+
+       log_handler_context = NULL;
 }
 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;
 
        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");
 
        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);
 }
 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;
 
        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");
 
        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");
        ck_assert_int_gt(log_handler_called, 0);
 
        log_handler_called = 0;
 
        libinput_destroy(li);
-       libinput_log_set_priority(pri);
+       log_handler_context = NULL;
 }
 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: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);
 
        return litest_run(argc, argv);
index 2547da5305508c7eed1f003a4809bf966f413df8..824c6b20d918cb12662c4c8b6e839c6c15b6c2a0 100644 (file)
@@ -131,6 +131,15 @@ static const struct libinput_interface interface = {
        .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
 open_udev(struct libinput **li)
 {
@@ -146,6 +155,11 @@ open_udev(struct libinput **li)
                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)) {
                fprintf(stderr, "Failed to set seat\n");
                libinput_destroy(*li);
@@ -166,6 +180,11 @@ open_device(struct libinput **li, const char *path)
                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);
        if (!device) {
                fprintf(stderr, "Failed to initialized device %s\n", path);
@@ -447,15 +466,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)
 {
@@ -465,11 +475,6 @@ 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 (mode == MODE_UDEV) {
                if (open_udev(&li))
                        return 1;