diff options
author | Tom Gundersen <teg@jklm.no> | 2014-11-11 22:33:27 +0100 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2014-12-11 13:54:18 +0100 |
commit | 6e67474a816b1021ca7a7beca23891ba35f26d89 (patch) | |
tree | bca2d33a3db9e42ef02a49030342aaf8463c148b | |
parent | 27cca8a55d5c20a926d3a7b865b1dbb00ba55f75 (diff) |
sd-device: sd_device_get_sysattr_{first,next}
-rw-r--r-- | src/libsystemd/sd-device/device-util.h | 5 | ||||
-rw-r--r-- | src/libsystemd/sd-device/sd-device.c | 37 | ||||
-rw-r--r-- | src/systemd/sd-device.h | 2 |
3 files changed, 44 insertions, 0 deletions
diff --git a/src/libsystemd/sd-device/device-util.h b/src/libsystemd/sd-device/device-util.h index e38441556..0fe15494b 100644 --- a/src/libsystemd/sd-device/device-util.h +++ b/src/libsystemd/sd-device/device-util.h @@ -36,3 +36,8 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(sd_device*, sd_device_unref); for (tag = sd_device_get_tag_first(device); \ tag; \ tag = sd_device_get_tag_next(device)) + +#define FOREACH_DEVICE_SYSATTR(device, key, value) \ + for (key = sd_device_get_sysattr_first(device, &(value)); \ + key; \ + key = sd_device_get_sysattr_next(device, &(value))) diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index 678aa7913..cb6de70c8 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -44,6 +44,8 @@ struct sd_device { Iterator properties_iterator; bool properties_modified; Hashmap *sysattrs; + Iterator sysattrs_iterator; + bool sysattrs_modified; Set *tags; Iterator tags_iterator; bool tags_modified; @@ -191,6 +193,7 @@ static int device_add_sysattr(sd_device *device, const char *_key, const char *_ r = hashmap_put(device->sysattrs, key, value); if (r < 0) return r; + device->sysattrs_modified = true; key = NULL; value = NULL; @@ -1379,3 +1382,37 @@ _public_ int sd_device_get_sysattr_value(sd_device *device, const char *sysattr, return 0; } + +_public_ const char *sd_device_get_sysattr_first(sd_device *device, const char **_value) { + const char *key; + const char *value; + + assert_return(device, NULL); + + device->sysattrs_modified = false; + device->sysattrs_iterator = ITERATOR_FIRST; + + value = hashmap_iterate(device->sysattrs, &device->sysattrs_iterator, (const void**) &key); + + if (_value) + *_value = value; + + return key; +} + +_public_ const char *sd_device_get_sysattr_next(sd_device *device, const char **_value) { + const char *key; + const char *value; + + assert_return(device, NULL); + + if (device->sysattrs_modified) + return NULL; + + value = hashmap_iterate(device->sysattrs, &device->sysattrs_iterator, (const void**) &key); + + if (_value) + *_value = value; + + return key; +} diff --git a/src/systemd/sd-device.h b/src/systemd/sd-device.h index 22c5458fb..3d5f05c7a 100644 --- a/src/systemd/sd-device.h +++ b/src/systemd/sd-device.h @@ -58,6 +58,8 @@ const char *sd_device_get_property_first(sd_device *device, const char **value); const char *sd_device_get_property_next(sd_device *device, const char **value); const char *sd_device_get_tag_first(sd_device *device); const char *sd_device_get_tag_next(sd_device *device); +const char *sd_device_get_sysattr_first(sd_device *device, const char **value); +const char *sd_device_get_sysattr_next(sd_device *device, const char **value); _SD_END_DECLARATIONS; |