[comp.lang.ada] MOTIF BINDING

GBODSO1@NUSVM.BITNET (HC Eng) (09/10/90)

Please refer to the item in Vol 90 Issue 168 about JPL coming up with
a Motif binding.  (Please note that I am very new to Ada.)  In the OSF Motif
toolkit, widgets are treated as objects and callbacks are passed as subprogram
pointers.  I am dying to know how this could be implemented in Ada since Ada
does not have a subprogram type.
Presently I am coding my own "Motif" toolkit in Ada for the IBM RS/6000 and
the stumbling block is the lack of the subprogram type (see Ada LI65).  I am
solving the problem very unsatisfactorily by making the interface layer call
a procedure CALLBACK(W) where W is the widget being activated.  Inside CALLBACK
is a giant IF and ELSIF block to cater for every widget declared in my program.
It is unsatisfactory because everytime I add a new widget, I must amend this
block.
Therefore, if there is something that I don't know that would make the Motif
binding possible, I would be very happy to hear it immediately.

beser@tron.UUCP (Eric Beser) (09/17/90)

In article <9009060654.AA09349@ajpo.sei.cmu.edu>, GBODSO1@NUSVM.BITNET (HC Eng) writes:

> a Motif binding.  (Please note that I am very new to Ada.)  In the OSF Motif
> toolkit, widgets are treated as objects and callbacks are passed as subprogram
> pointers.  I am dying to know how this could be implemented in Ada since Ada
> does not have a subprogram type.
> Presently I am coding my own "Motif" toolkit in Ada for the IBM RS/6000 and
> the stumbling block is the lack of the subprogram type (see Ada LI65).  I am
> solving the problem very unsatisfactorily by making the interface layer call
> a procedure CALLBACK(W) where W is the widget being activated.  Inside CALLBACK
> is a giant IF and ELSIF block to cater for every widget declared in my program.

At the last SigAda meeting in California, the discussion of callbacks in
X bindings was interesting, and highly compiler independent. There are
other ways to do what you want to do instead of the IF .. ELSIF block.
If the compiler supports it, procedure'Address could point to the head
of the procedure. However that is not often guaranteed. Task types may
be used, and in fact are used in some implementations of XT toolkit. If
there is an "Ada way" of doing things, this would fit the bill.

There are compiler specific pragmas (i.e. Meridian's pragma
call_in_Place) that generate code acceptable to callback, so that
procedure'address will actually work the way you want it to. 

The only other way to pass procedures as arguments are as action
procedures in generics. Your generic instantiation can call a C-level
interface procedure which calls your callback procedure. What you would
do is pass the address of the callback procedure to this interface
procedure that uses the C indirect calling mechanism.

I am developing a large reusable library for use by the Air Force, and
would be curious to see your results.

Eric Beser
Westinghouse Aerospace Software Engineering
(301) - 765 - 1010