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

Ralph Little skelband at gmail.com
Sat Aug 6 19:55:21 BST 2022


Hi,

On 2022-08-06 10:35, Thierry Huchard wrote:
>
> Le 6 août 2022 18:17:12 GMT+02:00, Ralph Little <skelband at gmail.com> a écrit :
>> Hi,
>> 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:
>>
>> SANE_Status
>> sanei_usb_find_devices (SANE_Int vendor, SANE_Int product, void *context,
>>              SANE_Status (*attach) (SANE_String_Const dev, void *context));
>>
>> void
>> 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, ...).
>
> Thierry
>
That is a good point.

We could introduce additional functions with the above signatures (e.g. 
sanei_usb_find_devices2()) but I feel that to be an unsatisfactory solution.

Any other suggestions/comments welcome.

Cheers,
Ralph





More information about the sane-devel mailing list