static int device_new_ud(sysview_device **out, sysview_seat *seat, unsigned int type, struct udev_device *ud) {
        _cleanup_(sysview_device_freep) sysview_device *device = NULL;
        int r;

        assert_return(seat, -EINVAL);
        assert_return(ud, -EINVAL);

        r = sysview_device_new(&device, seat, udev_device_get_syspath(ud));
        if (r < 0)
                return r;

        device->type = type;

        switch (type) {
        case SYSVIEW_DEVICE_EVDEV:
                device->evdev.ud = udev_device_ref(ud);
                break;
        case SYSVIEW_DEVICE_DRM:
                device->drm.ud = udev_device_ref(ud);
                break;
        default:
                assert_not_reached("sysview: invalid udev-device type");
        }

        if (out)
                *out = device;
        device = NULL;
        return 0;
}
Beispiel #2
0
UdevDevice::UdevDevice(const UdevDevice& source)
	:device(source.device)
	{
	/* Reference the device: */
	if(device!=0)
		udev_device_ref(device);
	}
Beispiel #3
0
struct ratbag_device*
ratbag_device_new(struct ratbag *ratbag, struct udev_device *udev_device,
		  const char *name, const struct input_id *id)
{
	struct ratbag_device *device = NULL;

	device = zalloc(sizeof(*device));
	device->name = strdup_safe(name);
	device->ratbag = ratbag_ref(ratbag);
	device->refcount = 1;
	device->udev_device = udev_device_ref(udev_device);
	device->ids = *id;
	device->data = ratbag_device_data_new_for_id(ratbag, id);
	list_init(&device->profiles);

	list_insert(&ratbag->devices, &device->link);

	/* We assume that most devices have this capability, so let's set it
	 * by default. The few devices that miss this capability should
	 * unset it instead.
	 */
	ratbag_device_set_capability(device,
				     RATBAG_DEVICE_CAP_QUERY_CONFIGURATION);

	return device;
}
Beispiel #4
0
DevicePrivate::DevicePrivate(struct udev_device *udev_, bool ref)
    : udev(udev_)
{
    if (ref) {
        udev_device_ref(udev);
    }
}
Beispiel #5
0
UdevDevice UdevDevice::getParent(void)
	{
	/* Get the parent device: */
	udev_device* parent=udev_device_get_parent(device);
	
	/* The parent device is not supposed to be unref'ed, so let's explicitly ref it here so that a later unref won't destroy it: */
	if(parent!=0)
		udev_device_ref(parent);
	
	return UdevDevice(parent);
	}
Beispiel #6
0
UdevDevice UdevDevice::getParent(const char* subsystem,const char* deviceType)
	{
	/* Get the parent device: */
	udev_device* parent=udev_device_get_parent_with_subsystem_devtype(device,subsystem,deviceType);
	
	/* The parent device is not supposed to be unref'ed, so let's explicitly ref it here so that a later unref won't hurt: */
	if(parent!=0)
		udev_device_ref(parent);
	
	return UdevDevice(parent);
	}
Beispiel #7
0
UdevDevice& UdevDevice::operator=(const UdevDevice& source)
	{
	if(device!=source.device)
		{
		if(device!=0)
			udev_device_unref(device);
		device=source.device;
		if(device!=0)
			udev_device_ref(device);
		}
	
	return *this;
	}
/**
 * @brief Create a new generic keyboard backlight controller object.
 *
 *
 * @param device The udev device that represents this keyboard backlight
 * controller. This device will be referenced internally.
 * @param type The type of the keyboard backlight controller.
 * @param ctx A context for the specific type of keyboard backlight
 * controller. This memory must be externally tracked.
 *
 * @return A new generic keyboard  backlight object initialized with the
 * specified input. However, all of the capabilities are not yet initalized.
 */
struct kb_controller *
kb_controller_new(struct udev_device *device,
    enum kb_controller_type type, void *ctx)
{
  struct kb_controller *kb = calloc(sizeof(struct kb_controller), 1);
  assert(kb != NULL);

  assert(device != NULL);
  udev_device_ref(device);
  kb->kbc_device = device;

  kb->kbc_type = type;
  kb->kbc_ctx = ctx;

  return kb;
}
Beispiel #9
0
/**
 * @brief
 *
 * @param device
 *
 * @return
 */
struct usp_pwm_t *
usp_pwm_new(struct udev_device *device, const char *name,
            enum usp_pwm_type_e type)
{
  struct usp_pwm_t *pwm = NULL;

  pwm = calloc(sizeof(struct usp_pwm_t), 1);
  assert(pwm != NULL);

  udev_device_ref(pwm->uspwm_device);
  pwm->uspwm_device = device;
  pwm->uspwm_type = type;
  pwm->uspwm_name = name;
  usp_ref_init(pwm, usp_pwm_delete);

  return pwm;
}
DevicePrivate &DevicePrivate::operator=(const DevicePrivate &other)
{
    udev_device_unref(udev);
    udev = udev_device_ref(other.udev);
    return *this;
}
Beispiel #11
0
int main(int argc, char **argv)
{
	int rc = 1;
	struct udev *udev = NULL;
	struct udev_device *device = NULL;
	const char *syspath,
	           *phys = NULL;
	const char *product;
	char group[1024];
	char *str;

	if (argc != 2)
		return 1;

	syspath = argv[1];

	udev = udev_new();
	if (!udev)
		goto out;

	device = udev_device_new_from_syspath(udev, syspath);
	if (!device)
		goto out;

	/* Find the first parent with ATTRS{phys} set. For tablets that
	 * value looks like usb-0000:00:14.0-1/input1. Drop the /input1
	 * bit and use the remainder as device group identifier */
	while (device != NULL) {
		struct udev_device *parent;

		phys = udev_device_get_sysattr_value(device, "phys");
		if (phys)
			break;

		parent = udev_device_get_parent(device);
		udev_device_ref(parent);
		udev_device_unref(device);
		device = parent;
	}

	if (!phys)
		goto out;

	/* udev sets PRODUCT on the same device we find PHYS on, let's rely
	   on that*/
	product = udev_device_get_property_value(device, "PRODUCT");
	if (!product)
		product = "";
	snprintf(group, sizeof(group), "%s:%s", product, phys);

	str = strstr(group, "/input");
	if (str)
		*str = '\0';

	/* Cintiq 22HD Touch has
	   usb-0000:00:14.0-6.3.1/input0 for the touch
	   usb-0000:00:14.0-6.3.0/input0 for the pen
	   Check if there's a . after the last -, if so, cut off the string
	   there.
	  */
	str = strrchr(group, '.');
	if (str && str > strrchr(group, '-'))
		*str = '\0';

	printf("%s\n", group);

	rc = 0;
out:
	if (device)
		udev_device_unref(device);
	if (udev)
		udev_unref(udev);

	return rc;
}