General ILU Info
The Inter-Language Unification system (ILU) is a multi-language object interface
system. The object interfaces provided by ILU hide implementation distinctions
between different languages, between different address spaces, and between
operating system types.
A D V E R T I S E M E N T
ILU can be used to build multi-lingual object-oriented
libraries ("class libraries") with well-specified language-independent
interfaces. It can also be used to implement distributed systems. It can also be
used to define and document interfaces between the modules of non-distributed
programs.
The 2.0 release of ILU contains support for the programming languages ANSI C,
C++, Modula-3, Python, and Common Lisp. It has been installed on many flavors of
UNIX, including SPARC machines running SunOS 4.1.3 and Solaris 2, SGI MIPS
machines running IRIX 5.2, Intel 486 machines running Linux 1.1.78, DEC Alpha
machines with OSF/1, IBM RS/6000 machines running AIX, and HP machines running
HP/UX. It runs on Microsoft Windows 3.1, Windows 95, and Windows NT
environments. It supports both threaded and non-threaded operation. Since one of
the implementation goals of ILU is to maximize compatibility with existing open
standards, ILU provides support for use of the OMG CORBA IDL interface
description language, and can be thought of as a CORBA ORB system (though with
omissions from and extensions to the CORBA spec). As another result, ILU
includes a self-contained implementation of ONC RPC.
ILU is available free from ftp://ftp.parc.xerox.com/pub/ilu/ilu.html.
Calculator-impl.c
/* The first thing we need to do is to include the generated header
* file, which describes the types and methods used by the Tutorial
* interface
*/
#include <Tutorial.h>
/* We define a function which creates a new instance of a Calculator
* object.
*/
Tutorial_Calculator
Create_Tutorial_Calculator ()
{
CORBA_double *the_value = (CORBA_double *) malloc(sizeof(CORBA_double));
*the_value = 0.0; /* zero out our value */
/* The function "Tutorial_Calculator__CreateTrue" is automatically
* generated into the file "Tutorial-true.c" by the c-stubber.
* It takes three arguments, INSTANCE-HANDLE, SERVER, and
* USER-DATA-FIELD, and returns a new instance of Tutorial_Calculator.
* We don't care about what the INSTANCE-HANDLE and SERVER of Calculator
* instances are, so we'll pass ILU_NIL (which is another name
* for NULL) for the first two arguments, which will cause ILU
* to choose reasonable default values for us.
*/
return (Tutorial_Calculator__CreateTrue (ILU_NIL, ILU_NIL, the_value));
}
/* Now to implement the method, we simply take the true prototype
* and add whatever code is necessary to actually perform the operation.
*/
void
server_Tutorial_Calculator_SetValue (
Tutorial_Calculator self,
CORBA_double v,
CORBA_Environment *env)
{
/* The user data field is available as the field "void *instanceData" of
* any object instance, so we'll just set it to be "v".
*/
*((CORBA_double *) (self->instanceData)) = v;
}
CORBA_double
server_Tutorial_Calculator_GetValue (
Tutorial_Calculator self,
CORBA_Environment *env)
{
return (*((CORBA_double *) (self->instanceData)));
}
void
server_Tutorial_Calculator_Add (
Tutorial_Calculator self,
CORBA_double v,
CORBA_Environment *env)
{
*((CORBA_double *) (self->instanceData)) += v;
}
void
server_Tutorial_Calculator_Subtract (
Tutorial_Calculator self,
CORBA_double v,
CORBA_Environment *env)
{
*((CORBA_double *) (self->instanceData)) -= v;
}
void
server_Tutorial_Calculator_Multiply (
Tutorial_Calculator self,
CORBA_double v,
CORBA_Environment *env)
{
*((CORBA_double *) (self->instanceData)) *= v;
}
/* The Divide method gets a little trickier. We have to compare the
* value "v" to zero, which for floating point values actually means
* comparing it to some epsilon to see whether it is less than that
* epsilon, and then if it is "zero" we need to signal an error, by
* "raising" the "DivideByZero" exception. The way of raising exceptions
* in ILU C is rather clumsy, so we'll define a macro to make it look
* prettier. We also define some macros to make testing the value
* of "v" a bit prettier.
*/
#define ABS(x) (((x)<0)?(-(x)):(x))
#define SOME_EPSILON 0.000000001 /* zero, practically speaking */
#define RAISE(env,exception) { (env)->returnCode=(exception);\
(env)->_major=CORBA_USER_EXCEPTION; }
void
server_Tutorial_Calculator_Divide (
Tutorial_Calculator self,
CORBA_double v,
CORBA_Environment *env)
{
if (ABS(v) < SOME_EPSILON)
RAISE(env, ex_Tutorial_DivideByZero)
else
*((CORBA_double *) (self->instanceData)) /= v;
}
server2.c
/* server2.c */
#include <stdio.h> /* for stderr and NULL */
/* Include the Tutorial2 header file, to get all the defined
* types and function prototypes. Note that Tutorial2.h will
* #include Tutorial.h for us.
*/
#include <Tutorial2.h>
int main (int ac, char **av)
{
Tutorial2_Factory theFactory;
ilu_Server theServer;
int stop;
/* this program is to be called with one argument, the server ID
to use ("Tutorial.foo.something.com" or something like that.)
*/
if (ac < 2)
{
fprintf (stderr, "Usage: server SERVER-ID\n");
exit(1);
}
/* In any server program, we have to initialize each interface
that we're providing types from, by calling the InitializeServer
method on that interface. In this case, it's both the
Tutorial and Tutorial2 interfaces.
*/
Tutorial__InitializeServer();
Tutorial2__InitializeServer();
/* We make a "kernel server", using the server ID that was
passed in on the command line, the default "object table",
the default protocol for data pickling and message packets,
the default transport system for getting data back and forth,
and we make this kernel server the default server for the
program.
*/
theServer = ILU_C_InitializeServer(av[1],
/* the server ID */
NULL,
/* use std object table */
NULL,
/* use default protocol */
NULL,
/* use default transport */
NULL,
/* no passport */
ilu_TRUE
/* establish as default server */
);
/* Now that we have a server, we create an instance of the
Factory object type, with the instance handle of "Factory",
by calling the automatically generated procedure
"Tutorial_Factory__CreateTrue()".
*/
theFactory = Tutorial2_Factory__CreateTrue ("theFactory",
/* instance handle */
theServer,
/* server to use */
NULL
/* no user data */
);
/* Now make the Factory object "well-known" by publishing it.
PublishObject will return NULL if it can't publish the
object; otherwise it will return a pointer to a string,
which is the "publish proof".
*/
if (ILU_C_PublishObject(theFactory) == NULL)
{
fprintf (stderr, "Can't publish theFactory object.\n");
exit(1);
}
else
{
/* Now we print the string binding handle (the object's name plus
its location) of the new instance.
*/
printf ("Factory instance published.\n");
printf ("Its SBH is \"%s\".\n", ILU_C_SBHOfObject(theFactory));
/* ilu_RunMainLoop() is an event dispatching loop. It may
be exited by invoking ilu_ExitMainLoop() passing the same
int * RunMainLoop was invoked with. */
ilu_RunMainLoop (&stop);
}
}
simple3.c
/* simple3.c */
#include <stdio.h> /* for NULL */
#include <stdlib.h> /* for atof */
/* Include the header file for the Tutorial interface, so that our
* types and methods will be defined.
*/
#include <Tutorial.h>
/* We define a new routine, "Get_Tutorial_Calculator", which
* finds the tutorial factory, then creates a new Calculator
* object for us.
*/
static Tutorial_Calculator
Get_Tutorial_Calculator (char *sid, char *ih)
{
Tutorial_Factory f;
Tutorial_Calculator c;
ILU_C_ENVIRONMENT env;
/* We have to call ILU_C_LookupObject() with the object ID of
* the factory object, and the "type" of the object we're looking
* for, which is always available as "TYPENAME__MSType".
*/
f = ILU_C_LookupObject (sid, ih, Tutorial_Factory__MSType);
if (f == NULL)
{
fprintf (stderr, "Couldn't find Factory object <%s %s>.\n",
sid, ih);
return (NULL);
}
/* Now call the CreateCalculator method on the factory, and check
* the result...
*/
c = Tutorial_Factory_CreateCalculator (f, &env);
if (! ILU_C_SUCCESSFUL(&env))
{
fprintf (stderr, "Call to CreateCalculator failed with exception <%s>.\n",
ILU_C_EXCEPTION_ID(&env));
return (NULL);
}
/* And return the calculator */
return (c);
}
/* A simple program:
* 1) make an instance of Tutorial.Calculator
* 2) add all the arguments by invoking the Add method
* 3) print the resultant value.
*/
int main (int argc, char **argv)
{
Tutorial_Calculator c;
CORBA_double v;
char *sid, *ih;
char **arg;
ILU_C_ENVIRONMENT env;
if (argc < 4)
{
fprintf (stderr, "Usage: %s FACTORY-OBJECT-SID FACTORY-OBJECT-IH NUMBER [NUMBER...]\n",
argv[0]);
exit(1);
}
Tutorial__Initialize();
sid = *++argv;
ih = *++argv;
if ((c = Get_Tutorial_Calculator(sid, ih)) == NULL)
{
fprintf (stderr, "Couldn't create calculator!\n");
exit(1);
}
/* clear the calculator before using it */
Tutorial_Calculator_SetValue (c, 0.0, &env);
if (! ILU_C_SUCCESSFUL(&env))
{
fprintf (stderr, "SetValue signalled <%s>.\n",
ILU_C_EXCEPTION_ID(&env));
exit(1);
}
/* now loop over the arguments, adding each in turn */
for (arg = ++argv; *arg != NULL; arg++)
{
v = atof (*arg);
Tutorial_Calculator_Add (c, v, &env);
if (! ILU_C_SUCCESSFUL(&env))
{
fprintf (stderr, "Add signalled <%s>.\n",
ILU_C_EXCEPTION_ID(&env));
exit(1);
}
}
/* and print the result */
v = Tutorial_Calculator_GetValue (c, &env);
if (! ILU_C_SUCCESSFUL(&env))
{
fprintf (stderr, "GetValue signalled <%s>.\n",
ILU_C_EXCEPTION_ID(&env));
exit(1);
}
else
printf ("the sum is %.5e\n", v);
exit (0);
}
simple4.c
/* simple4.c */
#include <stdio.h> /* for NULL */
#include <stdlib.h> /* for atof */
/* Include the header file for the Tutorial interface, so that our
* types and methods will be defined.
*/
#include <Tutorial2.h>
/* We define a new routine, "Get_Tutorial_Calculator", which
* finds the tutorial factory, then creates a new Calculator
* object for us.
*/
static Tutorial_Calculator
Get_Tutorial_Calculator (char *sid, char *ih)
{
Tutorial_Factory f;
Tutorial2_TapeCalculator c;
ILU_C_ENVIRONMENT env;
/* We have to call ILU_C_LookupObject() with the object ID of
* the factory object, and the "type" of the object we're looking
* for, which is always available as "TYPENAME__MSType".
*/
f = ILU_C_LookupObject (sid, ih, Tutorial2_Factory__MSType);
if (f == NULL)
{
fprintf (stderr, "Couldn't find Factory object <%s>.\n",
factoryObjectID);
return (NULL);
}
/* Now call the CreateCalculator method on the factory, and check
* the result...
*/
c = Tutorial2_Factory_CreateTapeCalculator (f, &env);
if (! ILU_C_SUCCESSFUL(&env))
{
fprintf (stderr, "Call to CreateCalculator failed with exception <%s>.\n",
ILU_C_EXCEPTION_ID(&env));
return (NULL);
}
else
printf ("Got calculator object \"%s\" of type \"%s\".\n",
ILU_C_SBHOfObject(c), ILU_C_ClassName(c));
/* And return the calculator */
return ((Tutorial_Calculator) c);
}
/* A routine to print an operation from a Tutorial2.RegisterTape */
static char *NameOfOp (Tutorial2_OpType ot)
{
static struct _ops { char *name; Tutorial2_OpType ot; } ops[] = {
{ "Add", Tutorial2_Add },
{ "Subtract", Tutorial2_Subtract },
{ "Divide", Tutorial2_Divide },
{ "Multiply", Tutorial2_Multiply },
{ "SetValue", Tutorial2_SetValue } };
int opslen = sizeof(ops)/sizeof(struct _ops);
int i;
char *result;
for (i = 0; i < opslen; i++)
if (ops[i].ot == ot)
return (ops[i].name);
return ILU_NIL;
}
static void PrintOperation (Tutorial2_Operation *op, void *userArg)
{
char *opname = NameOfOp (op->op);
if (opname == ILU_NIL)
printf ("** Unrecognized operation, op = %d!\n", op->op);
else
printf (" %s(%.5f) => %.5f\n", opname, op->value, op->accumulator);
}
int main (int argc, char **argv)
{
Tutorial_Calculator c;
ILU_C_ENVIRONMENT e;
char *line, *sid, *ih;
char buf[1000];
CORBA_double val;
CORBA_double newval = 0.0;
if (argc < 3)
{
fprintf (stderr, "Usage: %s FACTORY-OBJECT-SID FACTORY-OBJECT-IH\n",
argv[0]);
exit(1);
}
Tutorial2__Initialize();
sid = *++argv;
ih = *++argv;
if ((c = Get_Tutorial_Calculator(sid, ih)) == NULL)
{
fprintf (stderr, "Couldn't create calculator!\n");
exit(1);
}
Tutorial_Calculator_SetValue(c, 0.0, &e);
do {
printf ("%.5f\n> ", newval);
fflush(stdout);
*buf = 'q';
line = gets(buf);
switch (buf[0]) {
case '+':
val = atof(buf+1);
if (!((Tutorial_Calculator_Add(c, val, &e), ILU_C_SUCCESSFUL(&e))
&& (newval = Tutorial_Calculator_GetValue(c, &e),
ILU_C_SUCCESSFUL(&e))))
{
fprintf (stderr, "Operation <%s> signals error <%s>.\n",
buf, ILU_C_EXCEPTION_ID(&e));
}
break;
case '-':
val = atof(buf+1);
if (!((Tutorial_Calculator_Subtract(c, val, &e), ILU_C_SUCCESSFUL(&e))
&& (newval = Tutorial_Calculator_GetValue(c, &e),
ILU_C_SUCCESSFUL(&e))))
{
fprintf (stderr, "Operation <%s> signals error <%s>.\n",
buf, ILU_C_EXCEPTION_ID(&e));
}
break;
case '*':
val = atof(buf+1);
if (!((Tutorial_Calculator_Multiply(c, val, &e), ILU_C_SUCCESSFUL(&e))
&& (newval = Tutorial_Calculator_GetValue(c, &e),
ILU_C_SUCCESSFUL(&e))))
{
fprintf (stderr, "Operation <%s> signals error <%s>.\n",
buf, ILU_C_EXCEPTION_ID(&e));
}
break;
case '/':
val = atof(buf+1);
if (!((Tutorial_Calculator_Divide(c, val, &e), ILU_C_SUCCESSFUL(&e))
&& (newval = Tutorial_Calculator_GetValue(c, &e),
ILU_C_SUCCESSFUL(&e))))
{
fprintf (stderr, "Operation <%s> signals error <%s>.\n",
buf, ILU_C_EXCEPTION_ID(&e));
}
break;
case 'c':
if (!(Tutorial_Calculator_SetValue(c, 0.0, &e), ILU_C_SUCCESSFUL(&e)))
{
fprintf (stderr, "Operation <%s> signals error <%s>.\n",
buf, ILU_C_EXCEPTION_ID(&e));
}
newval = 0.0;
break;
case 'q':
line = NULL;
break;
case 't':
/* get the register tape and print it out */
{
Tutorial2_TapeCalculator tc = (Tutorial2_TapeCalculator) c;
Tutorial2_RegisterTape *rt;
rt = Tutorial2_TapeCalculator_GetTape (c, &e);
if (! ILU_C_SUCCESSFUL(&e))
{
fprintf (stderr, "Operation <%s> signals error <%s>.\n",
buf, ILU_C_EXCEPTION_ID(&e));
}
else
{
Tutorial2_RegisterTape_Every (rt, PrintOperation, ILU_NIL);
Tutorial2_RegisterTape__Free (rt);
}
}
break;
default:
fprintf (stderr, "Invalid operation <%s>\n", buf);
fprintf (stderr, "Valid ops are +, -, *, /, tape, clear, quit\n");
};
} while (line != NULL);
return (0);
}
|