udev: Add a method to get all properties of an UdevDevice

It's useful for debugging.
This commit is contained in:
Aleix Pol 2021-04-12 19:53:50 +02:00 committed by Aleix Pol Gonzalez
parent 01f7ef35e7
commit bec580f3c5
2 changed files with 17 additions and 0 deletions

View file

@ -256,6 +256,21 @@ const char *UdevDevice::property(const char *key)
return udev_device_get_property_value(m_device, key); return udev_device_get_property_value(m_device, key);
} }
QMap<QByteArray, QByteArray> UdevDevice::properties() const
{
QMap<QByteArray, QByteArray> r;
if (!m_device) {
return r;
}
auto it = udev_device_get_properties_list_entry(m_device);
auto current = it;
udev_list_entry_foreach (current, it) {
r.insert(udev_list_entry_get_name(current), udev_list_entry_get_value(current));
}
return r;
}
bool UdevDevice::hasProperty(const char *key, const char *value) bool UdevDevice::hasProperty(const char *key, const char *value)
{ {
const char *p = property(key); const char *p = property(key);

View file

@ -34,6 +34,8 @@ public:
const char *property(const char *key); const char *property(const char *key);
bool hasProperty(const char *key, const char *value); bool hasProperty(const char *key, const char *value);
QMap<QByteArray, QByteArray> properties() const;
operator udev_device*() const { operator udev_device*() const {
return m_device; return m_device;
} }