From 391a0e923e6bf8a0417e4239988884b6a3935a75 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 22 Feb 2019 12:30:56 +1000 Subject: [PATCH] Drop the Device.Id from the DBus interface The Device is an object on DBus, there is no need for another opaque ID, we can just emulate this in the client. In our case by using the object path and generating a sha1 from it. Signed-off-by: Peter Hutterer --- doc/dbus.rst | 10 ---------- ratbagd/ratbagd-device.c | 1 - tools/ratbagctl.in | 2 +- tools/ratbagd.py | 7 +++++-- 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/doc/dbus.rst b/doc/dbus.rst index 4ceca2e7..0bc95512 100644 --- a/doc/dbus.rst +++ b/doc/dbus.rst @@ -98,16 +98,6 @@ org.freedesktop.ratbag1.Device The **org.freedesktop.ratbag1.Device** interface describes a single device known to ratbagd. -.. attribute:: Id - - :type: as - :flags: read-only, constant - - A unique ID describing this device. This ID should not be used for presentation to - the user. This ID may be recycled when the device is removed. The - content of the ID is undefined, the client should treat it as an - opaque string. - .. attribute:: Model :type: s diff --git a/ratbagd/ratbagd-device.c b/ratbagd/ratbagd-device.c index 729cc2a2..c8ef74eb 100644 --- a/ratbagd/ratbagd-device.c +++ b/ratbagd/ratbagd-device.c @@ -217,7 +217,6 @@ ratbag_device_get_model(sd_bus *bus, const sd_bus_vtable ratbagd_device_vtable[] = { SD_BUS_VTABLE_START(0), - SD_BUS_PROPERTY("Id", "s", NULL, offsetof(struct ratbagd_device, sysname), SD_BUS_VTABLE_PROPERTY_CONST), 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("Profiles", "ao", ratbagd_device_get_profiles, 0, SD_BUS_VTABLE_PROPERTY_CONST), diff --git a/tools/ratbagctl.in b/tools/ratbagctl.in index 1ec50d62..70e33e84 100755 --- a/tools/ratbagctl.in +++ b/tools/ratbagctl.in @@ -61,7 +61,7 @@ def list_devices(r, args): print("No devices available.") for d in r.devices: - print("{:10s} {:32s}".format(d.id + ":", d.name)) + print("{:20s} {:32s}".format(d.id + ":", d.name)) def find_device(r, args): diff --git a/tools/ratbagd.py b/tools/ratbagd.py index 7d9d7584..c3c40d17 100644 --- a/tools/ratbagd.py +++ b/tools/ratbagd.py @@ -23,6 +23,7 @@ import os import sys +import hashlib from enum import IntEnum from evdev import ecodes @@ -299,6 +300,9 @@ class RatbagdDevice(_RatbagdDBus): for profile in self._profiles: profile.connect("notify::is-active", self._on_active_profile_changed) + # Use a SHA1 of our object path as our device's ID + self._id = hashlib.sha1(object_path.encode('utf-8')).hexdigest() + def _on_signal_received(self, proxy, sender_name, signal_name, parameters): if signal_name == "Resync": self.emit("resync") @@ -309,8 +313,7 @@ class RatbagdDevice(_RatbagdDBus): @GObject.Property def id(self): - """The unique identifier of this device.""" - return self._get_dbus_property("Id") + return self._id @GObject.Property def model(self):