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

Thierry Huchard thierry at ordissimo.com
Sat Aug 6 21:31:08 BST 2022

Le 2022-08-06 20:55, Ralph Little a écrit :
> 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.

it would be possible to add a pointer at the beginning of the file and 
to access this data using the get and set methods:

static void *data_device = NULL;

void sanei_usb_devices_data_set (void *data);
void *sanei_usb_devices_data_get (void);

> Cheers,
> Ralph

More information about the sane-devel mailing list