[sane-devel] sane_get_devices and sanei_usb_init

m. allan noah kitno455 at gmail.com
Tue Dec 2 12:53:23 UTC 2008


sorry ABC- this should have gone to list...

On Tue, Dec 2, 2008 at 7:51 AM, m. allan noah <kitno455 at gmail.com> wrote:
> On Mon, Dec 1, 2008 at 10:23 PM, ABC <abc at telekom.ru> wrote:
>> First of all sanei_usb_init() is not designed to be used for rescanning
>> after any other sanei_usb functions is called. It is just initialization
>> and rescanning ability is not documented side effect. As stated in
>> documentation: "Call this before any other sanei_usb function". So don't
>> call it after. (This doesn't state it should be called just once, so we
>> could rescan before first device is opened.)
>>
>> Second, we accessing devices just by index number, so if there is
>> appeared new device indexes could get changed. And third, yes it clears
>> internal structures, opened descriptors, whatever.
>>
>>
>> As I understand nobody of backend writers code so sane_get_devices()
>> could detect appearance of new devices in system. sanei_usb_init() is
>> usually called in sane_init(), there is get and remmebers internally
>> list (array) of present usb devices forever until program terminates.
>> Moreover, backend don't have access to that list directly but only via
>> attach callbacks, so config is parsed usually in sane_init() too, and
>> all found devices get "attached" to backend. Now backend have list of
>> devices that in practice can not be changed. In most backends
>> sane_get_devices() only _rebuild_ linear array of pointers to that list
>> created in sane_init. Actially that array doesn't need to be rebuilt
>> each time, it would not change.
>>
>> But when you write backend for a first time you don't know that. You
>> think "Why attach all devices in init if sane_get_devices should 'detect
>> when new devices become available'?" You trying to code it "right" way,
>> but later you realize it's don't work like this, at least for usb.
>
> thanks for the info. actually, the fujitsu backend calls
> sanei_usb_init in sane_get_devices, and splices its internal linked
> list together to deal with added and removed devices. however, i have
> only tested with adding a device when none were present. If there
> already were some devices detected, this could certainly scramble
> them. perhaps sanei_usb could be made smarter.
>
> allan
-- 
"The truth is an offense, but not a sin"



More information about the sane-devel mailing list