From 8a3222204e8bd3a1c7f7a1d41fcf30fa8ee46fe0 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 15 Oct 2015 12:53:04 +1000 Subject: [PATCH] hidpp: add hidpp_device_init() Make this into a somewhat more sensible API and default to printf as log handler. Signed-off-by: Peter Hutterer --- src/driver-hidpp10.c | 2 +- src/hidpp-generic.c | 14 ++++++++++++++ src/hidpp-generic.h | 4 ++++ src/hidpp10.h | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/driver-hidpp10.c b/src/driver-hidpp10.c index 92f0a92a..d049f4fa 100644 --- a/src/driver-hidpp10.c +++ b/src/driver-hidpp10.c @@ -226,9 +226,9 @@ hidpp10drv_probe(struct ratbag_device *device) } drv_data = zalloc(sizeof(*drv_data)); + hidpp_device_init(&base, device->hidraw.fd); base.log_handler = hidpp10_log; base.userdata = device; - base.hidraw_fd = device->hidraw.fd; /* We can treat all devices as wired devices here. If we talk to the * correct hidraw device the kernel adjusts the device index for us, diff --git a/src/hidpp-generic.c b/src/hidpp-generic.c index bdc615d3..bf8e26ce 100644 --- a/src/hidpp-generic.c +++ b/src/hidpp-generic.c @@ -290,3 +290,17 @@ hidpp_log_buffer(struct hidpp_device *dev, hidpp_log(dev, priority, "%s\n", output_buf); } + +static void +simple_log(void *userdata, enum hidpp_log_priority priority, const char *format, va_list args) +{ + vprintf(format, args); +} + +void +hidpp_device_init(struct hidpp_device *dev, int fd) +{ + dev->hidraw_fd = fd; + dev->log_handler = simple_log; + dev->userdata = NULL; +} diff --git a/src/hidpp-generic.h b/src/hidpp-generic.h index 8d0dc121..ba177b1a 100644 --- a/src/hidpp-generic.h +++ b/src/hidpp-generic.h @@ -89,6 +89,10 @@ struct hidpp_device { hidpp_log_handler log_handler; }; + +void +hidpp_device_init(struct hidpp_device *dev, int fd); + extern const char *hidpp_errors[0xFF]; const char * diff --git a/src/hidpp10.h b/src/hidpp10.h index 46b63113..a7f3379a 100644 --- a/src/hidpp10.h +++ b/src/hidpp10.h @@ -50,6 +50,7 @@ hidpp10_device_new_from_wpid(const struct hidpp_device *base, struct hidpp10_device* hidpp10_device_new_from_idx(const struct hidpp_device *base, int idx); + void hidpp10_device_destroy(struct hidpp10_device *dev);