[Nut-upsdev] usb_device_id_t structure

Arnaud Quette aquette.dev at gmail.com
Wed Nov 19 09:08:32 UTC 2008


Hi Arjen,

just a side note, Jean Luc and Dorothée should ack you SNMP mail today...

2008/11/19 Arjen de Korte <nut+devel at de-korte.org>:
> Arnaud,
>
> I have a question regarding the below structure you've added:
>
>> typedef struct usb_device_id_t {
>>        int vendorID;
>>        int productID;
>>        void*(*fun)();          /* handler for specific processing */
>> } usb_device_id;
>
> I don't understand the last element in this structure. While there can be
> plenty of reasons for functions returning (void *), I can't figure out what
> use this could possibly have here.

the base need was for tripplite_hid.c, which sets a battery scale
factor depending on the model.
no need to return something (it return NULL in fact) since it simply
set a global var to either 0.1 or 1.0...
so (void)(*fun)() is sufficient. but I leaved the door opened for
other/future needs, like in depth checking, and returning whether the
device is supported or not.

> Since this structure is supposed to be used as input to
> is_usb_device_supported() and that function returns an (int), what can we
> possibly do with the return value of (void *)(*fun)()? Using that, would
> require casting the (void *) pointer to something useful, but how would we
> tell this to is_usb_device_supported()? Could it be you actually meant
> (void)(*fun)(), ie a function that doesn't take parameters and returns
> nothing?

the end user (ie the claiming or opening function) is in charge of that.
up to it to do what it wants...

Note that this is the first iteration on this point.
the common USB things that will (should) appear for 2.4 might help in
getting a better visibility on what's needed...

Arnaud
-- 
Linux / Unix Expert R&D - MGE Office Protection Systems - http://www.mgeops.com
Network UPS Tools (NUT) Project Leader - http://www.networkupstools.org/
Debian Developer - http://people.debian.org/~aquette/
Free Software Developer - http://arnaud.quette.free.fr/


More information about the Nut-upsdev mailing list