forked from drath/libratbag
Rename "struct ratbag" to "struct ratbag_device"
Less ambiguous naming this way Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
@@ -101,7 +101,7 @@ print_key(uint8_t key)
|
||||
}
|
||||
|
||||
static int
|
||||
etekcity_has_capability(const struct ratbag *ratbag, enum ratbag_capability cap)
|
||||
etekcity_has_capability(const struct ratbag_device *device, enum ratbag_capability cap)
|
||||
{
|
||||
switch (cap) {
|
||||
case RATBAG_CAP_NONE:
|
||||
@@ -117,12 +117,12 @@ etekcity_has_capability(const struct ratbag *ratbag, enum ratbag_capability cap)
|
||||
}
|
||||
|
||||
static int
|
||||
etekcity_current_profile(struct ratbag *ratbag)
|
||||
etekcity_current_profile(struct ratbag_device *device)
|
||||
{
|
||||
uint8_t buf[3];
|
||||
int ret;
|
||||
|
||||
ret = ratbag_hidraw_raw_request(ratbag, ETEKCITY_REPORT_ID_PROFILE, buf,
|
||||
ret = ratbag_hidraw_raw_request(device, ETEKCITY_REPORT_ID_PROFILE, buf,
|
||||
sizeof(buf), HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
@@ -134,7 +134,7 @@ etekcity_current_profile(struct ratbag *ratbag)
|
||||
}
|
||||
|
||||
static int
|
||||
etekcity_set_current_profile(struct ratbag *ratbag, unsigned int index)
|
||||
etekcity_set_current_profile(struct ratbag_device *device, unsigned int index)
|
||||
{
|
||||
uint8_t buf[] = {ETEKCITY_REPORT_ID_PROFILE, 0x03, index};
|
||||
int ret;
|
||||
@@ -142,7 +142,7 @@ etekcity_set_current_profile(struct ratbag *ratbag, unsigned int index)
|
||||
if (index > ETEKCITY_PROFILE_MAX)
|
||||
return -EINVAL;
|
||||
|
||||
ret = ratbag_hidraw_raw_request(ratbag, buf[0], buf, sizeof(buf),
|
||||
ret = ratbag_hidraw_raw_request(device, buf[0], buf, sizeof(buf),
|
||||
HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
|
||||
|
||||
msleep(100);
|
||||
@@ -151,7 +151,7 @@ etekcity_set_current_profile(struct ratbag *ratbag, unsigned int index)
|
||||
}
|
||||
|
||||
static int
|
||||
etekcity_set_config_profile(struct ratbag *ratbag, uint8_t profile, uint8_t type)
|
||||
etekcity_set_config_profile(struct ratbag_device *device, uint8_t profile, uint8_t type)
|
||||
{
|
||||
uint8_t buf[] = {ETEKCITY_REPORT_ID_CONFIGURE_PROFILE, profile, type};
|
||||
int ret;
|
||||
@@ -159,7 +159,7 @@ etekcity_set_config_profile(struct ratbag *ratbag, uint8_t profile, uint8_t type
|
||||
if (profile > ETEKCITY_PROFILE_MAX)
|
||||
return -EINVAL;
|
||||
|
||||
ret = ratbag_hidraw_raw_request(ratbag, buf[0], buf, sizeof(buf),
|
||||
ret = ratbag_hidraw_raw_request(device, buf[0], buf, sizeof(buf),
|
||||
HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
|
||||
|
||||
msleep(100);
|
||||
@@ -170,18 +170,18 @@ etekcity_set_config_profile(struct ratbag *ratbag, uint8_t profile, uint8_t type
|
||||
static void
|
||||
etekcity_read_profile(struct ratbag_profile *profile, unsigned int index)
|
||||
{
|
||||
struct ratbag *ratbag = profile->ratbag;
|
||||
struct ratbag_device *device = profile->device;
|
||||
struct etekcity_data *drv_data;
|
||||
int rc;
|
||||
uint8_t *buf;
|
||||
|
||||
assert(index <= ETEKCITY_PROFILE_MAX);
|
||||
|
||||
drv_data = ratbag_get_drv_data(ratbag);
|
||||
drv_data = ratbag_get_drv_data(device);
|
||||
buf = drv_data->profiles[index];
|
||||
|
||||
etekcity_set_config_profile(ratbag, index, ETEKCITY_CONFIG_KEY_MAPPING);
|
||||
rc = ratbag_hidraw_raw_request(ratbag, ETEKCITY_REPORT_ID_KEY_MAPPING,
|
||||
etekcity_set_config_profile(device, index, ETEKCITY_CONFIG_KEY_MAPPING);
|
||||
rc = ratbag_hidraw_raw_request(device, ETEKCITY_REPORT_ID_KEY_MAPPING,
|
||||
buf, ETEKCITY_REPORT_SIZE_PROFILE,
|
||||
HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
|
||||
|
||||
@@ -190,7 +190,7 @@ etekcity_read_profile(struct ratbag_profile *profile, unsigned int index)
|
||||
if (rc < 50)
|
||||
return;
|
||||
|
||||
log_debug(ratbag->libratbag, "profile: %d %s:%d\n",
|
||||
log_debug(device->libratbag, "profile: %d %s:%d\n",
|
||||
buf[2],
|
||||
__FILE__, __LINE__);
|
||||
}
|
||||
@@ -208,39 +208,39 @@ etekcity_button_to_index(unsigned button)
|
||||
}
|
||||
|
||||
static void
|
||||
etekcity_read_button(struct ratbag *ratbag, struct ratbag_profile *profile,
|
||||
etekcity_read_button(struct ratbag_device *device, struct ratbag_profile *profile,
|
||||
struct ratbag_button *button)
|
||||
{
|
||||
struct etekcity_data *drv_data = ratbag_get_drv_data(ratbag);
|
||||
struct etekcity_data *drv_data = ratbag_get_drv_data(device);
|
||||
uint8_t data;
|
||||
unsigned index = etekcity_button_to_index(button->index);
|
||||
|
||||
data = drv_data->profiles[profile->index][3 + index * 3];
|
||||
if (data)
|
||||
log_debug(ratbag->libratbag,
|
||||
log_debug(device->libratbag,
|
||||
" - button%d: %s (%02x) %s:%d\n",
|
||||
button->index, print_key(data), data, __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
static int
|
||||
etekcity_write_button(struct ratbag *ratbag, struct ratbag_profile *profile,
|
||||
etekcity_write_button(struct ratbag_device *device, struct ratbag_profile *profile,
|
||||
struct ratbag_button *button)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
etekcity_probe(struct ratbag *ratbag, const struct ratbag_id id)
|
||||
etekcity_probe(struct ratbag_device *device, const struct ratbag_id id)
|
||||
{
|
||||
int rc;
|
||||
struct ratbag_profile *profile;
|
||||
struct etekcity_data *drv_data;
|
||||
|
||||
log_debug(ratbag->libratbag, "data: %d\n", id.data);
|
||||
log_debug(device->libratbag, "data: %d\n", id.data);
|
||||
|
||||
rc = ratbag_open_hidraw(ratbag);
|
||||
rc = ratbag_open_hidraw(device);
|
||||
if (rc) {
|
||||
log_error(ratbag->libratbag,
|
||||
log_error(device->libratbag,
|
||||
"Can't open corresponding hidraw node: '%s' (%d)\n",
|
||||
strerror(-rc),
|
||||
rc);
|
||||
@@ -251,15 +251,15 @@ etekcity_probe(struct ratbag *ratbag, const struct ratbag_id id)
|
||||
if (!drv_data)
|
||||
return -ENODEV;
|
||||
|
||||
ratbag_set_drv_data(ratbag, drv_data);
|
||||
ratbag_set_drv_data(device, drv_data);
|
||||
|
||||
ratbag->num_profiles = ETEKCITY_PROFILE_MAX;
|
||||
ratbag->num_buttons = ETEKCITY_BUTTON_MAX;
|
||||
device->num_profiles = ETEKCITY_PROFILE_MAX;
|
||||
device->num_buttons = ETEKCITY_BUTTON_MAX;
|
||||
|
||||
profile = ratbag_get_active_profile(ratbag);
|
||||
profile = ratbag_device_get_active_profile(device);
|
||||
|
||||
if (!profile) {
|
||||
log_error(ratbag->libratbag,
|
||||
log_error(device->libratbag,
|
||||
"Can't talk to the mouse: '%s' (%d)\n",
|
||||
strerror(-rc),
|
||||
rc);
|
||||
@@ -267,9 +267,9 @@ etekcity_probe(struct ratbag *ratbag, const struct ratbag_id id)
|
||||
goto err;
|
||||
}
|
||||
|
||||
log_info(ratbag->libratbag,
|
||||
log_info(device->libratbag,
|
||||
"'%s' is in profile %d\n",
|
||||
ratbag_get_name(ratbag),
|
||||
ratbag_device_get_name(device),
|
||||
profile->index);
|
||||
|
||||
profile = ratbag_profile_unref(profile);
|
||||
@@ -278,14 +278,14 @@ etekcity_probe(struct ratbag *ratbag, const struct ratbag_id id)
|
||||
|
||||
err:
|
||||
free(drv_data);
|
||||
ratbag_set_drv_data(ratbag, NULL);
|
||||
ratbag_set_drv_data(device, NULL);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static void
|
||||
etekcity_remove(struct ratbag *ratbag)
|
||||
etekcity_remove(struct ratbag_device *device)
|
||||
{
|
||||
free(ratbag_get_drv_data(ratbag));
|
||||
free(ratbag_get_drv_data(device));
|
||||
}
|
||||
|
||||
static const struct ratbag_id etekcity_table[] = {
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
#endif
|
||||
|
||||
int
|
||||
ratbag_open_hidraw(struct ratbag *ratbag)
|
||||
ratbag_open_hidraw(struct ratbag_device *ratbag)
|
||||
{
|
||||
struct hidraw_devinfo info;
|
||||
int fd, res;
|
||||
@@ -74,7 +74,7 @@ err:
|
||||
}
|
||||
|
||||
int
|
||||
ratbag_hidraw_raw_request(struct ratbag *ratbag, unsigned char reportnum,
|
||||
ratbag_hidraw_raw_request(struct ratbag_device *ratbag, unsigned char reportnum,
|
||||
uint8_t *buf, size_t len, unsigned char rtype, int reqtype)
|
||||
{
|
||||
char tmp_buf[HID_MAX_BUFFER_SIZE];
|
||||
@@ -110,7 +110,7 @@ ratbag_hidraw_raw_request(struct ratbag *ratbag, unsigned char reportnum,
|
||||
}
|
||||
|
||||
int
|
||||
ratbag_hidraw_output_report(struct ratbag *ratbag, uint8_t *buf, size_t len)
|
||||
ratbag_hidraw_output_report(struct ratbag_device *ratbag, uint8_t *buf, size_t len)
|
||||
{
|
||||
if (len < 1 || len > HID_MAX_BUFFER_SIZE || !buf || ratbag->hidraw_fd < 0)
|
||||
return -EINVAL;
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
#define HID_OUTPUT_REPORT 1
|
||||
#define HID_FEATURE_REPORT 2
|
||||
|
||||
int ratbag_open_hidraw(struct ratbag *ratbag);
|
||||
int ratbag_open_hidraw(struct ratbag_device *ratbag);
|
||||
|
||||
/**
|
||||
* ratbag_hidraw_raw_request - send report request to device
|
||||
@@ -50,7 +50,7 @@ int ratbag_open_hidraw(struct ratbag *ratbag);
|
||||
*
|
||||
* Same behavior as hid_hw_request, but with raw buffers instead.
|
||||
*/
|
||||
int ratbag_hidraw_raw_request(struct ratbag *ratbag, unsigned char reportnum,
|
||||
int ratbag_hidraw_raw_request(struct ratbag_device *ratbag, unsigned char reportnum,
|
||||
uint8_t *buf, size_t len, unsigned char rtype,
|
||||
int reqtype);
|
||||
|
||||
@@ -63,6 +63,6 @@ int ratbag_hidraw_raw_request(struct ratbag *ratbag, unsigned char reportnum,
|
||||
*
|
||||
* @return: count of data transfered, negative if error
|
||||
*/
|
||||
int ratbag_hidraw_output_report(struct ratbag *ratbag, uint8_t *buf, size_t len);
|
||||
int ratbag_hidraw_output_report(struct ratbag_device *ratbag, uint8_t *buf, size_t len);
|
||||
|
||||
#endif /* LIBRATBAG_HIDRAW_H */
|
||||
|
||||
@@ -51,7 +51,7 @@ struct libratbag {
|
||||
enum libratbag_log_priority log_priority;
|
||||
};
|
||||
|
||||
struct ratbag {
|
||||
struct ratbag_device {
|
||||
char *name;
|
||||
struct udev_device *udev_device;
|
||||
struct udev_device *udev_hidraw;
|
||||
@@ -78,16 +78,16 @@ struct ratbag_driver {
|
||||
char *name;
|
||||
const struct ratbag_id *table_ids;
|
||||
|
||||
int (*probe)(struct ratbag *ratbag, const struct ratbag_id id);
|
||||
void (*remove)(struct ratbag *ratbag);
|
||||
int (*probe)(struct ratbag_device *device, const struct ratbag_id id);
|
||||
void (*remove)(struct ratbag_device *device);
|
||||
void (*read_profile)(struct ratbag_profile *profile, unsigned int index);
|
||||
int (*write_profile)(struct ratbag_profile *profile);
|
||||
int (*get_active_profile)(struct ratbag *ratbag);
|
||||
int (*set_active_profile)(struct ratbag *ratbag, unsigned int index);
|
||||
int (*has_capability)(const struct ratbag *ratbag, enum ratbag_capability cap);
|
||||
void (*read_button)(struct ratbag *ratbag, struct ratbag_profile *profile,
|
||||
int (*get_active_profile)(struct ratbag_device *device);
|
||||
int (*set_active_profile)(struct ratbag_device *device, unsigned int index);
|
||||
int (*has_capability)(const struct ratbag_device *device, enum ratbag_capability cap);
|
||||
void (*read_button)(struct ratbag_device *device, struct ratbag_profile *profile,
|
||||
struct ratbag_button *button);
|
||||
int (*write_button)(struct ratbag *ratbag, struct ratbag_profile *profile,
|
||||
int (*write_button)(struct ratbag_device *device, struct ratbag_profile *profile,
|
||||
struct ratbag_button *button);
|
||||
|
||||
/* private */
|
||||
@@ -98,7 +98,7 @@ struct ratbag_profile {
|
||||
int refcount;
|
||||
struct list link;
|
||||
unsigned index;
|
||||
struct ratbag *ratbag;
|
||||
struct ratbag_device *device;
|
||||
struct list buttons;
|
||||
void *drv_data;
|
||||
void *user_data;
|
||||
@@ -107,7 +107,7 @@ struct ratbag_profile {
|
||||
struct ratbag_button {
|
||||
int refcount;
|
||||
struct list link;
|
||||
struct ratbag *ratbag;
|
||||
struct ratbag_device *device;
|
||||
struct ratbag_profile *profile;
|
||||
unsigned index;
|
||||
enum ratbag_button_type type;
|
||||
@@ -115,31 +115,31 @@ struct ratbag_button {
|
||||
};
|
||||
|
||||
static inline int
|
||||
ratbag_open_path(struct ratbag *ratbag, const char *path, int flags)
|
||||
ratbag_open_path(struct ratbag_device *device, const char *path, int flags)
|
||||
{
|
||||
struct libratbag *libratbag = ratbag->libratbag;
|
||||
struct libratbag *libratbag = device->libratbag;
|
||||
|
||||
return libratbag->interface->open_restricted(path, flags, libratbag->userdata);
|
||||
}
|
||||
|
||||
static inline void
|
||||
ratbag_close_fd(struct ratbag *ratbag, int fd)
|
||||
ratbag_close_fd(struct ratbag_device *device, int fd)
|
||||
{
|
||||
struct libratbag *libratbag = ratbag->libratbag;
|
||||
struct libratbag *libratbag = device->libratbag;
|
||||
|
||||
return libratbag->interface->close_restricted(fd, libratbag->userdata);
|
||||
}
|
||||
|
||||
static inline void
|
||||
ratbag_set_drv_data(struct ratbag *ratbag, void *drv_data)
|
||||
ratbag_set_drv_data(struct ratbag_device *device, void *drv_data)
|
||||
{
|
||||
ratbag->drv_data = drv_data;
|
||||
device->drv_data = drv_data;
|
||||
}
|
||||
|
||||
static inline void *
|
||||
ratbag_get_drv_data(struct ratbag *ratbag)
|
||||
ratbag_get_drv_data(struct ratbag_device *device)
|
||||
{
|
||||
return ratbag->drv_data;
|
||||
return device->drv_data;
|
||||
}
|
||||
|
||||
static inline void
|
||||
|
||||
175
src/libratbag.c
175
src/libratbag.c
@@ -98,7 +98,7 @@ libratbag_log_set_handler(struct libratbag *libratbag,
|
||||
|
||||
static inline struct udev_device *
|
||||
udev_device_from_devnode(struct libratbag *libratbag,
|
||||
struct ratbag *ratbag,
|
||||
struct ratbag_device *device,
|
||||
int fd)
|
||||
{
|
||||
struct udev_device *dev;
|
||||
@@ -128,7 +128,7 @@ udev_device_from_devnode(struct libratbag *libratbag,
|
||||
}
|
||||
|
||||
static struct udev_device *
|
||||
udev_find_hidraw(struct libratbag *libratbag, struct ratbag *ratbag)
|
||||
udev_find_hidraw(struct libratbag *libratbag, struct ratbag_device *device)
|
||||
{
|
||||
struct udev_enumerate *e;
|
||||
struct udev_list_entry *entry;
|
||||
@@ -138,7 +138,7 @@ udev_find_hidraw(struct libratbag *libratbag, struct ratbag *ratbag)
|
||||
struct udev_device *hidraw_udev = NULL;
|
||||
struct udev *udev = libratbag->udev;
|
||||
|
||||
hid_udev = udev_device_get_parent_with_subsystem_devtype(ratbag->udev_device, "hid", NULL);
|
||||
hid_udev = udev_device_get_parent_with_subsystem_devtype(device->udev_device, "hid", NULL);
|
||||
|
||||
e = udev_enumerate_new(udev);
|
||||
udev_enumerate_add_match_subsystem(e, "hidraw");
|
||||
@@ -169,24 +169,24 @@ out:
|
||||
}
|
||||
|
||||
static int
|
||||
ratbag_device_init_udev(struct libratbag *libratbag, struct ratbag *ratbag,
|
||||
ratbag_device_init_udev(struct libratbag *libratbag, struct ratbag_device *device,
|
||||
struct udev_device *udev_device)
|
||||
{
|
||||
struct udev_device *hidraw_udev;
|
||||
int rc = -ENODEV;
|
||||
|
||||
ratbag->udev_device = udev_device_ref(udev_device);
|
||||
device->udev_device = udev_device_ref(udev_device);
|
||||
|
||||
hidraw_udev = udev_find_hidraw(libratbag, ratbag);
|
||||
hidraw_udev = udev_find_hidraw(libratbag, device);
|
||||
if (!hidraw_udev)
|
||||
goto out;
|
||||
|
||||
ratbag->udev_hidraw = udev_device_ref(hidraw_udev);
|
||||
device->udev_hidraw = udev_device_ref(hidraw_udev);
|
||||
|
||||
log_debug(libratbag,
|
||||
"%s is associated to '%s'.\n",
|
||||
udev_device_get_devnode(ratbag->udev_hidraw),
|
||||
ratbag->name);
|
||||
udev_device_get_devnode(device->udev_hidraw),
|
||||
device->name);
|
||||
|
||||
rc = 0;
|
||||
udev_device_unref(hidraw_udev);
|
||||
@@ -195,7 +195,7 @@ out:
|
||||
}
|
||||
|
||||
static void
|
||||
ratbag_device_init(struct ratbag *rb)
|
||||
ratbag_device_init(struct ratbag_device *rb)
|
||||
{
|
||||
rb->hidraw_fd = -1;
|
||||
rb->refcount = 1;
|
||||
@@ -212,7 +212,7 @@ ratbag_match_id(const struct input_id *dev_id, const struct input_id *match_id)
|
||||
}
|
||||
|
||||
static struct ratbag_driver *
|
||||
ratbag_find_driver(struct libratbag *libratbag, struct ratbag *ratbag,
|
||||
ratbag_find_driver(struct libratbag *libratbag, struct ratbag_device *device,
|
||||
const struct input_id *dev_id)
|
||||
{
|
||||
struct ratbag_driver *driver;
|
||||
@@ -228,12 +228,12 @@ ratbag_find_driver(struct libratbag *libratbag, struct ratbag *ratbag,
|
||||
assert(driver->probe);
|
||||
matched_id.id = *dev_id;
|
||||
matched_id.data = matching_id->data;
|
||||
ratbag->driver = driver;
|
||||
rc = driver->probe(ratbag, matched_id);
|
||||
device->driver = driver;
|
||||
rc = driver->probe(device, matched_id);
|
||||
if (rc == 0)
|
||||
return driver;
|
||||
|
||||
ratbag->driver = NULL;
|
||||
device->driver = NULL;
|
||||
|
||||
if (rc != -ENODEV)
|
||||
return NULL;
|
||||
@@ -281,12 +281,12 @@ get_product_id(struct udev_device *device, struct input_id *id)
|
||||
return 0;
|
||||
}
|
||||
|
||||
LIBRATBAG_EXPORT struct ratbag*
|
||||
ratbag_new_from_udev_device(struct libratbag *libratbag,
|
||||
struct udev_device *udev_device)
|
||||
LIBRATBAG_EXPORT struct ratbag_device*
|
||||
ratbag_device_new_from_udev_device(struct libratbag *libratbag,
|
||||
struct udev_device *udev_device)
|
||||
{
|
||||
int rc;
|
||||
struct ratbag *ratbag = NULL;
|
||||
struct ratbag_device *device = NULL;
|
||||
struct ratbag_driver *driver;
|
||||
|
||||
if (!libratbag) {
|
||||
@@ -294,75 +294,75 @@ ratbag_new_from_udev_device(struct libratbag *libratbag,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ratbag = zalloc(sizeof(*ratbag));
|
||||
if (!ratbag)
|
||||
device = zalloc(sizeof(*device));
|
||||
if (!device)
|
||||
return NULL;
|
||||
|
||||
ratbag->libratbag = libratbag_ref(libratbag);
|
||||
if (get_product_id(udev_device, &ratbag->ids) != 0)
|
||||
device->libratbag = libratbag_ref(libratbag);
|
||||
if (get_product_id(udev_device, &device->ids) != 0)
|
||||
goto out_err;
|
||||
free(ratbag->name);
|
||||
ratbag->name = get_device_name(udev_device);
|
||||
if (!ratbag->name) {
|
||||
free(device->name);
|
||||
device->name = get_device_name(udev_device);
|
||||
if (!device->name) {
|
||||
errno = ENOMEM;
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
ratbag_device_init(ratbag);
|
||||
rc = ratbag_device_init_udev(libratbag, ratbag, udev_device);
|
||||
ratbag_device_init(device);
|
||||
rc = ratbag_device_init_udev(libratbag, device, udev_device);
|
||||
if (rc)
|
||||
goto out_err;
|
||||
|
||||
driver = ratbag_find_driver(libratbag, ratbag, &ratbag->ids);
|
||||
driver = ratbag_find_driver(libratbag, device, &device->ids);
|
||||
if (!driver) {
|
||||
errno = ENOTSUP;
|
||||
goto err_udev;
|
||||
}
|
||||
|
||||
return ratbag;
|
||||
return device;
|
||||
|
||||
err_udev:
|
||||
udev_device_unref(ratbag->udev_device);
|
||||
udev_device_unref(ratbag->udev_hidraw);
|
||||
udev_device_unref(device->udev_device);
|
||||
udev_device_unref(device->udev_hidraw);
|
||||
out_err:
|
||||
if (ratbag) {
|
||||
free(ratbag->name);
|
||||
ratbag->libratbag = libratbag_unref(ratbag->libratbag);
|
||||
if (device) {
|
||||
free(device->name);
|
||||
device->libratbag = libratbag_unref(device->libratbag);
|
||||
}
|
||||
free(ratbag);
|
||||
free(device);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LIBRATBAG_EXPORT struct ratbag *
|
||||
ratbag_unref(struct ratbag *ratbag)
|
||||
LIBRATBAG_EXPORT struct ratbag_device *
|
||||
ratbag_device_unref(struct ratbag_device *device)
|
||||
{
|
||||
if (ratbag == NULL)
|
||||
if (device == NULL)
|
||||
return NULL;
|
||||
|
||||
assert(ratbag->refcount > 0);
|
||||
ratbag->refcount--;
|
||||
if (ratbag->refcount > 0)
|
||||
return ratbag;
|
||||
assert(device->refcount > 0);
|
||||
device->refcount--;
|
||||
if (device->refcount > 0)
|
||||
return device;
|
||||
|
||||
if (ratbag->driver->remove)
|
||||
ratbag->driver->remove(ratbag);
|
||||
if (device->driver->remove)
|
||||
device->driver->remove(device);
|
||||
|
||||
udev_device_unref(ratbag->udev_device);
|
||||
udev_device_unref(ratbag->udev_hidraw);
|
||||
udev_device_unref(device->udev_device);
|
||||
udev_device_unref(device->udev_hidraw);
|
||||
|
||||
if (ratbag->hidraw_fd >= 0)
|
||||
close(ratbag->hidraw_fd);
|
||||
if (device->hidraw_fd >= 0)
|
||||
close(device->hidraw_fd);
|
||||
|
||||
ratbag->libratbag = libratbag_unref(ratbag->libratbag);
|
||||
free(ratbag->name);
|
||||
free(ratbag);
|
||||
device->libratbag = libratbag_unref(device->libratbag);
|
||||
free(device->name);
|
||||
free(device);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LIBRATBAG_EXPORT const char *
|
||||
ratbag_get_name(const struct ratbag* ratbag)
|
||||
ratbag_device_get_name(const struct ratbag_device* device)
|
||||
{
|
||||
return ratbag->name;
|
||||
return device->name;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -430,7 +430,7 @@ libratbag_unref(struct libratbag *libratbag)
|
||||
}
|
||||
|
||||
static struct ratbag_profile *
|
||||
ratbag_create_profile(struct ratbag *ratbag, unsigned int index)
|
||||
ratbag_create_profile(struct ratbag_device *device, unsigned int index)
|
||||
{
|
||||
struct ratbag_profile *profile;
|
||||
|
||||
@@ -439,14 +439,14 @@ ratbag_create_profile(struct ratbag *ratbag, unsigned int index)
|
||||
return NULL;
|
||||
|
||||
profile->refcount = 1;
|
||||
profile->ratbag = ratbag;
|
||||
profile->device = device;
|
||||
profile->index = index;
|
||||
|
||||
list_insert(&ratbag->profiles, &profile->link);
|
||||
list_insert(&device->profiles, &profile->link);
|
||||
list_init(&profile->buttons);
|
||||
|
||||
assert(ratbag->driver->read_profile);
|
||||
ratbag->driver->read_profile(profile, index);
|
||||
assert(device->driver->read_profile);
|
||||
device->driver->read_profile(profile, index);
|
||||
|
||||
return profile;
|
||||
}
|
||||
@@ -476,72 +476,73 @@ ratbag_profile_unref(struct ratbag_profile *profile)
|
||||
}
|
||||
|
||||
LIBRATBAG_EXPORT struct ratbag_profile *
|
||||
ratbag_get_profile_by_index(struct ratbag *ratbag, unsigned int index)
|
||||
ratbag_device_get_profile_by_index(struct ratbag_device *device, unsigned int index)
|
||||
{
|
||||
struct ratbag_profile *profile;
|
||||
|
||||
list_for_each(profile, &ratbag->profiles, link) {
|
||||
list_for_each(profile, &device->profiles, link) {
|
||||
if (profile->index == index) {
|
||||
assert(ratbag->driver->read_profile);
|
||||
ratbag->driver->read_profile(profile, index);
|
||||
assert(device->driver->read_profile);
|
||||
device->driver->read_profile(profile, index);
|
||||
return ratbag_profile_ref(profile);
|
||||
}
|
||||
}
|
||||
|
||||
return ratbag_create_profile(ratbag, index);
|
||||
return ratbag_create_profile(device, index);
|
||||
}
|
||||
|
||||
LIBRATBAG_EXPORT struct ratbag_profile *
|
||||
ratbag_get_active_profile(struct ratbag *ratbag)
|
||||
ratbag_device_get_active_profile(struct ratbag_device *device)
|
||||
{
|
||||
int current_profile;
|
||||
|
||||
assert(ratbag->driver->get_active_profile);
|
||||
current_profile = ratbag->driver->get_active_profile(ratbag);
|
||||
assert(device->driver->get_active_profile);
|
||||
current_profile = device->driver->get_active_profile(device);
|
||||
if (current_profile < 0) {
|
||||
errno = -current_profile;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ratbag_get_profile_by_index(ratbag, current_profile);
|
||||
return ratbag_device_get_profile_by_index(device, current_profile);
|
||||
}
|
||||
|
||||
LIBRATBAG_EXPORT unsigned int
|
||||
ratbag_get_num_profiles(struct ratbag *ratbag)
|
||||
ratbag_device_get_num_profiles(struct ratbag_device *device)
|
||||
{
|
||||
return ratbag->num_profiles;
|
||||
return device->num_profiles;
|
||||
}
|
||||
|
||||
LIBRATBAG_EXPORT unsigned int
|
||||
ratbag_get_num_buttons(struct ratbag *ratbag)
|
||||
ratbag_device_get_num_buttons(struct ratbag_device *device)
|
||||
{
|
||||
return ratbag->num_buttons;
|
||||
return device->num_buttons;
|
||||
}
|
||||
|
||||
LIBRATBAG_EXPORT int
|
||||
ratbag_has_capability(const struct ratbag *ratbag, enum ratbag_capability cap)
|
||||
ratbag_device_has_capability(const struct ratbag_device *device,
|
||||
enum ratbag_capability cap)
|
||||
{
|
||||
assert(ratbag->driver->has_capability);
|
||||
return ratbag->driver->has_capability(ratbag, cap);
|
||||
assert(device->driver->has_capability);
|
||||
return device->driver->has_capability(device, cap);
|
||||
}
|
||||
|
||||
LIBRATBAG_EXPORT int
|
||||
ratbag_set_active_profile(struct ratbag *ratbag,
|
||||
struct ratbag_profile *profile)
|
||||
ratbag_device_set_active_profile(struct ratbag_device *device,
|
||||
struct ratbag_profile *profile)
|
||||
{
|
||||
int rc;
|
||||
|
||||
assert(ratbag->driver->write_profile);
|
||||
rc = ratbag->driver->write_profile(profile);
|
||||
assert(device->driver->write_profile);
|
||||
rc = device->driver->write_profile(profile);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
assert(ratbag->driver->set_active_profile);
|
||||
return ratbag->driver->set_active_profile(ratbag, profile->index);
|
||||
assert(device->driver->set_active_profile);
|
||||
return device->driver->set_active_profile(device, profile->index);
|
||||
}
|
||||
|
||||
static struct ratbag_button *
|
||||
ratbag_create_button(struct ratbag *ratbag, struct ratbag_profile *profile,
|
||||
ratbag_create_button(struct ratbag_device *device, struct ratbag_profile *profile,
|
||||
unsigned int index)
|
||||
{
|
||||
struct ratbag_button *button;
|
||||
@@ -551,15 +552,15 @@ ratbag_create_button(struct ratbag *ratbag, struct ratbag_profile *profile,
|
||||
return NULL;
|
||||
|
||||
button->refcount = 1;
|
||||
button->ratbag = ratbag;
|
||||
button->device = device;
|
||||
button->profile = profile;
|
||||
button->index = index;
|
||||
|
||||
if (profile)
|
||||
list_insert(&profile->buttons, &button->link);
|
||||
|
||||
if (ratbag->driver->read_button)
|
||||
ratbag->driver->read_button(ratbag, profile, button);
|
||||
if (device->driver->read_button)
|
||||
device->driver->read_button(device, profile, button);
|
||||
|
||||
return button;
|
||||
}
|
||||
@@ -572,13 +573,13 @@ ratbag_profile_get_button_by_index(struct ratbag_profile *profile,
|
||||
|
||||
list_for_each(button, &profile->buttons, link) {
|
||||
if (button->index == index) {
|
||||
if (profile->ratbag->driver->read_button)
|
||||
profile->ratbag->driver->read_button(profile->ratbag, profile, button);
|
||||
if (profile->device->driver->read_button)
|
||||
profile->device->driver->read_button(profile->device, profile, button);
|
||||
return ratbag_button_ref(button);
|
||||
}
|
||||
}
|
||||
|
||||
return ratbag_create_button(profile->ratbag, profile, index);
|
||||
return ratbag_create_button(profile->device, profile, index);
|
||||
}
|
||||
|
||||
LIBRATBAG_EXPORT struct ratbag_button *
|
||||
|
||||
@@ -99,14 +99,14 @@ typedef void (*libratbag_log_handler)(struct libratbag *libratbag,
|
||||
|
||||
/**
|
||||
* @ingroup base
|
||||
* @struct ratbag
|
||||
* @struct ratbag_device
|
||||
*
|
||||
* A ratbag context represents one single device. This struct is
|
||||
* refcounted, use ratbag_ref() and ratbag_unref().
|
||||
* refcounted, use ratbag_device_ref() and ratbag_device_unref().
|
||||
*
|
||||
* FIXME: missing: set/get_userdata
|
||||
*/
|
||||
struct ratbag;
|
||||
struct ratbag_device;
|
||||
|
||||
/**
|
||||
* @ingroup device
|
||||
@@ -208,9 +208,9 @@ libratbag_unref(struct libratbag *libratbag);
|
||||
*
|
||||
* Create a new ratbag context from the given udev device.
|
||||
*/
|
||||
struct ratbag*
|
||||
ratbag_new_from_udev_device(struct libratbag *libratbag,
|
||||
struct udev_device *device);
|
||||
struct ratbag_device*
|
||||
ratbag_device_new_from_udev_device(struct libratbag *libratbag,
|
||||
struct udev_device *device);
|
||||
|
||||
/**
|
||||
* @ingroup base
|
||||
@@ -219,7 +219,7 @@ ratbag_new_from_udev_device(struct libratbag *libratbag,
|
||||
* @return The name of the device associated with the given ratbag.
|
||||
*/
|
||||
const char *
|
||||
ratbag_get_name(const struct ratbag* ratbag);
|
||||
ratbag_device_get_name(const struct ratbag_device* ratbag);
|
||||
|
||||
/**
|
||||
* @ingroup device
|
||||
@@ -270,7 +270,7 @@ enum ratbag_capability {
|
||||
* @retval 0 The context does not have the capability
|
||||
*/
|
||||
int
|
||||
ratbag_has_capability(const struct ratbag *ratbag, enum ratbag_capability cap);
|
||||
ratbag_device_has_capability(const struct ratbag_device *ratbag, enum ratbag_capability cap);
|
||||
|
||||
/**
|
||||
* @ingroup device
|
||||
@@ -288,7 +288,7 @@ ratbag_has_capability(const struct ratbag *ratbag, enum ratbag_capability cap);
|
||||
* @return The number of profiles available on this device.
|
||||
*/
|
||||
unsigned int
|
||||
ratbag_get_num_profiles(struct ratbag *ratbag);
|
||||
ratbag_device_get_num_profiles(struct ratbag_device *ratbag);
|
||||
|
||||
/**
|
||||
* @ingroup device
|
||||
@@ -299,7 +299,7 @@ ratbag_get_num_profiles(struct ratbag *ratbag);
|
||||
* @return The number of buttons available on this device.
|
||||
*/
|
||||
unsigned int
|
||||
ratbag_get_num_buttons(struct ratbag *ratbag);
|
||||
ratbag_device_get_num_buttons(struct ratbag_device *ratbag);
|
||||
|
||||
/**
|
||||
* @ingroup device
|
||||
@@ -320,7 +320,7 @@ ratbag_get_num_buttons(struct ratbag *ratbag);
|
||||
* @see ratbag_get_num_profiles
|
||||
*/
|
||||
struct ratbag_profile *
|
||||
ratbag_get_profile_by_index(struct ratbag *ratbag, unsigned int index);
|
||||
ratbag_device_get_profile_by_index(struct ratbag_device *ratbag, unsigned int index);
|
||||
|
||||
/**
|
||||
* @ingroup device
|
||||
@@ -337,7 +337,7 @@ ratbag_get_profile_by_index(struct ratbag *ratbag, unsigned int index);
|
||||
* @return The profile currently active on the device.
|
||||
*/
|
||||
struct ratbag_profile *
|
||||
ratbag_get_active_profile(struct ratbag *ratbag);
|
||||
ratbag_device_get_active_profile(struct ratbag_device *ratbag);
|
||||
|
||||
/**
|
||||
* @ingroup device
|
||||
@@ -350,8 +350,8 @@ ratbag_get_active_profile(struct ratbag *ratbag);
|
||||
* @return 0 on success or nonzero otherwise.
|
||||
*/
|
||||
int
|
||||
ratbag_set_active_profile(struct ratbag *ratbag,
|
||||
struct ratbag_profile *profile);
|
||||
ratbag_device_set_active_profile(struct ratbag_device *ratbag,
|
||||
struct ratbag_profile *profile);
|
||||
|
||||
/**
|
||||
* @ingroup device
|
||||
@@ -450,7 +450,7 @@ ratbag_profile_get_button_by_index(struct ratbag_profile *profile,
|
||||
* @see ratbag_get_num_buttons
|
||||
*/
|
||||
struct ratbag_button*
|
||||
ratbag_get_button_by_index(struct ratbag *ratbag, unsigned int index);
|
||||
ratbag_get_button_by_index(struct ratbag_device *ratbag, unsigned int index);
|
||||
|
||||
enum ratbag_button_type {
|
||||
RATBAG_BUTTON_TYPE_UNKNOWN = 0,
|
||||
@@ -674,13 +674,13 @@ ratbag_profile_unref(struct ratbag_profile *profile);
|
||||
* @ingroup base
|
||||
*
|
||||
* Add a reference to the context. A context is destroyed whenever the
|
||||
* reference count reaches 0. See @ref ratbag_unref.
|
||||
* reference count reaches 0. See @ref ratbag_device_unref.
|
||||
*
|
||||
* @param ratbag A previously initialized valid ratbag context
|
||||
* @return The passed ratbag context
|
||||
*/
|
||||
struct ratbag *
|
||||
ratbag_ref(struct ratbag *ratbag);
|
||||
struct ratbag_device *
|
||||
ratbag_device_ref(struct ratbag_device *ratbag);
|
||||
|
||||
/**
|
||||
* @ingroup base
|
||||
@@ -692,8 +692,8 @@ ratbag_ref(struct ratbag *ratbag);
|
||||
* @param ratbag A previously initialized ratbag context
|
||||
* @return NULL if context was destroyed otherwise the passed context
|
||||
*/
|
||||
struct ratbag *
|
||||
ratbag_unref(struct ratbag *ratbag);
|
||||
struct ratbag_device *
|
||||
ratbag_device_unref(struct ratbag_device *ratbag);
|
||||
|
||||
/**
|
||||
* @ingroup base
|
||||
|
||||
@@ -11,17 +11,17 @@ global:
|
||||
ratbag_button_ref;
|
||||
ratbag_button_unref;
|
||||
ratbag_profile_get_button_by_index;
|
||||
ratbag_get_active_profile;
|
||||
ratbag_get_name;
|
||||
ratbag_get_num_profiles;
|
||||
ratbag_get_num_buttons;
|
||||
ratbag_get_profile_by_index;
|
||||
ratbag_has_capability;
|
||||
ratbag_new_from_udev_device;
|
||||
ratbag_set_active_profile;
|
||||
ratbag_device_get_active_profile;
|
||||
ratbag_device_get_name;
|
||||
ratbag_device_get_num_profiles;
|
||||
ratbag_device_get_num_buttons;
|
||||
ratbag_device_get_profile_by_index;
|
||||
ratbag_device_has_capability;
|
||||
ratbag_device_new_from_udev_device;
|
||||
ratbag_device_set_active_profile;
|
||||
ratbag_profile_ref;
|
||||
ratbag_profile_unref;
|
||||
ratbag_unref;
|
||||
ratbag_device_unref;
|
||||
local:
|
||||
*;
|
||||
};
|
||||
|
||||
@@ -87,7 +87,7 @@ static int
|
||||
ratbag_cmd_info(struct libratbag *libratbag, uint32_t flags, int argc, char **argv)
|
||||
{
|
||||
const char *path;
|
||||
struct ratbag *rb;
|
||||
struct ratbag_device *rb;
|
||||
struct ratbag_profile *profile;
|
||||
struct ratbag_button *button;
|
||||
int i;
|
||||
@@ -107,25 +107,25 @@ ratbag_cmd_info(struct libratbag *libratbag, uint32_t flags, int argc, char **ar
|
||||
if (!udev_device)
|
||||
return 1;
|
||||
|
||||
rb = ratbag_new_from_udev_device(libratbag, udev_device);
|
||||
rb = ratbag_device_new_from_udev_device(libratbag, udev_device);
|
||||
if (!rb) {
|
||||
fprintf(stderr, "Looks like '%s' is not supported\n", path);
|
||||
goto out;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Opened '%s' (%s).\n", ratbag_get_name(rb), path);
|
||||
fprintf(stderr, "Opened '%s' (%s).\n", ratbag_device_get_name(rb), path);
|
||||
|
||||
profile = ratbag_get_profile_by_index(rb, 0);
|
||||
ratbag_set_active_profile(rb, profile);
|
||||
profile = ratbag_device_get_profile_by_index(rb, 0);
|
||||
ratbag_device_set_active_profile(rb, profile);
|
||||
profile = ratbag_profile_unref(profile);
|
||||
|
||||
profile = ratbag_get_active_profile(rb);
|
||||
for (i = 0; i < ratbag_get_num_buttons(rb); i++) {
|
||||
profile = ratbag_device_get_active_profile(rb);
|
||||
for (i = 0; i < ratbag_device_get_num_buttons(rb); i++) {
|
||||
button = ratbag_profile_get_button_by_index(profile, i);
|
||||
button = ratbag_button_unref(button);
|
||||
}
|
||||
profile = ratbag_profile_unref(profile);
|
||||
rb = ratbag_unref(rb);
|
||||
rb = ratbag_device_unref(rb);
|
||||
|
||||
rc = 0;
|
||||
out:
|
||||
|
||||
Reference in New Issue
Block a user