[sane-devel] Proposal to change function signatures of a couple of sanei_usb_* functions

Thierry Huchard thierry at ordissimo.com
Sat Aug 6 18:35:38 BST 2022

Le 6 août 2022 18:17:12 GMT+02:00, Ralph Little <skelband at gmail.com> a écrit :
>I'm having a go at writing my first SANE backend for a learning exercise.
>I notice that a few backends that use the functions: sanei_usb_attach_matching_devices() and sanei_usb_find_devices() require some context information in the callback function to complete the find function.
>This is typically because the backend is looping through a list of known device configurations and calling the sanei_* function on each one: the callback needs to know the element in that loop to complete the attach function in the callback.
>This is typically achieved with setting some global variables to be picked up by the callback function, or searching again through the original loop using information gleaned from the devicename (such as vendor and product), both of which are messy and ugly hacks.
>I propose that we change the function signature of the functions and the callback to include a (void *) context pointer:
>sanei_usb_find_devices (SANE_Int vendor, SANE_Int product, void *context,
>            SANE_Status (*attach) (SANE_String_Const dev, void *context));
>sanei_usb_attach_matching_devices (const char *name, void *context,
>                   SANE_Status (*attach) (const char *dev, void *context));
Hi Ralph,

Your change may impact proprietary backends (Brother, Canon, ...).


>I would have to change existing backends that rely on this function but I feel that it would be an improvement and clean up the processing of USB device detection.

Envoyé de mon appareil Android avec Courriel Ordissimo Mail. Veuillez excuser ma brièveté.

More information about the sane-devel mailing list