hidraw: make ratbag-hidraw responsible for all hidraw related operations

libratbag.c does not need to initialize anything hidraw related, so
move out everything to libratbag-hidraw.c.
That means that calling ratbag_close_hidraw() is not a requirement
whithin the drivers to exit properly.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
This commit is contained in:
Benjamin Tissoires
2015-10-07 16:05:09 -04:00
parent 7dfa8cb75e
commit 00f8f90288
4 changed files with 11 additions and 26 deletions

View File

@@ -133,7 +133,7 @@ out:
return hidraw_udev;
}
int
static int
ratbag_device_init_hidraw(struct ratbag_device *device)
{
struct udev_device *hidraw_udev;
@@ -143,12 +143,12 @@ ratbag_device_init_hidraw(struct ratbag_device *device)
if (!hidraw_udev)
goto out;
device->udev_hidraw = udev_device_ref(hidraw_udev);
device->hidraw.udev_hidraw = udev_device_ref(hidraw_udev);
log_debug(device->ratbag,
"%s is device '%s'.\n",
device->name,
udev_device_get_devnode(device->udev_hidraw));
udev_device_get_devnode(device->hidraw.udev_hidraw));
rc = 0;
udev_device_unref(hidraw_udev);
@@ -163,10 +163,11 @@ ratbag_open_hidraw(struct ratbag_device *device)
int fd, res;
const char *devnode;
if (!device->udev_hidraw)
return -EINVAL;
res = ratbag_device_init_hidraw(device);
if (res)
return res;
devnode = udev_device_get_devnode(device->udev_hidraw);
devnode = udev_device_get_devnode(device->hidraw.udev_hidraw);
fd = ratbag_open_path(device, devnode, O_RDWR);
if (fd < 0)
goto err;
@@ -225,6 +226,9 @@ ratbag_close_hidraw(struct ratbag_device *device)
if (device->hidraw.fd < 0)
return;
if (device->hidraw.udev_hidraw)
udev_device_unref(device->hidraw.udev_hidraw);
ratbag_close_fd(device, device->hidraw.fd);
device->hidraw.fd = -1;

View File

@@ -38,17 +38,9 @@ struct ratbag_hidraw {
int fd;
uint8_t *report_ids;
unsigned num_report_ids;
struct udev_device *udev_hidraw;
};
/**
* Initialize the hidraw internals.
*
* @param device the ratbag device
*
* @return 0 on success or a negative errno on error
*/
int ratbag_device_init_hidraw(struct ratbag_device *device);
/**
* Open the hidraw device associated with the device.
*

View File

@@ -62,7 +62,6 @@ struct ratbag_device {
void *userdata;
struct udev_device *udev_device;
struct udev_device *udev_hidraw;
struct ratbag_hidraw hidraw;
int refcount;
struct input_id ids;

View File

@@ -165,7 +165,6 @@ ratbag_device_new(struct ratbag *ratbag, struct udev_device *udev_device,
}
device->ratbag = ratbag_ref(ratbag);
device->hidraw.fd = -1;
device->refcount = 1;
if (udev_device)
device->udev_device = udev_device_ref(udev_device);
@@ -196,10 +195,6 @@ ratbag_device_destroy(struct ratbag_device *device)
if (device->udev_device)
udev_device_unref(device->udev_device);
if (device->udev_hidraw)
udev_device_unref(device->udev_hidraw);
ratbag_close_hidraw(device);
ratbag_unref(device->ratbag);
free(device->name);
@@ -380,7 +375,6 @@ LIBRATBAG_EXPORT struct ratbag_device*
ratbag_device_new_from_udev_device(struct ratbag *ratbag,
struct udev_device *udev_device)
{
int rc;
struct ratbag_device *device = NULL;
struct ratbag_driver *driver;
char *name = NULL;
@@ -411,10 +405,6 @@ ratbag_device_new_from_udev_device(struct ratbag *ratbag,
if (!device)
goto out_err;
rc = ratbag_device_init_hidraw(device);
if (rc)
goto out_err;
driver = ratbag_find_driver(device, &device->ids, NULL);
if (!driver) {
errno = ENOTSUP;