[sane-devel] what is stubs.c for?

Henning Meier-Geinitz henning@meier-geinitz.de
Thu, 26 Feb 2004 19:21:43 +0100


Hi,

On Thu, Feb 26, 2004 at 07:01:09AM -0800, Peter Mark Guevarra wrote:
> What is the purpose of the file stubs.c found in the backend directory?

That's a solution for the following problem:

SANE backends can be used in different ways:

a) One backend can be linked dynamically to a frontend.
b) One backend can be linked statically to a frontend.
c) Several backends are linked together with the dll backend and a
   frontend statically (preloading).
d) Several backends are linked together with the dll backend
   statically. The dll backend is linked dynamically to the frontend.
e) The frontend is linked to the dll backend dynamically. The dll
   backend loads the backends at run-time. That's the default on most
   platforms.
e) The frontend is linked to the dll backend statically. The dll
   backend loads the backends at run-time.

I hope I haven't forgotten a way.

With a), b), e), and f) the SANE API calls must be the same for all
backends. In case of c) and d) the API calls must be different
because you can't have the same symbols for different functions in the
same object. E.g. you couldn't distinguish between sane_open() of the
gt68xx and sane_open() of the epson backend.

So in case c) and d) the API calls look like this: 
sane_gt68xx_open(), sane_epson_open(), ...

stubs.c is linked to every backend library. Together with
include/sane/sanei_backend.h it contains all the magic :-)

In reality, it's a bit more complicated...
See backend/Makefile.in, dll.c, and dll-preload.c for details.

Bye,
  Henning