2010-05-20 21:11:58 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2010-05-22 00:04:00 -07:00
|
|
|
#include <Eeze.h>
|
2010-05-20 21:11:58 -07:00
|
|
|
#include "eeze_udev_private.h"
|
|
|
|
|
2010-05-22 14:44:26 -07:00
|
|
|
/**
|
2010-10-15 20:57:54 -07:00
|
|
|
* @addtogroup walks Walks
|
2010-05-22 14:44:26 -07:00
|
|
|
*
|
|
|
|
* These are functions which walk up the device chain.
|
|
|
|
*
|
|
|
|
* @ingroup udev
|
2010-10-15 20:57:54 -07:00
|
|
|
*
|
|
|
|
* @{
|
2010-05-22 14:44:26 -07:00
|
|
|
*/
|
|
|
|
|
2010-05-20 21:11:58 -07:00
|
|
|
/**
|
|
|
|
* Walks up the device chain starting at @p syspath,
|
|
|
|
* checking each device for @p sysattr with (optional) @p value.
|
|
|
|
*
|
|
|
|
* @param syspath The /sys/ path of the device to start at, with or without the /sys/
|
|
|
|
* @param sysattr The attribute to find
|
|
|
|
* @param value OPTIONAL: The value that @p sysattr should have, or NULL
|
|
|
|
*
|
|
|
|
* @return If the sysattr (with value) is found, returns TRUE. Else, false.
|
|
|
|
*/
|
|
|
|
EAPI Eina_Bool
|
2010-05-21 18:55:14 -07:00
|
|
|
eeze_udev_walk_check_sysattr(const char *syspath, const char *sysattr,
|
|
|
|
const char *value)
|
2010-05-20 21:11:58 -07:00
|
|
|
{
|
2010-05-21 18:55:14 -07:00
|
|
|
_udev_device *device, *child, *parent;
|
2010-10-12 19:53:38 -07:00
|
|
|
Eina_Bool ret = EINA_FALSE;
|
2010-05-21 18:55:14 -07:00
|
|
|
const char *test = NULL;
|
|
|
|
|
|
|
|
if (!udev)
|
2010-10-15 21:18:26 -07:00
|
|
|
return EINA_FALSE;
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2010-10-12 19:53:38 -07:00
|
|
|
if (!(device = _new_device(syspath)))
|
|
|
|
return EINA_FALSE;
|
2010-05-21 18:55:14 -07:00
|
|
|
|
|
|
|
for (parent = device; parent;
|
|
|
|
child = parent, parent = udev_device_get_parent(child))
|
|
|
|
{
|
2010-10-12 19:53:38 -07:00
|
|
|
if (!(test = udev_device_get_sysattr_value(parent, sysattr)))
|
|
|
|
continue;
|
|
|
|
if ((value && (!strcmp(test, value))) || (!value))
|
2010-05-21 18:55:14 -07:00
|
|
|
{
|
2010-10-12 19:53:38 -07:00
|
|
|
ret = EINA_TRUE;
|
|
|
|
break;
|
2010-05-21 18:55:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-20 21:11:58 -07:00
|
|
|
udev_device_unref(device);
|
2010-10-15 21:18:26 -07:00
|
|
|
return EINA_FALSE;
|
2010-05-20 21:11:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Walks up the device chain starting at @p syspath,
|
|
|
|
* checking each device for @p sysattr, and returns the value if found.
|
|
|
|
*
|
|
|
|
* @param syspath The /sys/ path of the device to start at, with or without the /sys/
|
|
|
|
* @param sysattr The attribute to find
|
|
|
|
*
|
2010-05-22 22:03:17 -07:00
|
|
|
* @return The stringshared value of @p sysattr if found, or NULL
|
2010-05-20 21:11:58 -07:00
|
|
|
*/
|
2010-05-21 18:55:14 -07:00
|
|
|
EAPI const char *
|
2010-05-20 21:11:58 -07:00
|
|
|
eeze_udev_walk_get_sysattr(const char *syspath, const char *sysattr)
|
|
|
|
{
|
2010-05-21 18:55:14 -07:00
|
|
|
_udev_device *device, *child, *parent;
|
|
|
|
const char *test = NULL;
|
|
|
|
|
|
|
|
if (!syspath)
|
|
|
|
return NULL;
|
|
|
|
|
2010-10-12 19:53:38 -07:00
|
|
|
if (!(device = _new_device(syspath)))
|
|
|
|
return NULL;
|
|
|
|
|
2010-05-21 18:55:14 -07:00
|
|
|
for (parent = device; parent;
|
|
|
|
child = parent, parent = udev_device_get_parent(child))
|
|
|
|
{
|
|
|
|
if ((test = udev_device_get_sysattr_value(parent, sysattr)))
|
|
|
|
{
|
|
|
|
test = eina_stringshare_add(test);
|
|
|
|
udev_device_unref(device);
|
|
|
|
return test;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-20 21:11:58 -07:00
|
|
|
udev_device_unref(device);
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-10-15 20:57:54 -07:00
|
|
|
|
|
|
|
/** @} */
|