BIG change, api break (again).
watches now return an int value that can be can be bitwise checked with & to reduce usage of strcmp overall memory allocation should be less (I think), some related bugs fixed along the way small memory leak in test app that I'm too lazy/blind to figure out **this should be the last commit that causes an api break SVN revision: 49118
This commit is contained in:
parent
9317ce25ac
commit
2e71c06192
|
@ -2,6 +2,13 @@
|
||||||
#include <Ecore.h>
|
#include <Ecore.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This demo program shows how to use some eeze functions. It roughly
|
||||||
|
* 1kb as of now, TODO is to fix this but I'm too lazy now and it's only
|
||||||
|
* a demo.
|
||||||
|
*/
|
||||||
|
|
||||||
typedef struct kbdmouse
|
typedef struct kbdmouse
|
||||||
{
|
{
|
||||||
Eina_List *kbds;
|
Eina_List *kbds;
|
||||||
|
@ -11,7 +18,7 @@ typedef struct kbdmouse
|
||||||
|
|
||||||
static void
|
static void
|
||||||
/* event will always be a syspath starting with /sys */
|
/* event will always be a syspath starting with /sys */
|
||||||
catch_events(const char *device, const char *event, void *data, Eeze_Udev_Watch *watch)
|
catch_events(const char *device, int event, void *data, Eeze_Udev_Watch *watch)
|
||||||
{
|
{
|
||||||
kbdmouse *akbdmouse = data;
|
kbdmouse *akbdmouse = data;
|
||||||
Eina_List *l;
|
Eina_List *l;
|
||||||
|
@ -40,7 +47,7 @@ end:
|
||||||
* we can retrieve them now even though the device has been removed and
|
* we can retrieve them now even though the device has been removed and
|
||||||
* is inaccessible to udev
|
* is inaccessible to udev
|
||||||
*/
|
*/
|
||||||
if (!strcmp(event, "add"))
|
if ((event & EEZE_UDEV_EVENT_ADD) == EEZE_UDEV_EVENT_ADD)
|
||||||
{
|
{
|
||||||
dev = eeze_udev_syspath_get_devpath(device);
|
dev = eeze_udev_syspath_get_devpath(device);
|
||||||
type = "plugged in";
|
type = "plugged in";
|
||||||
|
@ -52,19 +59,19 @@ end:
|
||||||
}
|
}
|
||||||
printf("You %s %s!\n", type, dev);
|
printf("You %s %s!\n", type, dev);
|
||||||
printf("All tests completed, exiting successfully!\n");
|
printf("All tests completed, exiting successfully!\n");
|
||||||
|
/* and the hash */
|
||||||
|
eina_hash_free(akbdmouse->hash);
|
||||||
/* now we free the lists */
|
/* now we free the lists */
|
||||||
eina_list_free(akbdmouse->kbds);
|
eina_list_free(akbdmouse->kbds);
|
||||||
eina_list_free(akbdmouse->mice);
|
eina_list_free(akbdmouse->mice);
|
||||||
/* and the hash */
|
|
||||||
eina_hash_free(akbdmouse->hash);
|
|
||||||
/* and the random storage struct */
|
/* and the random storage struct */
|
||||||
free(akbdmouse);
|
free(akbdmouse);
|
||||||
/* and quit the main loop */
|
|
||||||
ecore_main_loop_quit();
|
|
||||||
/* and delete the watch */
|
/* and delete the watch */
|
||||||
eeze_udev_watch_del(watch);
|
eeze_udev_watch_del(watch);
|
||||||
/* and shut down eudev */
|
/* and shut down eudev */
|
||||||
eeze_udev_shutdown();
|
eeze_udev_shutdown();
|
||||||
|
/* and quit the main loop */
|
||||||
|
ecore_main_loop_quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -88,9 +88,9 @@
|
||||||
/*bitmasks for watch events*/
|
/*bitmasks for watch events*/
|
||||||
#define EEZE_UDEV_EVENT_NONE 0x0000
|
#define EEZE_UDEV_EVENT_NONE 0x0000
|
||||||
#define EEZE_UDEV_EVENT_ADD 0x0001
|
#define EEZE_UDEV_EVENT_ADD 0x0001
|
||||||
#define EEZE_UDEV_EVENT_REMOVE 0x0001
|
#define EEZE_UDEV_EVENT_REMOVE 0x0002
|
||||||
#define EEZE_UDEV_EVENT_CHANGE 0x0002
|
#define EEZE_UDEV_EVENT_CHANGE 0x0004
|
||||||
#define EEZE_UDEV_EVENT_ONLINE 0x0004
|
#define EEZE_UDEV_EVENT_ONLINE 0x0008
|
||||||
#define EEZE_UDEV_EVENT_OFFLINE 0x0010
|
#define EEZE_UDEV_EVENT_OFFLINE 0x0010
|
||||||
|
|
||||||
/*FIXME: these probably need to be bitmasks with categories*/
|
/*FIXME: these probably need to be bitmasks with categories*/
|
||||||
|
@ -143,7 +143,7 @@ extern "C" {
|
||||||
EAPI Eina_Bool eeze_udev_walk_check_sysattr(const char *syspath, const char *sysattr, const char *value);
|
EAPI Eina_Bool eeze_udev_walk_check_sysattr(const char *syspath, const char *sysattr, const char *value);
|
||||||
EAPI const char *eeze_udev_walk_get_sysattr(const char *syspath, const char *sysattr);
|
EAPI const char *eeze_udev_walk_get_sysattr(const char *syspath, const char *sysattr);
|
||||||
|
|
||||||
EAPI Eeze_Udev_Watch *eeze_udev_watch_add(Eeze_Udev_Type type, int event, void(*func)(const char *, const char *, void *, Eeze_Udev_Watch *), void *user_data);
|
EAPI Eeze_Udev_Watch *eeze_udev_watch_add(Eeze_Udev_Type type, int event, void(*func)(const char *, int, void *, Eeze_Udev_Watch *), void *user_data);
|
||||||
EAPI void *eeze_udev_watch_del(Eeze_Udev_Watch *watch);
|
EAPI void *eeze_udev_watch_del(Eeze_Udev_Watch *watch);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#include <Eeze_Udev.h>
|
#include <Eeze_Udev.h>
|
||||||
#include "eeze_udev_private.h"
|
#include "eeze_udev_private.h"
|
||||||
|
|
||||||
|
extern _udev *udev;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup udev udev
|
* @defgroup udev udev
|
||||||
*
|
*
|
||||||
|
@ -16,7 +18,7 @@
|
||||||
*
|
*
|
||||||
* @param syspath The syspath of a device, with or without "/sys/"
|
* @param syspath The syspath of a device, with or without "/sys/"
|
||||||
* @return The syspath of the parent device
|
* @return The syspath of the parent device
|
||||||
*
|
*
|
||||||
* Return a syspath (/sys/$syspath) for the parent device.
|
* Return a syspath (/sys/$syspath) for the parent device.
|
||||||
*
|
*
|
||||||
* @ingroup udev
|
* @ingroup udev
|
||||||
|
@ -24,28 +26,24 @@
|
||||||
EAPI const char *
|
EAPI const char *
|
||||||
eeze_udev_syspath_get_parent(const char *syspath)
|
eeze_udev_syspath_get_parent(const char *syspath)
|
||||||
{
|
{
|
||||||
struct udev *udev;
|
_udev_device *device, *parent;
|
||||||
struct udev_device *device, *parent;
|
|
||||||
const char *ret;
|
const char *ret;
|
||||||
Eina_Strbuf *sbuf;
|
Eina_Strbuf *sbuf;
|
||||||
|
|
||||||
if (!syspath) return NULL;
|
if (!syspath)
|
||||||
udev = udev_new();
|
return NULL;
|
||||||
if (!udev) return NULL;
|
|
||||||
|
|
||||||
sbuf = eina_strbuf_new();
|
sbuf = eina_strbuf_new();
|
||||||
|
|
||||||
if (!strstr(syspath, "/sys/"))
|
if (!strstr(syspath, "/sys/"))
|
||||||
eina_strbuf_append(sbuf, "/sys/");
|
eina_strbuf_append(sbuf, "/sys/");
|
||||||
eina_strbuf_append(sbuf, syspath);
|
|
||||||
|
|
||||||
|
eina_strbuf_append(sbuf, syspath);
|
||||||
device = udev_device_new_from_syspath(udev, eina_strbuf_string_get(sbuf));
|
device = udev_device_new_from_syspath(udev, eina_strbuf_string_get(sbuf));
|
||||||
parent = udev_device_get_parent(device);
|
parent = udev_device_get_parent(device);
|
||||||
ret = eina_stringshare_add(udev_device_get_property_value(parent, "DEVPATH"));
|
ret = eina_stringshare_add(udev_device_get_property_value(parent, "DEVPATH"));
|
||||||
|
|
||||||
udev_device_unref(device);
|
udev_device_unref(device);
|
||||||
udev_unref(udev);
|
|
||||||
eina_strbuf_free(sbuf);
|
eina_strbuf_free(sbuf);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,34 +58,33 @@ eeze_udev_syspath_get_parent(const char *syspath)
|
||||||
EAPI Eina_List *
|
EAPI Eina_List *
|
||||||
eeze_udev_syspath_get_parents(const char *syspath)
|
eeze_udev_syspath_get_parents(const char *syspath)
|
||||||
{
|
{
|
||||||
struct udev *udev;
|
_udev_device *child, *parent, *device;
|
||||||
struct udev_device *child, *parent, *device;
|
|
||||||
const char *path;
|
const char *path;
|
||||||
Eina_Strbuf *sbuf;
|
Eina_Strbuf *sbuf;
|
||||||
Eina_List *devlist = NULL;
|
Eina_List *devlist = NULL;
|
||||||
|
|
||||||
if (!syspath) return NULL;
|
if (!syspath)
|
||||||
udev = udev_new();
|
return NULL;
|
||||||
if (!udev) return NULL;
|
|
||||||
|
|
||||||
sbuf = eina_strbuf_new();
|
sbuf = eina_strbuf_new();
|
||||||
|
|
||||||
if (!strstr(syspath, "/sys/"))
|
if (!strstr(syspath, "/sys/"))
|
||||||
eina_strbuf_append(sbuf, "/sys/");
|
eina_strbuf_append(sbuf, "/sys/");
|
||||||
eina_strbuf_append(sbuf, syspath);
|
|
||||||
|
|
||||||
|
eina_strbuf_append(sbuf, syspath);
|
||||||
device = udev_device_new_from_syspath(udev, eina_strbuf_string_get(sbuf));
|
device = udev_device_new_from_syspath(udev, eina_strbuf_string_get(sbuf));
|
||||||
|
|
||||||
if (!(parent = udev_device_get_parent(device)))
|
if (!(parent = udev_device_get_parent(device)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
for (; parent; child = parent, parent = udev_device_get_parent(child))
|
for (; parent; child = parent, parent = udev_device_get_parent(child))
|
||||||
{
|
{
|
||||||
path = udev_device_get_syspath(parent);
|
path = udev_device_get_syspath(parent);
|
||||||
devlist = eina_list_append(devlist, eina_stringshare_add(path));
|
devlist = eina_list_append(devlist, eina_stringshare_add(path));
|
||||||
}
|
}
|
||||||
udev_device_unref(device);
|
|
||||||
udev_unref(udev);
|
udev_device_unref(device);
|
||||||
|
return devlist;
|
||||||
return devlist;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,38 +92,36 @@ eeze_udev_syspath_get_parents(const char *syspath)
|
||||||
*
|
*
|
||||||
* @param syspath The /sys/ path with or without the /sys/
|
* @param syspath The /sys/ path with or without the /sys/
|
||||||
* @return A const char* with the /dev/ path or NULL on failure
|
* @return A const char* with the /dev/ path or NULL on failure
|
||||||
*
|
*
|
||||||
* Takes /sys/$PATH and turns it into the corresponding "/dev/x/y".
|
* Takes /sys/$PATH and turns it into the corresponding "/dev/x/y".
|
||||||
*
|
*
|
||||||
* @ingroup udev
|
* @ingroup udev
|
||||||
*/
|
*/
|
||||||
EAPI const char *
|
EAPI const char *
|
||||||
eeze_udev_syspath_get_devpath(const char *syspath)
|
eeze_udev_syspath_get_devpath(const char *syspath)
|
||||||
{
|
{
|
||||||
struct udev *udev;
|
_udev_device *device;
|
||||||
struct udev_device *device;
|
const char *name = NULL;
|
||||||
const char *name = NULL;
|
Eina_Strbuf *sbuf;
|
||||||
Eina_Strbuf *sbuf;
|
|
||||||
|
|
||||||
if (!syspath) return NULL;
|
if (!syspath)
|
||||||
udev = udev_new();
|
return NULL;
|
||||||
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));
|
sbuf = eina_strbuf_new();
|
||||||
if (!(name = udev_device_get_property_value(device, "DEVNAME")))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
name = eina_stringshare_add(name);
|
if (!strstr(syspath, "/sys/"))
|
||||||
udev_device_unref(device);
|
eina_strbuf_append(sbuf, "/sys/");
|
||||||
udev_unref(udev);
|
|
||||||
eina_strbuf_free(sbuf);
|
|
||||||
|
|
||||||
return name;
|
eina_strbuf_append(sbuf, syspath);
|
||||||
|
device = udev_device_new_from_syspath(udev, eina_strbuf_string_get(sbuf));
|
||||||
|
|
||||||
|
if (!(name = udev_device_get_property_value(device, "DEVNAME")))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
name = eina_stringshare_add(name);
|
||||||
|
udev_device_unref(device);
|
||||||
|
eina_strbuf_free(sbuf);
|
||||||
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -134,37 +129,34 @@ eeze_udev_syspath_get_devpath(const char *syspath)
|
||||||
*
|
*
|
||||||
* @param syspath The /sys/ path with or without the /sys/
|
* @param syspath The /sys/ path with or without the /sys/
|
||||||
* @return A const char* with the subsystem of the device or NULL on failure
|
* @return A const char* with the subsystem of the device or NULL on failure
|
||||||
*
|
*
|
||||||
* Takes /sys/$PATH and returns the corresponding device subsystem,
|
* Takes /sys/$PATH and returns the corresponding device subsystem,
|
||||||
* such as "input" for keyboards/mice.
|
* such as "input" for keyboards/mice.
|
||||||
*
|
*
|
||||||
* @ingroup udev
|
* @ingroup udev
|
||||||
*/
|
*/
|
||||||
EAPI const char *
|
EAPI const char *
|
||||||
eeze_udev_syspath_get_subsystem(const char *syspath)
|
eeze_udev_syspath_get_subsystem(const char *syspath)
|
||||||
{
|
{
|
||||||
struct udev *udev;
|
_udev_device *device;
|
||||||
struct udev_device *device;
|
const char *subsystem;
|
||||||
const char *subsystem;
|
Eina_Strbuf *sbuf;
|
||||||
Eina_Strbuf *sbuf;
|
|
||||||
|
|
||||||
if (!syspath) return NULL;
|
if (!syspath)
|
||||||
udev = udev_new();
|
return NULL;
|
||||||
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));
|
sbuf = eina_strbuf_new();
|
||||||
subsystem = eina_stringshare_add(udev_device_get_property_value(device, "SUBSYSTEM"));
|
|
||||||
|
|
||||||
udev_device_unref(device);
|
if (!strstr(syspath, "/sys/"))
|
||||||
udev_unref(udev);
|
eina_strbuf_append(sbuf, "/sys/");
|
||||||
eina_strbuf_free(sbuf);
|
|
||||||
|
|
||||||
return subsystem;
|
eina_strbuf_append(sbuf, syspath);
|
||||||
|
device = udev_device_new_from_syspath(udev, eina_strbuf_string_get(sbuf));
|
||||||
|
subsystem =
|
||||||
|
eina_stringshare_add(udev_device_get_property_value(device, "SUBSYSTEM"));
|
||||||
|
udev_device_unref(device);
|
||||||
|
eina_strbuf_free(sbuf);
|
||||||
|
return subsystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -173,35 +165,33 @@ eeze_udev_syspath_get_subsystem(const char *syspath)
|
||||||
* @param syspath The /sys/ path with or without the /sys/
|
* @param syspath The /sys/ path with or without the /sys/
|
||||||
* @param property The property to get; full list of these is a FIXME
|
* @param property The property to get; full list of these is a FIXME
|
||||||
* @return A const char* with the property or NULL on failure
|
* @return A const char* with the property or NULL on failure
|
||||||
*
|
*
|
||||||
* @ingroup udev
|
* @ingroup udev
|
||||||
*/
|
*/
|
||||||
EAPI const char *
|
EAPI const char *
|
||||||
eeze_udev_syspath_get_property(const char *syspath, const char *property)
|
eeze_udev_syspath_get_property(const char *syspath, const char *property)
|
||||||
{
|
{
|
||||||
struct udev *udev;
|
_udev_device *device;
|
||||||
struct udev_device *device;
|
const char *value = NULL, *test;
|
||||||
const char *value = NULL, *test;
|
Eina_Strbuf *sbuf;
|
||||||
Eina_Strbuf *sbuf;
|
|
||||||
|
|
||||||
if (!syspath || !property) return NULL;
|
if (!syspath || !property)
|
||||||
udev = udev_new();
|
return NULL;
|
||||||
if (!udev) return NULL;
|
|
||||||
|
|
||||||
sbuf = eina_strbuf_new();
|
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 (!strstr(syspath, "/sys/"))
|
||||||
if ((test = udev_device_get_property_value(device, property)));
|
eina_strbuf_append(sbuf, "/sys/");
|
||||||
value = eina_stringshare_add(test);
|
|
||||||
|
|
||||||
udev_device_unref(device);
|
eina_strbuf_append(sbuf, syspath);
|
||||||
udev_unref(udev);
|
device = udev_device_new_from_syspath(udev, eina_strbuf_string_get(sbuf));
|
||||||
eina_strbuf_free(sbuf);
|
|
||||||
|
|
||||||
return value;
|
if ((test = udev_device_get_property_value(device, property)))
|
||||||
|
value = eina_stringshare_add(test);
|
||||||
|
|
||||||
|
udev_device_unref(device);
|
||||||
|
eina_strbuf_free(sbuf);
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -210,35 +200,33 @@ eeze_udev_syspath_get_property(const char *syspath, const char *property)
|
||||||
* @param syspath The /sys/ path with or without the /sys/
|
* @param syspath The /sys/ path with or without the /sys/
|
||||||
* @param sysattr The sysattr to get; full list of these is a FIXME
|
* @param sysattr The sysattr to get; full list of these is a FIXME
|
||||||
* @return A const char* with the sysattr or NULL on failure
|
* @return A const char* with the sysattr or NULL on failure
|
||||||
*
|
*
|
||||||
* @ingroup udev
|
* @ingroup udev
|
||||||
*/
|
*/
|
||||||
EAPI const char *
|
EAPI const char *
|
||||||
eeze_udev_syspath_get_sysattr(const char *syspath, const char *sysattr)
|
eeze_udev_syspath_get_sysattr(const char *syspath, const char *sysattr)
|
||||||
{
|
{
|
||||||
struct udev *udev;
|
_udev_device *device;
|
||||||
struct udev_device *device;
|
const char *value = NULL, *test;
|
||||||
const char *value = NULL, *test;
|
Eina_Strbuf *sbuf;
|
||||||
Eina_Strbuf *sbuf;
|
|
||||||
|
|
||||||
if (!syspath || !sysattr) return NULL;
|
if (!syspath || !sysattr)
|
||||||
udev = udev_new();
|
return NULL;
|
||||||
if (!udev) return NULL;
|
|
||||||
|
|
||||||
sbuf = eina_strbuf_new();
|
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 (!strstr(syspath, "/sys/"))
|
||||||
if ((test = udev_device_get_sysattr_value(device, sysattr)));
|
eina_strbuf_append(sbuf, "/sys/");
|
||||||
value = eina_stringshare_add(test);
|
|
||||||
|
|
||||||
udev_device_unref(device);
|
eina_strbuf_append(sbuf, syspath);
|
||||||
udev_unref(udev);
|
device = udev_device_new_from_syspath(udev, eina_strbuf_string_get(sbuf));
|
||||||
eina_strbuf_free(sbuf);
|
|
||||||
|
|
||||||
return value;
|
if ((test = udev_device_get_sysattr_value(device, sysattr)))
|
||||||
|
value = eina_stringshare_add(test);
|
||||||
|
|
||||||
|
udev_device_unref(device);
|
||||||
|
eina_strbuf_free(sbuf);
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -246,43 +234,40 @@ eeze_udev_syspath_get_sysattr(const char *syspath, const char *sysattr)
|
||||||
*
|
*
|
||||||
* @param devpath The /dev/ path of the device
|
* @param devpath The /dev/ path of the device
|
||||||
* @return A const char* which corresponds to the /sys/ path of the device or NULL on failure
|
* @return A const char* which corresponds to the /sys/ path of the device or NULL on failure
|
||||||
*
|
*
|
||||||
* Takes "/dev/path" and returns the corresponding /sys/ path (without the "/sys/")
|
* Takes "/dev/path" and returns the corresponding /sys/ path (without the "/sys/")
|
||||||
*
|
*
|
||||||
* @ingroup udev
|
* @ingroup udev
|
||||||
*/
|
*/
|
||||||
EAPI const char *
|
EAPI const char *
|
||||||
eeze_udev_devpath_get_syspath(const char *devpath)
|
eeze_udev_devpath_get_syspath(const char *devpath)
|
||||||
{
|
{
|
||||||
struct udev *udev;
|
_udev_enumerate *en;
|
||||||
struct udev_enumerate *en;
|
_udev_list_entry *devs, *cur;
|
||||||
struct udev_list_entry *devs, *cur;
|
_udev_device *device;
|
||||||
struct udev_device *device;
|
|
||||||
const char *name, *ret;
|
const char *name, *ret;
|
||||||
|
|
||||||
if (!devpath) return NULL;
|
if (!devpath)
|
||||||
udev = udev_new();
|
return NULL;
|
||||||
if (!udev) return NULL;
|
|
||||||
en = udev_enumerate_new(udev);
|
en = udev_enumerate_new((udev));
|
||||||
if (!en) return NULL;
|
|
||||||
|
if (!en)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
udev_enumerate_add_match_property(en, "DEVNAME", devpath);
|
udev_enumerate_add_match_property(en, "DEVNAME", devpath);
|
||||||
udev_enumerate_scan_devices(en);
|
udev_enumerate_scan_devices(en);
|
||||||
devs = udev_enumerate_get_list_entry(en);
|
devs = udev_enumerate_get_list_entry(en);
|
||||||
|
|
||||||
udev_list_entry_foreach(cur, devs)
|
udev_list_entry_foreach(cur, devs)
|
||||||
{
|
{
|
||||||
name = udev_list_entry_get_name(cur);
|
name = udev_list_entry_get_name(cur);
|
||||||
device = udev_device_new_from_syspath(udev, name);
|
device = udev_device_new_from_syspath(udev, name);
|
||||||
ret = eina_stringshare_add(udev_device_get_sysname(device));
|
ret = eina_stringshare_add(udev_device_get_sysname(device));
|
||||||
|
|
||||||
udev_device_unref(device);
|
udev_device_unref(device);
|
||||||
break; /*just in case there's more than one somehow*/
|
break; /*just in case there's more than one somehow */
|
||||||
}
|
}
|
||||||
udev_enumerate_unref(en);
|
udev_enumerate_unref(en);
|
||||||
udev_unref(udev);
|
return ret;
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -290,43 +275,40 @@ eeze_udev_devpath_get_syspath(const char *devpath)
|
||||||
*
|
*
|
||||||
* @param devpath The /dev/ path of the device
|
* @param devpath The /dev/ path of the device
|
||||||
* @return A const char* with the subsystem of the device or NULL on failure
|
* @return A const char* with the subsystem of the device or NULL on failure
|
||||||
*
|
*
|
||||||
* Takes "/dev/path" and returns the subsystem of the device.
|
* Takes "/dev/path" and returns the subsystem of the device.
|
||||||
*
|
*
|
||||||
* @ingroup udev
|
* @ingroup udev
|
||||||
*/
|
*/
|
||||||
EAPI const char *
|
EAPI const char *
|
||||||
eeze_udev_devpath_get_subsystem(const char *devpath)
|
eeze_udev_devpath_get_subsystem(const char *devpath)
|
||||||
{
|
{
|
||||||
struct udev *udev;
|
_udev_enumerate *en;
|
||||||
struct udev_enumerate *en;
|
_udev_list_entry *devs, *cur;
|
||||||
struct udev_list_entry *devs, *cur;
|
_udev_device *device;
|
||||||
struct udev_device *device;
|
|
||||||
const char *name, *ret;
|
const char *name, *ret;
|
||||||
|
|
||||||
if (!devpath) return NULL;
|
if (!devpath)
|
||||||
udev = udev_new();
|
return NULL;
|
||||||
if (!udev) return NULL;
|
|
||||||
en = udev_enumerate_new(udev);
|
en = udev_enumerate_new((udev));
|
||||||
if (!en) return NULL;
|
|
||||||
|
if (!en)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
udev_enumerate_add_match_property(en, "DEVNAME", devpath);
|
udev_enumerate_add_match_property(en, "DEVNAME", devpath);
|
||||||
udev_enumerate_scan_devices(en);
|
udev_enumerate_scan_devices(en);
|
||||||
devs = udev_enumerate_get_list_entry(en);
|
devs = udev_enumerate_get_list_entry(en);
|
||||||
|
|
||||||
udev_list_entry_foreach(cur, devs)
|
udev_list_entry_foreach(cur, devs)
|
||||||
{
|
{
|
||||||
name = udev_list_entry_get_name(cur);
|
name = udev_list_entry_get_name(cur);
|
||||||
device = udev_device_new_from_syspath(udev, name);
|
device = udev_device_new_from_syspath(udev, name);
|
||||||
ret = eina_stringshare_add(udev_device_get_subsystem(device));
|
ret = eina_stringshare_add(udev_device_get_subsystem(device));
|
||||||
|
|
||||||
udev_device_unref(device);
|
udev_device_unref(device);
|
||||||
break; /*just in case there's more than one somehow*/
|
break; /*just in case there's more than one somehow */
|
||||||
}
|
}
|
||||||
udev_enumerate_unref(en);
|
udev_enumerate_unref(en);
|
||||||
udev_unref(udev);
|
return ret;
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -334,46 +316,48 @@ eeze_udev_devpath_get_subsystem(const char *devpath)
|
||||||
*
|
*
|
||||||
* @param syspath The /sys/ path with or without the /sys/
|
* @param syspath The /sys/ path with or without the /sys/
|
||||||
* @return If true, the device is a mouse
|
* @return If true, the device is a mouse
|
||||||
*
|
*
|
||||||
* @ingroup udev
|
* @ingroup udev
|
||||||
*/
|
*/
|
||||||
EAPI Eina_Bool
|
EAPI Eina_Bool
|
||||||
eeze_udev_syspath_is_mouse(const char *syspath)
|
eeze_udev_syspath_is_mouse(const char *syspath)
|
||||||
{
|
{
|
||||||
struct udev *udev;
|
_udev_device *device;
|
||||||
struct udev_device *device;
|
Eina_Bool mouse = 0;
|
||||||
Eina_Bool mouse = 0;
|
Eina_Strbuf *sbuf;
|
||||||
Eina_Strbuf *sbuf;
|
const char *test = NULL;
|
||||||
const char *test = NULL;
|
|
||||||
|
|
||||||
if (!syspath) return 0;
|
if (!syspath)
|
||||||
udev = udev_new();
|
return 0;
|
||||||
if (!udev) return 0;
|
|
||||||
|
|
||||||
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));
|
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));
|
||||||
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
||||||
mouse = _walk_parents_test_attr(device, "bInterfaceProtocol", "02");
|
mouse = _walk_parents_test_attr(device, "bInterfaceProtocol", "02");
|
||||||
if (!mouse)
|
|
||||||
{
|
if (!mouse)
|
||||||
test = udev_device_get_property_value(device, "ID_CLASS");
|
{
|
||||||
if ((test) && (!strcmp(test, "mouse")))
|
test = udev_device_get_property_value(device, "ID_CLASS");
|
||||||
mouse = 1;
|
|
||||||
}
|
if ((test) && (!strcmp(test, "mouse")))
|
||||||
|
mouse = 1;
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
test = udev_device_get_property_value(device, "ID_INPUT_MOUSE");
|
test = udev_device_get_property_value(device, "ID_INPUT_MOUSE");
|
||||||
if (test) mouse = atoi(test);
|
|
||||||
|
if (test)
|
||||||
|
mouse = atoi(test);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
udev_device_unref(device);
|
||||||
udev_device_unref(device);
|
eina_strbuf_free(sbuf);
|
||||||
udev_unref(udev);
|
return mouse;
|
||||||
eina_strbuf_free(sbuf);
|
|
||||||
|
|
||||||
return mouse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -381,46 +365,48 @@ eeze_udev_syspath_is_mouse(const char *syspath)
|
||||||
*
|
*
|
||||||
* @param syspath The /sys/ path with or without the /sys/
|
* @param syspath The /sys/ path with or without the /sys/
|
||||||
* @return If true, the device is a keyboard
|
* @return If true, the device is a keyboard
|
||||||
*
|
*
|
||||||
* @ingroup udev
|
* @ingroup udev
|
||||||
*/
|
*/
|
||||||
EAPI Eina_Bool
|
EAPI Eina_Bool
|
||||||
eeze_udev_syspath_is_kbd(const char *syspath)
|
eeze_udev_syspath_is_kbd(const char *syspath)
|
||||||
{
|
{
|
||||||
struct udev *udev;
|
_udev_device *device;
|
||||||
struct udev_device *device;
|
Eina_Bool kbd = 0;
|
||||||
Eina_Bool kbd = 0;
|
Eina_Strbuf *sbuf;
|
||||||
Eina_Strbuf *sbuf;
|
const char *test = NULL;
|
||||||
const char *test = NULL;
|
|
||||||
|
|
||||||
if (!syspath) return 0;
|
if (!syspath)
|
||||||
udev = udev_new();
|
return 0;
|
||||||
if (!udev) return 0;
|
|
||||||
|
|
||||||
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));
|
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));
|
||||||
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
||||||
kbd = _walk_parents_test_attr(device, "bInterfaceProtocol", "01");
|
kbd = _walk_parents_test_attr(device, "bInterfaceProtocol", "01");
|
||||||
if (!kbd)
|
|
||||||
{
|
if (!kbd)
|
||||||
test = udev_device_get_property_value(device, "ID_CLASS");
|
{
|
||||||
if ((test) && (!strcmp(test, "kbd")))
|
test = udev_device_get_property_value(device, "ID_CLASS");
|
||||||
kbd = 1;
|
|
||||||
}
|
if ((test) && (!strcmp(test, "kbd")))
|
||||||
#else
|
kbd = 1;
|
||||||
test = udev_device_get_property_value(device, "ID_INPUT_KEYBOARD");
|
}
|
||||||
if (test) kbd = atoi(test);
|
|
||||||
|
#else
|
||||||
|
test = udev_device_get_property_value(device, "ID_INPUT_KEYBOARD");
|
||||||
|
|
||||||
|
if (test)
|
||||||
|
kbd = atoi(test);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
udev_device_unref(device);
|
||||||
udev_device_unref(device);
|
eina_strbuf_free(sbuf);
|
||||||
udev_unref(udev);
|
return kbd;
|
||||||
eina_strbuf_free(sbuf);
|
|
||||||
|
|
||||||
return kbd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -428,37 +414,37 @@ eeze_udev_syspath_is_kbd(const char *syspath)
|
||||||
*
|
*
|
||||||
* @param syspath The /sys/ path with or without the /sys/
|
* @param syspath The /sys/ path with or without the /sys/
|
||||||
* @return If true, the device is a touchpad
|
* @return If true, the device is a touchpad
|
||||||
*
|
*
|
||||||
* @ingroup udev
|
* @ingroup udev
|
||||||
*/
|
*/
|
||||||
EAPI Eina_Bool
|
EAPI Eina_Bool
|
||||||
eeze_udev_syspath_is_touchpad(const char *syspath)
|
eeze_udev_syspath_is_touchpad(const char *syspath)
|
||||||
{
|
{
|
||||||
struct udev *udev;
|
_udev_device *device;
|
||||||
struct udev_device *device;
|
Eina_Bool touchpad = 0;
|
||||||
Eina_Bool touchpad = 0;
|
Eina_Strbuf *sbuf;
|
||||||
Eina_Strbuf *sbuf;
|
|
||||||
|
|
||||||
if (!syspath) return 0;
|
if (!syspath)
|
||||||
udev = udev_new();
|
return 0;
|
||||||
if (!udev) return 0;
|
|
||||||
|
|
||||||
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));
|
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));
|
||||||
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
||||||
touchpad = _walk_parents_test_attr(device, "resolution", NULL);
|
touchpad = _walk_parents_test_attr(device, "resolution", NULL);
|
||||||
#else
|
#else
|
||||||
const char *test;
|
const char *test;
|
||||||
test = udev_device_get_property_value(device, "ID_INPUT_TOUCHPAD");
|
test = udev_device_get_property_value(device, "ID_INPUT_TOUCHPAD");
|
||||||
if (test) touchpad = atoi(test);
|
|
||||||
#endif
|
|
||||||
udev_device_unref(device);
|
|
||||||
udev_unref(udev);
|
|
||||||
eina_strbuf_free(sbuf);
|
|
||||||
|
|
||||||
return touchpad;
|
if (test)
|
||||||
|
touchpad = atoi(test);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
udev_device_unref(device);
|
||||||
|
eina_strbuf_free(sbuf);
|
||||||
|
return touchpad;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "eeze_udev_private.h"
|
#include "eeze_udev_private.h"
|
||||||
#include <Eeze_Udev.h>
|
#include <Eeze_Udev.h>
|
||||||
|
|
||||||
|
extern _udev *udev;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of all syspaths that are (or should be) the same
|
* Returns a list of all syspaths that are (or should be) the same
|
||||||
|
@ -18,68 +19,67 @@
|
||||||
EAPI Eina_List *
|
EAPI Eina_List *
|
||||||
eeze_udev_find_similar_from_syspath(const char *syspath)
|
eeze_udev_find_similar_from_syspath(const char *syspath)
|
||||||
{
|
{
|
||||||
struct udev *udev;
|
_udev_device *device;
|
||||||
struct udev_device *device;
|
_udev_list_entry *devs, *cur;
|
||||||
struct udev_list_entry *devs, *cur;
|
_udev_enumerate *en;
|
||||||
struct udev_enumerate *en;
|
|
||||||
Eina_List *l, *ret = NULL;
|
Eina_List *l, *ret = NULL;
|
||||||
Eina_Strbuf *sbuf;
|
Eina_Strbuf *sbuf;
|
||||||
const char *vendor, *model, *revision, *devname, *dev;
|
const char *vendor, *model, *revision, *devname, *dev;
|
||||||
|
|
||||||
if (!syspath) return NULL;
|
if (!syspath)
|
||||||
udev = udev_new();
|
return NULL;
|
||||||
if (!udev) return NULL;
|
|
||||||
en = udev_enumerate_new(udev);
|
en = udev_enumerate_new((udev));
|
||||||
|
|
||||||
if (!en)
|
if (!en)
|
||||||
{
|
return NULL;
|
||||||
udev_unref(udev);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
sbuf = eina_strbuf_new();
|
sbuf = eina_strbuf_new();
|
||||||
|
|
||||||
if (!strstr(syspath, "/sys/"))
|
if (!strstr(syspath, "/sys/"))
|
||||||
eina_strbuf_append(sbuf, "/sys/");
|
eina_strbuf_append(sbuf, "/sys/");
|
||||||
eina_strbuf_append(sbuf, syspath);
|
|
||||||
|
|
||||||
|
eina_strbuf_append(sbuf, syspath);
|
||||||
device = udev_device_new_from_syspath(udev, syspath);
|
device = udev_device_new_from_syspath(udev, syspath);
|
||||||
vendor = udev_device_get_property_value(device, "ID_VENDOR_ID");
|
vendor = udev_device_get_property_value(device, "ID_VENDOR_ID");
|
||||||
|
|
||||||
if (vendor)
|
if (vendor)
|
||||||
udev_enumerate_add_match_property(en, "ID_VENDOR_ID", vendor);
|
udev_enumerate_add_match_property(en, "ID_VENDOR_ID", vendor);
|
||||||
|
|
||||||
model = udev_device_get_property_value(device, "ID_MODEL_ID");
|
model = udev_device_get_property_value(device, "ID_MODEL_ID");
|
||||||
|
|
||||||
if (model)
|
if (model)
|
||||||
udev_enumerate_add_match_property(en, "ID_MODEL_ID", model);
|
udev_enumerate_add_match_property(en, "ID_MODEL_ID", model);
|
||||||
|
|
||||||
revision = udev_device_get_property_value(device, "ID_REVISION");
|
revision = udev_device_get_property_value(device, "ID_REVISION");
|
||||||
|
|
||||||
if (revision)
|
if (revision)
|
||||||
udev_enumerate_add_match_property(en, "ID_REVISION", revision);
|
udev_enumerate_add_match_property(en, "ID_REVISION", revision);
|
||||||
|
|
||||||
udev_enumerate_scan_devices(en);
|
udev_enumerate_scan_devices(en);
|
||||||
udev_device_unref(device);
|
udev_device_unref(device);
|
||||||
|
|
||||||
devs = udev_enumerate_get_list_entry(en);
|
devs = udev_enumerate_get_list_entry(en);
|
||||||
udev_list_entry_foreach(cur, devs)
|
udev_list_entry_foreach(cur, devs)
|
||||||
{
|
{
|
||||||
devname = udev_list_entry_get_name(cur);
|
devname = udev_list_entry_get_name(cur);
|
||||||
/* verify unlisted device */
|
/* verify unlisted device */
|
||||||
EINA_LIST_FOREACH(ret, l, dev)
|
|
||||||
if (!strcmp(dev, devname))
|
EINA_LIST_FOREACH(ret, l, dev) if (!strcmp(dev, devname))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ret = eina_list_prepend(ret, eina_stringshare_add(devname));
|
ret = eina_list_prepend(ret, eina_stringshare_add(devname));
|
||||||
device = udev_device_new_from_syspath(udev, devname);
|
device = udev_device_new_from_syspath(udev, devname);
|
||||||
|
|
||||||
/* only device roots have this sysattr,
|
/* only device roots have this sysattr,
|
||||||
* and we only need to check parents of the roots
|
* and we only need to check parents of the roots
|
||||||
*/
|
*/
|
||||||
if (udev_device_get_sysattr_value(device, "idVendor"))
|
if (udev_device_get_sysattr_value(device, "idVendor"))
|
||||||
_get_unlisted_parents(ret, device);
|
_get_unlisted_parents(ret, device);
|
||||||
|
|
||||||
udev_device_unref(device);
|
udev_device_unref(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
udev_enumerate_unref(en);
|
udev_enumerate_unref(en);
|
||||||
udev_unref(udev);
|
|
||||||
eina_strbuf_free(sbuf);
|
eina_strbuf_free(sbuf);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,42 +95,43 @@ eeze_udev_find_similar_from_syspath(const char *syspath)
|
||||||
* @ingroup udev
|
* @ingroup udev
|
||||||
*/
|
*/
|
||||||
EAPI void
|
EAPI void
|
||||||
eeze_udev_find_unlisted_similar(Eina_List *list)
|
eeze_udev_find_unlisted_similar(Eina_List * list)
|
||||||
{
|
{
|
||||||
struct udev *udev;
|
_udev_device *device;
|
||||||
struct udev_device *device;
|
_udev_list_entry *devs, *cur;
|
||||||
struct udev_list_entry *devs, *cur;
|
_udev_enumerate *en;
|
||||||
struct udev_enumerate *en;
|
|
||||||
Eina_List *l;
|
Eina_List *l;
|
||||||
const char *vendor, *model, *revision, *devname, *dev;
|
const char *vendor, *model, *revision, *devname, *dev;
|
||||||
|
|
||||||
if (!list) return;
|
if (!list)
|
||||||
udev = udev_new();
|
return;
|
||||||
if (!udev) return;
|
|
||||||
|
|
||||||
EINA_LIST_FOREACH(list, l, dev)
|
EINA_LIST_FOREACH(list, l, dev)
|
||||||
{
|
{
|
||||||
en = udev_enumerate_new(udev);
|
en = udev_enumerate_new((udev));
|
||||||
if (!en)
|
|
||||||
{
|
if (!en)
|
||||||
udev_unref(udev);
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
device = udev_device_new_from_syspath(udev, dev);
|
device = udev_device_new_from_syspath(udev, dev);
|
||||||
|
|
||||||
if ((vendor = udev_device_get_property_value(device, "ID_VENDOR_ID")))
|
if ((vendor = udev_device_get_property_value(device, "ID_VENDOR_ID")))
|
||||||
udev_enumerate_add_match_property(en, "ID_VENDOR_ID", vendor);
|
udev_enumerate_add_match_property(en, "ID_VENDOR_ID", vendor);
|
||||||
else if ((vendor = udev_device_get_property_value(device, "ID_VENDOR")))
|
else
|
||||||
udev_enumerate_add_match_property(en, "ID_VENDOR", vendor);
|
if ((vendor = udev_device_get_property_value(device, "ID_VENDOR")))
|
||||||
|
udev_enumerate_add_match_property(en, "ID_VENDOR", vendor);
|
||||||
|
|
||||||
if ((model = udev_device_get_property_value(device, "ID_MODEL_ID")))
|
if ((model = udev_device_get_property_value(device, "ID_MODEL_ID")))
|
||||||
udev_enumerate_add_match_property(en, "ID_MODEL_ID", model);
|
udev_enumerate_add_match_property(en, "ID_MODEL_ID", model);
|
||||||
else if ((model = udev_device_get_property_value(device, "ID_MODEL")))
|
else
|
||||||
udev_enumerate_add_match_property(en, "ID_MODEL", model);
|
if ((model = udev_device_get_property_value(device, "ID_MODEL")))
|
||||||
|
udev_enumerate_add_match_property(en, "ID_MODEL", model);
|
||||||
|
|
||||||
if ((revision = udev_device_get_property_value(device, "ID_REVISION")))
|
if ((revision = udev_device_get_property_value(device, "ID_REVISION")))
|
||||||
udev_enumerate_add_match_property(en, "ID_REVISION", revision);
|
udev_enumerate_add_match_property(en, "ID_REVISION", revision);
|
||||||
|
|
||||||
udev_enumerate_scan_devices(en);
|
udev_enumerate_scan_devices(en);
|
||||||
udev_device_unref(device);
|
udev_device_unref(device);
|
||||||
|
|
||||||
devs = udev_enumerate_get_list_entry(en);
|
devs = udev_enumerate_get_list_entry(en);
|
||||||
udev_list_entry_foreach(cur, devs)
|
udev_list_entry_foreach(cur, devs)
|
||||||
{
|
{
|
||||||
|
@ -144,11 +145,9 @@ eeze_udev_find_unlisted_similar(Eina_List *list)
|
||||||
_get_unlisted_parents(list, device);
|
_get_unlisted_parents(list, device);
|
||||||
|
|
||||||
udev_device_unref(device);
|
udev_device_unref(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
udev_enumerate_unref(en);
|
udev_enumerate_unref(en);
|
||||||
}
|
}
|
||||||
udev_unref(udev);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +157,7 @@ eeze_udev_find_unlisted_similar(Eina_List *list)
|
||||||
* @param type A Eeze_Udev_Type or 0
|
* @param type A Eeze_Udev_Type or 0
|
||||||
* @param name A filter for the device name or NULL
|
* @param name A filter for the device name or NULL
|
||||||
* @return A Eina_List* of matched devices or NULL on failure
|
* @return A Eina_List* of matched devices or NULL on failure
|
||||||
*
|
*
|
||||||
* Return a list of syspaths (/sys/$syspath) for matching udev devices.
|
* Return a list of syspaths (/sys/$syspath) for matching udev devices.
|
||||||
*
|
*
|
||||||
* @ingroup udev
|
* @ingroup udev
|
||||||
|
@ -166,19 +165,19 @@ eeze_udev_find_unlisted_similar(Eina_List *list)
|
||||||
EAPI Eina_List *
|
EAPI Eina_List *
|
||||||
eeze_udev_find_by_type(const Eeze_Udev_Type etype, const char *name)
|
eeze_udev_find_by_type(const Eeze_Udev_Type etype, const char *name)
|
||||||
{
|
{
|
||||||
struct udev *udev;
|
_udev_enumerate *en;
|
||||||
struct udev_enumerate *en;
|
_udev_list_entry *devs, *cur;
|
||||||
struct udev_list_entry *devs, *cur;
|
_udev_device *device, *parent;
|
||||||
struct udev_device *device, *parent;
|
|
||||||
const char *devname, *test;
|
const char *devname, *test;
|
||||||
Eina_List *ret = NULL;
|
Eina_List *ret = NULL;
|
||||||
|
|
||||||
if ((!etype) && (!name)) return NULL;
|
if ((!etype) && (!name))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
udev = udev_new();
|
en = udev_enumerate_new((udev));
|
||||||
if (!udev) return NULL;
|
|
||||||
en = udev_enumerate_new(udev);
|
if (!en)
|
||||||
if (!en) return NULL;
|
return NULL;
|
||||||
|
|
||||||
switch (etype)
|
switch (etype)
|
||||||
{
|
{
|
||||||
|
@ -236,67 +235,68 @@ eeze_udev_find_by_type(const Eeze_Udev_Type etype, const char *name)
|
||||||
case EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR:
|
case EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR:
|
||||||
udev_enumerate_add_match_subsystem(en, "hwmon");
|
udev_enumerate_add_match_subsystem(en, "hwmon");
|
||||||
break;
|
break;
|
||||||
/*
|
/*
|
||||||
case EEZE_UDEV_TYPE_ANDROID:
|
case EEZE_UDEV_TYPE_ANDROID:
|
||||||
udev_enumerate_add_match_subsystem(en, "block");
|
udev_enumerate_add_match_subsystem(en, "block");
|
||||||
udev_enumerate_add_match_property(en, "ID_MODEL", "Android_*");
|
udev_enumerate_add_match_property(en, "ID_MODEL", "Android_*");
|
||||||
break;
|
break;
|
||||||
*/
|
*/
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
udev_enumerate_scan_devices(en);
|
udev_enumerate_scan_devices(en);
|
||||||
devs = udev_enumerate_get_list_entry(en);
|
devs = udev_enumerate_get_list_entry(en);
|
||||||
|
|
||||||
udev_list_entry_foreach(cur, devs)
|
udev_list_entry_foreach(cur, devs)
|
||||||
{
|
{
|
||||||
devname = udev_list_entry_get_name(cur);
|
devname = udev_list_entry_get_name(cur);
|
||||||
device = udev_device_new_from_syspath(udev, devname);
|
device = udev_device_new_from_syspath(udev, devname);
|
||||||
|
|
||||||
if (etype == EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR)
|
if (etype == EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR)
|
||||||
{/* ensure that temp input exists somewhere in this device chain */
|
{ /* ensure that temp input exists somewhere in this device chain */
|
||||||
if (!_walk_parents_test_attr(device, "temp1_input", NULL))
|
if (!_walk_parents_test_attr(device, "temp1_input", NULL))
|
||||||
goto out;
|
goto out;
|
||||||
/* if device is not the one which has the temp input, we must go up the chain */
|
|
||||||
if (!(test = udev_device_get_sysattr_value(device, "temp1_input")))
|
|
||||||
{
|
|
||||||
devname = NULL;
|
|
||||||
for (parent = udev_device_get_parent(device); parent; parent = udev_device_get_parent(parent))/*check for parent*/
|
|
||||||
if (((test = udev_device_get_sysattr_value(parent, "temp1_input"))))
|
|
||||||
{
|
|
||||||
devname = udev_device_get_syspath(parent);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!devname)
|
/* if device is not the one which has the temp input, we must go up the chain */
|
||||||
goto out;
|
if (!(test = udev_device_get_sysattr_value(device, "temp1_input")))
|
||||||
}
|
{
|
||||||
|
devname = NULL;
|
||||||
|
|
||||||
|
for (parent = udev_device_get_parent(device); parent; parent = udev_device_get_parent(parent)) /*check for parent */
|
||||||
|
if (((test = udev_device_get_sysattr_value(parent, "temp1_input"))))
|
||||||
|
{
|
||||||
|
devname = udev_device_get_syspath(parent);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!devname)
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (etype == EEZE_UDEV_TYPE_DRIVE_INTERNAL)
|
else
|
||||||
{
|
if (etype == EEZE_UDEV_TYPE_DRIVE_INTERNAL)
|
||||||
if (udev_device_get_property_value(device, "ID_USB_DRIVER"))
|
{
|
||||||
goto out;
|
if (udev_device_get_property_value(device, "ID_USB_DRIVER"))
|
||||||
}
|
goto out;
|
||||||
else if (etype == EEZE_UDEV_TYPE_DRIVE_REMOVABLE)
|
}
|
||||||
{
|
else
|
||||||
if (!(test = udev_device_get_property_value(device, "ID_USB_DRIVER")))
|
if (etype == EEZE_UDEV_TYPE_DRIVE_REMOVABLE)
|
||||||
goto out;
|
{
|
||||||
}
|
if (!
|
||||||
|
(test = udev_device_get_property_value(device, "ID_USB_DRIVER")))
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
if (name)
|
if (name)
|
||||||
if (!strstr(devname, name))
|
if (!strstr(devname, name))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ret = eina_list_append(ret, eina_stringshare_add(devname));
|
ret = eina_list_append(ret, eina_stringshare_add(devname));
|
||||||
|
|
||||||
out:
|
out:
|
||||||
udev_device_unref(device);
|
udev_device_unref(device);
|
||||||
}
|
}
|
||||||
udev_enumerate_unref(en);
|
udev_enumerate_unref(en);
|
||||||
udev_unref(udev);
|
return ret;
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -306,28 +306,29 @@ out:
|
||||||
* @param type "ID_INPUT_KEY", "ID_INPUT_MOUSE", "ID_INPUT_TOUCHPAD", NULL, etc
|
* @param type "ID_INPUT_KEY", "ID_INPUT_MOUSE", "ID_INPUT_TOUCHPAD", NULL, etc
|
||||||
* @param name A filter for the device name, or NULL
|
* @param name A filter for the device name, or NULL
|
||||||
* @return A Eina_List* of matched devices or NULL on failure
|
* @return A Eina_List* of matched devices or NULL on failure
|
||||||
*
|
*
|
||||||
* Return a list of syspaths (/sys/$syspath) for matching udev devices.
|
* Return a list of syspaths (/sys/$syspath) for matching udev devices.
|
||||||
* Requires at least one filter.
|
* Requires at least one filter.
|
||||||
*
|
*
|
||||||
* @ingroup udev
|
* @ingroup udev
|
||||||
*/
|
*/
|
||||||
EAPI Eina_List *
|
EAPI Eina_List *
|
||||||
eeze_udev_find_by_filter(const char *subsystem, const char *type, const char *name)
|
eeze_udev_find_by_filter(const char *subsystem, const char *type,
|
||||||
|
const char *name)
|
||||||
{
|
{
|
||||||
struct udev *udev;
|
_udev_enumerate *en;
|
||||||
struct udev_enumerate *en;
|
_udev_list_entry *devs, *cur;
|
||||||
struct udev_list_entry *devs, *cur;
|
_udev_device *device;
|
||||||
struct udev_device *device;
|
|
||||||
const char *devname;
|
const char *devname;
|
||||||
Eina_List *ret = NULL;
|
Eina_List *ret = NULL;
|
||||||
|
|
||||||
if ((!subsystem) && (!type) && (!name)) return NULL;
|
if ((!subsystem) && (!type) && (!name))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
udev = udev_new();
|
en = udev_enumerate_new((udev));
|
||||||
if (!udev) return NULL;
|
|
||||||
en = udev_enumerate_new(udev);
|
if (!en)
|
||||||
if (!en) return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (subsystem)
|
if (subsystem)
|
||||||
udev_enumerate_add_match_subsystem(en, subsystem);
|
udev_enumerate_add_match_subsystem(en, subsystem);
|
||||||
|
@ -335,67 +336,58 @@ eeze_udev_find_by_filter(const char *subsystem, const char *type, const char *na
|
||||||
udev_enumerate_add_match_property(en, type, "1");
|
udev_enumerate_add_match_property(en, type, "1");
|
||||||
udev_enumerate_scan_devices(en);
|
udev_enumerate_scan_devices(en);
|
||||||
devs = udev_enumerate_get_list_entry(en);
|
devs = udev_enumerate_get_list_entry(en);
|
||||||
|
|
||||||
udev_list_entry_foreach(cur, devs)
|
udev_list_entry_foreach(cur, devs)
|
||||||
{
|
{
|
||||||
devname = udev_list_entry_get_name(cur);
|
devname = udev_list_entry_get_name(cur);
|
||||||
device = udev_device_new_from_syspath(udev, devname);
|
device = udev_device_new_from_syspath(udev, devname);
|
||||||
|
|
||||||
if (name)
|
if (name)
|
||||||
if (!strstr(devname,name))
|
if (!strstr(devname, name))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ret = eina_list_append(ret, eina_stringshare_add(devname));
|
ret = eina_list_append(ret, eina_stringshare_add(devname));
|
||||||
|
|
||||||
out:
|
out:
|
||||||
udev_device_unref(device);
|
udev_device_unref(device);
|
||||||
}
|
}
|
||||||
udev_enumerate_unref(en);
|
udev_enumerate_unref(en);
|
||||||
udev_unref(udev);
|
return ret;
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find a list of devices by a sysattr (and, optionally, a value of that sysattr).
|
* Find a list of devices by a sysattr (and, optionally, a value of that sysattr).
|
||||||
*
|
*
|
||||||
* @param sysattr The attribute to find
|
* @param sysattr The attribute to find
|
||||||
* @param value Optional: the value that the attribute should have
|
* @param value Optional: the value that the attribute should have
|
||||||
*
|
*
|
||||||
* @return A list of the devices found with the attribute
|
* @return A list of the devices found with the attribute
|
||||||
*/
|
*/
|
||||||
EAPI Eina_List *
|
EAPI Eina_List *
|
||||||
eeze_udev_find_by_sysattr(const char *sysattr, const char *value)
|
eeze_udev_find_by_sysattr(const char *sysattr, const char *value)
|
||||||
{
|
{
|
||||||
struct udev *udev;
|
_udev_enumerate *en;
|
||||||
struct udev_enumerate *en;
|
_udev_list_entry *devs, *cur;
|
||||||
struct udev_list_entry *devs, *cur;
|
_udev_device *device;
|
||||||
struct udev_device *device;
|
|
||||||
const char *devname;
|
const char *devname;
|
||||||
Eina_List *ret = NULL;
|
Eina_List *ret = NULL;
|
||||||
|
|
||||||
if (!sysattr) return NULL;
|
if (!sysattr)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
udev = udev_new();
|
en = udev_enumerate_new((udev));
|
||||||
if (!udev) return NULL;
|
|
||||||
en = udev_enumerate_new(udev);
|
if (!en)
|
||||||
if (!en) return NULL;
|
return NULL;
|
||||||
|
|
||||||
udev_enumerate_add_match_sysattr(en, sysattr, value);
|
udev_enumerate_add_match_sysattr(en, sysattr, value);
|
||||||
udev_enumerate_scan_devices(en);
|
udev_enumerate_scan_devices(en);
|
||||||
devs = udev_enumerate_get_list_entry(en);
|
devs = udev_enumerate_get_list_entry(en);
|
||||||
|
|
||||||
udev_list_entry_foreach(cur, devs)
|
udev_list_entry_foreach(cur, devs)
|
||||||
{
|
{
|
||||||
devname = udev_list_entry_get_name(cur);
|
devname = udev_list_entry_get_name(cur);
|
||||||
device = udev_device_new_from_syspath(udev, devname);
|
device = udev_device_new_from_syspath(udev, devname);
|
||||||
|
|
||||||
ret = eina_list_append(ret, eina_stringshare_add(devname));
|
ret = eina_list_append(ret, eina_stringshare_add(devname));
|
||||||
|
|
||||||
udev_device_unref(device);
|
udev_device_unref(device);
|
||||||
}
|
}
|
||||||
udev_enumerate_unref(en);
|
udev_enumerate_unref(en);
|
||||||
udev_unref(udev);
|
return ret;
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,44 +1,56 @@
|
||||||
#include "eeze_udev_private.h"
|
#ifdef HAVE_CONFIG_H
|
||||||
#include <Eeze_Udev.h>
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
int _e_eeze_udev_log_dom = -1;
|
#include <Eeze_Udev.h>
|
||||||
int _e_eeze_udev_init_count = 0;
|
#include "eeze_udev_private.h"
|
||||||
|
|
||||||
|
_udev *udev;
|
||||||
|
|
||||||
|
int _eeze_udev_log_dom = -1;
|
||||||
|
int _eeze_udev_init_count = 0;
|
||||||
|
|
||||||
EAPI int
|
EAPI int
|
||||||
eeze_udev_init(void)
|
eeze_udev_init(void)
|
||||||
{
|
{
|
||||||
if (++_e_eeze_udev_init_count != 1)
|
if (++_eeze_udev_init_count != 1)
|
||||||
return _e_eeze_udev_init_count;
|
return _eeze_udev_init_count;
|
||||||
|
|
||||||
if (!eina_init())
|
if (!eina_init())
|
||||||
return --_e_eeze_udev_init_count;
|
return --_eeze_udev_init_count;
|
||||||
|
|
||||||
_e_eeze_udev_log_dom = eina_log_domain_register
|
_eeze_udev_log_dom = eina_log_domain_register
|
||||||
("eeze_udev", E_EEZE_COLOR_DEFAULT);
|
("eeze_udev", eeze_COLOR_DEFAULT);
|
||||||
if (_e_eeze_udev_log_dom < 0)
|
|
||||||
|
if (_eeze_udev_log_dom < 0)
|
||||||
{
|
{
|
||||||
EINA_LOG_ERR("Could not register 'eeze_udev' log domain.");
|
EINA_LOG_ERR("Could not register 'eeze_udev' log domain.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _e_eeze_udev_init_count;
|
if (!((udev) = udev_new()))
|
||||||
|
{
|
||||||
|
EINA_LOG_ERR("Could not initialize udev library!");
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _eeze_udev_init_count;
|
||||||
fail:
|
fail:
|
||||||
eina_log_domain_unregister(_e_eeze_udev_log_dom);
|
eina_log_domain_unregister(_eeze_udev_log_dom);
|
||||||
_e_eeze_udev_log_dom = -1;
|
_eeze_udev_log_dom = -1;
|
||||||
eina_shutdown();
|
eina_shutdown();
|
||||||
return _e_eeze_udev_init_count;
|
return _eeze_udev_init_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI int
|
EAPI int
|
||||||
eeze_udev_shutdown(void)
|
eeze_udev_shutdown(void)
|
||||||
{
|
{
|
||||||
if (--_e_eeze_udev_init_count != 0)
|
if (--_eeze_udev_init_count != 0)
|
||||||
return _e_eeze_udev_init_count;
|
return _eeze_udev_init_count;
|
||||||
|
|
||||||
eina_log_domain_unregister(_e_eeze_udev_log_dom);
|
udev_unref(udev);
|
||||||
_e_eeze_udev_log_dom = -1;
|
eina_log_domain_unregister(_eeze_udev_log_dom);
|
||||||
|
_eeze_udev_log_dom = -1;
|
||||||
eina_shutdown();
|
eina_shutdown();
|
||||||
|
return _eeze_udev_init_count;
|
||||||
return _e_eeze_udev_init_count;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,42 +5,65 @@
|
||||||
#include <Eeze_Udev.h>
|
#include <Eeze_Udev.h>
|
||||||
#include "eeze_udev_private.h"
|
#include "eeze_udev_private.h"
|
||||||
|
|
||||||
|
extern _udev *udev;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* copies a device
|
||||||
|
*/
|
||||||
|
_udev_device *
|
||||||
|
_copy_device(_udev_device * device)
|
||||||
|
{
|
||||||
|
const char *syspath;
|
||||||
|
|
||||||
|
if (!(syspath = udev_device_get_syspath(device)))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return udev_device_new_from_syspath(udev, syspath);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* private function to simulate udevadm info -a
|
* private function to simulate udevadm info -a
|
||||||
* walks up the device tree checking each node for sysattr
|
* walks up the device tree checking each node for sysattr
|
||||||
* with value $value
|
* with value $value
|
||||||
*/
|
*/
|
||||||
Eina_Bool
|
Eina_Bool
|
||||||
_walk_parents_test_attr(struct udev_device *device, const char *sysattr, const char* value)
|
_walk_parents_test_attr(_udev_device * device, const char *sysattr,
|
||||||
|
const char *value)
|
||||||
{
|
{
|
||||||
struct udev_device *parent, *child = device;
|
_udev_device *parent, *child = device;
|
||||||
const char *test;
|
const char *test;
|
||||||
|
|
||||||
if ((test = udev_device_get_sysattr_value(device, sysattr)))
|
if ((test = udev_device_get_sysattr_value(device, sysattr)))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
parent = udev_device_get_parent(child);
|
parent = udev_device_get_parent(child);
|
||||||
|
|
||||||
for (; parent; child = parent, parent = udev_device_get_parent(child))
|
for (; parent; child = parent, parent = udev_device_get_parent(child))
|
||||||
{
|
{
|
||||||
if (!(test = udev_device_get_sysattr_value(parent, sysattr)))
|
if (!(test = udev_device_get_sysattr_value(parent, sysattr)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!value)
|
if (!value)
|
||||||
return 1;
|
return 1;
|
||||||
else if (!strcmp(test, value))
|
else
|
||||||
return 1;
|
if (!strcmp(test, value))
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
_walk_parents_get_attr(struct udev_device *device, const char *sysattr)
|
_walk_parents_get_attr(_udev_device * device, const char *sysattr)
|
||||||
{
|
{
|
||||||
struct udev_device *parent, *child = device;
|
_udev_device *parent, *child = device;
|
||||||
const char *test;
|
const char *test;
|
||||||
|
|
||||||
if ((test = udev_device_get_sysattr_value(device, sysattr)))
|
if ((test = udev_device_get_sysattr_value(device, sysattr)))
|
||||||
return eina_stringshare_add(test);
|
return eina_stringshare_add(test);
|
||||||
|
|
||||||
parent = udev_device_get_parent(child);
|
parent = udev_device_get_parent(child);
|
||||||
|
|
||||||
for (; parent; child = parent, parent = udev_device_get_parent(child))
|
for (; parent; child = parent, parent = udev_device_get_parent(child))
|
||||||
{
|
{
|
||||||
if ((test = udev_device_get_sysattr_value(parent, sysattr)))
|
if ((test = udev_device_get_sysattr_value(parent, sysattr)))
|
||||||
|
@ -55,30 +78,39 @@ _walk_parents_get_attr(struct udev_device *device, const char *sysattr)
|
||||||
* stringshare adding all devices that are not in the list
|
* stringshare adding all devices that are not in the list
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
_get_unlisted_parents(Eina_List *list, struct udev_device *device)
|
_get_unlisted_parents(Eina_List * list, _udev_device * device)
|
||||||
{
|
{
|
||||||
struct udev_device *parent, *child = device;
|
_udev_device *parent, *child = device;
|
||||||
const char *test, *devname, *vendor, *vendor2, *model, *model2;
|
const char *test, *devname, *vendor, *vendor2, *model, *model2;
|
||||||
Eina_List *l;
|
Eina_List *l;
|
||||||
Eina_Bool found;
|
Eina_Bool found;
|
||||||
|
|
||||||
if (!(vendor = udev_device_get_property_value(child, "ID_VENDOR_ID")))
|
if (!(vendor = udev_device_get_property_value(child, "ID_VENDOR_ID")))
|
||||||
vendor = udev_device_get_property_value(child, "ID_VENDOR");
|
vendor = udev_device_get_property_value(child, "ID_VENDOR");
|
||||||
|
|
||||||
if (!(model = udev_device_get_property_value(child, "ID_MODEL_ID")))
|
if (!(model = udev_device_get_property_value(child, "ID_MODEL_ID")))
|
||||||
model = udev_device_get_property_value(child, "ID_MODEL");
|
model = udev_device_get_property_value(child, "ID_MODEL");
|
||||||
|
|
||||||
parent = udev_device_get_parent(child);
|
parent = udev_device_get_parent(child);
|
||||||
|
|
||||||
for (; parent; child = parent, parent = udev_device_get_parent(child))
|
for (; parent; child = parent, parent = udev_device_get_parent(child))
|
||||||
{
|
{
|
||||||
found = 0;
|
found = 0;
|
||||||
|
|
||||||
if (!(vendor2 = udev_device_get_property_value(child, "ID_VENDOR_ID")))
|
if (!(vendor2 = udev_device_get_property_value(child, "ID_VENDOR_ID")))
|
||||||
vendor2 = udev_device_get_property_value(child, "ID_VENDOR");
|
vendor2 = udev_device_get_property_value(child, "ID_VENDOR");
|
||||||
|
|
||||||
if (!(model2 = udev_device_get_property_value(child, "ID_MODEL_ID")))
|
if (!(model2 = udev_device_get_property_value(child, "ID_MODEL_ID")))
|
||||||
model2 = udev_device_get_property_value(child, "ID_MODEL");
|
model2 = udev_device_get_property_value(child, "ID_MODEL");
|
||||||
if ((!model2 && model) || (model2 && !model) || (!vendor2 && vendor) || (vendor2 && !vendor))
|
|
||||||
break;
|
if ((!model2 && model) || (model2 && !model) || (!vendor2 && vendor)
|
||||||
else if (((model && model2) && (strcmp(model, model2))) ||
|
|| (vendor2 && !vendor))
|
||||||
((vendor && vendor2) && (strcmp(vendor, vendor2))))
|
|
||||||
break;
|
break;
|
||||||
|
else
|
||||||
|
if (((model && model2) && (strcmp(model, model2))) ||
|
||||||
|
((vendor && vendor2) && (strcmp(vendor, vendor2))))
|
||||||
|
break;
|
||||||
|
|
||||||
devname = udev_device_get_syspath(parent);
|
devname = udev_device_get_syspath(parent);
|
||||||
EINA_LIST_FOREACH(list, l, test)
|
EINA_LIST_FOREACH(list, l, test)
|
||||||
{
|
{
|
||||||
|
@ -88,8 +120,10 @@ _get_unlisted_parents(Eina_List *list, struct udev_device *device)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found)
|
if (!found)
|
||||||
list = eina_list_prepend(list, eina_stringshare_add(devname));
|
list = eina_list_prepend(list, eina_stringshare_add(devname));
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#ifndef EEZE_UDEV_PRIVATE_H
|
#ifndef EEZE_UDEV_PRIVATE_H
|
||||||
#define EEZE_UDEV_PRIVATE_H
|
#define EEZE_UDEV_PRIVATE_H
|
||||||
#include "Eeze_Udev.h"
|
#include "Eeze_Udev.h"
|
||||||
#ifndef E_EEZE_COLOR_DEFAULT
|
#ifndef eeze_COLOR_DEFAULT
|
||||||
#define E_EEZE_COLOR_DEFAULT EINA_COLOR_CYAN
|
#define eeze_COLOR_DEFAULT EINA_COLOR_CYAN
|
||||||
#endif
|
#endif
|
||||||
extern int _e_eeze_udev_log_dom;
|
extern int _eeze_udev_log_dom;
|
||||||
#ifdef ERR
|
#ifdef ERR
|
||||||
#undef ERR
|
#undef ERR
|
||||||
#endif
|
#endif
|
||||||
|
@ -18,13 +18,20 @@ extern int _e_eeze_udev_log_dom;
|
||||||
#undef DBG
|
#undef DBG
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DBG(...) EINA_LOG_DOM_DBG(_e_eeze_udev_log_dom, __VA_ARGS__)
|
#define DBG(...) EINA_LOG_DOM_DBG(_eeze_udev_log_dom, __VA_ARGS__)
|
||||||
#define INFO(...) EINA_LOG_DOM_INFO(_e_eeze_udev_log_dom, __VA_ARGS__)
|
#define INFO(...) EINA_LOG_DOM_INFO(_eeze_udev_log_dom, __VA_ARGS__)
|
||||||
#define WARN(...) EINA_LOG_DOM_WARN(_e_eeze_udev_log_dom, __VA_ARGS__)
|
#define WARN(...) EINA_LOG_DOM_WARN(_eeze_udev_log_dom, __VA_ARGS__)
|
||||||
#define ERR(...) EINA_LOG_DOM_ERR(_e_eeze_udev_log_dom, __VA_ARGS__)
|
#define ERR(...) EINA_LOG_DOM_ERR(_eeze_udev_log_dom, __VA_ARGS__)
|
||||||
|
|
||||||
Eina_Bool _walk_parents_test_attr(struct udev_device *device, const char *sysattr, const char* value);
|
typedef struct udev _udev;
|
||||||
const char *_walk_parents_get_attr(struct udev_device *device, const char *sysattr);
|
typedef struct udev_list_entry _udev_list_entry;
|
||||||
void _get_unlisted_parents(Eina_List *list, struct udev_device *device);
|
typedef struct udev_device _udev_device;
|
||||||
|
typedef struct udev_enumerate _udev_enumerate;
|
||||||
|
typedef struct udev_monitor _udev_monitor;
|
||||||
|
|
||||||
|
Eina_Bool _walk_parents_test_attr(_udev_device *device, const char *sysattr, const char* value);
|
||||||
|
const char *_walk_parents_get_attr(_udev_device *device, const char *sysattr);
|
||||||
|
void _get_unlisted_parents(Eina_List *list, _udev_device *device);
|
||||||
|
_udev_device *_copy_device(_udev_device *device);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#include <Eeze_Udev.h>
|
#include <Eeze_Udev.h>
|
||||||
#include "eeze_udev_private.h"
|
#include "eeze_udev_private.h"
|
||||||
|
|
||||||
|
extern _udev *udev;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Walks up the device chain starting at @p syspath,
|
* Walks up the device chain starting at @p syspath,
|
||||||
* checking each device for @p sysattr with (optional) @p value.
|
* checking each device for @p sysattr with (optional) @p value.
|
||||||
|
@ -16,45 +18,47 @@
|
||||||
* @return If the sysattr (with value) is found, returns TRUE. Else, false.
|
* @return If the sysattr (with value) is found, returns TRUE. Else, false.
|
||||||
*/
|
*/
|
||||||
EAPI Eina_Bool
|
EAPI Eina_Bool
|
||||||
eeze_udev_walk_check_sysattr(const char *syspath, const char *sysattr, const char *value)
|
eeze_udev_walk_check_sysattr(const char *syspath, const char *sysattr,
|
||||||
|
const char *value)
|
||||||
{
|
{
|
||||||
struct udev *udev;
|
_udev_device *device, *child, *parent;
|
||||||
struct udev_device *device, *child, *parent;
|
Eina_Strbuf *sbuf;
|
||||||
Eina_Strbuf *sbuf;
|
const char *test = NULL;
|
||||||
const char *test = NULL;
|
|
||||||
|
|
||||||
if (!syspath) return 0;
|
if (!udev)
|
||||||
udev = udev_new();
|
return 0;
|
||||||
if (!udev) return 0;
|
|
||||||
|
|
||||||
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));
|
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));
|
||||||
|
|
||||||
|
for (parent = device; parent;
|
||||||
|
child = parent, parent = udev_device_get_parent(child))
|
||||||
|
{
|
||||||
|
if ((test = udev_device_get_sysattr_value(parent, sysattr)))
|
||||||
|
{
|
||||||
|
if (value)
|
||||||
|
{
|
||||||
|
if (!strcmp(test, value))
|
||||||
|
{
|
||||||
|
eina_strbuf_free(sbuf);
|
||||||
|
udev_device_unref(device);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
eina_strbuf_free(sbuf);
|
||||||
|
udev_device_unref(device);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (parent = device; parent; child = parent, parent = udev_device_get_parent(child))
|
|
||||||
{
|
|
||||||
if ((test = udev_device_get_sysattr_value(parent, sysattr)))
|
|
||||||
{
|
|
||||||
if (value)
|
|
||||||
{
|
|
||||||
if (!strcmp(test, value))
|
|
||||||
{
|
|
||||||
eina_strbuf_free(sbuf);
|
|
||||||
udev_device_unref(device);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
eina_strbuf_free(sbuf);
|
|
||||||
udev_device_unref(device);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
eina_strbuf_free(sbuf);
|
eina_strbuf_free(sbuf);
|
||||||
udev_device_unref(device);
|
udev_device_unref(device);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -69,35 +73,36 @@ eeze_udev_walk_check_sysattr(const char *syspath, const char *sysattr, const cha
|
||||||
*
|
*
|
||||||
* @return The value of @p sysattr if found, or NULL
|
* @return The value of @p sysattr if found, or NULL
|
||||||
*/
|
*/
|
||||||
EAPI const char*
|
EAPI const char *
|
||||||
eeze_udev_walk_get_sysattr(const char *syspath, const char *sysattr)
|
eeze_udev_walk_get_sysattr(const char *syspath, const char *sysattr)
|
||||||
{
|
{
|
||||||
struct udev *udev;
|
_udev_device *device, *child, *parent;
|
||||||
struct udev_device *device, *child, *parent;
|
Eina_Strbuf *sbuf;
|
||||||
Eina_Strbuf *sbuf;
|
const char *test = NULL;
|
||||||
const char *test = NULL;
|
|
||||||
|
|
||||||
if (!syspath) return NULL;
|
if (!syspath)
|
||||||
udev = udev_new();
|
return NULL;
|
||||||
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));
|
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));
|
||||||
|
|
||||||
|
for (parent = device; parent;
|
||||||
|
child = parent, parent = udev_device_get_parent(child))
|
||||||
|
{
|
||||||
|
if ((test = udev_device_get_sysattr_value(parent, sysattr)))
|
||||||
|
{
|
||||||
|
eina_strbuf_free(sbuf);
|
||||||
|
test = eina_stringshare_add(test);
|
||||||
|
udev_device_unref(device);
|
||||||
|
return test;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (parent = device; parent; child = parent, parent = udev_device_get_parent(child))
|
|
||||||
{
|
|
||||||
if ((test = udev_device_get_sysattr_value(parent, sysattr)))
|
|
||||||
{
|
|
||||||
eina_strbuf_free(sbuf);
|
|
||||||
test = eina_stringshare_add(test);
|
|
||||||
udev_device_unref(device);
|
|
||||||
return test;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
eina_strbuf_free(sbuf);
|
eina_strbuf_free(sbuf);
|
||||||
udev_device_unref(device);
|
udev_device_unref(device);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -5,10 +5,12 @@
|
||||||
#include <Eeze_Udev.h>
|
#include <Eeze_Udev.h>
|
||||||
#include "eeze_udev_private.h"
|
#include "eeze_udev_private.h"
|
||||||
|
|
||||||
|
extern _udev *udev;
|
||||||
|
|
||||||
/* opaque */
|
/* opaque */
|
||||||
struct Eeze_Udev_Watch
|
struct Eeze_Udev_Watch
|
||||||
{
|
{
|
||||||
struct udev_monitor *mon;
|
_udev_monitor *mon;
|
||||||
Ecore_Fd_Handler *handler;
|
Ecore_Fd_Handler *handler;
|
||||||
Eeze_Udev_Type type;
|
Eeze_Udev_Type type;
|
||||||
};
|
};
|
||||||
|
@ -16,195 +18,245 @@ struct Eeze_Udev_Watch
|
||||||
/* private */
|
/* private */
|
||||||
struct _store_data
|
struct _store_data
|
||||||
{
|
{
|
||||||
void(*func)(const char *, const char *, void *, Eeze_Udev_Watch *);
|
void (*func)(const char *, int, void *, Eeze_Udev_Watch *);
|
||||||
void *data;
|
void *data;
|
||||||
int event;
|
int event;
|
||||||
struct udev_monitor *mon;
|
_udev_monitor *mon;
|
||||||
Eeze_Udev_Type type;
|
Eeze_Udev_Type type;
|
||||||
Eeze_Udev_Watch *watch;
|
Eeze_Udev_Watch *watch;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* private function to further filter watch results based on Eeze_Udev_Type
|
/* private function to further filter watch results based on Eeze_Udev_Type
|
||||||
* specified; helpful for new udev versions, but absolutely required for
|
* specified; helpful for new udev versions, but absolutely required for
|
||||||
* old udev, which does not implement filtering in device monitors.
|
* old udev, which does not implement filtering in device monitors.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
_get_syspath_from_watch(void *data, Ecore_Fd_Handler *fd_handler)
|
_get_syspath_from_watch(void *data, Ecore_Fd_Handler * fd_handler)
|
||||||
{
|
{
|
||||||
struct _store_data *store = data;
|
struct _store_data *store = data;
|
||||||
struct udev_device *device, *parent, *tmpdev;
|
_udev_device *device, *parent, *tmpdev;
|
||||||
const char *ret, *test;
|
const char *ret, *test;
|
||||||
void(*func)(const char *, const char *, void *, Eeze_Udev_Watch *) = store->func;
|
void (*func)(const char *, int, void *, Eeze_Udev_Watch *) = store->func;
|
||||||
void *sdata = store->data;
|
void *sdata = store->data;
|
||||||
Eeze_Udev_Watch *watch = store->watch;
|
Eeze_Udev_Watch *watch = store->watch;
|
||||||
int cap = 0;
|
int cap = 0, event = 0;
|
||||||
|
|
||||||
if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
|
if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
device = udev_monitor_receive_device(store->mon);
|
device = udev_monitor_receive_device(store->mon);
|
||||||
if (!device) return 1;
|
|
||||||
|
if (!device)
|
||||||
|
return 1;
|
||||||
|
|
||||||
switch (store->type)
|
switch (store->type)
|
||||||
{
|
{
|
||||||
case EEZE_UDEV_TYPE_KEYBOARD:
|
case EEZE_UDEV_TYPE_KEYBOARD:
|
||||||
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
||||||
if ((!(test = udev_device_get_subsystem(device))) || (strcmp(test, "input")))
|
if ((!(test = udev_device_get_subsystem(device)))
|
||||||
|
|| (strcmp(test, "input")))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
test = udev_device_get_property_value(device, "ID_CLASS");
|
test = udev_device_get_property_value(device, "ID_CLASS");
|
||||||
if ((_walk_parents_test_attr(device, "bInterfaceProtocol", "01")) || ((test) && (!strcmp(test, "kbd"))))
|
|
||||||
|
if ((_walk_parents_test_attr(device, "bInterfaceProtocol", "01"))
|
||||||
|
|| ((test) && (!strcmp(test, "kbd"))))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
goto error;
|
goto error;
|
||||||
#endif
|
#endif
|
||||||
if (!udev_device_get_property_value(device, "ID_INPUT_KEYBOARD"))
|
if (!udev_device_get_property_value(device, "ID_INPUT_KEYBOARD"))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case EEZE_UDEV_TYPE_MOUSE:
|
case EEZE_UDEV_TYPE_MOUSE:
|
||||||
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
||||||
if ((!(test = udev_device_get_subsystem(device))) || (strcmp(test, "input")))
|
if ((!(test = udev_device_get_subsystem(device)))
|
||||||
|
|| (strcmp(test, "input")))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
test = udev_device_get_property_value(device, "ID_CLASS");
|
test = udev_device_get_property_value(device, "ID_CLASS");
|
||||||
if ((_walk_parents_test_attr(device, "bInterfaceProtocol", "02")) || ((test) && (!strcmp(test, "mouse"))))
|
|
||||||
|
if ((_walk_parents_test_attr(device, "bInterfaceProtocol", "02"))
|
||||||
|
|| ((test) && (!strcmp(test, "mouse"))))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
goto error;
|
goto error;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!udev_device_get_property_value(device, "ID_INPUT_MOUSE"))
|
if (!udev_device_get_property_value(device, "ID_INPUT_MOUSE"))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case EEZE_UDEV_TYPE_TOUCHPAD:
|
case EEZE_UDEV_TYPE_TOUCHPAD:
|
||||||
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
||||||
if ((!(test = udev_device_get_subsystem(device))) || (strcmp(test, "input")))
|
if ((!(test = udev_device_get_subsystem(device)))
|
||||||
|
|| (strcmp(test, "input")))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (_walk_parents_test_attr(device, "resolution", NULL))
|
if (_walk_parents_test_attr(device, "resolution", NULL))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
goto error;
|
goto error;
|
||||||
#endif
|
#endif
|
||||||
if (!udev_device_get_property_value(device, "ID_INPUT_TOUCHPAD"))
|
if (!udev_device_get_property_value(device, "ID_INPUT_TOUCHPAD"))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case EEZE_UDEV_TYPE_DRIVE_MOUNTABLE:
|
case EEZE_UDEV_TYPE_DRIVE_MOUNTABLE:
|
||||||
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
||||||
if ((!(test = udev_device_get_subsystem(device))) || (strcmp(test, "block")))
|
if ((!(test = udev_device_get_subsystem(device)))
|
||||||
|
|| (strcmp(test, "block")))
|
||||||
goto error;
|
goto error;
|
||||||
#endif
|
#endif
|
||||||
test = udev_device_get_sysattr_value(device, "capability");
|
test = udev_device_get_sysattr_value(device, "capability");
|
||||||
if (test) cap = atoi(test);
|
|
||||||
|
if (test)
|
||||||
|
cap = atoi(test);
|
||||||
|
|
||||||
if (!(test = (udev_device_get_property_value(device, "ID_FS_USAGE"))) ||
|
if (!(test = (udev_device_get_property_value(device, "ID_FS_USAGE"))) ||
|
||||||
(strcmp("filesystem", test)) || (cap == 52))
|
(strcmp("filesystem", test)) || (cap == 52))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case EEZE_UDEV_TYPE_DRIVE_INTERNAL:
|
case EEZE_UDEV_TYPE_DRIVE_INTERNAL:
|
||||||
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
||||||
if ((!(test = udev_device_get_subsystem(device))) || (strcmp(test, "block")))
|
if ((!(test = udev_device_get_subsystem(device)))
|
||||||
|
|| (strcmp(test, "block")))
|
||||||
goto error;
|
goto error;
|
||||||
#endif
|
#endif
|
||||||
if (!(test = udev_device_get_property_value(device, "ID_BUS")) || (strcmp("ata", test)) ||
|
if (!(test = udev_device_get_property_value(device, "ID_BUS"))
|
||||||
!(test = udev_device_get_sysattr_value(device, "removable")) || (atoi(test)))
|
|| (strcmp("ata", test))
|
||||||
|
|| !(test = udev_device_get_sysattr_value(device, "removable"))
|
||||||
|
|| (atoi(test)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case EEZE_UDEV_TYPE_DRIVE_REMOVABLE:
|
case EEZE_UDEV_TYPE_DRIVE_REMOVABLE:
|
||||||
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
||||||
if ((!(test = udev_device_get_subsystem(device))) || (strcmp(test, "block")))
|
if ((!(test = udev_device_get_subsystem(device)))
|
||||||
|
|| (strcmp(test, "block")))
|
||||||
goto error;
|
goto error;
|
||||||
#endif
|
#endif
|
||||||
if ((!(test = udev_device_get_sysattr_value(device, "removable")) || (!atoi(test))) &&
|
if ((!(test = udev_device_get_sysattr_value(device, "removable"))
|
||||||
(!(test = udev_device_get_sysattr_value(device, "capability")) || (atoi(test) != 10)))
|
|| (!atoi(test)))
|
||||||
|
&& (!(test = udev_device_get_sysattr_value(device, "capability"))
|
||||||
|
|| (atoi(test) != 10)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case EEZE_UDEV_TYPE_DRIVE_CDROM:
|
case EEZE_UDEV_TYPE_DRIVE_CDROM:
|
||||||
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
||||||
if ((!(test = udev_device_get_subsystem(device))) || (strcmp(test, "block")))
|
if ((!(test = udev_device_get_subsystem(device)))
|
||||||
|
|| (strcmp(test, "block")))
|
||||||
goto error;
|
goto error;
|
||||||
#endif
|
#endif
|
||||||
if (!udev_device_get_property_value(device, "ID_CDROM"))
|
if (!udev_device_get_property_value(device, "ID_CDROM"))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case EEZE_UDEV_TYPE_POWER_AC:
|
case EEZE_UDEV_TYPE_POWER_AC:
|
||||||
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
||||||
if ((!(test = udev_device_get_subsystem(device))) || (strcmp(test, "power_supply")))
|
if ((!(test = udev_device_get_subsystem(device)))
|
||||||
|
|| (strcmp(test, "power_supply")))
|
||||||
goto error;
|
goto error;
|
||||||
#endif
|
#endif
|
||||||
if (!(test = (udev_device_get_property_value(device, "POWER_SUPPLY_TYPE"))) ||
|
if (!(test = udev_device_get_property_value(device, "POWER_SUPPLY_TYPE"))
|
||||||
(strcmp("Mains", test)))
|
|| (strcmp("Mains", test)))
|
||||||
goto error;
|
goto error;
|
||||||
break;
|
break;
|
||||||
case EEZE_UDEV_TYPE_POWER_BAT:
|
case EEZE_UDEV_TYPE_POWER_BAT:
|
||||||
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
||||||
if ((!(test = udev_device_get_subsystem(device))) || (strcmp(test, "power_supply")))
|
if ((!(test = udev_device_get_subsystem(device)))
|
||||||
|
|| (strcmp(test, "power_supply")))
|
||||||
goto error;
|
goto error;
|
||||||
#endif
|
#endif
|
||||||
if (!(test = (udev_device_get_property_value(device, "POWER_SUPPLY_TYPE"))) ||
|
if (!(test = udev_device_get_property_value(device, "POWER_SUPPLY_TYPE"))
|
||||||
(strcmp("Battery", test)))
|
|| (strcmp("Battery", test)))
|
||||||
goto error;
|
goto error;
|
||||||
break;
|
break;
|
||||||
case EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR:
|
case EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR:
|
||||||
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
||||||
if ((!(test = udev_device_get_subsystem(device))) || (strcmp(test, "hwmon")))
|
if ((!(test = udev_device_get_subsystem(device)))
|
||||||
|
|| (strcmp(test, "hwmon")))
|
||||||
goto error;
|
goto error;
|
||||||
#endif /* have to do stuff up here since we need info from the parent */
|
#endif /* have to do stuff up here since we need info from the parent */
|
||||||
if (!_walk_parents_test_attr(device, "temp1_input", NULL))
|
if (!_walk_parents_test_attr(device, "temp1_input", NULL))
|
||||||
goto error;
|
|
||||||
/* if device is not the one which has the temp input, we must go up the chain */
|
|
||||||
if (!(test = udev_device_get_sysattr_value(device, "temp1_input")))
|
|
||||||
{
|
|
||||||
tmpdev = NULL;
|
|
||||||
for (parent = udev_device_get_parent(device); parent; parent = udev_device_get_parent(parent))/*check for parent*/
|
|
||||||
if (((test = udev_device_get_sysattr_value(parent, "temp1_input"))))
|
|
||||||
{
|
|
||||||
tmpdev = parent;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
tmpdev = device;
|
|
||||||
if ((!tmpdev) || !(test = udev_device_get_action(device)) || (!(ret = udev_device_get_syspath(tmpdev))))
|
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
(*func)(eina_stringshare_add(ret), test, sdata, watch);
|
/* if device is not the one which has the temp input, we must go up the chain */
|
||||||
udev_device_unref(device);
|
if (!(test = udev_device_get_sysattr_value(device, "temp1_input")))
|
||||||
return 1;
|
{
|
||||||
|
for (parent = udev_device_get_parent(device); parent; parent = udev_device_get_parent(parent)) /*check for parent */
|
||||||
|
if (((test =
|
||||||
|
udev_device_get_sysattr_value(parent, "temp1_input"))))
|
||||||
|
{
|
||||||
|
tmpdev = device;
|
||||||
|
|
||||||
|
if (!(device = _copy_device(parent)))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
udev_device_unref(tmpdev);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
/*
|
|
||||||
case EEZE_UDEV_TYPE_ANDROID:
|
|
||||||
udev_monitor_filter_add_match_subsystem_devtype(mon, "input", "usb_interface");
|
|
||||||
break;
|
|
||||||
*/
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!(test = udev_device_get_action(device))) || (!(ret = udev_device_get_syspath(device))))
|
if ((!(test = udev_device_get_action(device)))
|
||||||
|
|| (!(ret = udev_device_get_syspath(device))))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (store->event)
|
if (store->event)
|
||||||
{
|
{
|
||||||
if (!strcmp(test, "add"))
|
if (!strcmp(test, "add"))
|
||||||
|
{
|
||||||
|
if ((store->event & EEZE_UDEV_EVENT_ADD) != EEZE_UDEV_EVENT_ADD)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
event |= EEZE_UDEV_EVENT_ADD;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if (!strcmp(test, "remove"))
|
||||||
{
|
{
|
||||||
if ((store->event & ~EEZE_UDEV_EVENT_ADD))
|
if ((store->event & EEZE_UDEV_EVENT_REMOVE) !=
|
||||||
goto error;
|
EEZE_UDEV_EVENT_REMOVE)
|
||||||
}
|
goto error;
|
||||||
else if (!strcmp(test, "remove"))
|
|
||||||
{
|
event |= EEZE_UDEV_EVENT_REMOVE;
|
||||||
if ((store->event & ~EEZE_UDEV_EVENT_REMOVE))
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
else if (!strcmp(test, "change"))
|
|
||||||
{
|
|
||||||
if ((store->event & ~EEZE_UDEV_EVENT_CHANGE))
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
else if (!strcmp(test, "online"))
|
|
||||||
{
|
|
||||||
if ((store->event & ~EEZE_UDEV_EVENT_ONLINE))
|
|
||||||
goto error;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
if (!strcmp(test, "change"))
|
||||||
if ((store->event & ~EEZE_UDEV_EVENT_OFFLINE))
|
{
|
||||||
goto error;
|
if ((store->event & EEZE_UDEV_EVENT_CHANGE) !=
|
||||||
}
|
EEZE_UDEV_EVENT_CHANGE)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
event |= EEZE_UDEV_EVENT_CHANGE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if (!strcmp(test, "online"))
|
||||||
|
{
|
||||||
|
if ((store->event & EEZE_UDEV_EVENT_ONLINE) !=
|
||||||
|
EEZE_UDEV_EVENT_ONLINE)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
event |= EEZE_UDEV_EVENT_ONLINE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ((store->event & EEZE_UDEV_EVENT_OFFLINE) !=
|
||||||
|
EEZE_UDEV_EVENT_OFFLINE)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
event |= EEZE_UDEV_EVENT_OFFLINE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(*func)(eina_stringshare_add(ret), eina_stringshare_add(test), sdata, watch);
|
(*func)(eina_stringshare_add(ret), event, sdata, watch);
|
||||||
error:
|
error:
|
||||||
udev_device_unref(device);
|
udev_device_unref(device);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -219,28 +271,31 @@ error:
|
||||||
* @param user_data Data to pass to the callback function
|
* @param user_data Data to pass to the callback function
|
||||||
*
|
*
|
||||||
* @return A watch struct for the watch type specified, or NULL on failure
|
* @return A watch struct for the watch type specified, or NULL on failure
|
||||||
*
|
*
|
||||||
* @ingroup udev
|
* @ingroup udev
|
||||||
*/
|
*/
|
||||||
EAPI Eeze_Udev_Watch *
|
EAPI Eeze_Udev_Watch *
|
||||||
eeze_udev_watch_add(Eeze_Udev_Type type, int event, void(*func)(const char *syspath, const char *event, void *data, Eeze_Udev_Watch *watch), void *user_data)
|
eeze_udev_watch_add(Eeze_Udev_Type type, int event,
|
||||||
|
void (*func)(const char *syspath, int event, void *data,
|
||||||
|
Eeze_Udev_Watch * watch), void *user_data)
|
||||||
{
|
{
|
||||||
struct udev *udev;
|
_udev_monitor *mon;
|
||||||
struct udev_monitor *mon;
|
|
||||||
int fd;
|
int fd;
|
||||||
Ecore_Fd_Handler *handler;
|
Ecore_Fd_Handler *handler;
|
||||||
Eeze_Udev_Watch *watch;
|
Eeze_Udev_Watch *watch;
|
||||||
struct _store_data *store;
|
struct _store_data *store;
|
||||||
|
|
||||||
if (!(store = calloc(sizeof(struct _store_data), 1))) return NULL;
|
if (!(store = calloc(sizeof(struct _store_data), 1)))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if (!(watch = malloc(sizeof(Eeze_Udev_Watch))))
|
if (!(watch = malloc(sizeof(Eeze_Udev_Watch))))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!(udev = udev_new()))
|
|
||||||
goto error;
|
|
||||||
if (!(mon = udev_monitor_new_from_netlink(udev, "udev")))
|
if (!(mon = udev_monitor_new_from_netlink(udev, "udev")))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
#ifndef OLD_UDEV_RRRRRRRRRRRRRR
|
#ifndef OLD_UDEV_RRRRRRRRRRRRRR
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case EEZE_UDEV_TYPE_KEYBOARD:
|
case EEZE_UDEV_TYPE_KEYBOARD:
|
||||||
|
@ -266,23 +321,26 @@ eeze_udev_watch_add(Eeze_Udev_Type type, int event, void(*func)(const char *sysp
|
||||||
break;
|
break;
|
||||||
case EEZE_UDEV_TYPE_POWER_AC:
|
case EEZE_UDEV_TYPE_POWER_AC:
|
||||||
case EEZE_UDEV_TYPE_POWER_BAT:
|
case EEZE_UDEV_TYPE_POWER_BAT:
|
||||||
udev_monitor_filter_add_match_subsystem_devtype(mon, "power_supply", NULL);
|
udev_monitor_filter_add_match_subsystem_devtype(mon, "power_supply",
|
||||||
|
NULL);
|
||||||
break;
|
break;
|
||||||
case EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR:
|
case EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR:
|
||||||
udev_monitor_filter_add_match_subsystem_devtype(mon, "hwmon", NULL);
|
udev_monitor_filter_add_match_subsystem_devtype(mon, "hwmon", NULL);
|
||||||
break;
|
break;
|
||||||
/*
|
/*
|
||||||
case EEZE_UDEV_TYPE_ANDROID:
|
case EEZE_UDEV_TYPE_ANDROID:
|
||||||
udev_monitor_filter_add_match_subsystem_devtype(mon, "input", "usb_interface");
|
udev_monitor_filter_add_match_subsystem_devtype(mon, "input", "usb_interface");
|
||||||
break;
|
break;
|
||||||
*/
|
*/
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (udev_monitor_enable_receiving(mon))
|
if (udev_monitor_enable_receiving(mon))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
fd = udev_monitor_get_fd(mon);
|
fd = udev_monitor_get_fd(mon);
|
||||||
store->func = func;
|
store->func = func;
|
||||||
store->data = user_data;
|
store->data = user_data;
|
||||||
|
@ -290,19 +348,19 @@ eeze_udev_watch_add(Eeze_Udev_Type type, int event, void(*func)(const char *sysp
|
||||||
store->type = type;
|
store->type = type;
|
||||||
store->watch = watch;
|
store->watch = watch;
|
||||||
store->event = event;
|
store->event = event;
|
||||||
if (!(handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, _get_syspath_from_watch, store, NULL, NULL)))
|
|
||||||
|
if (!(handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ,
|
||||||
|
_get_syspath_from_watch, store, NULL, NULL)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
watch->mon = mon;
|
watch->mon = mon;
|
||||||
watch->handler = handler;
|
watch->handler = handler;
|
||||||
|
|
||||||
return watch;
|
return watch;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
free(store);
|
free(store);
|
||||||
free(watch);
|
free(watch);
|
||||||
udev_monitor_unref(mon);
|
udev_monitor_unref(mon);
|
||||||
udev_unref(udev);
|
return NULL;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -316,24 +374,23 @@ error:
|
||||||
* @ingroup udev
|
* @ingroup udev
|
||||||
*/
|
*/
|
||||||
EAPI void *
|
EAPI void *
|
||||||
eeze_udev_watch_del(Eeze_Udev_Watch *watch)
|
eeze_udev_watch_del(Eeze_Udev_Watch * watch)
|
||||||
{
|
{
|
||||||
struct udev *udev;
|
|
||||||
struct _store_data *sdata;
|
struct _store_data *sdata;
|
||||||
void *ret;
|
void *ret;
|
||||||
|
|
||||||
if ((!watch) || (!watch->mon) || (!watch->handler)) return NULL;
|
if ((!watch) || (!watch->mon) || (!watch->handler))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
udev = udev_monitor_get_udev(watch->mon);
|
|
||||||
udev_monitor_unref(watch->mon);
|
udev_monitor_unref(watch->mon);
|
||||||
udev_unref(udev);
|
|
||||||
sdata = ecore_main_fd_handler_del(watch->handler);
|
sdata = ecore_main_fd_handler_del(watch->handler);
|
||||||
|
|
||||||
if (sdata)
|
if (sdata)
|
||||||
{
|
{
|
||||||
ret = sdata->data;
|
ret = sdata->data;
|
||||||
free(sdata);
|
free(sdata);
|
||||||
}
|
}
|
||||||
free(watch);
|
|
||||||
|
|
||||||
|
free(watch);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue