[sane-devel] Developers take note: Backend initialization
m. allan noah
kitno455 at gmail.com
Tue Dec 7 13:32:48 UTC 2010
On Tue, Dec 7, 2010 at 12:43 AM, Olaf Meeuwissen
<olaf.meeuwissen at avasys.jp> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> On 2010-12-07 12:17, m. allan noah wrote:
>> Now that we are seeing more frontends like button monitors, a common
>> initialization problem has become evident. The sane standard
>> specifically says that sane_get_devices() can be called repeatedly to
>> discover new devices. Unfortunately, many backends do this discovery
>> just once by calling sanei_usb_init() only from sane_init(). This
>> prevents the backend from detecting device insertion/removal events.
>> In preparation for the upcoming release, I'd like to ask all backend
>> authors to please review your code and make the following corrections
>> if required.
> With all due respect
>> 1. Move calls to sanei_usb_init() to sane_get_devices()
> How does this work when a frontend does not call sane_get_devices() and
> immediately tries to sane_open() a USB device?
Yes- I thought of this after I went to bed last night, and decided not
to post a correction until this morning. Hopefully no one has
re-written alot of code in the meantime :)
> Backends can safely call sanei_usb_init() in both sane_init() and
> sane_get_devices(). They should just move the device discovery logic to
> sane_get_devices() and call that from sane_init() if they really still
> want to do discovery at sane_init().
Actually, since sane_init() calls are usually followed by
sane_get_devices(), it makes more sense to do this within sane_open()
if no device name is given or if the list is not already loaded. This
is the technique I used for the fujitsu backend.
>> 2. If a list of devices is maintained within the backend, add/remove
>> devices as required at each call to sane_get_devices()
>> 3. Do not destroy and recreate devices which have not changed, as the
>> front-end may have cached that handle.
> Such frontends should be cluebatted. The spec only guarantees that the
> returned list remains unchanged and valid until
> (a) another call to sane_get_devices()
> (b) a call to sane_exit()
> Repeatedly calling sane_get_devices() means you should not be hanging on
> to SANE_Device's from earlier lists. Backends are free to do as they
> please with that list when you call sane_get_devices().
> Hanging on to SANE_Handle's is fine as these have been sane_open()ed.
Yes- You are correct regarding the distinction between handle and
device. However, the SANE_handle is often 'tied' to the SANE_Device
internal to the backend, so one has to be careful not to destroy the
SANE_Handle when shifting SANE_Device entries around.
> The epkowa backend should be spec compliant wrt repeatedly calling
> sane_get_devices() since iscan-2.14.0.
I have little doubt that your code is in error :)
"The truth is an offense, but not a sin"
More information about the sane-devel