[sane-devel] Developers take note: Backend initialization

Olaf Meeuwissen olaf.meeuwissen at avasys.jp
Tue Dec 7 23:04:23 UTC 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 2010年12月07日 22:32, m. allan noah wrote:
> 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:
>>> [...]
>>> 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().
> 
> 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.

The problem is with "usually".  Backend maintainers have no guarantee
from the spec that frontends will do so.

In the epkowa backend I also call sane_get_devices() in sane_open() if
it hasn't been called yet but that's just because I'm too lazy to:
 - decide what the first available device is in case of no device name
 - bother with validating the device name properly (it's easier to see
whether it's in the list)

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

If it is internal to the backend then backend maintainers just have to
do what they need to do already anyway (regardless of any frontends):
make sure they don't shoot themselves in the foot ;-)

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

iEYEARECAAYFAkz+vXcACgkQt5qrxaZLMnIHCACfbzdj9qY4gVOq97AdeS0fGKCK
T5cAoJie9fq4AFB7CALWvLXM7SuB5Mr6
=QDO5
-----END PGP SIGNATURE-----



More information about the sane-devel mailing list