#include <Ecore.h>
#include <stdio.h>
-
/**
* This demo program shows how to use some eeze_udev functions. It roughly
* 1kb as of now, TODO is to fix this but I'm too lazy now and it's only
static void
/* event will always be a syspath starting with /sys */
-catch_events(const char *device, Eeze_Udev_Event event, void *data, Eeze_Udev_Watch *watch)
+catch_events(const char *device,
+ Eeze_Udev_Event event,
+ void *data,
+ Eeze_Udev_Watch *watch)
{
kbdmouse *akbdmouse = data;
Eina_List *l;
eina_stringshare_del(data);
}
-int main()
+int
+main()
{
Eina_List *type, *l;
const char *name, *check, *check2;
EINA_LIST_FOREACH(type, l, name)
{
/* add the devpath to the hash for use in the cb later */
- if ((check = eeze_udev_syspath_get_devpath(name)))
- eina_hash_direct_add(hash, name, check);
- printf("Found keyboard: %s\n", name);
+ if ((check = eeze_udev_syspath_get_devpath(name)))
+ eina_hash_direct_add(hash, name, check);
+ printf("Found keyboard: %s\n", name);
}
/* we save this list for later, because once a device is unplugged it can
* no longer be detected by udev, and any related properties are unusable unless
EINA_LIST_FOREACH(type, l, name)
{ /* add the devpath to the hash for use in the cb later */
if ((check = eeze_udev_syspath_get_devpath(name)))
- eina_hash_direct_add(hash, name, check); /* get a property using the device's syspath */
+ eina_hash_direct_add(hash, name, check); /* get a property using the device's syspath */
printf("Found mouse %s with vendor: %s\n", name, eeze_udev_walk_get_sysattr(name, "manufacturer"));
}
/* we save this list for later, because once a device is unplugged it can
type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_MOUNTABLE, NULL);
type = eeze_udev_find_unlisted_similar(type);
EINA_LIST_FREE(type, name)
- {
- printf("Found device: %s\n", name); /* get a property using the device's syspath */
- if ((check = eeze_udev_syspath_get_property(name, "DEVNAME")))
- {
- printf("\tYou probably know it better as %s\n", check);
- eina_stringshare_del(check);
- }
- if ((check = eeze_udev_syspath_get_property(name, "ID_FS_TYPE")))
- {
- printf("\tIt's formatted as %s", check);
- eina_stringshare_del(check);
- check = eeze_udev_syspath_get_property(name, "FSTAB_DIR");
- if (check)
- {
- printf(", and gets mounted at %s", check);
- eina_stringshare_del(check);
- }
- printf("!\n");
- }
- eina_stringshare_del(name);
- }
+ {
+ printf("Found device: %s\n", name); /* get a property using the device's syspath */
+ if ((check = eeze_udev_syspath_get_property(name, "DEVNAME")))
+ {
+ printf("\tYou probably know it better as %s\n", check);
+ eina_stringshare_del(check);
+ }
+ if ((check = eeze_udev_syspath_get_property(name, "ID_FS_TYPE")))
+ {
+ printf("\tIt's formatted as %s", check);
+ eina_stringshare_del(check);
+ check = eeze_udev_syspath_get_property(name, "FSTAB_DIR");
+ if (check)
+ {
+ printf(", and gets mounted at %s", check);
+ eina_stringshare_del(check);
+ }
+ printf("!\n");
+ }
+ eina_stringshare_del(name);
+ }
printf("\nInternal drives, anyone? With serial numbers?\n");
/* find all internal drives using type EEZE_UDEV_TYPE_DRIVE_INTERNAL */
eina_stringshare_del(name);
}
-
/* set a udev watch, grab all events because no EEZE_UDEV_TYPE filter is specified,
* set the events to be sent to callback function catch_events(), and attach
* kbdmouse to the watch as associated data
return 0;
}
+
int _eeze_udev_log_dom = -1;
int _eeze_init_count = 0;
-
/**
* @defgroup main main
- *
+ *
* These are general eeze functions which include init and shutdown.
*/
/**
* Initialize the eeze library.
* @return The number of times the function has been called, or -1 on failure.
- *
+ *
* This function should be called prior to using any eeze functions, and MUST
* be called prior to using any udev functions to avoid a segv.
- *
+ *
* @ingroup main
*/
EAPI int
return 0;
_eeze_udev_log_dom = eina_log_domain_register
- ("eeze_udev", EEZE_UDEV_COLOR_DEFAULT);
+ ("eeze_udev", EEZE_UDEV_COLOR_DEFAULT);
if (_eeze_udev_log_dom < 0)
{
/**
* Shut down the eeze library.
- * @return The number of times the eeze_init has been called, or -1 when
+ * @return The number of times the eeze_init has been called, or -1 when
* all occurrences of eeze have been shut down.
- *
+ *
* This function should be called when no further eeze functions will be called.
- *
+ *
* @ingroup main
*/
EAPI int
eina_shutdown();
return _eeze_init_count;
}
+
* @addtogroup find Find
*
* These are functions which find/supplement lists of devices.
- *
+ *
* @ingroup udev
*
* @{
udev_list_entry_foreach(cur, devs)
{
devname = udev_list_entry_get_name(cur);
- /* verify unlisted device */
+ /* verify unlisted device */
EINA_LIST_FOREACH(ret, l, dev)
if (!strcmp(dev, devname))
ret = eina_list_prepend(ret, eina_stringshare_add(devname));
device = udev_device_new_from_syspath(udev, devname);
- /* only device roots have this sysattr,
- * and we only need to check parents of the roots
- */
+ /* only device roots have this sysattr,
+ * and we only need to check parents of the roots
+ */
if (udev_device_get_sysattr_value(device, "idVendor"))
ret = _get_unlisted_parents(ret, device);
* stringshared.
*/
EAPI Eina_List *
-eeze_udev_find_unlisted_similar(Eina_List * list)
+eeze_udev_find_unlisted_similar(Eina_List *list)
{
_udev_device *device;
_udev_list_entry *devs, *cur;
en = udev_enumerate_new((udev));
if (!en)
- return NULL;
+ return NULL;
device = _new_device(dev);
if (!device) continue;
if ((vendor = udev_device_get_property_value(device, "ID_VENDOR_ID")))
udev_enumerate_add_match_property(en, "ID_VENDOR_ID", vendor);
else
- if ((vendor = udev_device_get_property_value(device, "ID_VENDOR")))
- 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")))
udev_enumerate_add_match_property(en, "ID_MODEL_ID", model);
else
- if ((model = udev_device_get_property_value(device, "ID_MODEL")))
- 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")))
udev_enumerate_add_match_property(en, "ID_REVISION", revision);
* Return a list of syspaths (/sys/$syspath) for matching udev devices.
*/
EAPI Eina_List *
-eeze_udev_find_by_type(Eeze_Udev_Type etype, const char *name)
+eeze_udev_find_by_type(Eeze_Udev_Type etype,
+ const char *name)
{
_udev_enumerate *en;
_udev_list_entry *devs, *cur;
switch (etype)
{
- case EEZE_UDEV_TYPE_NONE:
- break;
- case EEZE_UDEV_TYPE_KEYBOARD:
- udev_enumerate_add_match_subsystem(en, "input");
+ case EEZE_UDEV_TYPE_NONE:
+ break;
+
+ case EEZE_UDEV_TYPE_KEYBOARD:
+ udev_enumerate_add_match_subsystem(en, "input");
#ifndef OLD_UDEV_RRRRRRRRRRRRRR
- udev_enumerate_add_match_property(en, "ID_INPUT_KEYBOARD", "1");
+ udev_enumerate_add_match_property(en, "ID_INPUT_KEYBOARD", "1");
#else
- udev_enumerate_add_match_property(en, "ID_CLASS", "kbd");
+ udev_enumerate_add_match_property(en, "ID_CLASS", "kbd");
#endif
- break;
- case EEZE_UDEV_TYPE_MOUSE:
- udev_enumerate_add_match_subsystem(en, "input");
+ break;
+
+ case EEZE_UDEV_TYPE_MOUSE:
+ udev_enumerate_add_match_subsystem(en, "input");
#ifndef OLD_UDEV_RRRRRRRRRRRRRR
- udev_enumerate_add_match_property(en, "ID_INPUT_MOUSE", "1");
+ udev_enumerate_add_match_property(en, "ID_INPUT_MOUSE", "1");
#else
- udev_enumerate_add_match_property(en, "ID_CLASS", "mouse");
+ udev_enumerate_add_match_property(en, "ID_CLASS", "mouse");
#endif
- break;
- case EEZE_UDEV_TYPE_TOUCHPAD:
- udev_enumerate_add_match_subsystem(en, "input");
+ break;
+
+ case EEZE_UDEV_TYPE_TOUCHPAD:
+ udev_enumerate_add_match_subsystem(en, "input");
#ifndef OLD_UDEV_RRRRRRRRRRRRRR
- udev_enumerate_add_match_property(en, "ID_INPUT_TOUCHPAD", "1");
+ udev_enumerate_add_match_property(en, "ID_INPUT_TOUCHPAD", "1");
#endif
- break;
- case EEZE_UDEV_TYPE_DRIVE_MOUNTABLE:
- udev_enumerate_add_match_subsystem(en, "block");
- udev_enumerate_add_match_property(en, "ID_FS_USAGE", "filesystem");
- /* parent node */
- udev_enumerate_add_nomatch_sysattr(en, "capability", "50");
- break;
- case EEZE_UDEV_TYPE_DRIVE_INTERNAL:
- udev_enumerate_add_match_subsystem(en, "block");
- udev_enumerate_add_match_property(en, "ID_TYPE", "disk");
- udev_enumerate_add_match_property(en, "ID_BUS", "ata");
- udev_enumerate_add_match_sysattr(en, "removable", "0");
- break;
- case EEZE_UDEV_TYPE_DRIVE_REMOVABLE:
- udev_enumerate_add_match_subsystem(en, "block");
- udev_enumerate_add_match_property(en, "ID_TYPE", "disk");
- break;
- case EEZE_UDEV_TYPE_DRIVE_CDROM:
- udev_enumerate_add_match_subsystem(en, "block");
- udev_enumerate_add_match_property(en, "ID_CDROM", "1");
- break;
- case EEZE_UDEV_TYPE_POWER_AC:
- udev_enumerate_add_match_subsystem(en, "power_supply");
- udev_enumerate_add_match_sysattr(en, "type", "Mains");
- break;
- case EEZE_UDEV_TYPE_POWER_BAT:
- udev_enumerate_add_match_subsystem(en, "power_supply");
- udev_enumerate_add_match_sysattr(en, "type", "Battery");
- break;
- case EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR:
- udev_enumerate_add_match_subsystem(en, "hwmon");
- break;
- /*
- case EEZE_UDEV_TYPE_ANDROID:
- udev_enumerate_add_match_subsystem(en, "block");
- udev_enumerate_add_match_property(en, "ID_MODEL", "Android_*");
- break;
- */
- default:
- break;
+ break;
+
+ case EEZE_UDEV_TYPE_DRIVE_MOUNTABLE:
+ udev_enumerate_add_match_subsystem(en, "block");
+ udev_enumerate_add_match_property(en, "ID_FS_USAGE", "filesystem");
+ /* parent node */
+ udev_enumerate_add_nomatch_sysattr(en, "capability", "50");
+ break;
+
+ case EEZE_UDEV_TYPE_DRIVE_INTERNAL:
+ udev_enumerate_add_match_subsystem(en, "block");
+ udev_enumerate_add_match_property(en, "ID_TYPE", "disk");
+ udev_enumerate_add_match_property(en, "ID_BUS", "ata");
+ udev_enumerate_add_match_sysattr(en, "removable", "0");
+ break;
+
+ case EEZE_UDEV_TYPE_DRIVE_REMOVABLE:
+ udev_enumerate_add_match_subsystem(en, "block");
+ udev_enumerate_add_match_property(en, "ID_TYPE", "disk");
+ break;
+
+ case EEZE_UDEV_TYPE_DRIVE_CDROM:
+ udev_enumerate_add_match_subsystem(en, "block");
+ udev_enumerate_add_match_property(en, "ID_CDROM", "1");
+ break;
+
+ case EEZE_UDEV_TYPE_POWER_AC:
+ udev_enumerate_add_match_subsystem(en, "power_supply");
+ udev_enumerate_add_match_sysattr(en, "type", "Mains");
+ break;
+
+ case EEZE_UDEV_TYPE_POWER_BAT:
+ udev_enumerate_add_match_subsystem(en, "power_supply");
+ udev_enumerate_add_match_sysattr(en, "type", "Battery");
+ break;
+
+ case EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR:
+ udev_enumerate_add_match_subsystem(en, "hwmon");
+ break;
+
+ /*
+ case EEZE_UDEV_TYPE_ANDROID:
+ udev_enumerate_add_match_subsystem(en, "block");
+ udev_enumerate_add_match_property(en, "ID_MODEL", "Android_*");
+ break;
+ */
+ default:
+ break;
}
udev_enumerate_scan_devices(en);
devname = udev_list_entry_get_name(cur);
device = udev_device_new_from_syspath(udev, devname);
- if (etype == EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR)
- { /* ensure that temp input exists somewhere in this device chain */
- if (!_walk_parents_test_attr(device, "temp1_input", NULL))
- 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)
- goto out;
- }
+ if (etype == EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR) /* ensure that temp input exists somewhere in this device chain */
+ {
+ if (!_walk_parents_test_attr(device, "temp1_input", NULL))
+ 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)
+ goto out;
+ }
}
else if (etype == EEZE_UDEV_TYPE_DRIVE_INTERNAL)
- {
- if (udev_device_get_property_value(device, "ID_USB_DRIVER"))
- goto out;
- }
- else if (etype == EEZE_UDEV_TYPE_DRIVE_REMOVABLE)
- {
- if (!(test = udev_device_get_property_value(device, "ID_USB_DRIVER")))
+ {
+ if (udev_device_get_property_value(device, "ID_USB_DRIVER"))
+ goto out;
+ }
+ else if (etype == EEZE_UDEV_TYPE_DRIVE_REMOVABLE)
+ {
+ if (!(test = udev_device_get_property_value(device, "ID_USB_DRIVER")))
+ goto out;
+ }
+ else if (etype == EEZE_UDEV_TYPE_DRIVE_MOUNTABLE)
+ {
+ int devcheck;
+
+ devcheck = open(udev_device_get_devnode(device), O_RDONLY | O_EXCL);
+ if (errno)
+ {
+ if (devcheck >= 0) close(devcheck);
goto out;
- }
- else if (etype == EEZE_UDEV_TYPE_DRIVE_MOUNTABLE)
- {
- int devcheck;
-
- devcheck = open(udev_device_get_devnode(device), O_RDONLY | O_EXCL);
- if (errno)
- {
- if (devcheck >= 0) close(devcheck);
- goto out;
- }
- if (devcheck < 0) goto out;
- close(devcheck);
- }
+ }
+ if (devcheck < 0) goto out;
+ close(devcheck);
+ }
if (name && (!strstr(devname, name)))
- goto out;
+ goto out;
ret = eina_list_append(ret, eina_stringshare_add(devname));
out:
* Requires at least one filter.
*/
EAPI Eina_List *
-eeze_udev_find_by_filter(const char *subsystem, const char *type,
+eeze_udev_find_by_filter(const char *subsystem,
+ const char *type,
const char *name)
{
_udev_enumerate *en;
* @param value Optional: the value that the attribute should have
*
* @return A stringshared list of the devices found with the attribute
- *
+ *
* @ingroup find
*/
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)
{
_udev_enumerate *en;
_udev_list_entry *devs, *cur;
* copies a device
*/
_udev_device *
-_copy_device(_udev_device * device)
+_copy_device(_udev_device *device)
{
const char *syspath;
* with value $value
*/
Eina_Bool
-_walk_parents_test_attr(_udev_device * device, const char *sysattr,
- const char *value)
+_walk_parents_test_attr(_udev_device *device,
+ const char *sysattr,
+ const char *value)
{
_udev_device *parent, *child = device;
const char *test;
if (!value)
return EINA_TRUE;
else
- if (!strcmp(test, value))
- return EINA_TRUE;
+ if (!strcmp(test, value))
+ return EINA_TRUE;
}
return EINA_TRUE;
}
const char *
-_walk_parents_get_attr(_udev_device * device, const char *sysattr)
+_walk_parents_get_attr(_udev_device *device,
+ const char *sysattr)
{
_udev_device *parent, *child = device;
const char *test;
* stringshare adding all devices that are not in the list
*/
Eina_List *
-_get_unlisted_parents(Eina_List * list, _udev_device * device)
+_get_unlisted_parents(Eina_List *list,
+ _udev_device *device)
{
_udev_device *parent, *child = device;
const char *test, *devname, *vendor, *vendor2, *model, *model2;
|| (vendor2 && !vendor))
break;
else
- if (((model && model2) && (strcmp(model, model2))) ||
- ((vendor && vendor2) && (strcmp(vendor, vendor2))))
- break;
+ if (((model && model2) && (strcmp(model, model2))) ||
+ ((vendor && vendor2) && (strcmp(vendor, vendor2))))
+ break;
devname = udev_device_get_syspath(parent);
EINA_LIST_FOREACH(list, l, test)
return list;
}
+
/**
* @addtogroup syspath Syspath
*
- * These are functions which interact with the syspath (/sys/$PATH) of
+ * These are functions which interact with the syspath (/sys/$PATH) of
* a device.
- *
+ *
* @ingroup udev
*
* @{
* @return A stringshared char* with the property or NULL on failure
*/
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)
{
_udev_device *device;
const char *value = NULL, *test;
* @return A stringshared char* with the sysattr or NULL on failure
*/
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)
{
_udev_device *device;
const char *value = NULL, *test;
udev_list_entry_foreach(cur, devs)
{
ret = eina_stringshare_add(udev_list_entry_get_name(cur));
- break; /*just in case there's more than one somehow */
+ break; /*just in case there's more than one somehow */
}
udev_enumerate_unref(en);
return ret;
* @addtogroup walks Walks
*
* These are functions which walk up the device chain.
- *
+ *
* @ingroup udev
*
* @{
* @return If the sysattr (with value) is found, returns TRUE. Else, false.
*/
EAPI Eina_Bool
-eeze_udev_walk_check_sysattr(const char *syspath, const char *sysattr,
+eeze_udev_walk_check_sysattr(const char *syspath,
+ const char *sysattr,
const char *value)
{
_udev_device *device, *child, *parent;
return EINA_FALSE;
for (parent = device; parent;
- child = parent, parent = udev_device_get_parent(child))
+ child = parent, parent = udev_device_get_parent(child))
{
if (!(test = udev_device_get_sysattr_value(parent, sysattr)))
continue;
* @return The stringshared value of @p sysattr if found, or NULL
*/
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)
{
_udev_device *device, *child, *parent;
const char *test = NULL;
if (!(device = _new_device(syspath)))
return NULL;
-
+
for (parent = device; parent;
- child = parent, parent = udev_device_get_parent(child))
+ child = parent, parent = udev_device_get_parent(child))
{
if ((test = udev_device_get_sysattr_value(parent, sysattr)))
{
/* opaque */
struct Eeze_Udev_Watch
{
- _udev_monitor *mon;
+ _udev_monitor *mon;
Ecore_Fd_Handler *handler;
- Eeze_Udev_Type type;
- void *data;
+ Eeze_Udev_Type type;
+ void *data;
};
/* private */
struct _store_data
{
- void (*func)(const char *, Eeze_Udev_Event, void *, Eeze_Udev_Watch *);
- void *data;
- int event;
- _udev_monitor *mon;
- Eeze_Udev_Type type;
+ void (*func)(const char *,
+ Eeze_Udev_Event,
+ void *,
+ Eeze_Udev_Watch *);
+ void *data;
+ int event;
+ _udev_monitor *mon;
+ Eeze_Udev_Type type;
Eeze_Udev_Watch *watch;
};
* the watch object itself in case you want to stop the watch easily in a callback.
*
* @ingroup udev
- *
+ *
* @{
*/
* specified; helpful for new udev versions, but absolutely required for
* old udev, which does not implement filtering in device monitors.
*/
-static Eina_Bool
-_get_syspath_from_watch(void *data, Ecore_Fd_Handler * fd_handler)
+static Eina_Bool
+_get_syspath_from_watch(void *data,
+ Ecore_Fd_Handler *fd_handler)
{
struct _store_data *store = data;
_udev_device *device = NULL, *parent, *tmpdev;
switch (store->type)
{
- case EEZE_UDEV_TYPE_KEYBOARD:
+ case EEZE_UDEV_TYPE_KEYBOARD:
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
- if ((!(test = udev_device_get_subsystem(device)))
- || (strcmp(test, "input")))
- goto error;
+ if ((!(test = udev_device_get_subsystem(device)))
+ || (strcmp(test, "input")))
+ 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"))))
- break;
+ if ((_walk_parents_test_attr(device, "bInterfaceProtocol", "01"))
+ || ((test) && (!strcmp(test, "kbd"))))
+ break;
- goto error;
+ goto error;
#endif
- if ((!udev_device_get_property_value(device, "ID_INPUT_KEYBOARD")) &&
- (!udev_device_get_property_value(device, "ID_INPUT_KEY")))
- goto error;
+ if ((!udev_device_get_property_value(device, "ID_INPUT_KEYBOARD")) &&
+ (!udev_device_get_property_value(device, "ID_INPUT_KEY")))
+ goto error;
- break;
- case EEZE_UDEV_TYPE_MOUSE:
+ break;
+
+ case EEZE_UDEV_TYPE_MOUSE:
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
- if ((!(test = udev_device_get_subsystem(device)))
- || (strcmp(test, "input")))
- goto error;
+ if ((!(test = udev_device_get_subsystem(device)))
+ || (strcmp(test, "input")))
+ 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"))))
- break;
+ if ((_walk_parents_test_attr(device, "bInterfaceProtocol", "02"))
+ || ((test) && (!strcmp(test, "mouse"))))
+ break;
- goto error;
+ goto error;
#endif
- if (!udev_device_get_property_value(device, "ID_INPUT_MOUSE"))
- goto error;
+ if (!udev_device_get_property_value(device, "ID_INPUT_MOUSE"))
+ goto error;
- break;
- case EEZE_UDEV_TYPE_TOUCHPAD:
+ break;
+
+ case EEZE_UDEV_TYPE_TOUCHPAD:
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
- if ((!(test = udev_device_get_subsystem(device)))
- || (strcmp(test, "input")))
- goto error;
+ if ((!(test = udev_device_get_subsystem(device)))
+ || (strcmp(test, "input")))
+ goto error;
- if (_walk_parents_test_attr(device, "resolution", NULL))
- break;
+ if (_walk_parents_test_attr(device, "resolution", NULL))
+ break;
- goto error;
+ goto error;
#endif
- if (!udev_device_get_property_value(device, "ID_INPUT_TOUCHPAD"))
- goto error;
+ if (!udev_device_get_property_value(device, "ID_INPUT_TOUCHPAD"))
+ goto error;
- break;
- case EEZE_UDEV_TYPE_DRIVE_MOUNTABLE:
+ break;
+
+ case EEZE_UDEV_TYPE_DRIVE_MOUNTABLE:
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
- if ((!(test = udev_device_get_subsystem(device)))
- || (strcmp(test, "block")))
- goto error;
+ if ((!(test = udev_device_get_subsystem(device)))
+ || (strcmp(test, "block")))
+ goto error;
#endif
- test = udev_device_get_sysattr_value(device, "capability");
+ test = udev_device_get_sysattr_value(device, "capability");
- if (test)
- cap = strtol(test, NULL, 10);
+ if (test)
+ cap = strtol(test, NULL, 10);
- if (!(test = (udev_device_get_property_value(device, "ID_FS_USAGE"))) ||
- (strcmp("filesystem", test)) || (cap == 50))
- goto error;
- {
- int devcheck;
+ if (!(test = (udev_device_get_property_value(device, "ID_FS_USAGE"))) ||
+ (strcmp("filesystem", test)) || (cap == 50))
+ goto error;
+ {
+ int devcheck;
- devcheck = open(udev_device_get_devnode(device), O_RDONLY | O_EXCL);
- if ((devcheck < 0) || errno) goto error;
- close(devcheck);
- }
+ devcheck = open(udev_device_get_devnode(device), O_RDONLY | O_EXCL);
+ if ((devcheck < 0) || errno) goto error;
+ close(devcheck);
+ }
- break;
- case EEZE_UDEV_TYPE_DRIVE_INTERNAL:
+ break;
+
+ case EEZE_UDEV_TYPE_DRIVE_INTERNAL:
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
- if ((!(test = udev_device_get_subsystem(device)))
- || (strcmp(test, "block")))
- goto error;
+ if ((!(test = udev_device_get_subsystem(device)))
+ || (strcmp(test, "block")))
+ goto error;
#endif
- if (!(test = udev_device_get_property_value(device, "ID_BUS"))
- || (strcmp("ata", test))
- || !(test = udev_device_get_sysattr_value(device, "removable"))
- || (strtol(test, NULL, 10)))
- goto error;
+ if (!(test = udev_device_get_property_value(device, "ID_BUS"))
+ || (strcmp("ata", test))
+ || !(test = udev_device_get_sysattr_value(device, "removable"))
+ || (strtol(test, NULL, 10)))
+ goto error;
- break;
- case EEZE_UDEV_TYPE_DRIVE_REMOVABLE:
+ break;
+
+ case EEZE_UDEV_TYPE_DRIVE_REMOVABLE:
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
- if ((!(test = udev_device_get_subsystem(device)))
- || (strcmp(test, "block")))
- goto error;
+ if ((!(test = udev_device_get_subsystem(device)))
+ || (strcmp(test, "block")))
+ goto error;
#endif
- if ((!(test = udev_device_get_sysattr_value(device, "removable"))
- || (!strtol(test, NULL, 10)))
- && (!(test = udev_device_get_sysattr_value(device, "capability"))
- || (strtol(test, NULL, 10) != 10)))
- goto error;
+ if ((!(test = udev_device_get_sysattr_value(device, "removable"))
+ || (!strtol(test, NULL, 10)))
+ && (!(test = udev_device_get_sysattr_value(device, "capability"))
+ || (strtol(test, NULL, 10) != 10)))
+ goto error;
- break;
- case EEZE_UDEV_TYPE_DRIVE_CDROM:
+ break;
+
+ case EEZE_UDEV_TYPE_DRIVE_CDROM:
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
- if ((!(test = udev_device_get_subsystem(device)))
- || (strcmp(test, "block")))
- goto error;
+ if ((!(test = udev_device_get_subsystem(device)))
+ || (strcmp(test, "block")))
+ goto error;
#endif
- if (!udev_device_get_property_value(device, "ID_CDROM"))
- goto error;
+ if (!udev_device_get_property_value(device, "ID_CDROM"))
+ goto error;
- break;
- case EEZE_UDEV_TYPE_POWER_AC:
+ break;
+
+ case EEZE_UDEV_TYPE_POWER_AC:
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
- if ((!(test = udev_device_get_subsystem(device)))
- || (strcmp(test, "power_supply")))
- goto error;
+ if ((!(test = udev_device_get_subsystem(device)))
+ || (strcmp(test, "power_supply")))
+ goto error;
#endif
- if (!(test = udev_device_get_property_value(device, "POWER_SUPPLY_TYPE"))
- || (strcmp("Mains", test)))
- goto error;
- break;
- case EEZE_UDEV_TYPE_POWER_BAT:
+ if (!(test = udev_device_get_property_value(device, "POWER_SUPPLY_TYPE"))
+ || (strcmp("Mains", test)))
+ goto error;
+ break;
+
+ case EEZE_UDEV_TYPE_POWER_BAT:
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
- if ((!(test = udev_device_get_subsystem(device)))
- || (strcmp(test, "power_supply")))
- goto error;
+ if ((!(test = udev_device_get_subsystem(device)))
+ || (strcmp(test, "power_supply")))
+ goto error;
#endif
- if (!(test = udev_device_get_property_value(device, "POWER_SUPPLY_TYPE"))
- || (strcmp("Battery", test)))
- goto error;
- break;
- case EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR:
+ if (!(test = udev_device_get_property_value(device, "POWER_SUPPLY_TYPE"))
+ || (strcmp("Battery", test)))
+ goto error;
+ break;
+
+ case EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR:
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
- if ((!(test = udev_device_get_subsystem(device)))
- || (strcmp(test, "hwmon")))
- goto error;
+ if ((!(test = udev_device_get_subsystem(device)))
+ || (strcmp(test, "hwmon")))
+ goto error;
#endif /* have to do stuff up here since we need info from the parent */
- if (!_walk_parents_test_attr(device, "temp1_input", NULL))
- goto error;
+ 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 (!udev_device_get_sysattr_value(device, "temp1_input"))
- {
- for (parent = udev_device_get_parent(device); parent; parent = udev_device_get_parent(parent)) /*check for parent */
- if (udev_device_get_sysattr_value(parent, "temp1_input"))
- {
- tmpdev = device;
+ /* if device is not the one which has the temp input, we must go up the chain */
+ if (!udev_device_get_sysattr_value(device, "temp1_input"))
+ {
+ for (parent = udev_device_get_parent(device); parent; parent = udev_device_get_parent(parent)) /*check for parent */
+ if (udev_device_get_sysattr_value(parent, "temp1_input"))
+ {
+ tmpdev = device;
- if (!(device = _copy_device(parent)))
- goto error;
+ if (!(device = _copy_device(parent)))
+ goto error;
- udev_device_unref(tmpdev);
- break;
- }
- }
+ udev_device_unref(tmpdev);
+ break;
+ }
+ }
- break;
- default:
- break;
+ break;
+
+ default:
+ break;
}
if ((!(test = udev_device_get_action(device)))
- || (!(ret = udev_device_get_syspath(device))))
+ || (!(ret = udev_device_get_syspath(device))))
goto error;
if (store->event)
event |= EEZE_UDEV_EVENT_ADD;
}
else
- if (!strcmp(test, "remove"))
- {
- if ((store->event & EEZE_UDEV_EVENT_REMOVE) !=
- EEZE_UDEV_EVENT_REMOVE)
- goto error;
-
- event |= EEZE_UDEV_EVENT_REMOVE;
- }
- else
- if (!strcmp(test, "change"))
- {
- 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;
- }
+ if (!strcmp(test, "remove"))
+ {
+ if ((store->event & EEZE_UDEV_EVENT_REMOVE) !=
+ EEZE_UDEV_EVENT_REMOVE)
+ goto error;
+
+ event |= EEZE_UDEV_EVENT_REMOVE;
+ }
+ else
+ if (!strcmp(test, "change"))
+ {
+ 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), event, sdata, watch);
+ (*func)(eina_stringshare_add(ret), event, sdata, watch);
error:
if (device)
udev_device_unref(device);
return EINA_TRUE;
}
+
/**
* Add a watch for a device type
*
* binary &.
*/
EAPI Eeze_Udev_Watch *
-eeze_udev_watch_add(Eeze_Udev_Type type, int event,
- Eeze_Udev_Watch_Cb cb, void *user_data)
+eeze_udev_watch_add(Eeze_Udev_Type type,
+ int event,
+ Eeze_Udev_Watch_Cb cb,
+ void *user_data)
{
_udev_monitor *mon = NULL;
int fd;
switch (type)
{
- case EEZE_UDEV_TYPE_KEYBOARD:
- udev_monitor_filter_add_match_subsystem_devtype(mon, "input", NULL);
- break;
- case EEZE_UDEV_TYPE_MOUSE:
- udev_monitor_filter_add_match_subsystem_devtype(mon, "input", NULL);
- break;
- case EEZE_UDEV_TYPE_TOUCHPAD:
- udev_monitor_filter_add_match_subsystem_devtype(mon, "input", NULL);
- break;
- case EEZE_UDEV_TYPE_DRIVE_MOUNTABLE:
- udev_monitor_filter_add_match_subsystem_devtype(mon, "block", NULL);
- break;
- case EEZE_UDEV_TYPE_DRIVE_INTERNAL:
- udev_monitor_filter_add_match_subsystem_devtype(mon, "block", NULL);
- break;
- case EEZE_UDEV_TYPE_DRIVE_REMOVABLE:
- udev_monitor_filter_add_match_subsystem_devtype(mon, "block", NULL);
- break;
- case EEZE_UDEV_TYPE_DRIVE_CDROM:
- udev_monitor_filter_add_match_subsystem_devtype(mon, "block", NULL);
- break;
- case EEZE_UDEV_TYPE_POWER_AC:
- case EEZE_UDEV_TYPE_POWER_BAT:
- udev_monitor_filter_add_match_subsystem_devtype(mon, "power_supply",
- NULL);
- break;
- case EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR:
- udev_monitor_filter_add_match_subsystem_devtype(mon, "hwmon", NULL);
- break;
- /*
- case EEZE_UDEV_TYPE_ANDROID:
- udev_monitor_filter_add_match_subsystem_devtype(mon, "input", "usb_interface");
- break;
- */
- default:
- break;
+ case EEZE_UDEV_TYPE_KEYBOARD:
+ udev_monitor_filter_add_match_subsystem_devtype(mon, "input", NULL);
+ break;
+
+ case EEZE_UDEV_TYPE_MOUSE:
+ udev_monitor_filter_add_match_subsystem_devtype(mon, "input", NULL);
+ break;
+
+ case EEZE_UDEV_TYPE_TOUCHPAD:
+ udev_monitor_filter_add_match_subsystem_devtype(mon, "input", NULL);
+ break;
+
+ case EEZE_UDEV_TYPE_DRIVE_MOUNTABLE:
+ udev_monitor_filter_add_match_subsystem_devtype(mon, "block", NULL);
+ break;
+
+ case EEZE_UDEV_TYPE_DRIVE_INTERNAL:
+ udev_monitor_filter_add_match_subsystem_devtype(mon, "block", NULL);
+ break;
+
+ case EEZE_UDEV_TYPE_DRIVE_REMOVABLE:
+ udev_monitor_filter_add_match_subsystem_devtype(mon, "block", NULL);
+ break;
+
+ case EEZE_UDEV_TYPE_DRIVE_CDROM:
+ udev_monitor_filter_add_match_subsystem_devtype(mon, "block", NULL);
+ break;
+
+ case EEZE_UDEV_TYPE_POWER_AC:
+ case EEZE_UDEV_TYPE_POWER_BAT:
+ udev_monitor_filter_add_match_subsystem_devtype(mon, "power_supply",
+ NULL);
+ break;
+
+ case EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR:
+ udev_monitor_filter_add_match_subsystem_devtype(mon, "hwmon", NULL);
+ break;
+
+ /*
+ case EEZE_UDEV_TYPE_ANDROID:
+ udev_monitor_filter_add_match_subsystem_devtype(mon, "input", "usb_interface");
+ break;
+ */
+ default:
+ break;
}
#endif
store->watch = watch;
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;
watch->mon = mon;
* Deletes a watch, closing file descriptors and freeing related udev memory.
*/
EAPI void *
-eeze_udev_watch_del(Eeze_Udev_Watch * watch)
+eeze_udev_watch_del(Eeze_Udev_Watch *watch)
{
struct _store_data *sdata;
void *ret = NULL;