[Nut-upsdev] NUT and libhid

Arjen de Korte nut+devel at de-korte.org
Tue Aug 14 18:27:14 UTC 2007

Peter Selinger wrote:

> If libhid wants to be a library one day, it should be reentrant. It's
> true that a NUT driver connects to one and only one HID device.
> However, the same may not be true for a generic application, which
> could connect to many devices at once. So in the interest of good
> style, all global variables should one day be replaced by a hid_state
> variable that gets passed to each function call.
> Currently, there are still two global variables: pDesc and rbuf. They
> still exist because my strategy for updating the code was to make a
> series of small, unobtrusive and easy-to-test changes, rather than a
> single major rewrite. For the reason outlined above, I think the goal
> should be to eliminate these. 
> This said, the underlying libusb-0.1.10a library also has global
> state. However, the global state of that library is restricted to the
> usb bus structure, which is truly global, in the sense that one
> computer has only one USB system, to which all busses are
> connected. Each device is accessible via its own hid_dev_handle_t
> *udev. So one could make a wrapper around libusb-0.1.10a that is
> mostly reentrant. 

Thanks for the explanation, that makes a lot of sense (should have
thought about that myself).


> All you have to do is set the timestamp to 0 for the report(s) you
> would like to invalidate. I don't see why making it a global variable
> makes this any easier or harder.  -- Peter

You're absolutely right here. I was just wondering how to get from udev
to the report buffer. But that is probably something I don't have to
worry about right now, since the report buffer is still global.

Best regards, Arjen

More information about the Nut-upsdev mailing list