forked from drath/libratbag
hidpp: wrap the log handler init into a function
Almost a decent API now. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
@@ -227,8 +227,7 @@ 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;
|
||||
hidpp_device_set_log_handler(&base, hidpp10_log, HIDPP_LOG_PRIORITY_RAW, device);
|
||||
|
||||
/* 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,
|
||||
|
||||
@@ -258,6 +258,9 @@ hidpp_log(struct hidpp_device *dev,
|
||||
{
|
||||
va_list args;
|
||||
|
||||
if (dev->log_priority > priority)
|
||||
return;
|
||||
|
||||
va_start(args, format);
|
||||
dev->log_handler(dev->userdata, priority, format, args);
|
||||
va_end(args);
|
||||
@@ -301,6 +304,16 @@ void
|
||||
hidpp_device_init(struct hidpp_device *dev, int fd)
|
||||
{
|
||||
dev->hidraw_fd = fd;
|
||||
dev->log_handler = simple_log;
|
||||
dev->userdata = NULL;
|
||||
hidpp_device_set_log_handler(dev, simple_log, HIDPP_LOG_PRIORITY_INFO, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
hidpp_device_set_log_handler(struct hidpp_device *dev,
|
||||
hidpp_log_handler log_handler,
|
||||
enum hidpp_log_priority priority,
|
||||
void *userdata)
|
||||
{
|
||||
dev->log_handler = log_handler;
|
||||
dev->log_priority = priority;
|
||||
dev->userdata = userdata;
|
||||
}
|
||||
|
||||
@@ -87,11 +87,16 @@ struct hidpp_device {
|
||||
int hidraw_fd;
|
||||
void *userdata;
|
||||
hidpp_log_handler log_handler;
|
||||
enum hidpp_log_priority log_priority;
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
hidpp_device_init(struct hidpp_device *dev, int fd);
|
||||
void
|
||||
hidpp_device_set_log_handler(struct hidpp_device *dev,
|
||||
hidpp_log_handler log_handler,
|
||||
enum hidpp_log_priority priority,
|
||||
void *userdata);
|
||||
|
||||
extern const char *hidpp_errors[0xFF];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user