forked from enlightenment/efl
parent
961244f70a
commit
1707697d8a
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ _udev *udev;
|
|||
int _eeze_udev_log_dom = -1;
|
||||
int _eeze_init_count = 0;
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup main main
|
||||
*
|
||||
|
@ -96,3 +95,4 @@ eeze_shutdown(void)
|
|||
eina_shutdown();
|
||||
return _eeze_init_count;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -188,6 +189,7 @@ eeze_udev_find_by_type(Eeze_Udev_Type etype, const char *name)
|
|||
{
|
||||
case EEZE_UDEV_TYPE_NONE:
|
||||
break;
|
||||
|
||||
case EEZE_UDEV_TYPE_KEYBOARD:
|
||||
udev_enumerate_add_match_subsystem(en, "input");
|
||||
#ifndef OLD_UDEV_RRRRRRRRRRRRRR
|
||||
|
@ -196,6 +198,7 @@ eeze_udev_find_by_type(Eeze_Udev_Type etype, const char *name)
|
|||
udev_enumerate_add_match_property(en, "ID_CLASS", "kbd");
|
||||
#endif
|
||||
break;
|
||||
|
||||
case EEZE_UDEV_TYPE_MOUSE:
|
||||
udev_enumerate_add_match_subsystem(en, "input");
|
||||
#ifndef OLD_UDEV_RRRRRRRRRRRRRR
|
||||
|
@ -204,43 +207,52 @@ eeze_udev_find_by_type(Eeze_Udev_Type etype, const char *name)
|
|||
udev_enumerate_add_match_property(en, "ID_CLASS", "mouse");
|
||||
#endif
|
||||
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");
|
||||
#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");
|
||||
|
@ -258,8 +270,8 @@ 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 (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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -377,7 +390,8 @@ out:
|
|||
* @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;
|
||||
|
|
|
@ -48,7 +48,8 @@ _copy_device(_udev_device * device)
|
|||
* with value $value
|
||||
*/
|
||||
Eina_Bool
|
||||
_walk_parents_test_attr(_udev_device * device, const char *sysattr,
|
||||
_walk_parents_test_attr(_udev_device *device,
|
||||
const char *sysattr,
|
||||
const char *value)
|
||||
{
|
||||
_udev_device *parent, *child = device;
|
||||
|
@ -75,7 +76,8 @@ _walk_parents_test_attr(_udev_device * device, const char *sysattr,
|
|||
}
|
||||
|
||||
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;
|
||||
|
@ -148,3 +151,4 @@ _get_unlisted_parents(Eina_List * list, _udev_device * device)
|
|||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
@ -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;
|
||||
|
|
|
@ -23,7 +23,10 @@ struct Eeze_Udev_Watch
|
|||
/* private */
|
||||
struct _store_data
|
||||
{
|
||||
void (*func)(const char *, Eeze_Udev_Event, void *, Eeze_Udev_Watch *);
|
||||
void (*func)(const char *,
|
||||
Eeze_Udev_Event,
|
||||
void *,
|
||||
Eeze_Udev_Watch *);
|
||||
void *data;
|
||||
int event;
|
||||
_udev_monitor *mon;
|
||||
|
@ -51,7 +54,8 @@ struct _store_data
|
|||
* old udev, which does not implement filtering in device monitors.
|
||||
*/
|
||||
static Eina_Bool
|
||||
_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;
|
||||
_udev_device *device = NULL, *parent, *tmpdev;
|
||||
|
@ -90,6 +94,7 @@ _get_syspath_from_watch(void *data, Ecore_Fd_Handler * fd_handler)
|
|||
goto error;
|
||||
|
||||
break;
|
||||
|
||||
case EEZE_UDEV_TYPE_MOUSE:
|
||||
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
||||
if ((!(test = udev_device_get_subsystem(device)))
|
||||
|
@ -109,6 +114,7 @@ _get_syspath_from_watch(void *data, Ecore_Fd_Handler * fd_handler)
|
|||
goto error;
|
||||
|
||||
break;
|
||||
|
||||
case EEZE_UDEV_TYPE_TOUCHPAD:
|
||||
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
||||
if ((!(test = udev_device_get_subsystem(device)))
|
||||
|
@ -124,6 +130,7 @@ _get_syspath_from_watch(void *data, Ecore_Fd_Handler * fd_handler)
|
|||
goto error;
|
||||
|
||||
break;
|
||||
|
||||
case EEZE_UDEV_TYPE_DRIVE_MOUNTABLE:
|
||||
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
||||
if ((!(test = udev_device_get_subsystem(device)))
|
||||
|
@ -147,6 +154,7 @@ _get_syspath_from_watch(void *data, Ecore_Fd_Handler * fd_handler)
|
|||
}
|
||||
|
||||
break;
|
||||
|
||||
case EEZE_UDEV_TYPE_DRIVE_INTERNAL:
|
||||
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
||||
if ((!(test = udev_device_get_subsystem(device)))
|
||||
|
@ -160,6 +168,7 @@ _get_syspath_from_watch(void *data, Ecore_Fd_Handler * fd_handler)
|
|||
goto error;
|
||||
|
||||
break;
|
||||
|
||||
case EEZE_UDEV_TYPE_DRIVE_REMOVABLE:
|
||||
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
||||
if ((!(test = udev_device_get_subsystem(device)))
|
||||
|
@ -173,6 +182,7 @@ _get_syspath_from_watch(void *data, Ecore_Fd_Handler * fd_handler)
|
|||
goto error;
|
||||
|
||||
break;
|
||||
|
||||
case EEZE_UDEV_TYPE_DRIVE_CDROM:
|
||||
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
||||
if ((!(test = udev_device_get_subsystem(device)))
|
||||
|
@ -183,6 +193,7 @@ _get_syspath_from_watch(void *data, Ecore_Fd_Handler * fd_handler)
|
|||
goto error;
|
||||
|
||||
break;
|
||||
|
||||
case EEZE_UDEV_TYPE_POWER_AC:
|
||||
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
||||
if ((!(test = udev_device_get_subsystem(device)))
|
||||
|
@ -193,6 +204,7 @@ _get_syspath_from_watch(void *data, Ecore_Fd_Handler * fd_handler)
|
|||
|| (strcmp("Mains", test)))
|
||||
goto error;
|
||||
break;
|
||||
|
||||
case EEZE_UDEV_TYPE_POWER_BAT:
|
||||
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
||||
if ((!(test = udev_device_get_subsystem(device)))
|
||||
|
@ -203,6 +215,7 @@ _get_syspath_from_watch(void *data, Ecore_Fd_Handler * fd_handler)
|
|||
|| (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)))
|
||||
|
@ -229,6 +242,7 @@ _get_syspath_from_watch(void *data, Ecore_Fd_Handler * fd_handler)
|
|||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -289,6 +303,7 @@ error:
|
|||
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;
|
||||
|
@ -329,32 +346,41 @@ eeze_udev_watch_add(Eeze_Udev_Type type, int event,
|
|||
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");
|
||||
|
|
Loading…
Reference in New Issue