From e7baca25dc83bc395b9a7c96ee3d85381671039f Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Thu, 20 May 2010 07:30:41 +0000 Subject: [PATCH] somehow I forgot a sysattr function... SVN revision: 49058 --- legacy/eeze/src/lib/udev/Eeze_Udev.h | 2 ++ legacy/eeze/src/lib/udev/eeze_udev.c | 44 ++++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/legacy/eeze/src/lib/udev/Eeze_Udev.h b/legacy/eeze/src/lib/udev/Eeze_Udev.h index c511773b94..8d9c38a096 100644 --- a/legacy/eeze/src/lib/udev/Eeze_Udev.h +++ b/legacy/eeze/src/lib/udev/Eeze_Udev.h @@ -85,6 +85,7 @@ * @ingroup udev */ +/*bitmasks for watch events*/ #define EEZE_UDEV_EVENT_NONE 0x0000 #define EEZE_UDEV_EVENT_ADD 0x0001 #define EEZE_UDEV_EVENT_REMOVE 0x0001 @@ -130,6 +131,7 @@ extern "C" { EAPI const char *eeze_udev_syspath_get_devpath(const char *syspath); EAPI const char *eeze_udev_syspath_get_subsystem(const char *syspath); EAPI const char *eeze_udev_syspath_get_property(const char *syspath, const char *property); + EAPI const char *eeze_udev_syspath_get_sysattr(const char *syspath, const char *sysattr); EAPI const char *eeze_udev_devpath_get_syspath(const char *devpath); EAPI const char *eeze_udev_devpath_get_subsystem(const char *devpath); diff --git a/legacy/eeze/src/lib/udev/eeze_udev.c b/legacy/eeze/src/lib/udev/eeze_udev.c index 76ff4a2adc..c75c6cd33f 100644 --- a/legacy/eeze/src/lib/udev/eeze_udev.c +++ b/legacy/eeze/src/lib/udev/eeze_udev.c @@ -171,10 +171,7 @@ eeze_udev_syspath_get_subsystem(const char *syspath) * * @param syspath The /sys/ path with or without the /sys/ * @param property The property to get; full list of these is a FIXME - * @return A const char* with the subsystem of the device or NULL on failure - * - * Takes /sys/$PATH and returns the corresponding device subsystem, - * such as "input" for keyboards/mice. + * @return A const char* with the property or NULL on failure * * @ingroup udev */ @@ -186,7 +183,7 @@ eeze_udev_syspath_get_property(const char *syspath, const char *property) const char *value = NULL, *test; Eina_Strbuf *sbuf; - if (!syspath) return NULL; + if (!syspath || !property) return NULL; udev = udev_new(); if (!udev) return NULL; @@ -206,6 +203,43 @@ eeze_udev_syspath_get_property(const char *syspath, const char *property) return value; } +/** + * Get the sysattr value of a device from the /sys/ path. + * + * @param syspath The /sys/ path with or without the /sys/ + * @param sysattr The sysattr to get; full list of these is a FIXME + * @return A const char* with the sysattr or NULL on failure + * + * @ingroup udev + */ +EAPI const char * +eeze_udev_syspath_get_sysattr(const char *syspath, const char *sysattr) +{ + struct udev *udev; + struct udev_device *device; + const char *value = NULL, *test; + Eina_Strbuf *sbuf; + + if (!syspath || !sysattr) return NULL; + udev = udev_new(); + if (!udev) return NULL; + + sbuf = eina_strbuf_new(); + if (!strstr(syspath, "/sys/")) + eina_strbuf_append(sbuf, "/sys/"); + eina_strbuf_append(sbuf, syspath); + + device = udev_device_new_from_syspath(udev, eina_strbuf_string_get(sbuf)); + if ((test = udev_device_get_sysattr_value(device, sysattr))); + value = eina_stringshare_add(test); + + udev_device_unref(device); + udev_unref(udev); + eina_strbuf_free(sbuf); + + return value; +} + /** * Get the syspath of a device from the /dev/ path. *