[Kde-hardware-devel] Semantics of Solid::Device::listFromType()

Raphael Kubo da Costa rakuco at FreeBSD.org
Sat Jul 21 00:05:54 UTC 2012


Hey there,

When I sent review request #105615 a few days ago, Alberto Villa brought
up the point that the handling of `parentUdi' and `type' in
DeviceManager::devicesFromQuery() looked weird, and it looks like it is
true on a few different backends: kupnp (if I understood the code
correctly), udev, udisks, upower and wmi (in a different way).

The documentation for Solid::Ifaces::DeviceManager::devicesFromQuery(),
which is called by Solid::Device::listFromType(), seems to state that
the parameters `parentUdi' and `type' are parsed separately, and the
method returns the union of the sets found by each of them. In other
words, if I pass a non-empty QString to `parentUdi' and pass
Solid::DeviceInterface::Unknown to `type', I should get all devices
(regardless of their type) which have the given parent.

However, the backends I mentioned above usually follow the pattern below
when implementing devicesFromQuery():

  if (!parentUdi.isEmpty()) {
      foreach (const QString &udi, getAllDeviceUdis()) {
          Device device(udi);
          if (device.queryDeviceInterface(type) &&
              device.parentUdi() == parentUdi) {
              addDeviceToList(device);
          }
      }
  } else if (type != Solid::DeviceInterface::Unknown) {
      // Mostly the same code, without checking the parent.
  } else {
      return allDevices();
  }

The problem with this approach is that passing a non-empty parent and
Unknown as the type will, in this case, normally fail to find devices
because queryDeviceInterface(Solid::DeviceInterface::Unknown) usually
just returns false.

The hal and iokit backends seem to follow the proper semantics.

So my question is whether all those backends I mentioned are really
doing the wrong thing or it is just the documentation that is
misleading (and thus the other backends need to be fixed).



More information about the Kde-hardware-devel mailing list