forked from drath/libratbag
Add the various set/get_user_data() functions
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
@@ -52,6 +52,8 @@ struct ratbag {
|
||||
|
||||
struct ratbag_device {
|
||||
char *name;
|
||||
void *userdata;
|
||||
|
||||
struct udev_device *udev_device;
|
||||
struct udev_device *udev_hidraw;
|
||||
int hidraw_fd;
|
||||
@@ -178,6 +180,8 @@ struct ratbag_driver {
|
||||
|
||||
struct ratbag_profile {
|
||||
int refcount;
|
||||
void *userdata;
|
||||
|
||||
struct list link;
|
||||
unsigned index;
|
||||
struct ratbag_device *device;
|
||||
@@ -218,6 +222,7 @@ struct ratbag_button_action {
|
||||
|
||||
struct ratbag_button {
|
||||
int refcount;
|
||||
void *userdata;
|
||||
struct list link;
|
||||
struct ratbag_profile *profile;
|
||||
unsigned index;
|
||||
|
||||
@@ -895,3 +895,22 @@ ratbag_button_unref(struct ratbag_button *button)
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
#define func_userdata(T) \
|
||||
LIBRATBAG_EXPORT void \
|
||||
T##_set_user_data(struct T *ptr, void *userdata) \
|
||||
{ \
|
||||
ptr->userdata = userdata; \
|
||||
} \
|
||||
\
|
||||
LIBRATBAG_EXPORT void * \
|
||||
T##_get_user_data(const struct T *ptr) \
|
||||
{ \
|
||||
return ptr->userdata; \
|
||||
} \
|
||||
|
||||
func_userdata(ratbag)
|
||||
func_userdata(ratbag_device)
|
||||
func_userdata(ratbag_profile)
|
||||
func_userdata(ratbag_button)
|
||||
|
||||
112
src/libratbag.h
112
src/libratbag.h
@@ -94,8 +94,6 @@ typedef void (*ratbag_log_handler)(struct ratbag *ratbag,
|
||||
*
|
||||
* A ratbag context represents one single device. This struct is
|
||||
* refcounted, use ratbag_device_ref() and ratbag_device_unref().
|
||||
*
|
||||
* FIXME: missing: set/get_userdata
|
||||
*/
|
||||
struct ratbag_device;
|
||||
|
||||
@@ -107,8 +105,6 @@ struct ratbag_device;
|
||||
* RATBAG_CAP_SWITCHABLE_PROFILE capability.
|
||||
* This struct is refcounted, use ratbag_profile_ref() and
|
||||
* ratbag_profile_unref().
|
||||
*
|
||||
* FIXME: missing: set/get_userdata
|
||||
*/
|
||||
struct ratbag_profile;
|
||||
|
||||
@@ -120,8 +116,6 @@ struct ratbag_profile;
|
||||
*
|
||||
* This struct is refcounted, use ratbag_button_ref() and
|
||||
* ratbag_button_unref().
|
||||
*
|
||||
* FIXME: missing: set/get_userdata
|
||||
*/
|
||||
struct ratbag_button;
|
||||
|
||||
@@ -169,6 +163,34 @@ struct ratbag *
|
||||
ratbag_create_context(const struct ratbag_interface *interface,
|
||||
void *userdata);
|
||||
|
||||
/**
|
||||
* @ingroup base
|
||||
*
|
||||
* Set caller-specific data associated with this context. libratbag does
|
||||
* not manage, look at, or modify this data. The caller must ensure the
|
||||
* data is valid.
|
||||
*
|
||||
* Setting userdata overrides the one provided to ratbag_create_context().
|
||||
*
|
||||
* @param ratbag A previously initialized ratbag context
|
||||
* @param userdata Caller-specific data passed to the various callback
|
||||
* interfaces.
|
||||
*/
|
||||
void
|
||||
ratbag_set_user_data(struct ratbag *ratbag, void *userdata);
|
||||
|
||||
/**
|
||||
* @ingroup base
|
||||
*
|
||||
* Get the caller-specific data associated with this context, if any.
|
||||
*
|
||||
* @param ratbag A previously initialized ratbag context
|
||||
* @return The caller-specific data previously assigned in
|
||||
* ratbag_create_context (or ratbag_set_user_data()).
|
||||
*/
|
||||
void*
|
||||
ratbag_get_user_data(const struct ratbag *ratbag);
|
||||
|
||||
/**
|
||||
* @ingroup base
|
||||
*
|
||||
@@ -203,6 +225,32 @@ struct ratbag_device*
|
||||
ratbag_device_new_from_udev_device(struct ratbag *ratbag,
|
||||
struct udev_device *device);
|
||||
|
||||
/**
|
||||
* @ingroup device
|
||||
*
|
||||
* Set caller-specific data associated with this device. libratbag does
|
||||
* not manage, look at, or modify this data. The caller must ensure the
|
||||
* data is valid.
|
||||
*
|
||||
* @param device A previously initialized device
|
||||
* @param userdata Caller-specific data passed to the various callback
|
||||
* interfaces.
|
||||
*/
|
||||
void
|
||||
ratbag_device_set_user_data(struct ratbag_device *device, void *userdata);
|
||||
|
||||
/**
|
||||
* @ingroup device
|
||||
*
|
||||
* Get the caller-specific data associated with this device, if any.
|
||||
*
|
||||
* @param device A previously initialized ratbag device
|
||||
* @return The caller-specific data previously assigned in
|
||||
* ratbag_device_set_user_data().
|
||||
*/
|
||||
void*
|
||||
ratbag_device_get_user_data(const struct ratbag_device *device);
|
||||
|
||||
/**
|
||||
* @ingroup device
|
||||
*
|
||||
@@ -285,6 +333,32 @@ ratbag_device_get_num_profiles(struct ratbag_device *ratbag);
|
||||
unsigned int
|
||||
ratbag_device_get_num_buttons(struct ratbag_device *ratbag);
|
||||
|
||||
/**
|
||||
* @ingroup device
|
||||
*
|
||||
* Set caller-specific data associated with this profile. libratbag does
|
||||
* not manage, look at, or modify this data. The caller must ensure the
|
||||
* data is valid.
|
||||
*
|
||||
* @param profile A previously initialized profile
|
||||
* @param userdata Caller-specific data passed to the various callback
|
||||
* interfaces.
|
||||
*/
|
||||
void
|
||||
ratbag_profile_set_user_data(struct ratbag_profile *profile, void *userdata);
|
||||
|
||||
/**
|
||||
* @ingroup device
|
||||
*
|
||||
* Get the caller-specific data associated with this profile, if any.
|
||||
*
|
||||
* @param profile A previously initialized ratbag profile
|
||||
* @return The caller-specific data previously assigned in
|
||||
* ratbag_profile_set_user_data().
|
||||
*/
|
||||
void*
|
||||
ratbag_profile_get_user_data(const struct ratbag_profile *profile);
|
||||
|
||||
/**
|
||||
* @ingroup device
|
||||
*
|
||||
@@ -408,6 +482,32 @@ struct ratbag_button*
|
||||
ratbag_profile_get_button_by_index(struct ratbag_profile *profile,
|
||||
unsigned int index);
|
||||
|
||||
/**
|
||||
* @ingroup device
|
||||
*
|
||||
* Set caller-specific data associated with this button. libratbag does
|
||||
* not manage, look at, or modify this data. The caller must ensure the
|
||||
* data is valid.
|
||||
*
|
||||
* @param button A previously initialized button
|
||||
* @param userdata Caller-specific data passed to the various callback
|
||||
* interfaces.
|
||||
*/
|
||||
void
|
||||
ratbag_button_set_user_data(struct ratbag_button *button, void *userdata);
|
||||
|
||||
/**
|
||||
* @ingroup device
|
||||
*
|
||||
* Get the caller-specific data associated with this button, if any.
|
||||
*
|
||||
* @param button A previously initialized ratbag button
|
||||
* @return The caller-specific data previously assigned in
|
||||
* ratbag_button_set_user_data().
|
||||
*/
|
||||
void*
|
||||
ratbag_button_get_user_data(const struct ratbag_button *button);
|
||||
|
||||
enum ratbag_button_type {
|
||||
RATBAG_BUTTON_TYPE_UNKNOWN = 0,
|
||||
|
||||
|
||||
@@ -10,9 +10,11 @@ global:
|
||||
ratbag_button_get_button;
|
||||
ratbag_button_get_key;
|
||||
ratbag_button_get_special;
|
||||
ratbag_button_get_user_data;
|
||||
ratbag_button_set_button;
|
||||
ratbag_button_set_key;
|
||||
ratbag_button_set_special;
|
||||
ratbag_button_set_user_data;
|
||||
ratbag_button_unref;
|
||||
ratbag_device_unref;
|
||||
ratbag_device_get_active_profile;
|
||||
@@ -20,20 +22,26 @@ global:
|
||||
ratbag_device_get_num_profiles;
|
||||
ratbag_device_get_num_buttons;
|
||||
ratbag_device_get_profile_by_index;
|
||||
ratbag_device_get_user_data;
|
||||
ratbag_device_has_capability;
|
||||
ratbag_device_new_from_udev_device;
|
||||
ratbag_device_ref;
|
||||
ratbag_device_set_user_data;
|
||||
ratbag_device_set_active_profile;
|
||||
ratbag_get_user_data;
|
||||
ratbag_log_get_priority;
|
||||
ratbag_log_set_handler;
|
||||
ratbag_log_set_priority;
|
||||
ratbag_profile_get_button_by_index;
|
||||
ratbag_profile_get_report_rate_hz;
|
||||
ratbag_profile_get_resolution_dpi;
|
||||
ratbag_profile_get_user_data;
|
||||
ratbag_profile_set_resolution_dpi;
|
||||
ratbag_profile_set_user_data;
|
||||
ratbag_profile_ref;
|
||||
ratbag_profile_unref;
|
||||
ratbag_ref;
|
||||
ratbag_set_user_data;
|
||||
ratbag_unref;
|
||||
local:
|
||||
*;
|
||||
|
||||
Reference in New Issue
Block a user