2010-05-16 19:59:07 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2010-05-13 03:49:17 -07:00
|
|
|
|
2010-05-22 00:04:00 -07:00
|
|
|
#include <Eeze.h>
|
2010-05-16 19:59:07 -07:00
|
|
|
#include "eeze_udev_private.h"
|
2010-05-14 00:36:43 -07:00
|
|
|
|
2010-05-13 03:49:17 -07:00
|
|
|
EAPI const char *
|
2010-05-16 19:59:07 -07:00
|
|
|
eeze_udev_syspath_get_parent(const char *syspath)
|
2010-05-13 03:49:17 -07:00
|
|
|
{
|
2010-05-21 18:55:14 -07:00
|
|
|
_udev_device *device, *parent;
|
2010-05-13 14:21:12 -07:00
|
|
|
const char *ret;
|
2010-05-13 03:49:17 -07:00
|
|
|
|
2010-05-21 18:55:14 -07:00
|
|
|
if (!syspath)
|
|
|
|
return NULL;
|
|
|
|
|
2010-10-12 19:53:38 -07:00
|
|
|
if (!(device = _new_device(syspath)))
|
|
|
|
return NULL;
|
2010-05-13 03:49:17 -07:00
|
|
|
parent = udev_device_get_parent(device);
|
2010-10-21 11:50:09 -07:00
|
|
|
ret = eina_stringshare_add(udev_device_get_syspath(parent));
|
2010-05-13 03:49:17 -07:00
|
|
|
udev_device_unref(device);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eina_List *
|
2010-05-16 19:59:07 -07:00
|
|
|
eeze_udev_syspath_get_parents(const char *syspath)
|
2010-05-13 03:49:17 -07:00
|
|
|
{
|
2010-05-21 18:55:14 -07:00
|
|
|
_udev_device *child, *parent, *device;
|
2010-05-16 19:59:07 -07:00
|
|
|
const char *path;
|
|
|
|
Eina_List *devlist = NULL;
|
2010-05-13 03:49:17 -07:00
|
|
|
|
2010-05-21 18:55:14 -07:00
|
|
|
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
|
|
|
|
2010-05-16 19:59:07 -07:00
|
|
|
if (!(parent = udev_device_get_parent(device)))
|
|
|
|
return NULL;
|
2010-05-21 18:55:14 -07:00
|
|
|
|
|
|
|
for (; parent; child = parent, parent = udev_device_get_parent(child))
|
|
|
|
{
|
|
|
|
path = udev_device_get_syspath(parent);
|
|
|
|
devlist = eina_list_append(devlist, eina_stringshare_add(path));
|
|
|
|
}
|
|
|
|
|
|
|
|
udev_device_unref(device);
|
|
|
|
return devlist;
|
2010-05-13 03:49:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI const char *
|
2010-05-13 22:21:52 -07:00
|
|
|
eeze_udev_syspath_get_devpath(const char *syspath)
|
2010-05-13 03:49:17 -07:00
|
|
|
{
|
2010-05-21 18:55:14 -07:00
|
|
|
_udev_device *device;
|
|
|
|
const char *name = 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
|
|
|
|
2010-10-21 11:50:09 -07:00
|
|
|
if (!(name = udev_device_get_devnode(device)))
|
2010-05-21 18:55:14 -07:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
name = eina_stringshare_add(name);
|
|
|
|
udev_device_unref(device);
|
|
|
|
return name;
|
2010-05-13 03:49:17 -07:00
|
|
|
}
|
|
|
|
|
2011-03-18 10:10:50 -07:00
|
|
|
EAPI const char *
|
|
|
|
eeze_udev_syspath_get_devname(const char *syspath)
|
|
|
|
{
|
|
|
|
_udev_device *device;
|
|
|
|
const char *name = NULL;
|
|
|
|
|
|
|
|
if (!syspath)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(device = _new_device(syspath)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(name = udev_device_get_sysname(device)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
name = eina_stringshare_add(name);
|
|
|
|
udev_device_unref(device);
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2010-05-13 03:49:17 -07:00
|
|
|
EAPI const char *
|
2010-05-13 22:21:52 -07:00
|
|
|
eeze_udev_syspath_get_subsystem(const char *syspath)
|
2010-05-13 03:49:17 -07:00
|
|
|
{
|
2010-05-21 18:55:14 -07:00
|
|
|
_udev_device *device;
|
|
|
|
const char *subsystem;
|
|
|
|
|
|
|
|
if (!syspath)
|
|
|
|
return NULL;
|
|
|
|
|
2010-10-12 19:53:38 -07:00
|
|
|
if (!(device = _new_device(syspath)))
|
|
|
|
return NULL;
|
|
|
|
subsystem = eina_stringshare_add(udev_device_get_property_value(device, "SUBSYSTEM"));
|
2010-05-21 18:55:14 -07:00
|
|
|
udev_device_unref(device);
|
|
|
|
return subsystem;
|
2010-05-13 03:49:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI const char *
|
2011-01-05 10:46:32 -08:00
|
|
|
eeze_udev_syspath_get_property(const char *syspath,
|
|
|
|
const char *property)
|
2010-05-13 03:49:17 -07:00
|
|
|
{
|
2010-05-21 18:55:14 -07:00
|
|
|
_udev_device *device;
|
|
|
|
const char *value = NULL, *test;
|
2010-05-13 03:49:17 -07:00
|
|
|
|
2010-05-21 18:55:14 -07:00
|
|
|
if (!syspath || !property)
|
|
|
|
return NULL;
|
2010-05-13 03:49:17 -07:00
|
|
|
|
2010-10-12 19:53:38 -07:00
|
|
|
if (!(device = _new_device(syspath)))
|
|
|
|
return NULL;
|
2010-05-21 18:55:14 -07:00
|
|
|
if ((test = udev_device_get_property_value(device, property)))
|
|
|
|
value = eina_stringshare_add(test);
|
2010-05-13 03:49:17 -07:00
|
|
|
|
2010-05-21 18:55:14 -07:00
|
|
|
udev_device_unref(device);
|
|
|
|
return value;
|
2010-05-13 03:49:17 -07:00
|
|
|
}
|
|
|
|
|
2010-05-20 00:30:41 -07:00
|
|
|
EAPI const char *
|
2011-01-05 10:46:32 -08:00
|
|
|
eeze_udev_syspath_get_sysattr(const char *syspath,
|
|
|
|
const char *sysattr)
|
2010-05-20 00:30:41 -07:00
|
|
|
{
|
2010-05-21 18:55:14 -07:00
|
|
|
_udev_device *device;
|
|
|
|
const char *value = NULL, *test;
|
2010-05-20 00:30:41 -07:00
|
|
|
|
2010-05-21 18:55:14 -07:00
|
|
|
if (!syspath || !sysattr)
|
|
|
|
return NULL;
|
2010-05-20 00:30:41 -07:00
|
|
|
|
2010-10-12 19:53:38 -07:00
|
|
|
if (!(device = _new_device(syspath)))
|
|
|
|
return NULL;
|
2010-05-21 18:55:14 -07:00
|
|
|
|
|
|
|
if ((test = udev_device_get_sysattr_value(device, sysattr)))
|
|
|
|
value = eina_stringshare_add(test);
|
2010-05-20 00:30:41 -07:00
|
|
|
|
2010-05-21 18:55:14 -07:00
|
|
|
udev_device_unref(device);
|
|
|
|
return value;
|
2010-05-20 00:30:41 -07:00
|
|
|
}
|
|
|
|
|
2010-05-13 03:49:17 -07:00
|
|
|
EAPI Eina_Bool
|
2010-05-13 22:21:52 -07:00
|
|
|
eeze_udev_syspath_is_mouse(const char *syspath)
|
2010-05-13 03:49:17 -07:00
|
|
|
{
|
2010-10-15 21:18:26 -07:00
|
|
|
_udev_device *device = NULL;
|
|
|
|
Eina_Bool mouse = EINA_FALSE;
|
2010-05-21 18:55:14 -07:00
|
|
|
const char *test = NULL;
|
|
|
|
|
|
|
|
if (!syspath)
|
2010-10-12 19:53:38 -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
|
|
|
|
|
|
|
test = udev_device_get_property_value(device, "ID_INPUT_MOUSE");
|
2010-05-13 03:49:17 -07:00
|
|
|
|
2010-10-15 21:18:26 -07:00
|
|
|
if (test && (test[0] == '1'))
|
|
|
|
mouse = EINA_TRUE;
|
2010-05-13 03:49:17 -07:00
|
|
|
|
2010-05-21 18:55:14 -07:00
|
|
|
udev_device_unref(device);
|
|
|
|
return mouse;
|
2010-05-13 03:49:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eina_Bool
|
2010-05-13 22:21:52 -07:00
|
|
|
eeze_udev_syspath_is_kbd(const char *syspath)
|
2010-05-13 03:49:17 -07:00
|
|
|
{
|
2010-10-15 21:18:26 -07:00
|
|
|
_udev_device *device = NULL;
|
|
|
|
Eina_Bool kbd = EINA_FALSE;
|
2010-05-21 18:55:14 -07:00
|
|
|
const char *test = NULL;
|
|
|
|
|
|
|
|
if (!syspath)
|
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-13 03:49:17 -07:00
|
|
|
|
2010-05-21 18:55:14 -07:00
|
|
|
test = udev_device_get_property_value(device, "ID_INPUT_KEYBOARD");
|
|
|
|
|
2010-10-15 21:18:26 -07:00
|
|
|
if (test && (test[0] == '1'))
|
|
|
|
kbd = EINA_TRUE;
|
2010-05-21 18:55:14 -07:00
|
|
|
|
|
|
|
udev_device_unref(device);
|
|
|
|
return kbd;
|
2010-05-13 03:49:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eina_Bool
|
2010-05-13 22:21:52 -07:00
|
|
|
eeze_udev_syspath_is_touchpad(const char *syspath)
|
2010-05-13 03:49:17 -07:00
|
|
|
{
|
2010-10-15 21:18:26 -07:00
|
|
|
_udev_device *device = NULL;
|
|
|
|
Eina_Bool touchpad = EINA_FALSE;
|
2013-01-03 12:42:37 -08:00
|
|
|
const char *test;
|
2010-05-21 18:55:14 -07:00
|
|
|
|
|
|
|
if (!syspath)
|
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;
|
2013-01-03 12:42:37 -08:00
|
|
|
|
2010-05-21 18:55:14 -07:00
|
|
|
test = udev_device_get_property_value(device, "ID_INPUT_TOUCHPAD");
|
2010-05-13 03:49:17 -07:00
|
|
|
|
2010-10-15 21:18:26 -07:00
|
|
|
if (test && (test[0] == '1'))
|
|
|
|
touchpad = EINA_TRUE;
|
2010-05-21 18:55:14 -07:00
|
|
|
|
|
|
|
udev_device_unref(device);
|
|
|
|
return touchpad;
|
2010-05-13 03:49:17 -07:00
|
|
|
}
|
2010-05-22 14:44:26 -07:00
|
|
|
|
2012-06-29 01:18:12 -07:00
|
|
|
EAPI Eina_Bool
|
|
|
|
eeze_udev_syspath_is_joystick(const char *syspath)
|
|
|
|
{
|
|
|
|
_udev_device *device = NULL;
|
|
|
|
Eina_Bool joystick = EINA_FALSE;
|
|
|
|
const char *test;
|
|
|
|
|
|
|
|
if (!syspath)
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
|
|
|
if (!(device = _new_device(syspath)))
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
|
|
|
test = udev_device_get_property_value(device, "ID_INPUT_JOYSTICK");
|
|
|
|
|
|
|
|
if (test && (test[0] == '1'))
|
|
|
|
joystick = EINA_TRUE;
|
|
|
|
|
|
|
|
udev_device_unref(device);
|
|
|
|
return joystick;
|
|
|
|
}
|
|
|
|
|
2010-05-22 14:44:26 -07:00
|
|
|
EAPI const char *
|
|
|
|
eeze_udev_devpath_get_syspath(const char *devpath)
|
|
|
|
{
|
|
|
|
_udev_enumerate *en;
|
|
|
|
_udev_list_entry *devs, *cur;
|
2010-10-16 13:03:36 -07:00
|
|
|
const char *ret = NULL;
|
2010-05-22 14:44:26 -07:00
|
|
|
|
|
|
|
if (!devpath)
|
|
|
|
return NULL;
|
|
|
|
|
2011-11-10 20:11:26 -08:00
|
|
|
en = udev_enumerate_new(udev);
|
2010-05-22 14:44:26 -07:00
|
|
|
|
|
|
|
if (!en)
|
|
|
|
return NULL;
|
|
|
|
|
2010-10-16 12:59:43 -07:00
|
|
|
udev_enumerate_add_match_property(en, "DEVNAME", devpath);
|
2010-05-22 14:44:26 -07:00
|
|
|
udev_enumerate_scan_devices(en);
|
|
|
|
devs = udev_enumerate_get_list_entry(en);
|
|
|
|
udev_list_entry_foreach(cur, devs)
|
|
|
|
{
|
2010-10-16 13:03:36 -07:00
|
|
|
ret = eina_stringshare_add(udev_list_entry_get_name(cur));
|
2011-01-05 10:46:32 -08:00
|
|
|
break; /*just in case there's more than one somehow */
|
2010-05-22 14:44:26 -07:00
|
|
|
}
|
|
|
|
udev_enumerate_unref(en);
|
|
|
|
return ret;
|
|
|
|
}
|