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 <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer
2015-10-15 12:53:04 +10:00
parent 9e4bafba8f
commit 8a3222204e
4 changed files with 20 additions and 1 deletions

View File

@@ -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,

View File

@@ -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;
}

View File

@@ -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 *

View File

@@ -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);