[Kde-hardware-devel] solid device api proposal: ancestor

Andriy Gapon avg at icyb.net.ua
Thu Mar 15 22:03:38 UTC 2012


I would like to propose to extend Device class interface with something like this:

template <class DevIface> DevIface *ancestor()
{
    Solid::Device parentDevice = *this;

    while ((parentDevice = parentDevice.parent()).isValid()) {
        if (parentDevice.is<DevIface>()) {
            return parentDevice.as<DevIface>();
        }
    }
    return NULL;
}

The purpose is to reach up to an ancestor of a given type (if any).
This could be used for example to easily get a StorageDrive device for a given
StorageVolume device (with possible intermediate partition devices).

Thank you.
-- 
Andriy Gapon


More information about the Kde-hardware-devel mailing list