[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    API addition in Solid
From:       Matthias Kretz <kretz () kde ! org>
Date:       2007-11-17 15:16:01
Message-ID: 200711171616.05314.kretz () kde ! org
[Download RAW message or body]

[Attachment #2 (multipart/mixed)]


Hi,

I need a globally unique identifier for the devices listed by Solid. And 
Solid::Device::udi() is not that.

So I added the API and implementation for it, but the HAL implementation 
currently is just proof-of-concept and the fakecomputer.xml doesn't have any 
uniqueIdentifiers for now.

I need this to fix the problem of initial ordering of audio devices in phonon. 
Without a globally unique identifier I cannot have a "hardware database" 
where the ordering of devices can be "fixed".

-- 
________________________________________________________
Matthias Kretz (Germany)                            <><
http://Vir.homelinux.org/
MatthiasKretz@gmx.net, kretz@kde.org,
Matthias.Kretz@urz.uni-heidelberg.de

["solid-unique-id.patch" (text/x-diff)]

Index: device.h
===================================================================
--- device.h	(revision 737258)
+++ device.h	(working copy)
@@ -133,6 +133,9 @@
         /**
          * Retrieves the Universal Device Identifier (UDI).
          *
+         * \warning Don't use the UDI for anything except communication with Solid. \
Also don't store +         * UDIs as there's no guarantee that the UDI stays the same \
when the hardware setup changed. +         *
          * @return the udi of the device
          */
         QString udi() const;
@@ -145,7 +148,17 @@
          */
         QString parentUdi() const;
 
+        /**
+         * Returns a string that globally and uniquely identifies the device.
+         *
+         * \warning Not every device has such an identifier. Sometimes you can find \
a +         * uniqueIdentifier at the parent device, though.
+         *
+         * @return The unique id of the device, or QString() if it has none.
+         */
+        QString uniqueIdentifier() const;
 
+
         /**
          * Retrieves the parent of the Device.
          *
Index: device.cpp
===================================================================
--- device.cpp	(revision 737258)
+++ device.cpp	(working copy)
@@ -100,6 +100,11 @@
     return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), parentUdi());
 }
 
+QString Solid::Device::uniqueIdentifier() const
+{
+    return_SOLID_CALL(Ifaces::Device *, d->backendObject(), QString(), \
uniqueIdentifier()); +}
+
 Solid::Device Solid::Device::parent() const
 {
     QString udi = parentUdi();
Index: ifaces/device.h
===================================================================
--- ifaces/device.h	(revision 737258)
+++ ifaces/device.h	(working copy)
@@ -72,7 +72,17 @@
          */
         virtual QString parentUdi() const;
 
+        /**
+         * Returns a string that globally and uniquely identifies the device.
+         *
+         * \warning Not every device has such an identifier. Sometimes you can find \
a +         * uniqueIdentifier at the parent device, though.
+         *
+         * @return The unique id of the device, or QString() if it has none.
+         */
+        virtual QString uniqueIdentifier() const = 0;
 
+
         /**
          * Retrieves the name of the device vendor.
          *
Index: backends/hal/haldevice.cpp
===================================================================
--- backends/hal/haldevice.cpp	(revision 737258)
+++ backends/hal/haldevice.cpp	(working copy)
@@ -115,6 +115,25 @@
     return property("info.parent").toString();
 }
 
+QString HalDevice::uniqueIdentifier() const
+{
+    const QVariant vendor_id = property("pci.vendor_id");
+    if (vendor_id.isValid()) {
+        const QVariant product_id = property("pci.product_id");
+        if (product_id.isValid()) {
+            const QVariant subsys_vendor_id = property("pci.subsys_vendor_id");
+            if (subsys_vendor_id.isValid()) {
+                const QVariant subsys_product_id = \
property("pci.subsys_product_id"); +                if (subsys_product_id.isValid()) \
{ +                    return vendor_id.toString() + QLatin1Char('_') + \
product_id.toString() + QLatin1Char('_') +                        + \
subsys_vendor_id.toString() + QLatin1Char('_') + subsys_product_id.toString(); +      \
} +            }
+        }
+    }
+    return QString();
+}
+
 QString HalDevice::vendor() const
 {
     return property("info.vendor").toString();
Index: backends/hal/haldevice.h
===================================================================
--- backends/hal/haldevice.h	(revision 737258)
+++ backends/hal/haldevice.h	(working copy)
@@ -48,6 +48,7 @@
 
     virtual QString udi() const;
     virtual QString parentUdi() const;
+    virtual QString uniqueIdentifier() const;
 
     virtual QString vendor() const;
     virtual QString product() const;
Index: backends/fakehw/fakedevice.h
===================================================================
--- backends/fakehw/fakedevice.h	(revision 737258)
+++ backends/fakehw/fakedevice.h	(working copy)
@@ -39,6 +39,7 @@
 public Q_SLOTS:
     virtual QString udi() const;
     virtual QString parentUdi() const;
+    virtual QString uniqueIdentifier() const;
     virtual QString vendor() const;
     virtual QString product() const;
     virtual QString icon() const;
Index: backends/fakehw/fakedevice.cpp
===================================================================
--- backends/fakehw/fakedevice.cpp	(revision 737258)
+++ backends/fakehw/fakedevice.cpp	(working copy)
@@ -92,6 +92,11 @@
     return d->propertyMap["parent"].toString();
 }
 
+QString FakeDevice::uniqueIdentifier() const
+{
+    return d->propertyMap["uniqueIdentifier"].toString();
+}
+
 QString FakeDevice::vendor() const
 {
     return d->propertyMap["vendor"].toString();


["signature.asc" (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic