device: add firmware version API

This commit is contained in:
Yaroslav Chvanov
2022-11-14 21:10:17 +03:00
parent 17f8f0516b
commit 440292fda1
8 changed files with 74 additions and 0 deletions

View File

@@ -158,6 +158,15 @@ known to ratbagd.
The device's name, suitable for presentation to the user.
.. attribute:: FirmwareVersion
:type: s
:flags: read-only, constant
A device-specific string with the firmware version, or the empty
string. For devices with a major/minor or purely numeric firmware
version, the conversion into a string is implementation-defined.
.. attribute:: Profiles
:type: ao

View File

@@ -220,10 +220,27 @@ ratbag_device_get_model(sd_bus *bus,
return sd_bus_message_append(reply, "s", model);
}
static int
ratbagd_device_get_firmware_version(sd_bus *bus,
const char *path,
const char *interface,
const char *property,
sd_bus_message *reply,
void *userdata,
sd_bus_error *error)
{
struct ratbagd_device *device = userdata;
struct ratbag_device *lib_device = device->lib_device;
const char* version = ratbag_device_get_firmware_version(lib_device);
return sd_bus_message_append(reply, "s", version);
}
const sd_bus_vtable ratbagd_device_vtable[] = {
SD_BUS_VTABLE_START(0),
SD_BUS_PROPERTY("Model", "s", ratbag_device_get_model, 0, SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("Name", "s", ratbagd_device_get_device_name, 0, SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("FirmwareVersion", "s", ratbagd_device_get_firmware_version, 0, SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("Profiles", "ao", ratbagd_device_get_profiles, 0, SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_METHOD("Commit", "", "u", ratbagd_device_commit, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_SIGNAL("Resync", "", 0),

View File

@@ -147,6 +147,8 @@ struct ratbag_device {
unsigned num_buttons;
unsigned num_leds;
char* firmware_version;
void *drv_data;
struct list link;

View File

@@ -228,6 +228,7 @@ ratbag_device_destroy(struct ratbag_device *device)
ratbag_unref(device->ratbag);
ratbag_device_data_unref(device->data);
free(device->name);
free(device->firmware_version);
free(device);
}
@@ -1622,6 +1623,19 @@ ratbag_device_get_user_data(const struct ratbag_device *ratbag_device)
return ratbag_device->userdata;
}
LIBRATBAG_EXPORT const char*
ratbag_device_get_firmware_version(const struct ratbag_device *ratbag_device)
{
return ratbag_device->firmware_version;
}
LIBRATBAG_EXPORT void
ratbag_device_set_firmware_version(struct ratbag_device *device, const char* fw)
{
free(device->firmware_version);
device->firmware_version = strdup_safe(fw);
}
LIBRATBAG_EXPORT void*
ratbag_profile_get_user_data(const struct ratbag_profile *ratbag_profile)
{

View File

@@ -421,6 +421,26 @@ ratbag_device_set_user_data(struct ratbag_device *device, void *userdata);
void*
ratbag_device_get_user_data(const struct ratbag_device *device);
/**
* @ingroup device
*
* Set the firmware version of the device.
*
* @param device A previously initialized ratbag device
* @param fw The firmware version of the device.
*/
void
ratbag_device_set_firmware_version(struct ratbag_device *device, const char* fw);
/**
* @ingroup device
*
* @param device A previously initialized ratbag device
* @return The firmware version of the device.
*/
const char*
ratbag_device_get_firmware_version(const struct ratbag_device *device);
/**
* @ingroup device
*

View File

@@ -262,6 +262,11 @@ class RatbagdDevice(metaclass=MetaRatbag):
"""The device name, usually provided by the kernel."""
return libratbag.ratbag_device_get_name(self._device)
@property
def firmware_version(self):
"""The firmware version of the device."""
return libratbag.ratbag_device_get_firmware_version(self._device)
@property
def profiles(self):
"""A list of RatbagdProfile objects provided by this device."""

View File

@@ -229,6 +229,8 @@ def print_device(d, level):
print(" " * level + "{} - {}".format(d.id, d.name))
print(" " * level + " Model: {}".format(d.model))
if d.firmware_version:
print(" " * level + " Firmware version: {}".format(d.firmware_version))
print(" " * level + " Number of Buttons: {}".format(len(p.buttons)))
print(" " * level + " Number of Leds: {}".format(len(p.leds)))
print(" " * level + "Number of Profiles: {}".format(len(d.profiles)))

View File

@@ -347,6 +347,11 @@ class RatbagdDevice(_RatbagdDBus):
"""The device name, usually provided by the kernel."""
return self._get_dbus_property("Name")
@GObject.Property
def firmware_version(self):
"""The firmware version of the device."""
return self._get_dbus_property("FirmwareVersion")
@GObject.Property
def profiles(self):
"""A list of RatbagdProfile objects provided by this device."""