[sane-devel] Developers take note: Backend initialization

Olaf Meeuwissen olaf.meeuwissen at avasys.jp
Tue Dec 7 05:43:08 UTC 2010

Hash: SHA1

On 2010-12-07 12:17, m. allan noah wrote:
> Authors-
> 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?

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().

> 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.

> A quick git grep shows that the following backends _MAY_ exhibit this problem:
> [...]
> epson

This backend has been deprecated, in 1.0.20, in favour of epson2.

> epson2

This backend still has a few warts.

The epkowa backend should be spec compliant wrt repeatedly calling
sane_get_devices() since iscan-2.14.0.

Hope this helps,
- -- 
Olaf Meeuwissen, LPIC-2           FLOSS Engineer -- AVASYS CORPORATION
FSF Associate Member #1962               Help support software freedom
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/


More information about the sane-devel mailing list