A user's guide for OpenXM C library.

How to use OpenXM C library?

In order to use libox.a, you need to include the following header files:

#include <ox_toolkit.h>

1. Types

1.1 CMO (Common Math Object)
The following structures are defined in ox_toolkit.h:

cmo
cmo_null
cmo_int32
cmo_datum
cmo_string
cmo_mathcap
cmo_list
cmo_monomial32
cmo_zz
cmo_qq
cmo_zero
cmo_dms_generic
cmo_ring_by_name
cmo_distributed_polynomial
cmo_indeterminate
cmo_error2

The cmo above is abstract base class; you never make an object of cmo
class.

1.2 OX objects
The following structures are defined in ox_toolkit.h:

ox
ox_command
ox_data

The ox above is abstract base class.

2. How to make CMObjects?

Use the following functions to generate an object.  It returns a
pointer to the object.  
new_cmo_null();
new_cmo_int32(int i);
new_cmo_string(char* s);
new_cmo_mathcap(cmo* ob);
new_cmo_list();
new_cmo_monomial32();
new_cmo_monomial32_size(int size);
new_cmo_zz();
new_cmo_zz_size(int size);
new_cmo_zz_set_si(int integer);
new_cmo_zz_noinit();
new_cmo_zero();
new_cmo_distributed_polynomial();
new_cmo_dms_generic();
new_cmo_ring_by_name(cmo* ob);
new_cmo_indeterminate(cmo* ob);
new_cmo_error2(cmo* ob);

4. High-level API

High-level API is prepared to help an implementation of OpenXM clients.

4.1 How to make connections to OpenXM servers?

In order to open a connection to an OpenXM server, you need to call
ox_start() or to call ox_start_insecure_nonreverse().

OXFILE *ox_start(char* host, char* prog1, char* prog2);
OXFILE *ox_start_insecure_nonreverse(char* host, short portControl, short portStream);

The ox_start() function invoke an OpenXM server on its local machine
and open a connection to the server with "reverse" mode.  The client
choose a port number of TCP/IP automatically.

The ox_start_insecure_nonreverse() function open a connection to an
OpenXM server run on a remote host and you need to provide port numbers.

4.2 How to close connections to OpenXM servers?

In order to close a connection to an OpenXM server, you need to call
ox_close() or to call ox_shutdown().

void ox_close(OXFILE *sv);
void ox_shutdown(OXFILE *sv);

4.3 How to command to OpenXM stack machines?

void  ox_push_cmd(OXFILE *sv, int sm_code);

ox_push_cmd() sends an operation code to an OpenXM stack machine.
See OpenXM/include/ox_toolkit_tags.h for a list of operation codes.

4.4 How to receive a CMO?

void  ox_push_cmo(OXFILE *sv, cmo *c);
cmo*  ox_pop_cmo(OXFILE *sv);
char* ox_popString(OXFILE *sv);


int ox_pops(OXFILE *sv, int num);


int ox_flush(OXFILE *sv);


void ox_reset(OXFILE *sv);


void ox_execute_string(OXFILE *sv, char* str);


int ox_cmo_rpc(OXFILE *sv, char *function, int argc, cmo *argv[]);

cmo_mathcap* ox_mathcap(OXFILE *sv);


5. Low-level API.

In this section, ``fd'' is an identifier of an OpenXM connection.

5.1 How to decide a byte order of integers?

int decideByteOrderServer(int fd, int order);

You need to call it when your OpenXM server is initialized.
This function always choose the network byte order 
as an expression for integers.

5.2 

int send_int32(int fd, int integer);
int receive_int32(int fd);

send_int32() writes 32bits integer to an OpenXM connection.
receive_int32() reads 32bits integer from an OpenXM connection.

5.3 

int  send_cmo(int fd, cmo* m);
cmo* receive_cmo(int fd);

send_cmo() writes an CMObject to an OpenXM connection.
receive_cmo() reads an CMObject from an OpenXM connection.

5.4

int next_serial();

next_serial() generates a serial number for ox message.

5.5

int  send_ox_tag(int fd, int tag);
int  receive_ox_tag(int fd);

send_ox_tag() writes a tag and an automatically generated serial number 
of an ox message to an OpenXM conection.
receive_ox_tag() reads a tag and a serial number of an ox message.

5.6 Sending OX messages.

int  send_ox(int fd, ox* m);
int  send_ox_cmo(int fd, cmo* m);
void send_ox_command(int fd, int sm_command);


6. Parser for OX expressions

We have a parser which generate an OX object or a CMO from a string
encoded OX/CMO expression.  In this section, we explain the parser.

6.1 Setting an option

int setflag_parse(int flag);

We set an option for the parser.  If we call
setflag_parse(PFLAG_ADDREV), then the parser admits external
expressios.

6.2 Initializing

int init_parser(char *str);

We give the parser an OX/CMO expression, that is, a Lisp style string.

6.3 Getting an object

cmo *parse();

The parser returns an OX/CMO object.  If the given string is illegal,
then the parser returns NULL.

8. Sample programs.

testclient

This is a small OpenXM client.  We send an OX message by inputting an
OX expression and display data messages gotten from a server.

bconv

A byte code encoder.  It shows a byte stream which corresponds to an
OX expression.

ox_Xsample

