Section 16.3 - Ada Bindings
The previous material should help you develop a "binding" (interface)
between software components, where one component is written in Ada
and another component is written in another language.
Naturally, it's easier if someone else or a tool
does the job for you.
Before you can evaluate what someone else has done, you need to
understand the major types of bindings between an Ada program and another
program.
These types are called "direct" and "abstract":
- A "direct" (also called "thin") binding
provides a one-to-one mapping to Ada
of whatever interface the foreign program provides.
Direct bindings are easy to understand if you understand the foreign
program's interface, and direct bindings for Ada are easy to create.
In particular, you can use the existing documentation, which is a very
important advantage for complex interfaces (like windowing systems).
Unfortunately, direct bindings are often a little clumsy to work with and
often don't provide the protection usually provided by Ada interfaces.
Thus, it's often nicer to work with "abstract" bindings.
- An "abstract" (also called "thick") binding provide a more
abstract, Ada-like view of the foreign program.
Unfortunately, while "abstract" bindings are nicer to work with, it takes
work and time to create the right abstractions.
Thus abstract bindings are harder to create.
Here are some other things you need to know about bindings:
- "Direct" and "abstract" are really extremes on a continuum;
there are bindings that are "mostly direct" but have been abstracted a
little, and there are "abstract" bindings that have some direct
one-to-one mappings.
- The terms "thick" and "thin" have other
related meanings (involving how a standard is written),
which is why I've used the terms "direct" and "abstract" here.
Now that you understand these basic issues, you can go hunt for
ways to make this interfacing job easier.
The Ada Information Clearinghouse maintains a
list
of source (including Ada bindings) and a
document
listing existing Ada bindings for other products and standards.
Their list is incomplete, but it's a good starting point, especially
for common products or standards such as POSIX, X windows, Microsoft Windows,
or SQL databases.
HBAP also
maintains a list of existing Ada bindings.
If you're interfacing with a commercial product, ask the vendor
to supply you with an Ada interface.
You could also post a request to
comp.lang.ada
if you can't find what you're looking for.
Here are some commonly-requested bindings:
-
Win32 API.
This is an interface for Microsoft Windows NT, Microsoft Windows 95, and OS/2;
a subset of Win32 works under Microsoft Windows 3.1.
-
X11Ada
is an Ada 95 binding to Motif and X11 developed by Intermetrics.
See the general listings given earlier for other X-related bindings and
information.
-
Relational databases generally use SQL as their query language.
Although you can embed SQL queries in Ada as you can with other languages,
a better approach is a specialized interface language that lets you
really take advantage of both languages.
There's an ISO standard (ISO/IEC 12227) of such a language, named SAMeDL.
The
SAMeDL specification,
as well as a
rationale for SAMeDL
and
notes on applications.
-
An Ada binding to CORBA's IDL has been developed, enabling you to request
and receive requests from other programs (written in arbitrary languages
and located on arbitrary machines) via CORBA.
You can learn more from the
Ada
bindings working group, and you can download
the
specification
from the Object Management Group (OMG).
There are also tools to automatically generate direct (thin)
Ada bindings to C libraries.
Here are three tools (there are others as well):
- C2Ada translates C into Ada; it can handle complete programs, but its
primary use has been to
translate C header files into Ada to create Ada bindings.
C2Ada was created as a major upgrade to Cbind (below).
C2Ada is easy to use to create simple bindings,
but it also provides many "hooks" (in the form of a
configuration file) to support control on the translation process.
C2Ada is available via
Intermetrics.
- Cbind translates C declarations and C preprocessor definitions
into Ada package(s).
Its strength is in ease-of-use; just type:
"cbind file.h > file.ads".
Cbind is available via
Rational
and
Walnut Creek.
- CtoAda
translates declarations from C to Ada.
CtoAda's strength is that it provides many "hooks" to allow a programmer
to control the translation.
This gives more control at the expense
of requiring more work by the programmer.
Quiz:
If you want to quickly create a binding to another language
and don't mind that it might be a little clumsy to use,
what kind of binding would you create?
- Direct ("thin") binding
- Abstract ("thick") binding
You may also:
David A. Wheeler (dwheeler@dwheeler.com)
The master copy of this file is at
"http://www.adahome.com/Tutorials/Lovelace/s16s3.htm".