diff options
author | David Herrmann <dh.herrmann@gmail.com> | 2013-03-16 14:27:26 +0100 |
---|---|---|
committer | David Herrmann <dh.herrmann@gmail.com> | 2013-11-03 12:23:26 +0100 |
commit | 37eae950f019903db2556e2c617d34aa69a34e7a (patch) | |
tree | ee7d87abf83cd6cffc8a030a2521247a516867e0 /src | |
parent | 7083e7dbc505ee8ee2ceb2280e46869466396688 (diff) |
uterm: input: use shl_llog instead of shl_log
We should use library-logging in uterm to avoid cluttering stderr for
applications. Hence, use llog instead of log directly.
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/kmscon_seat.c | 3 | ||||
-rw-r--r-- | src/uterm_input.c | 47 | ||||
-rw-r--r-- | src/uterm_input.h | 12 | ||||
-rw-r--r-- | src/uterm_input_internal.h | 5 | ||||
-rw-r--r-- | src/uterm_input_uxkb.c | 53 |
5 files changed, 75 insertions, 45 deletions
diff --git a/src/kmscon_seat.c b/src/kmscon_seat.c index 2bde083..9f5f664 100644 --- a/src/kmscon_seat.c +++ b/src/kmscon_seat.c @@ -716,7 +716,8 @@ int kmscon_seat_new(struct kmscon_seat **out, seat->conf->xkb_options, keymap, seat->conf->xkb_repeat_delay, - seat->conf->xkb_repeat_rate); + seat->conf->xkb_repeat_rate, + log_llog, NULL); free(keymap); if (ret) diff --git a/src/uterm_input.c b/src/uterm_input.c index c248ee8..6fcbc4b 100644 --- a/src/uterm_input.c +++ b/src/uterm_input.c @@ -39,12 +39,12 @@ #include "eloop.h" #include "shl_dlist.h" #include "shl_hook.h" -#include "shl_log.h" +#include "shl_llog.h" #include "shl_misc.h" #include "uterm_input.h" #include "uterm_input_internal.h" -#define LOG_SUBSYSTEM "input" +#define LLOG_SUBSYSTEM "uterm_input" /* How many longs are needed to hold \n bits. */ #define NLONGS(n) (((n) + LONG_BIT - 1) / LONG_BIT) @@ -70,7 +70,7 @@ static void input_data_dev(struct ev_fd *fd, int mask, void *data) int i; if (mask & (EV_HUP | EV_ERR)) { - log_debug("EOF on %s", dev->node); + llog_debug(dev->input, "EOF on %s", dev->node); input_free_dev(dev); return; } @@ -81,14 +81,15 @@ static void input_data_dev(struct ev_fd *fd, int mask, void *data) if (len < 0) { if (errno == EWOULDBLOCK) break; - log_warn("reading from %s failed (%d): %m", - dev->node, errno); + llog_warn(dev->input, "reading from %s failed (%d): %m", + dev->node, errno); input_free_dev(dev); } else if (len == 0) { - log_debug("EOF on %s", dev->node); + llog_debug(dev->input, "EOF on %s", dev->node); input_free_dev(dev); } else if (len % sizeof(*ev)) { - log_warn("invalid input_event on %s", dev->node); + llog_warn(dev->input, "invalid input_event on %s", + dev->node); } else { n = len / sizeof(*ev); for (i = 0; i < n; i++) @@ -107,7 +108,8 @@ static int input_wake_up_dev(struct uterm_input_dev *dev) dev->rfd = open(dev->node, O_CLOEXEC | O_NONBLOCK | O_RDWR); if (dev->rfd < 0) { - log_warn("cannot open device %s (%d): %m", dev->node, errno); + llog_warn(dev->input, "cannot open device %s (%d): %m", + dev->node, errno); return -EFAULT; } @@ -182,7 +184,7 @@ static void input_new_dev(struct uterm_input *input, goto err_kbd; } - log_debug("new device %s", node); + llog_debug(input, "new device %s", node); shl_dlist_link(&input->devices, &dev->list); return; @@ -204,7 +206,7 @@ err_free: static void input_free_dev(struct uterm_input_dev *dev) { - log_debug("free device %s", dev->node); + llog_debug(dev->input, "free device %s", dev->node); input_sleep_dev(dev); shl_dlist_unlink(&dev->list); uxkb_dev_destroy(dev); @@ -225,7 +227,9 @@ int uterm_input_new(struct uterm_input **out, const char *options, const char *keymap, unsigned int repeat_delay, - unsigned int repeat_rate) + unsigned int repeat_rate, + uterm_input_log_t log, + void *log_data) { struct uterm_input *input; int ret; @@ -247,6 +251,8 @@ int uterm_input_new(struct uterm_input **out, return -ENOMEM; memset(input, 0, sizeof(*input)); input->ref = 1; + input->llog = log; + input->llog_data = log_data; input->eloop = eloop; input->repeat_delay = repeat_delay; input->repeat_rate = repeat_rate; @@ -260,7 +266,7 @@ int uterm_input_new(struct uterm_input **out, if (ret) goto err_hook; - log_debug("new object %p", input); + llog_debug(input, "new object %p", input); ev_eloop_ref(input->eloop); *out = input; return 0; @@ -289,7 +295,7 @@ void uterm_input_unref(struct uterm_input *input) if (!input || !input->ref || --input->ref) return; - log_debug("free object %p", input); + llog_debug(input, "free object %p", input); while (input->devices.next != &input->devices) { dev = shl_dlist_entry(input->devices.next, @@ -309,7 +315,8 @@ void uterm_input_unref(struct uterm_input *input) * We go over the possible capabilities and return a mask of enum * uterm_input_device_capability's. */ -static unsigned int probe_device_capabilities(const char *node) +static unsigned int probe_device_capabilities(struct uterm_input *input, + const char *node) { int i, fd, ret; unsigned int capabilities = 0; @@ -351,8 +358,8 @@ static unsigned int probe_device_capabilities(const char *node) return capabilities; err_ioctl: - log_warn("cannot probe capabilities of device %s (%d): %m", - node, errno); + llog_warn(input, "cannot probe capabilities of device %s (%d): %m", + node, errno); close(fd); return 0; } @@ -365,9 +372,9 @@ void uterm_input_add_dev(struct uterm_input *input, const char *node) if (!input || !node) return; - capabilities = probe_device_capabilities(node); + capabilities = probe_device_capabilities(input, node); if (!(capabilities & UTERM_DEVICE_HAS_KEYS)) { - log_debug("ignoring non-useful device %s", node); + llog_debug(input, "ignoring non-useful device %s", node); return; } @@ -429,7 +436,7 @@ void uterm_input_sleep(struct uterm_input *input) if (input->awake != 0) return; - log_debug("going to sleep"); + llog_debug(input, "going to sleep"); shl_dlist_for_each(iter, &input->devices) { dev = shl_dlist_entry(iter, @@ -453,7 +460,7 @@ void uterm_input_wake_up(struct uterm_input *input) if (input->awake != 1) return; - log_debug("wakeing up"); + llog_debug(input, "wakeing up"); shl_dlist_for_each_safe(iter, tmp, &input->devices) { dev = shl_dlist_entry(iter, diff --git a/src/uterm_input.h b/src/uterm_input.h index 43faccc..1d5d1f0 100644 --- a/src/uterm_input.h +++ b/src/uterm_input.h @@ -40,6 +40,15 @@ struct uterm_input; +typedef void (*uterm_input_log_t) (void *data, + const char *file, + int line, + const char *func, + const char *subs, + unsigned int sev, + const char *format, + va_list args); + /* keep in sync with shl_xkb_mods */ enum uterm_input_modifier { UTERM_SHIFT_MASK = (1 << 0), @@ -72,7 +81,8 @@ typedef void (*uterm_input_cb) (struct uterm_input *input, int uterm_input_new(struct uterm_input **out, struct ev_eloop *eloop, const char *model, const char *layout, const char *variant, const char *options, const char *keymap, - unsigned int repeat_delay, unsigned int repeat_rate); + unsigned int repeat_delay, unsigned int repeat_rate, + uterm_input_log_t log, void *log_data); void uterm_input_ref(struct uterm_input *input); void uterm_input_unref(struct uterm_input *input); diff --git a/src/uterm_input_internal.h b/src/uterm_input_internal.h index 6491d33..04e6cc9 100644 --- a/src/uterm_input_internal.h +++ b/src/uterm_input_internal.h @@ -1,7 +1,7 @@ /* * uterm - Linux User-Space Terminal * - * Copyright (c) 2011-2012 David Herrmann <dh.herrmann@googlemail.com> + * Copyright (c) 2011-2013 David Herrmann <dh.herrmann@gmail.com> * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files @@ -35,6 +35,7 @@ #include <xkbcommon/xkbcommon-keysyms.h> #include "eloop.h" #include "shl_dlist.h" +#include "shl_llog.h" #include "shl_misc.h" #include "uterm_input.h" @@ -65,6 +66,8 @@ struct uterm_input_dev { struct uterm_input { unsigned long ref; + llog_submit_t llog; + void *llog_data; struct ev_eloop *eloop; int awake; unsigned int repeat_rate; diff --git a/src/uterm_input_uxkb.c b/src/uterm_input_uxkb.c index 14d9937..af6bd05 100644 --- a/src/uterm_input_uxkb.c +++ b/src/uterm_input_uxkb.c @@ -33,12 +33,12 @@ #include <unistd.h> #include <xkbcommon/xkbcommon.h> #include "shl_hook.h" -#include "shl_log.h" +#include "shl_llog.h" #include "shl_misc.h" #include "uterm_input.h" #include "uterm_input_internal.h" -#define LOG_SUBSYSTEM "input_uxkb" +#define LLOG_SUBSYSTEM "uterm_input_uxkb" extern const char _binary_src_uterm_input_fallback_xkb_bin_start[]; extern const char _binary_src_uterm_input_fallback_xkb_bin_end[]; @@ -64,7 +64,7 @@ int uxkb_desc_init(struct uterm_input *input, input->ctx = xkb_context_new(0); if (!input->ctx) { - log_error("cannot create XKB context"); + llog_error(input, "cannot create XKB context"); return -ENOMEM; } @@ -73,17 +73,18 @@ int uxkb_desc_init(struct uterm_input *input, input->keymap = xkb_keymap_new_from_string(input->ctx, keymap, XKB_KEYMAP_FORMAT_TEXT_V1, 0); if (input->keymap) { - log_debug("new keyboard description from memory"); + llog_debug(input, + "new keyboard description from memory"); return 0; } - log_warn("cannot parse keymap, reverting to rmlvo"); + llog_warn(input, "cannot parse keymap, reverting to rmlvo"); } input->keymap = xkb_keymap_new_from_names(input->ctx, &rmlvo, 0); if (!input->keymap) { - log_warn("failed to create keymap (%s, %s, %s, %s), " - "reverting to default system keymap", + llog_warn(input, "failed to create keymap (%s, %s, %s, %s), " + "reverting to default system keymap", model, layout, variant, options); rmlvo.model = ""; @@ -94,22 +95,23 @@ int uxkb_desc_init(struct uterm_input *input, input->keymap = xkb_keymap_new_from_names(input->ctx, &rmlvo, 0); if (!input->keymap) { - log_warn("failed to create XKB default keymap, " - "reverting to built-in fallback"); + llog_warn(input, "failed to create XKB default keymap, " + "reverting to built-in fallback"); input->keymap = xkb_keymap_new_from_string(input->ctx, fallback, XKB_KEYMAP_FORMAT_TEXT_V1, 0); if (!input->keymap) { - log_error("cannot create fallback keymap"); + llog_error(input, + "cannot create fallback keymap"); ret = -EFAULT; goto err_ctx; } } - log_debug("new fallback keyboard description"); + llog_debug(input, "new fallback keyboard description"); } else { - log_debug("new keyboard description (%s, %s, %s, %s)", - model, layout, variant, options); + llog_debug(input, "new keyboard description (%s, %s, %s, %s)", + model, layout, variant, options); } return 0; @@ -144,7 +146,7 @@ int uxkb_dev_init(struct uterm_input_dev *dev) dev->state = xkb_state_new(dev->input->keymap); if (!dev->state) { - log_error("cannot create XKB state"); + llog_error(dev->input, "cannot create XKB state"); ret = -ENOMEM; goto err_timer; } @@ -197,7 +199,8 @@ static void uxkb_dev_update_keyboard_leds(struct uterm_input_dev *dev) ret = write(dev->rfd, events, sizeof(events)); if (ret != sizeof(events)) - log_warning("cannot update LED state (%d): %m", errno); + llog_warning(dev->input, "cannot update LED state (%d): %m", + errno); } static inline int uxkb_dev_resize_event(struct uterm_input_dev *dev, size_t s) @@ -208,7 +211,8 @@ static inline int uxkb_dev_resize_event(struct uterm_input_dev *dev, size_t s) tmp = realloc(dev->event.keysyms, sizeof(uint32_t) * s); if (!tmp) { - log_warning("cannot reallocate keysym buffer"); + llog_warning(dev->input, + "cannot reallocate keysym buffer"); return -ENOKEY; } dev->event.keysyms = tmp; @@ -216,7 +220,8 @@ static inline int uxkb_dev_resize_event(struct uterm_input_dev *dev, size_t s) tmp = realloc(dev->event.codepoints, sizeof(uint32_t) * s); if (!tmp) { - log_warning("cannot reallocate codepoints buffer"); + llog_warning(dev->input, + "cannot reallocate codepoints buffer"); return -ENOKEY; } dev->event.codepoints = tmp; @@ -224,7 +229,8 @@ static inline int uxkb_dev_resize_event(struct uterm_input_dev *dev, size_t s) tmp = realloc(dev->repeat_event.keysyms, sizeof(uint32_t) * s); if (!tmp) { - log_warning("cannot reallocate keysym buffer"); + llog_warning(dev->input, + "cannot reallocate keysym buffer"); return -ENOKEY; } dev->repeat_event.keysyms = tmp; @@ -232,7 +238,8 @@ static inline int uxkb_dev_resize_event(struct uterm_input_dev *dev, size_t s) tmp = realloc(dev->repeat_event.codepoints, sizeof(uint32_t) * s); if (!tmp) { - log_warning("cannot reallocate codepoints buffer"); + llog_warning(dev->input, + "cannot reallocate codepoints buffer"); return -ENOKEY; } dev->repeat_event.codepoints = tmp; @@ -392,7 +399,8 @@ void uxkb_dev_sleep(struct uterm_input_dev *dev) ioctl(dev->rfd, EVIOCGKEY(sizeof(dev->key_state_bits)), dev->key_state_bits); if (errno) - log_warn("failed to save keyboard state (%d): %m", errno); + llog_warn(dev->input, "failed to save keyboard state (%d): %m", + errno); } void uxkb_dev_wake_up(struct uterm_input_dev *dev) @@ -407,8 +415,9 @@ void uxkb_dev_wake_up(struct uterm_input_dev *dev) errno = 0; ioctl(dev->rfd, EVIOCGKEY(sizeof(cur_bits)), cur_bits); if (errno) { - log_warn("failed to get current keyboard state (%d): %m", - errno); + llog_warn(dev->input, + "failed to get current keyboard state (%d): %m", + errno); return; } |