Re: Sysfs properties with libudev (for example capabilities/key)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Oct 31, 2010 at 7:39 AM, Laszlo Papp <djszapi@xxxxxxxxxxxx> wrote:
> On Sun, Oct 31, 2010 at 7:23 AM, Greg KH <greg@xxxxxxxxx> wrote:
>> On Sun, Oct 31, 2010 at 07:04:30AM -0700, Laszlo Papp wrote:
>>> Hi,
>>>
>>> You can check the code out more in-depth in the following with the
>>> produced output. This is the compilation command I used for testing:
>>> gcc -Wall -o test -ggdb -ludev  main.c.
>>>
>>> I just would like to get the real input devices.. so VID/PID: (null)
>>> (null) and related device node entries are undesired.
>>
>> But those are "real" input devices, why do you think otherwise?
>>
>> If you don't want them, then filter them out by ignoring the event
>> types, but note that they are needed by your system to work properly
>> (i.e. x.org uses them.)
>>
>> So your code is working as designed, I just don't think that you
>> realized there are all of these input devices present :)
>>
>> thanks,
>>
>> greg k-h
>>
>
> root /home/djszapi #  cat main.c
> #include <libudev.h>
> #include <stdio.h>
>
> int main()
> {
>    struct udev *udev;
>    struct udev_enumerate *enumerate;
>    struct udev_list_entry *devices;
>    struct udev_list_entry *dev_list_entry;
>    struct udev_device *dev;
>
>    udev = udev_new();
>    if (!udev) {
>        printf("Cannot create udev\n");
>        return -1;
>    }
>
>    enumerate = udev_enumerate_new(udev);
>    udev_enumerate_add_match_subsystem(enumerate, "input");
>    udev_enumerate_scan_devices(enumerate);
>    devices = udev_enumerate_get_list_entry(enumerate);
>
>    udev_list_entry_foreach(dev_list_entry, devices) {
>        const char *path;
>        path = udev_list_entry_get_name(dev_list_entry);
>        dev = udev_device_new_from_syspath(udev, path);
>        dev = udev_device_get_parent_with_subsystem_devtype(dev, "input", 0);
>        if (dev == 0)
>            continue;
>
>        printf("Device Node Path: %s, Name: %s\r\n", path,
>                udev_device_get_sysattr_value(dev, "name"));
>        printf("VID/PID: %s %s\r\n",
>                udev_device_get_sysattr_value(dev,"id/vendor"),
>                udev_device_get_sysattr_value(dev, "id/product"));
>        udev_device_unref(dev);
>    }
>
>    udev_enumerate_unref(enumerate);
>    udev_unref(udev);
>
>    return 0;
> }
> root /home/djszapi #  ./test
> Device Node Path:
> /sys/devices/LNXSYSTM:00/LNXPWRBN:00/input/input3/event3, Name: Power
> Button
> VID/PID: 0000 0001
> Device Node Path:
> /sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0C:00/input/input2/event2,
> Name: Power Button
> VID/PID: 0000 0001
> Device Node Path:
> /sys/devices/pci0000:00/0000:00:04.0/usb2/2-10/2-10:1.0/input/input5/event5,
> Name: Logitech USB Optical Mouse
> VID/PID: 046d c00c
> Device Node Path:
> /sys/devices/pci0000:00/0000:00:04.0/usb2/2-10/2-10:1.0/input/input5/mouse1,
> Name: Logitech USB Optical Mouse
> VID/PID: 046d c00c
> Device Node Path:
> /sys/devices/pci0000:00/0000:00:09.0/input/input6/event6, Name: HDA
> Digital PCBeep
> VID/PID: 10ec 0662
> Device Node Path:
> /sys/devices/platform/i8042/serio0/input/input1/event1, Name: AT
> Translated Set 2 keyboard
> VID/PID: 0001 0001
> Device Node Path: /sys/devices/platform/pcspkr/input/input4/event4,
> Name: PC Speaker
> VID/PID: 001f 0001
> Device Node Path: /sys/devices/virtual/input/input0/event0, Name:
> Macintosh mouse button emulation
> VID/PID: 0001 0001
> Device Node Path: /sys/devices/virtual/input/input0/mouse0, Name:
> Macintosh mouse button emulation
> VID/PID: 0001 0001
> root /home/djszapi #
>
> Better, but every device occurs two times o_O
>
> Best Regards,
> Laszlo Papp
>

root /sys/devices/platform/i8042/serio0/input/input1 #  cd /home/djszapi/
root /home/djszapi #  cat main.c
#include <libudev.h>
#include <stdio.h>

int main()
{
    struct udev *udev;
    struct udev_enumerate *enumerate;
    struct udev_list_entry *devices;
    struct udev_list_entry *dev_list_entry;
    struct udev_device *dev;
    struct udev_device *parent_dev;

    udev = udev_new();
    if (!udev) {
        printf("Cannot create udev\n");
        return -1;
    }

    enumerate = udev_enumerate_new(udev);
    udev_enumerate_add_match_subsystem(enumerate, "input");
    udev_enumerate_scan_devices(enumerate);
    devices = udev_enumerate_get_list_entry(enumerate);

    udev_list_entry_foreach(dev_list_entry, devices) {
        const char *path;
        path = udev_list_entry_get_name(dev_list_entry);
        dev = udev_device_new_from_syspath(udev, path);
        parent_dev =
udev_device_get_parent_with_subsystem_devtype(dev, "input", 0);
        if (parent_dev) {
            udev_device_unref(parent_dev);
            continue;
        }

        printf("Device Node Path: %s, Name: %s\r\n", path,
                udev_device_get_sysattr_value(dev, "name"));
        printf("VID/PID: %s %s\r\n",
                udev_device_get_sysattr_value(dev,"id/vendor"),
                udev_device_get_sysattr_value(dev, "id/product"));
        udev_device_unref(dev);
    }

    udev_enumerate_unref(enumerate);
    udev_unref(udev);

    return 0;
}
root /home/djszapi #  gcc -Wall -o test -ggdb -ludev  main.c
root /home/djszapi #  ./test
Device Node Path: /sys/devices/LNXSYSTM:00/LNXPWRBN:00/input/input3,
Name: Power Button
VID/PID: 0000 0001
Device Node Path:
/sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0C:00/input/input2, Name:
Power Button
VID/PID: 0000 0001
Device Node Path:
/sys/devices/pci0000:00/0000:00:04.0/usb2/2-10/2-10:1.0/input/input5,
Name: Logitech USB Optical Mouse
VID/PID: 046d c00c
Device Node Path: /sys/devices/pci0000:00/0000:00:09.0/input/input6,
Name: HDA Digital PCBeep
VID/PID: 10ec 0662
Device Node Path: /sys/devices/platform/i8042/serio0/input/input1,
Name: AT Translated Set 2 keyboard
VID/PID: 0001 0001
Device Node Path: /sys/devices/platform/pcspkr/input/input4, Name: PC Speaker
VID/PID: 001f 0001
Device Node Path: /sys/devices/virtual/input/input0, Name: Macintosh
mouse button emulation
VID/PID: 0001 0001
Device Node Path: /sys/devices/virtual/input/mice, Name: (null)
VID/PID: (null) (null)
root /home/djszapi #

OK, seems to work, but please fix me, if this is not the way to do it.

Best Regards,
Laszlo Papp
--
To unsubscribe from this list: send the line "unsubscribe linux-hotplug" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel]     [Linux DVB]     [Asterisk Internet PBX]     [DCCP]     [Netdev]     [X.org]     [Util Linux NG]     [Fedora Women]     [ALSA Devel]     [Linux USB]

  Powered by Linux