[sane-devel] Sane API Suggestion

Major A andras@users.sourceforge.net
Sun, 20 Jul 2003 16:18:30 +0100

> > A thin C interface layer could then use one callback dispatcher to
> > handle all C callbacks.  The callback dispatcher could use stdarg.h
> > to process the other args or perhaps they could be passed to the
> > callback using a count and array.
> Well, maybe the other developers have more experience with other
> languages. My first impression however, is that this makes the
> interface more complicated and complex. However, I'm no expert in
> interface design so if the other developers say it's better that way,
> I'll accept that.

Scheme is a full-blown functional language, and thus very different
from a pure procedural language. You can see from GObject (loosely
part of GTK+) how difficult it is to approach object-oriented
programming with C, and emulating functional programming in C would
certainly be totally impractical.

No C API will ever approach the full closure capabilities of Scheme,
so some sacrifices on the Scheme side must always be made when
interfacing C code.

> > In the future, I would be happy to contribute a scheme->sane interface 
> > library to the sane project, but it sure would be nice if the sane api was 
> > more non-C friendly.
> Well, it's a C interface so beeing C-friendly is a feature :-)

The SANE API is designed to be simple and portable, and any change
towards object orientation or functional programming would only bloat
it unnecessarily. Sorry, if you want to interface Scheme to SANE,
you'll have to adapt to the way things are.

Adding a callback data argument to both sane_init() and
SANE_Authorization_Callback would cause a number of problems, in
particular that of network transparency. Scheme or C++ programmers
would certainly like to use that parameter as a pointer to a
structure, but that only works if the size of the argument is at least
that of void*. Since the latter varies across platforms, this would be
ugly and non-portable.

Since the only callback in SANE is the one responsible for
authentication, I'd say it wouldn't be worth changing anything. A
Scheme frontend would either have to relay the authentication request
to the user, in which case the callback data is not used, or look up
username and password in a database, in which case the resource string
supplied is sufficient.


Major Andras
    e-mail: andras@users.sourceforge.net
    www:    http://andras.webhop.org/