/** * Checks whether the device is a keyboard. * * @param syspath The /sys/ path with or without the /sys/ * @return If true, the device is a keyboard */ EAPI Eina_Bool eeze_udev_syspath_is_kbd(const char *syspath) { _udev_device *device = NULL; Eina_Bool kbd = EINA_FALSE; const char *test = NULL; if (!syspath) return EINA_FALSE; if (!(device = _new_device(syspath))) return EINA_FALSE; #ifdef OLD_UDEV_RRRRRRRRRRRRRR kbd = _walk_parents_test_attr(device, "bInterfaceProtocol", "01"); if (!kbd) { test = udev_device_get_property_value(device, "ID_CLASS"); if ((test) && (!strcmp(test, "kbd"))) kbd = EINA_TRUE; } #else test = udev_device_get_property_value(device, "ID_INPUT_KEYBOARD"); if (test && (test[0] == '1')) kbd = EINA_TRUE; #endif udev_device_unref(device); return kbd; }
/** * Checks whether the device is a mouse. * * @param syspath The /sys/ path with or without the /sys/ * @return If true, the device is a mouse */ EAPI Eina_Bool eeze_udev_syspath_is_mouse(const char *syspath) { _udev_device *device = NULL; Eina_Bool mouse = EINA_FALSE; const char *test = NULL; if (!syspath) return EINA_FALSE; if (!(device = _new_device(syspath))) return EINA_FALSE; #ifdef OLD_UDEV_RRRRRRRRRRRRRR mouse = _walk_parents_test_attr(device, "bInterfaceProtocol", "02"); if (!mouse) { test = udev_device_get_property_value(device, "ID_CLASS"); if ((test) && (!strcmp(test, "mouse"))) mouse = EINA_TRUE; } #else test = udev_device_get_property_value(device, "ID_INPUT_MOUSE"); if (test && (test[0] == '1')) mouse = EINA_TRUE; #endif udev_device_unref(device); return mouse; }
/** * Checks whether the device is a touchpad. * * @param syspath The /sys/ path with or without the /sys/ * @return If true, the device is a touchpad */ EAPI Eina_Bool eeze_udev_syspath_is_touchpad(const char *syspath) { _udev_device *device = NULL; Eina_Bool touchpad = EINA_FALSE; if (!syspath) return EINA_FALSE; if (!(device = _new_device(syspath))) return EINA_FALSE; #ifdef OLD_UDEV_RRRRRRRRRRRRRR touchpad = _walk_parents_test_attr(device, "resolution", NULL); #else const char *test; test = udev_device_get_property_value(device, "ID_INPUT_TOUCHPAD"); if (test && (test[0] == '1')) touchpad = EINA_TRUE; #endif udev_device_unref(device); return touchpad; }
/* private function to further filter watch results based on Eeze_Udev_Type * 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) { struct _store_data *store = data; _udev_device *device = NULL, *parent, *tmpdev; const char *ret, *test; Eeze_Udev_Watch_Cb func = store->func; void *sdata = store->data; Eeze_Udev_Watch *watch = store->watch; int event = 0; if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) return EINA_TRUE; device = udev_monitor_receive_device(store->mon); if (!device) return EINA_TRUE; 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_NONE) && ((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_NONE) && ((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_NONE) && ((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_NONE) && ((store->event & EEZE_UDEV_EVENT_ONLINE) != EEZE_UDEV_EVENT_ONLINE)) goto error; event |= EEZE_UDEV_EVENT_ONLINE; } else { if ((store->event != EEZE_UDEV_EVENT_NONE) && ((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; switch (store->type) { case EEZE_UDEV_TYPE_KEYBOARD: #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", "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 (!(test = (udev_device_get_property_value(device, "ID_FS_USAGE"))) || (strcmp("filesystem", test))) goto error; { int devcheck; devcheck = open(udev_device_get_devnode(device), O_RDONLY); if (devcheck < 0) goto error; close(devcheck); } break; case EEZE_UDEV_TYPE_DRIVE_INTERNAL: if (udev_device_get_property_value(device, "ID_FS_USAGE")) goto error; test = udev_device_get_sysattr_value(device, "removable"); if (test && test[0] == '1') goto error; test = udev_device_get_property_value(device, "ID_BUS"); if ((!test) || strcmp(test, "ata")) goto error; test = udev_device_get_property_value(device, "ID_TYPE"); if ((!test) || strcmp(test, "disk")) goto error; break; case EEZE_UDEV_TYPE_DRIVE_REMOVABLE: if (udev_device_get_sysattr_value(device, "partition")) goto error; test = udev_device_get_sysattr_value(device, "removable"); if ((!test) || (test[0] == '0')) goto error; test = udev_device_get_property_value(device, "ID_TYPE"); if ((!test) || strcmp(test, "disk")) goto error; break; case EEZE_UDEV_TYPE_DRIVE_CDROM: 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 test = udev_device_get_property_value(device, "POWER_SUPPLY_ONLINE"); if (!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 test = udev_device_get_property_value(device, "POWER_SUPPLY_PRESENT"); if (!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; } out: (*func)(eina_stringshare_add(ret), event, sdata, watch); error: if (device) udev_device_unref(device); return EINA_TRUE; }