1
0
forked from drath/libratbag

Embbed the hidraw private elements in its own struct

mechanical patch

the hidraw_fd should only be used in libratbag_hidraw, so better having
it in its own struct so we can extend the hidraw elements without touching
ratbag_device.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>

# Conflicts:
#	src/libratbag-hidraw.c
This commit is contained in:
Benjamin Tissoires
2015-09-12 09:46:08 -04:00
parent 1ca65ce7cb
commit b0e5508da9
4 changed files with 19 additions and 14 deletions

View File

@@ -59,7 +59,7 @@ ratbag_open_hidraw(struct ratbag_device *device)
goto err;
}
device->hidraw_fd = fd;
device->hidraw.fd = fd;
return 0;
@@ -72,11 +72,11 @@ err:
void
ratbag_close_hidraw(struct ratbag_device *device)
{
if (device->hidraw_fd < 0)
if (device->hidraw.fd < 0)
return;
ratbag_close_fd(device, device->hidraw_fd);
device->hidraw_fd = -1;
ratbag_close_fd(device, device->hidraw.fd);
device->hidraw.fd = -1;
}
int
@@ -86,7 +86,7 @@ ratbag_hidraw_raw_request(struct ratbag_device *device, unsigned char reportnum,
char tmp_buf[HID_MAX_BUFFER_SIZE];
int rc;
if (len < 1 || len > HID_MAX_BUFFER_SIZE || !buf || device->hidraw_fd < 0)
if (len < 1 || len > HID_MAX_BUFFER_SIZE || !buf || device->hidraw.fd < 0)
return -EINVAL;
if (rtype != HID_FEATURE_REPORT)
@@ -97,7 +97,7 @@ ratbag_hidraw_raw_request(struct ratbag_device *device, unsigned char reportnum,
memset(tmp_buf, 0, len);
tmp_buf[0] = reportnum;
rc = ioctl(device->hidraw_fd, HIDIOCGFEATURE(len), tmp_buf);
rc = ioctl(device->hidraw.fd, HIDIOCGFEATURE(len), tmp_buf);
if (rc < 0)
return -errno;
@@ -105,7 +105,7 @@ ratbag_hidraw_raw_request(struct ratbag_device *device, unsigned char reportnum,
return rc;
case HID_REQ_SET_REPORT:
buf[0] = reportnum;
rc = ioctl(device->hidraw_fd, HIDIOCSFEATURE(len), buf);
rc = ioctl(device->hidraw.fd, HIDIOCSFEATURE(len), buf);
if (rc < 0)
return -errno;
@@ -120,10 +120,10 @@ ratbag_hidraw_output_report(struct ratbag_device *device, uint8_t *buf, size_t l
{
int rc;
if (len < 1 || len > HID_MAX_BUFFER_SIZE || !buf || device->hidraw_fd < 0)
if (len < 1 || len > HID_MAX_BUFFER_SIZE || !buf || device->hidraw.fd < 0)
return -EINVAL;
rc = write(device->hidraw_fd, buf, len);
rc = write(device->hidraw.fd, buf, len);
if (rc < 0)
return -errno;
@@ -140,10 +140,10 @@ ratbag_hidraw_read_input_report(struct ratbag_device *device, uint8_t *buf, size
int rc;
struct pollfd fds;
if (len < 1 || !buf || device->hidraw_fd < 0)
if (len < 1 || !buf || device->hidraw.fd < 0)
return -EINVAL;
fds.fd = device->hidraw_fd;
fds.fd = device->hidraw.fd;
fds.events = POLLIN;
rc = poll(&fds, 1, 1000);
@@ -153,6 +153,6 @@ ratbag_hidraw_read_input_report(struct ratbag_device *device, uint8_t *buf, size
if (rc == 0)
return -ETIMEDOUT;
rc = read(device->hidraw_fd, buf, len);
rc = read(device->hidraw.fd, buf, len);
return rc >= 0 ? rc : -errno;
}

View File

@@ -34,6 +34,10 @@
#define HID_OUTPUT_REPORT 1
#define HID_FEATURE_REPORT 2
struct ratbag_hidraw {
int fd;
};
/**
* Open the hidraw device associated with the device.
*

View File

@@ -31,6 +31,7 @@
#include "libratbag.h"
#include "libratbag-util.h"
#include "libratbag-hidraw.h"
#define BUS_ANY 0xffff
#define VENDOR_ANY 0xffff
@@ -62,7 +63,7 @@ struct ratbag_device {
struct udev_device *udev_device;
struct udev_device *udev_hidraw;
int hidraw_fd;
struct ratbag_hidraw hidraw;
int refcount;
struct input_id ids;
struct ratbag_driver *driver;

View File

@@ -234,7 +234,7 @@ ratbag_device_new(struct ratbag *ratbag, struct udev_device *udev_device,
}
device->ratbag = ratbag_ref(ratbag);
device->hidraw_fd = -1;
device->hidraw.fd = -1;
device->refcount = 1;
if (udev_device)
device->udev_device = udev_device_ref(udev_device);