Update list of usb devices

后端 未结 1 332
别跟我提以往
别跟我提以往 2021-01-01 04:23

I want create module which update list of usb devices automatically (not only mass storage). Now it works very rude - it has additional thread, which after 1 second update l

相关标签:
1条回答
  • 2021-01-01 05:15

    This question appears to be half design, half implementation. It seems you're most concerned about finding some way for Java USB services like jUSB to service hotplug events from the system, allowing you to have an event called via inversion of control instead of running a thread that passionately and iteratively polls the system in the background.

    The support you seek was implemented back in 2005 as JSR-80, and appears to live on, in the matter of all great projects that overstepped their commercial support, as javax-usb on SourceForge. Note that in their toy example (in javax-usb-example/src/ShowTopology.java), their preferred model is still polling based.

    Not all is lost, however! In the properties file for javax.usb, we find this:

    # If polling should be used instead of waiting for a hotplug notification.

    # Some kernel versions have a bug, and don't update the device node(s) until many seconds after waking up threads waiting on the devices file. If you are not getting hotplug events on a moderately to heavily loaded system, use polling.

    # Note that since the new (buggy?) kernel behavior breaks javax.usb, this defaults to true!

    # If you know your kernel isn't broken you can set this to false.

    #com.ibm.jusb.os.linux.LinuxUsbServices.topologyUpdateUsePolling = true

    And in javax-usb/src/javax/usb/event/UsbServicesListener.java, we see a model for setting up a USB event listener that you can proceed to use when a device is attached or detached from the system. No documentation is externally given on whether this works, however, and the docs themselves appear to be mostly 8 years old.

    Therefore, it's reasonable assume that while the support theoretically exists, it's lagged, stale, and in desperate need of an update by the community. This is the kind of thing that this fine community on SO could help fix, so I'll begin to close by pointing directly to the project itself.

    For now, until enhanced hardware or hotplug support exists, polling is still the best solution.

    (Additional reference implementation of javax-usb)

    0 讨论(0)
提交回复
热议问题