ecrustified for formatting

SVN revision: 55898
This commit is contained in:
Mike Blumenkrantz 2011-01-05 18:46:32 +00:00
parent 961244f70a
commit 1707697d8a
7 changed files with 437 additions and 386 deletions

View File

@ -2,7 +2,6 @@
#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
@ -18,7 +17,10 @@ typedef struct kbdmouse
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;
@ -80,7 +82,8 @@ hash_free(void *data)
eina_stringshare_del(data);
}
int main()
int
main()
{
Eina_List *type, *l;
const char *name, *check, *check2;
@ -104,9 +107,9 @@ int main()
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
@ -121,7 +124,7 @@ int main()
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
@ -135,27 +138,27 @@ int main()
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 */
@ -187,7 +190,6 @@ int main()
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
@ -200,3 +202,4 @@ int main()
return 0;
}

View File

@ -17,10 +17,9 @@ _udev *udev;
int _eeze_udev_log_dom = -1;
int _eeze_init_count = 0;
/**
* @defgroup main main
*
*
* These are general eeze functions which include init and shutdown.
*/
@ -30,10 +29,10 @@ EAPI Eeze_Version *eeze_version = &_version;
/**
* 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
@ -46,7 +45,7 @@ eeze_init(void)
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)
{
@ -76,11 +75,11 @@ eina_fail:
/**
* 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
@ -96,3 +95,4 @@ eeze_shutdown(void)
eina_shutdown();
return _eeze_init_count;
}

View File

@ -14,7 +14,7 @@
* @addtogroup find Find
*
* These are functions which find/supplement lists of devices.
*
*
* @ingroup udev
*
* @{
@ -68,7 +68,7 @@ eeze_udev_find_similar_from_syspath(const char *syspath)
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))
@ -77,9 +77,9 @@ eeze_udev_find_similar_from_syspath(const char *syspath)
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);
@ -101,7 +101,7 @@ eeze_udev_find_similar_from_syspath(const char *syspath)
* 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;
@ -117,7 +117,7 @@ eeze_udev_find_unlisted_similar(Eina_List * list)
en = udev_enumerate_new((udev));
if (!en)
return NULL;
return NULL;
device = _new_device(dev);
if (!device) continue;
@ -125,14 +125,14 @@ eeze_udev_find_unlisted_similar(Eina_List * list)
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);
@ -168,7 +168,8 @@ eeze_udev_find_unlisted_similar(Eina_List * list)
* 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;
@ -186,69 +187,80 @@ eeze_udev_find_by_type(Eeze_Udev_Type etype, const char *name)
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);
@ -258,53 +270,53 @@ eeze_udev_find_by_type(Eeze_Udev_Type etype, const char *name)
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 (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;
/* 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;
}
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 (!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")))
goto out;
}
else if (etype == EEZE_UDEV_TYPE_DRIVE_MOUNTABLE)
{
int devcheck;
{
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;
}
if (devcheck < 0) goto out;
close(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 (name && (!strstr(devname, name)))
goto out;
goto out;
ret = eina_list_append(ret, eina_stringshare_add(devname));
out:
@ -326,7 +338,8 @@ 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;
@ -373,11 +386,12 @@ out:
* @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;

View File

@ -32,7 +32,7 @@ _new_device(const char *syspath)
* copies a device
*/
_udev_device *
_copy_device(_udev_device * device)
_copy_device(_udev_device *device)
{
const char *syspath;
@ -48,8 +48,9 @@ _copy_device(_udev_device * device)
* 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;
@ -67,15 +68,16 @@ _walk_parents_test_attr(_udev_device * device, const char *sysattr,
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;
@ -99,7 +101,8 @@ _walk_parents_get_attr(_udev_device * device, const char *sysattr)
* 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;
@ -128,9 +131,9 @@ _get_unlisted_parents(Eina_List * list, _udev_device * device)
|| (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)
@ -148,3 +151,4 @@ _get_unlisted_parents(Eina_List * list, _udev_device * device)
return list;
}

View File

@ -8,9 +8,9 @@
/**
* @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
*
* @{
@ -134,7 +134,8 @@ eeze_udev_syspath_get_subsystem(const char *syspath)
* @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;
@ -159,7 +160,8 @@ eeze_udev_syspath_get_property(const char *syspath, const char *property)
* @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;
@ -317,7 +319,7 @@ eeze_udev_devpath_get_syspath(const char *devpath)
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;

View File

@ -9,7 +9,7 @@
* @addtogroup walks Walks
*
* These are functions which walk up the device chain.
*
*
* @ingroup udev
*
* @{
@ -26,7 +26,8 @@
* @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;
@ -40,7 +41,7 @@ eeze_udev_walk_check_sysattr(const char *syspath, const char *sysattr,
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;
@ -65,7 +66,8 @@ eeze_udev_walk_check_sysattr(const char *syspath, const char *sysattr,
* @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;
@ -75,9 +77,9 @@ eeze_udev_walk_get_sysattr(const char *syspath, const char *sysattr)
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)))
{

View File

@ -14,20 +14,23 @@
/* 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;
};
@ -42,7 +45,7 @@ struct _store_data
* the watch object itself in case you want to stop the watch easily in a callback.
*
* @ingroup udev
*
*
* @{
*/
@ -50,8 +53,9 @@ struct _store_data
* 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;
@ -71,170 +75,180 @@ _get_syspath_from_watch(void *data, Ecore_Fd_Handler * fd_handler)
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;
#endif
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:
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
if ((!(test = udev_device_get_subsystem(device)))
|| (strcmp(test, "input")))
goto error;
test = udev_device_get_property_value(device, "ID_CLASS");
if ((_walk_parents_test_attr(device, "bInterfaceProtocol", "02"))
|| ((test) && (!strcmp(test, "mouse"))))
break;
goto error;
#endif
if (!udev_device_get_property_value(device, "ID_INPUT_MOUSE"))
goto error;
break;
case EEZE_UDEV_TYPE_TOUCHPAD:
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
if ((!(test = udev_device_get_subsystem(device)))
|| (strcmp(test, "input")))
goto error;
if (_walk_parents_test_attr(device, "resolution", NULL))
break;
goto error;
#endif
if (!udev_device_get_property_value(device, "ID_INPUT_TOUCHPAD"))
goto error;
break;
case EEZE_UDEV_TYPE_DRIVE_MOUNTABLE:
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
if ((!(test = udev_device_get_subsystem(device)))
|| (strcmp(test, "block")))
goto error;
#endif
if ((!udev_device_get_property_value(device, "ID_INPUT_KEYBOARD")) &&
(!udev_device_get_property_value(device, "ID_INPUT_KEY")))
goto error;
test = udev_device_get_sysattr_value(device, "capability");
break;
case EEZE_UDEV_TYPE_MOUSE:
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;
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:
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
if ((!(test = udev_device_get_subsystem(device)))
|| (strcmp(test, "input")))
goto error;
test = udev_device_get_property_value(device, "ID_CLASS");
if ((_walk_parents_test_attr(device, "bInterfaceProtocol", "02"))
|| ((test) && (!strcmp(test, "mouse"))))
break;
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 (!udev_device_get_property_value(device, "ID_INPUT_MOUSE"))
goto error;
break;
break;
case EEZE_UDEV_TYPE_TOUCHPAD:
case EEZE_UDEV_TYPE_DRIVE_REMOVABLE:
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
if ((!(test = udev_device_get_subsystem(device)))
|| (strcmp(test, "input")))
goto error;
if (_walk_parents_test_attr(device, "resolution", NULL))
break;
if ((!(test = udev_device_get_subsystem(device)))
|| (strcmp(test, "block")))
goto error;
#endif
if (!udev_device_get_property_value(device, "ID_INPUT_TOUCHPAD"))
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_MOUNTABLE:
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
test = udev_device_get_sysattr_value(device, "capability");
if (!udev_device_get_property_value(device, "ID_CDROM"))
goto error;
if (test)
cap = strtol(test, NULL, 10);
break;
if (!(test = (udev_device_get_property_value(device, "ID_FS_USAGE"))) ||
(strcmp("filesystem", test)) || (cap == 50))
goto error;
case EEZE_UDEV_TYPE_POWER_AC:
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
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:
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
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:
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
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 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"))
{
int devcheck;
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;
devcheck = open(udev_device_get_devnode(device), O_RDONLY | O_EXCL);
if ((devcheck < 0) || errno) goto error;
close(devcheck);
if (!(device = _copy_device(parent)))
goto error;
udev_device_unref(tmpdev);
break;
}
}
break;
case EEZE_UDEV_TYPE_DRIVE_INTERNAL:
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
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;
break;
break;
case EEZE_UDEV_TYPE_DRIVE_REMOVABLE:
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
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;
break;
case EEZE_UDEV_TYPE_DRIVE_CDROM:
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
if ((!(test = udev_device_get_subsystem(device)))
|| (strcmp(test, "block")))
goto error;
#endif
if (!udev_device_get_property_value(device, "ID_CDROM"))
goto error;
break;
case EEZE_UDEV_TYPE_POWER_AC:
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
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:
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
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:
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
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 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;
udev_device_unref(tmpdev);
break;
}
}
break;
default:
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)
@ -247,48 +261,49 @@ _get_syspath_from_watch(void *data, Ecore_Fd_Handler * fd_handler)
event |= EEZE_UDEV_EVENT_ADD;
}
else
if (!strcmp(test, "remove"))
{
if ((store->event & EEZE_UDEV_EVENT_REMOVE) !=
EEZE_UDEV_EVENT_REMOVE)
goto error;
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_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_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_ONLINE;
}
else
{
if ((store->event & EEZE_UDEV_EVENT_OFFLINE) !=
EEZE_UDEV_EVENT_OFFLINE)
goto error;
event |= EEZE_UDEV_EVENT_OFFLINE;
}
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
*
@ -304,8 +319,10 @@ error:
* 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;
@ -326,42 +343,51 @@ eeze_udev_watch_add(Eeze_Udev_Type type, int event,
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
@ -377,8 +403,8 @@ eeze_udev_watch_add(Eeze_Udev_Type type, int event,
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;
@ -404,7 +430,7 @@ error:
* 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;