2010-05-16 19:59:07 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-01-05 10:42:49 -08:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2011-01-16 00:14:42 -08:00
|
|
|
#include <unistd.h>
|
2011-01-05 10:42:49 -08:00
|
|
|
|
2010-10-12 19:53:33 -07:00
|
|
|
#include <Ecore.h>
|
2010-10-15 21:42:34 -07:00
|
|
|
#include <Eeze.h>
|
2010-05-16 19:59:07 -07:00
|
|
|
#include "eeze_udev_private.h"
|
2010-05-13 03:49:17 -07:00
|
|
|
|
|
|
|
/* opaque */
|
2010-05-14 00:02:50 -07:00
|
|
|
struct Eeze_Udev_Watch
|
2010-05-13 03:49:17 -07:00
|
|
|
{
|
2011-01-05 10:46:32 -08:00
|
|
|
_udev_monitor *mon;
|
2010-05-13 03:49:17 -07:00
|
|
|
Ecore_Fd_Handler *handler;
|
2011-01-05 10:46:32 -08:00
|
|
|
Eeze_Udev_Type type;
|
|
|
|
void *data;
|
2010-05-13 03:49:17 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/* private */
|
|
|
|
struct _store_data
|
|
|
|
{
|
2011-01-05 10:46:32 -08:00
|
|
|
void (*func)(const char *,
|
|
|
|
Eeze_Udev_Event,
|
|
|
|
void *,
|
|
|
|
Eeze_Udev_Watch *);
|
|
|
|
void *data;
|
2011-03-03 08:30:45 -08:00
|
|
|
Eeze_Udev_Event event;
|
2011-01-05 10:46:32 -08:00
|
|
|
_udev_monitor *mon;
|
|
|
|
Eeze_Udev_Type type;
|
2010-05-14 00:02:50 -07:00
|
|
|
Eeze_Udev_Watch *watch;
|
2010-05-13 03:49:17 -07:00
|
|
|
};
|
|
|
|
|
2010-05-14 00:02:50 -07:00
|
|
|
/* private function to further filter watch results based on Eeze_Udev_Type
|
2010-05-16 19:59:07 -07:00
|
|
|
* specified; helpful for new udev versions, but absolutely required for
|
|
|
|
* old udev, which does not implement filtering in device monitors.
|
2010-05-13 03:49:17 -07:00
|
|
|
*/
|
2011-01-05 10:46:32 -08:00
|
|
|
static Eina_Bool
|
|
|
|
_get_syspath_from_watch(void *data,
|
|
|
|
Ecore_Fd_Handler *fd_handler)
|
2010-05-13 03:49:17 -07:00
|
|
|
{
|
|
|
|
struct _store_data *store = data;
|
2010-10-15 21:18:26 -07:00
|
|
|
_udev_device *device = NULL, *parent, *tmpdev;
|
2010-05-13 03:49:17 -07:00
|
|
|
const char *ret, *test;
|
2010-07-30 11:19:04 -07:00
|
|
|
Eeze_Udev_Watch_Cb func = store->func;
|
2010-05-13 03:49:17 -07:00
|
|
|
void *sdata = store->data;
|
2010-05-14 00:02:50 -07:00
|
|
|
Eeze_Udev_Watch *watch = store->watch;
|
2010-05-21 18:55:14 -07:00
|
|
|
int cap = 0, event = 0;
|
2010-05-13 03:49:17 -07:00
|
|
|
|
|
|
|
if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
|
2010-06-24 11:04:01 -07:00
|
|
|
return EINA_TRUE;
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2010-05-13 03:49:17 -07:00
|
|
|
device = udev_monitor_receive_device(store->mon);
|
2010-05-21 18:55:14 -07:00
|
|
|
|
|
|
|
if (!device)
|
2010-06-24 11:04:01 -07:00
|
|
|
return EINA_TRUE;
|
2010-05-13 03:49:17 -07:00
|
|
|
|
2011-03-03 08:30:45 -08:00
|
|
|
if ((!(test = udev_device_get_action(device)))
|
|
|
|
|| (!(ret = udev_device_get_syspath(device))))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (store->event)
|
|
|
|
{
|
|
|
|
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_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 ((event & EEZE_UDEV_EVENT_OFFLINE) || (event & EEZE_UDEV_EVENT_REMOVE))
|
|
|
|
goto out;
|
2010-05-13 14:21:12 -07:00
|
|
|
switch (store->type)
|
|
|
|
{
|
2011-01-05 10:46:32 -08:00
|
|
|
case EEZE_UDEV_TYPE_KEYBOARD:
|
2010-05-13 22:45:09 -07:00
|
|
|
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
2011-01-05 10:46:32 -08:00
|
|
|
if ((!(test = udev_device_get_subsystem(device)))
|
|
|
|
|| (strcmp(test, "input")))
|
|
|
|
goto error;
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2011-01-05 10:46:32 -08:00
|
|
|
test = udev_device_get_property_value(device, "ID_CLASS");
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2011-01-05 10:46:32 -08:00
|
|
|
if ((_walk_parents_test_attr(device, "bInterfaceProtocol", "01"))
|
|
|
|
|| ((test) && (!strcmp(test, "kbd"))))
|
|
|
|
break;
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2011-01-05 10:46:32 -08:00
|
|
|
goto error;
|
2010-05-13 22:45:09 -07:00
|
|
|
#endif
|
2011-01-05 10:46:32 -08:00
|
|
|
if ((!udev_device_get_property_value(device, "ID_INPUT_KEYBOARD")) &&
|
|
|
|
(!udev_device_get_property_value(device, "ID_INPUT_KEY")))
|
|
|
|
goto error;
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2011-01-05 10:46:32 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EEZE_UDEV_TYPE_MOUSE:
|
2010-05-13 22:45:09 -07:00
|
|
|
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
2011-01-05 10:46:32 -08:00
|
|
|
if ((!(test = udev_device_get_subsystem(device)))
|
|
|
|
|| (strcmp(test, "input")))
|
|
|
|
goto error;
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2011-01-05 10:46:32 -08:00
|
|
|
test = udev_device_get_property_value(device, "ID_CLASS");
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2011-01-05 10:46:32 -08:00
|
|
|
if ((_walk_parents_test_attr(device, "bInterfaceProtocol", "02"))
|
|
|
|
|| ((test) && (!strcmp(test, "mouse"))))
|
|
|
|
break;
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2011-01-05 10:46:32 -08:00
|
|
|
goto error;
|
2010-05-13 22:45:09 -07:00
|
|
|
#endif
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2011-01-05 10:46:32 -08:00
|
|
|
if (!udev_device_get_property_value(device, "ID_INPUT_MOUSE"))
|
|
|
|
goto error;
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2011-01-05 10:46:32 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EEZE_UDEV_TYPE_TOUCHPAD:
|
2010-05-13 22:45:09 -07:00
|
|
|
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
2011-01-05 10:46:32 -08:00
|
|
|
if ((!(test = udev_device_get_subsystem(device)))
|
|
|
|
|| (strcmp(test, "input")))
|
|
|
|
goto error;
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2011-01-05 10:46:32 -08:00
|
|
|
if (_walk_parents_test_attr(device, "resolution", NULL))
|
|
|
|
break;
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2011-01-05 10:46:32 -08:00
|
|
|
goto error;
|
2010-05-13 22:45:09 -07:00
|
|
|
#endif
|
2011-01-05 10:46:32 -08:00
|
|
|
if (!udev_device_get_property_value(device, "ID_INPUT_TOUCHPAD"))
|
|
|
|
goto error;
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2011-01-05 10:46:32 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EEZE_UDEV_TYPE_DRIVE_MOUNTABLE:
|
2010-05-13 22:45:09 -07:00
|
|
|
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
2011-01-05 10:46:32 -08:00
|
|
|
if ((!(test = udev_device_get_subsystem(device)))
|
|
|
|
|| (strcmp(test, "block")))
|
|
|
|
goto error;
|
2010-05-13 22:45:09 -07:00
|
|
|
#endif
|
2011-01-05 10:46:32 -08:00
|
|
|
test = udev_device_get_sysattr_value(device, "capability");
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2011-01-05 10:46:32 -08:00
|
|
|
if (test)
|
|
|
|
cap = strtol(test, NULL, 10);
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2011-01-05 10:46:32 -08:00
|
|
|
if (!(test = (udev_device_get_property_value(device, "ID_FS_USAGE"))) ||
|
|
|
|
(strcmp("filesystem", test)) || (cap == 50))
|
|
|
|
goto error;
|
|
|
|
{
|
|
|
|
int devcheck;
|
2011-01-05 10:42:49 -08:00
|
|
|
|
2011-01-05 10:46:32 -08:00
|
|
|
devcheck = open(udev_device_get_devnode(device), O_RDONLY | O_EXCL);
|
2011-01-05 13:13:38 -08:00
|
|
|
if (devcheck < 0) goto error;
|
2011-01-05 10:46:32 -08:00
|
|
|
close(devcheck);
|
|
|
|
}
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2011-01-05 10:46:32 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EEZE_UDEV_TYPE_DRIVE_INTERNAL:
|
2010-05-13 22:45:09 -07:00
|
|
|
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
2011-01-05 10:46:32 -08:00
|
|
|
if ((!(test = udev_device_get_subsystem(device)))
|
|
|
|
|| (strcmp(test, "block")))
|
|
|
|
goto error;
|
2010-05-13 22:45:09 -07:00
|
|
|
#endif
|
2011-01-05 10:46:32 -08:00
|
|
|
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;
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2011-01-05 10:46:32 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EEZE_UDEV_TYPE_DRIVE_REMOVABLE:
|
2010-05-13 22:45:09 -07:00
|
|
|
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
2011-01-05 10:46:32 -08:00
|
|
|
if ((!(test = udev_device_get_subsystem(device)))
|
|
|
|
|| (strcmp(test, "block")))
|
|
|
|
goto error;
|
2010-05-13 22:45:09 -07:00
|
|
|
#endif
|
2011-01-05 10:46:32 -08:00
|
|
|
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;
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2011-01-05 10:46:32 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EEZE_UDEV_TYPE_DRIVE_CDROM:
|
2010-05-13 22:45:09 -07:00
|
|
|
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
2011-01-05 10:46:32 -08:00
|
|
|
if ((!(test = udev_device_get_subsystem(device)))
|
|
|
|
|| (strcmp(test, "block")))
|
|
|
|
goto error;
|
2010-05-13 22:45:09 -07:00
|
|
|
#endif
|
2011-01-05 10:46:32 -08:00
|
|
|
if (!udev_device_get_property_value(device, "ID_CDROM"))
|
|
|
|
goto error;
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2011-01-05 10:46:32 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EEZE_UDEV_TYPE_POWER_AC:
|
2010-05-13 22:45:09 -07:00
|
|
|
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
2011-01-05 10:46:32 -08:00
|
|
|
if ((!(test = udev_device_get_subsystem(device)))
|
|
|
|
|| (strcmp(test, "power_supply")))
|
|
|
|
goto error;
|
2010-05-13 22:45:09 -07:00
|
|
|
#endif
|
2011-01-05 10:46:32 -08:00
|
|
|
if (!(test = udev_device_get_property_value(device, "POWER_SUPPLY_TYPE"))
|
|
|
|
|| (strcmp("Mains", test)))
|
|
|
|
goto error;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EEZE_UDEV_TYPE_POWER_BAT:
|
2010-05-13 22:45:09 -07:00
|
|
|
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
2011-01-05 10:46:32 -08:00
|
|
|
if ((!(test = udev_device_get_subsystem(device)))
|
|
|
|
|| (strcmp(test, "power_supply")))
|
|
|
|
goto error;
|
2010-05-13 22:45:09 -07:00
|
|
|
#endif
|
2011-01-05 10:46:32 -08:00
|
|
|
if (!(test = udev_device_get_property_value(device, "POWER_SUPPLY_TYPE"))
|
|
|
|
|| (strcmp("Battery", test)))
|
|
|
|
goto error;
|
|
|
|
break;
|
|
|
|
|
2011-03-12 10:39:33 -08:00
|
|
|
case EEZE_UDEV_TYPE_NET:
|
|
|
|
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
|
|
|
if ((!(test = udev_device_get_subsystem(device)))
|
|
|
|
|| (strcmp(test, "net")))
|
|
|
|
goto error;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
2011-01-05 10:46:32 -08:00
|
|
|
case EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR:
|
2010-05-19 21:28:05 -07:00
|
|
|
#ifdef OLD_UDEV_RRRRRRRRRRRRRR
|
2011-01-05 10:46:32 -08:00
|
|
|
if ((!(test = udev_device_get_subsystem(device)))
|
|
|
|
|| (strcmp(test, "hwmon")))
|
|
|
|
goto error;
|
2010-05-19 21:28:05 -07:00
|
|
|
#endif /* have to do stuff up here since we need info from the parent */
|
2011-01-05 10:46:32 -08:00
|
|
|
if (!_walk_parents_test_attr(device, "temp1_input", NULL))
|
|
|
|
goto error;
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2011-01-05 10:46:32 -08:00
|
|
|
/* 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;
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2011-01-05 10:46:32 -08:00
|
|
|
if (!(device = _copy_device(parent)))
|
|
|
|
goto error;
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2011-01-05 10:46:32 -08:00
|
|
|
udev_device_unref(tmpdev);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2011-01-05 10:46:32 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2010-05-13 03:49:17 -07:00
|
|
|
}
|
2011-03-03 08:30:45 -08:00
|
|
|
out:
|
2011-01-05 10:46:32 -08:00
|
|
|
(*func)(eina_stringshare_add(ret), event, sdata, watch);
|
2010-05-13 03:49:17 -07:00
|
|
|
error:
|
2010-10-15 21:18:26 -07:00
|
|
|
if (device)
|
|
|
|
udev_device_unref(device);
|
2010-06-24 11:04:01 -07:00
|
|
|
return EINA_TRUE;
|
2010-05-13 03:49:17 -07:00
|
|
|
}
|
2011-01-05 10:46:32 -08:00
|
|
|
|
2010-05-14 00:02:50 -07:00
|
|
|
EAPI Eeze_Udev_Watch *
|
2011-01-05 10:46:32 -08:00
|
|
|
eeze_udev_watch_add(Eeze_Udev_Type type,
|
|
|
|
int event,
|
|
|
|
Eeze_Udev_Watch_Cb cb,
|
|
|
|
void *user_data)
|
2010-05-13 03:49:17 -07:00
|
|
|
{
|
2010-05-22 11:50:27 -07:00
|
|
|
_udev_monitor *mon = NULL;
|
2010-05-13 03:49:17 -07:00
|
|
|
int fd;
|
|
|
|
Ecore_Fd_Handler *handler;
|
2010-10-15 21:18:26 -07:00
|
|
|
Eeze_Udev_Watch *watch = NULL;
|
|
|
|
struct _store_data *store = NULL;
|
2010-05-13 03:49:17 -07:00
|
|
|
|
2010-11-22 15:04:45 -08:00
|
|
|
if (!(store = calloc(1, sizeof(struct _store_data))))
|
2010-05-21 18:55:14 -07:00
|
|
|
return NULL;
|
|
|
|
|
2010-05-14 00:02:50 -07:00
|
|
|
if (!(watch = malloc(sizeof(Eeze_Udev_Watch))))
|
2010-05-13 14:21:12 -07:00
|
|
|
goto error;
|
2010-05-13 03:49:17 -07:00
|
|
|
|
|
|
|
if (!(mon = udev_monitor_new_from_netlink(udev, "udev")))
|
2010-05-13 14:21:12 -07:00
|
|
|
goto error;
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2010-05-13 22:45:09 -07:00
|
|
|
#ifndef OLD_UDEV_RRRRRRRRRRRRRR
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2010-05-13 03:49:17 -07:00
|
|
|
switch (type)
|
|
|
|
{
|
2011-01-05 10:46:32 -08:00
|
|
|
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;
|
|
|
|
|
2011-03-12 10:39:33 -08:00
|
|
|
case EEZE_UDEV_TYPE_NET:
|
|
|
|
udev_monitor_filter_add_match_subsystem_devtype(mon, "net", NULL);
|
|
|
|
break;
|
|
|
|
|
2011-01-05 10:46:32 -08:00
|
|
|
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;
|
2010-05-13 03:49:17 -07:00
|
|
|
}
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2010-05-13 22:45:09 -07:00
|
|
|
#endif
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2010-05-13 03:49:17 -07:00
|
|
|
if (udev_monitor_enable_receiving(mon))
|
|
|
|
goto error;
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2010-05-13 03:49:17 -07:00
|
|
|
fd = udev_monitor_get_fd(mon);
|
2010-07-30 11:19:04 -07:00
|
|
|
store->func = cb;
|
2010-05-13 03:49:17 -07:00
|
|
|
store->data = user_data;
|
|
|
|
store->mon = mon;
|
|
|
|
store->type = type;
|
|
|
|
store->watch = watch;
|
2010-05-19 21:28:05 -07:00
|
|
|
store->event = event;
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2011-01-05 10:46:32 -08:00
|
|
|
if (!(handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ,
|
|
|
|
_get_syspath_from_watch, store, NULL, NULL)))
|
2010-05-13 03:49:17 -07:00
|
|
|
goto error;
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2010-05-13 03:49:17 -07:00
|
|
|
watch->mon = mon;
|
|
|
|
watch->handler = handler;
|
|
|
|
return watch;
|
|
|
|
error:
|
2010-10-15 21:18:26 -07:00
|
|
|
if (store)
|
|
|
|
free(store);
|
|
|
|
if (watch)
|
|
|
|
free(watch);
|
|
|
|
if (mon)
|
|
|
|
udev_monitor_unref(mon);
|
|
|
|
ERR("Could not create watch!");
|
2010-05-21 18:55:14 -07:00
|
|
|
return NULL;
|
2010-05-13 03:49:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void *
|
2011-01-05 10:46:32 -08:00
|
|
|
eeze_udev_watch_del(Eeze_Udev_Watch *watch)
|
2010-05-13 03:49:17 -07:00
|
|
|
{
|
2010-05-13 14:21:12 -07:00
|
|
|
struct _store_data *sdata;
|
2010-05-22 11:50:27 -07:00
|
|
|
void *ret = NULL;
|
2010-05-13 03:49:17 -07:00
|
|
|
|
2010-05-21 18:55:14 -07:00
|
|
|
if ((!watch) || (!watch->mon) || (!watch->handler))
|
|
|
|
return NULL;
|
2010-05-13 03:49:17 -07:00
|
|
|
|
2010-05-17 17:17:13 -07:00
|
|
|
sdata = ecore_main_fd_handler_del(watch->handler);
|
2010-07-29 19:53:46 -07:00
|
|
|
udev_monitor_unref(watch->mon);
|
2010-05-21 18:55:14 -07:00
|
|
|
|
2010-05-13 13:52:27 -07:00
|
|
|
if (sdata)
|
|
|
|
{
|
|
|
|
ret = sdata->data;
|
|
|
|
free(sdata);
|
|
|
|
}
|
2010-05-13 03:49:17 -07:00
|
|
|
|
2010-05-21 18:55:14 -07:00
|
|
|
free(watch);
|
2010-05-13 03:49:17 -07:00
|
|
|
return ret;
|
|
|
|
}
|